bot.rb 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. content = event.message.content
  34. if content == '!hello'
  35. event.respond("Hello there #{event.author.name}")
  36. end
  37. end
  38. # This will trigger on every reaction is added in discord
  39. bot.reaction_add do |event|
  40. end
  41. # This will trigger on every reaction is removed in discord
  42. bot.reaction_remove do |event|
  43. end
  44. # This will trigger when a member is updated
  45. bot.member_update do |event|
  46. end
  47. # This will trigger when anyone joins the server
  48. bot.member_join do |event|
  49. end
  50. # This will trigger when anyone leaves the server
  51. bot.member_leave do |event|
  52. end
  53. # This will trigger when anyone is banned from the server
  54. bot.user_ban do |event|
  55. end
  56. # This will trigger when anyone is un-banned from the server
  57. bot.user_unban do |event|
  58. end
  59. bot.run