| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121 |
- require 'bundler'
- require 'erb'
- require 'yaml'
- require 'json'
- require 'terminal-table'
- BOT_ENV = ENV.fetch('BOT_ENV') { 'development' }
- Bundler.require(:default, BOT_ENV)
- require 'active_record'
- # Constants: such as roles and channel ids
- HAP_ROTOM = "https://static.pokemonpets.com/images/monsters-images-800-800/479-Rotom.png"
- # ---
- Dotenv.load if BOT_ENV != 'production'
- db_yml = File.open('config/database.yml') do |erb|
- ERB.new(erb.read).result
- end
- db_config = YAML.safe_load(db_yml)[BOT_ENV]
- ActiveRecord::Base.logger = ActiveSupport::Logger.new(STDOUT)
- ActiveRecord::Base.establish_connection(
- adapter: 'postgresql',
- host: db_config.fetch('host') { 'localhost' },
- database: db_config['database'],
- user: db_config['user'],
- password: db_config['password']
- )
- Dir['app/**/*.rb'].each { |f| require File.join(File.expand_path(__dir__), f) }
- token = ENV['DISCORD_BOT_TOKEN']
- bot = Discordrb::Bot.new(token: token)
- # Methods: define basic methods here
- # ---
- # Commands: structure basic bot commands here
- hello = Command.new(:hello) do |event|
- user = event.author.nickname || event.author.name
- greetings = [
- "Hi there, #{user}",
- "Greetings #{user}, you lovable bum",
- "Alola, #{user}",
- "Hello, #{user}! The Guildmasters have been waiting",
- "#{user} would like to battle!"
- ]
- Embed.new(
- description: greetings.sample,
- color: event.author.color.combined,
- thumbnail: {
- url: HAP_ROTOM
- }
- )
- end
- # ---
- commands = [
- hello
- ]
- # This will trigger on every message sent in discord
- bot.message do |event|
- content = event.message.content
- if (match = /^pkmn-(\w+)/.match(content))
- command = match[1]
- if cmd = commands.detect { |c| c.name == command.to_sym }
- reply = cmd.call(content, event)
- if reply.is_a? Embed
- event.send_embed("", reply)
- elsif reply
- event.respond(reply)
- else
- event.respond("Something went wrong!")
- end
- end
- end
- end
- # This will trigger on every reaction is added in discord
- bot.reaction_add do |event|
- end
- # This will trigger on every reaction is removed in discord
- bot.reaction_remove do |event|
- end
- # This will trigger when a member is updated
- bot.member_update do |event|
- end
- # This will trigger when anyone joins the server
- bot.member_join do |event|
- end
- # This will trigger when anyone leaves the server
- bot.member_leave do |event|
- end
- # This will trigger when anyone is banned from the server
- bot.user_ban do |event|
- end
- # This will trigger when anyone is un-banned from the server
- bot.user_unban do |event|
- end
- bot.run
|