File tree Expand file tree Collapse file tree 5 files changed +57
-2
lines changed
Expand file tree Collapse file tree 5 files changed +57
-2
lines changed Original file line number Diff line number Diff line change @@ -4,8 +4,8 @@ source "https://rubygems.org"
44gem "rails" , "~> 8.0.2"
55# The modern asset pipeline for Rails [https://github.com/rails/propshaft]
66
7- gem ' discordrb'
8- gem ' dotenv-rails'
7+ gem " discordrb"
8+ gem " dotenv-rails"
99
1010gem "propshaft"
1111# Use postgresql as the database for Active Record
Original file line number Diff line number Diff line change 1+ module Discord
2+ # This class handles running and setting up the bot.
3+ class Bot
4+ class << self
5+ attr_accessor :configuration
6+
7+ def configure
8+ self . configuration ||= Discord ::Configuration . new
9+ if block_given?
10+ yield ( configuration )
11+ end
12+ new ( configuration )
13+ end
14+ end
15+
16+ attr_accessor :bot
17+
18+ delegate :send_message , to : :bot
19+
20+ def initialize ( configuration )
21+ @bot = Discordrb ::Bot . new ( token : configuration . token )
22+ @bot . ready do
23+ Rails . logger . info "✅ Bot is online and connected to Discord!"
24+ puts "✅ Bot is online and connected to Discord!"
25+ end
26+ end
27+ end
28+ end
Original file line number Diff line number Diff line change 1+ module Discord
2+ # This class encapsulates the configuration used by the discord bot.
3+ class Configuration
4+ attr_accessor :token , :log_mode
5+
6+ def initialize
7+ @token = nil
8+ # @log_mode = :normal
9+ end
10+ end
11+ end
Original file line number Diff line number Diff line change 1+ DISCORD_BOT_TOKEN=<insert bot token here>
Original file line number Diff line number Diff line change 1+ namespace :discord do
2+ desc "Configure and run the discord bot"
3+ task start_bot : :environment do
4+ bot . run
5+ end
6+ end
7+
8+ def bot
9+ @bot ||= begin
10+ bot_wrapper = Discord ::Bot . configure do |config |
11+ config . token = ENV . fetch ( "DISCORD_BOT_TOKEN" )
12+ end
13+ bot_wrapper . bot
14+ end
15+ end
You can’t perform that action at this time.
0 commit comments