bot.rb 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. require 'bundler'
  2. require 'erb'
  3. require 'yaml'
  4. require 'json'
  5. require 'terminal-table'
  6. BOT_ENV = ENV.fetch('BOT_ENV') { 'development' }
  7. Bundler.require(:default, BOT_ENV)
  8. require 'active_record'
  9. # Constants: such as roles and channel ids
  10. # ---
  11. Dotenv.load if BOT_ENV != 'production'
  12. db_yml = File.open('config/database.yml') do |erb|
  13. ERB.new(erb.read).result
  14. end
  15. db_config = YAML.safe_load(db_yml)[BOT_ENV]
  16. ActiveRecord::Base.logger = ActiveSupport::Logger.new(STDOUT)
  17. ActiveRecord::Base.establish_connection(
  18. adapter: 'postgresql',
  19. host: db_config.fetch('host') { 'localhost' },
  20. database: db_config['database'],
  21. user: db_config['user'],
  22. password: db_config['password']
  23. )
  24. Dir['app/**/*.rb'].each { |f| require File.join(File.expand_path(__dir__), f) }
  25. token = ENV['DISCORD_BOT_TOKEN']
  26. bot = Discordrb::Bot.new(token: token)
  27. # Methods: define basic methods here
  28. # ---
  29. # Commands: structure basic bot commands here
  30. # ---
  31. # This will trigger on every message sent in discord
  32. bot.message do |event|
  33. end
  34. # This will trigger on every reaction is added in discord
  35. bot.reaction_add do |event|
  36. end
  37. # This will trigger on every reaction is removed in discord
  38. bot.reaction_remove do |event|
  39. end
  40. # This will trigger when a member is updated
  41. bot.member_update do |event|
  42. end
  43. # This will trigger when anyone joins the server
  44. bot.member_join do |event|
  45. end
  46. # This will trigger when anyone leaves the server
  47. bot.member_leave do |event|
  48. end
  49. # This will trigger when anyone is banned from the server
  50. bot.user_ban do |event|
  51. end
  52. # This will trigger when anyone is un-banned from the server
  53. bot.user_unban do |event|
  54. end
  55. bot.run