73 lines
2.1 KiB
Ruby
73 lines
2.1 KiB
Ruby
# FrugalityBot
|
|
# Copyright (C) 2026 Eri (csxkdv/nxkdv) nxkdv@thenight.club
|
|
#
|
|
# This program is free software: you can redistribute it and/or modify
|
|
# it under the terms of the GNU General Public License as published by
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
# (at your option) any later version.
|
|
#
|
|
# This program is distributed in the hope that it will be useful,
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
# GNU General Public License for more details.
|
|
#
|
|
# You should have received a copy of the GNU General Public License
|
|
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
require 'discordrb'
|
|
require_relative 'database'
|
|
|
|
class FrugalityBot
|
|
def initialize
|
|
@bot = Discordrb::Bot.new(
|
|
token: ENV['BOT_TOKEN'],
|
|
intents: [:servers, :server_messages]
|
|
)
|
|
|
|
@db = Database.new
|
|
|
|
load_commands
|
|
setup_events
|
|
end
|
|
|
|
def run
|
|
@bot.run
|
|
end
|
|
|
|
private
|
|
|
|
def load_commands
|
|
# 1. We look for all .rb files in "src/commands/..."
|
|
comm_files = Dir[File.join(__dir__, 'commands', '*.rb')]
|
|
|
|
comm_files.each do |file|
|
|
require file # We import the file
|
|
|
|
# We convert filename to module name
|
|
# This mean that 'echo.rb' turns into 'Echo'
|
|
# 'server_info' would turn into 'ServerInfo'
|
|
filename = File.basename(file, '.rb')
|
|
module_name = filename.split('_').map(&:capitalize).join
|
|
|
|
begin
|
|
comm_module = Commands.const_get(module_name)
|
|
|
|
comm_module.register(@bot, @db)
|
|
puts "Loaded command: #{module_name}"
|
|
sleep(1.5)
|
|
rescue NameError => e
|
|
puts "Could not load #{filename}: Module 'Commands::#{module_name}' was not found."
|
|
rescue StandardError => e
|
|
puts "Error loading: #{filename}: #{e.message}"
|
|
end
|
|
end
|
|
puts "Commands loaded."
|
|
end
|
|
|
|
def setup_events
|
|
@bot.ready do
|
|
puts "#{@bot.profile.username} is online"
|
|
@bot.update_status("online", "Checking the economy...", nil, 0, false, 0)
|
|
end
|
|
end
|
|
end |