Skip to content

Instantly share code, notes, and snippets.

@swarley
Created January 10, 2021 06:06
Show Gist options
  • Save swarley/e7fcc68672f37083c00ecba28c47f6cc to your computer and use it in GitHub Desktop.
Save swarley/e7fcc68672f37083c00ecba28c47f6cc to your computer and use it in GitHub Desktop.
module TestContainer
extend Discordrb::EventContainer
message contains: /i'm (.+)/ do |event|
event.respond("Hi, #{event.content.match(/i'm (.+)\b/)[1]}. I'm Dad!")
end
end
module CommandContainer
extend Discordrb::Commands::CommandContainer
command :ping do |event|
'Pong!'
end
command :'8ball' do |event|
['yes', 'no', 'maybe', 'unsure', 'ask again later', 'unlikely'].sample
end
end
require 'discordrb'
load 'containers.rb'
CONTAINERS = [TestContainer, CommandContainer]
def load_containers(bot)
# Remove all handlers
bot.clear!
CONTAINERS.map(&:clear!)
# Reload the file
load 'containers.rb'
# Register handlers onto the bot
CONTAINERS.each do |container|
Discordrb::LOGGER.info("Loading #{container.name}")
container.clear!
bot.include!(container)
end
end
bot = Discordrb::Commands::CommandBot.new(token: ENV['INOSUKE_TOKEN'], prefix: '.')
# Load initial containers
CONTAINERS.each {|container| bot.include!(container) }
bot.command(:reload) do |event|
load_containers(event.bot)
end
bot.run
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment