From 25673d1ab000f4cc58b668146158c47ce9aea685 Mon Sep 17 00:00:00 2001 From: DroidDevelopment Date: Thu, 14 Nov 2024 16:10:28 -0500 Subject: [PATCH] Switch to YAML files. --- .gitignore | 2 +- .rubocop.yaml => .rubocop.yml | 0 Gemfile | 2 -- README.md | 2 +- core.rb | 27 ++++++++------------------- example.yaml => example.yml | 0 src/frost/admin/status.rb | 2 +- src/frost/admin/utilities.rb | 6 +++--- src/frost/affections/punch.rb | 2 +- src/frost/commands/commands.rb | 3 +-- src/frost/data/constants.rb | 20 ++++++++++---------- src/frost/data/functions.rb | 5 ++--- src/frost/data/schema.rb | 3 +-- src/frost/snow/steal.rb | 2 +- 14 files changed, 30 insertions(+), 46 deletions(-) rename .rubocop.yaml => .rubocop.yml (100%) rename example.yaml => example.yml (100%) diff --git a/.gitignore b/.gitignore index b470439..37d385f 100644 --- a/.gitignore +++ b/.gitignore @@ -7,4 +7,4 @@ travis.yml .DS_Store? # Credentials -config.yaml \ No newline at end of file +config.yml \ No newline at end of file diff --git a/.rubocop.yaml b/.rubocop.yml similarity index 100% rename from .rubocop.yaml rename to .rubocop.yml diff --git a/Gemfile b/Gemfile index baec30e..4c40159 100644 --- a/Gemfile +++ b/Gemfile @@ -10,8 +10,6 @@ gem 'rufus-scheduler' gem 'tzinfo-data' -gem 'require_all' - gem 'sequel' gem 'pg' diff --git a/README.md b/README.md index 0c5c944..0a2f210 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,7 @@ CREATE DATABASE frigid OWNER frost; 4. **Fill in configuration variables** -Change the name of the `example.yaml` file to `config.yaml` and fill in all the variables. +Change the name of the `example.yml` file to `config.yml` and fill in all the variables. ```yaml # Discord related credentials. diff --git a/core.rb b/core.rb index e632f39..05e14e3 100644 --- a/core.rb +++ b/core.rb @@ -1,26 +1,17 @@ # frozen_string_literal: true -$LOAD_PATH.unshift File.join(File.expand_path(__dir__), 'src/frost') - require 'discordrb' -require 'require_all' - -require_all 'src/frost/tags' -require_all 'src/frost/pins' -require_all 'src/frost/data' -require_all 'src/frost/snow' -require_all 'src/frost/voice' -require_all 'src/frost/admin' -require_all 'src/frost/emojis' -require_all 'src/frost/events' -require_all 'src/frost/boosters' -require_all 'src/frost/affections' -require_all 'src/frost/moderation' - -bot = Discordrb::Bot.new(token: YAML['Discord']['TOKEN'], intents: 32_905, log_mode: :normal) + +$LOAD_PATH.unshift './src/frost' + +Dir['./src/frost/**/*.rb'].each { |file| require file if !file.include?('commands.rb') } + +bot = Discordrb::Bot.new(token: CONFIG['Discord']['TOKEN'], intents: 32_905, log_mode: :normal) bot.ready { bot.custom_status(ACTIVITY[1], ACTIVITY[2]) } +at_exit { bot.stop } + bot.include! EventRoles bot.include! TagCommands bot.include! BoosterPerks @@ -39,6 +30,4 @@ bot.include! ManualPinArchiver bot.include! ModerationCommands -at_exit { bot.stop } - bot.run diff --git a/example.yaml b/example.yml similarity index 100% rename from example.yaml rename to example.yml diff --git a/src/frost/admin/status.rb b/src/frost/admin/status.rb index 7c7994b..17b0c07 100644 --- a/src/frost/admin/status.rb +++ b/src/frost/admin/status.rb @@ -10,7 +10,7 @@ def update_status(data) return end - unless YAML['Discord']['CONTRIBUTORS'].include?(data.user.id) + unless CONFIG['Discord']['CONTRIBUTORS'].include?(data.user.id) data.edit_response(content: RESPONSE[12]) return end diff --git a/src/frost/admin/utilities.rb b/src/frost/admin/utilities.rb index 895e0c0..20783a0 100644 --- a/src/frost/admin/utilities.rb +++ b/src/frost/admin/utilities.rb @@ -6,7 +6,7 @@ # Turns the bot off and kills the Gateway connection. def shutdown_command(data) - if data.user.id == YAML['Discord']['OWNER']&.to_i + if data.user.id == CONFIG['Discord']['OWNER']&.to_i data.edit_response(content: RESPONSE[19]) data.bot.stop else @@ -16,7 +16,7 @@ def shutdown_command(data) # Restarts the Gateway connection. def restart_command(data) - if data.user.id == YAML['Discord']['OWNER']&.to_i + if data.user.id == CONFIG['Discord']['OWNER']&.to_i data.edit_response(content: RESPONSE[67]) exec('bundle exec ruby --yjit core.rb') else @@ -26,7 +26,7 @@ def restart_command(data) # Allows us to execute arbitrary code on the current proccess. def eval_command(data) - if data.user.id == YAML['Discord']['OWNER']&.to_i + if data.user.id == CONFIG['Discord']['OWNER']&.to_i begin result = eval data.options['code'] data.edit_response(content: "**Success:** ```#{data.options['code']}``` **Result:** ```#{result}```") diff --git a/src/frost/affections/punch.rb b/src/frost/affections/punch.rb index 9ae5816..e53a94f 100644 --- a/src/frost/affections/punch.rb +++ b/src/frost/affections/punch.rb @@ -8,7 +8,7 @@ module PunchAffection application_command(:punch) do |event| event.defer(ephemeral: false) - return unless YAML['Discord']['COMMANDS'].include?(event.user.id) + return unless CONFIG['Discord']['COMMANDS'].include?(event.user.id) event.edit_response(content: "<@#{event.options['target']}>") do |builder| builder.add_embed do |embed| diff --git a/src/frost/commands/commands.rb b/src/frost/commands/commands.rb index caaf613..ce1ec5a 100644 --- a/src/frost/commands/commands.rb +++ b/src/frost/commands/commands.rb @@ -4,11 +4,10 @@ $LOAD_PATH.unshift File.join(File.expand_path(__dir__), 'src/frost') -require 'YAML-rb' require 'discordrb' require 'data/constants' -bot = Discordrb::Bot.new(token: YAML['Discord']['TOKEN'], intents: 0) +bot = Discordrb::Bot.new(token: CONFIG['Discord']['TOKEN'], intents: 0) bot.ready { bot.set_status(ACTIVITY[3], ACTIVITY[4]) } diff --git a/src/frost/data/constants.rb b/src/frost/data/constants.rb index e5c9a33..9d8dfd9 100644 --- a/src/frost/data/constants.rb +++ b/src/frost/data/constants.rb @@ -135,14 +135,14 @@ # Emojis for phases of the moon used by the moon commands. MOON = { - 'New Moon' => 🌑, - 'Waxing Crescent' => 🌒, - 'First Quarter' => 🌓, - 'Waxing Gibbous' => 🌔, - 'Full Moon' => 🌕, - 'Waning Gibbous' => 🌖, - 'Last Quarter' => 🌗, - 'Waning Crescent' => 🌘 + 'New Moon' => '🌑', + 'Waxing Crescent' => '🌒', + 'First Quarter' => '🌓', + 'Waxing Gibbous' => '🌔', + 'Full Moon' => '🌕', + 'Waning Gibbous' => '🌖', + 'Last Quarter' => '🌗', + 'Waning Crescent' => '🌘' }.freeze # UI components including color values; primarily used by the bot when sending embeds. @@ -165,10 +165,10 @@ }.freeze # The YAML configuration file used by the bot. -YAML = YAML.load_file(File.join(File.expand_path('../../..', __dir__), 'config.yaml')) +CONFIG = YAML.load_file(File.join(File.expand_path('../../..', __dir__), 'config.yml')) # The Lavalink wrapper used to convert URL's and queries into track metadata. -LAVALINK = Calliope::Request.new(YAML['Lavalink']['ADDRESS'], YAML['Lavalink']['PASSWORD']) +LAVALINK = Calliope::Request.new(CONFIG['Lavalink']['ADDRESS'], CONFIG['Lavalink']['PASSWORD']) # A series of regular expressions utilized by the bot. # REGEX[4] is used to ensure a name doesn't contain any bad words. diff --git a/src/frost/data/functions.rb b/src/frost/data/functions.rb index d33fbc8..6071e57 100644 --- a/src/frost/data/functions.rb +++ b/src/frost/data/functions.rb @@ -2,7 +2,6 @@ require 'json' require 'time' -require 'YAML-rb' require 'net/http' require 'discordrb' require 'data/embeds' @@ -48,14 +47,14 @@ def hit_or_miss? # @param user [Integer, String] An ID that uniquely identifies a user. # @return [Boolean] Returns true if the user is boosting the server; false otherwise. def get_booster_status(server, user) - Discordrb::API::Server.resolve_booster(YAML['Discord']['TOKEN'], server, user) + Discordrb::API::Server.resolve_booster(CONFIG['Discord']['TOKEN'], server, user) end # Deletes a role in a guild. # @param server [Integer, String] An ID that uniquely identifies a guild. # @param role [Integer, String] An ID that uniquely identifies a role. def delete_guild_role(server, role) - Discordrb::API::Server.delete_role(YAML['Discord']['TOKEN'], server, role, REASON[6]) + Discordrb::API::Server.delete_role(CONFIG['Discord']['TOKEN'], server, role, REASON[6]) rescue Dsicordrb::Errors::NotFound true end diff --git a/src/frost/data/schema.rb b/src/frost/data/schema.rb index 974d5f5..58338a1 100644 --- a/src/frost/data/schema.rb +++ b/src/frost/data/schema.rb @@ -1,10 +1,9 @@ # frozen_string_literal: true require 'sequel' -require 'YAML-rb' require 'data/constants' -POSTGRES = Sequel.connect(YAML['Postgres']['URL'], max_connections: 7) +POSTGRES = Sequel.connect(CONFIG['Postgres']['URL'], max_connections: 7) POSTGRES.create_table?(:Event_Settings) do primary_key :id diff --git a/src/frost/snow/steal.rb b/src/frost/snow/steal.rb index b2cedec..7edcb0b 100644 --- a/src/frost/snow/steal.rb +++ b/src/frost/snow/steal.rb @@ -18,7 +18,7 @@ def steal_snowball(data) snowball_records(user: data.user.id, type: :add_user) unless snowball_records(user: data.user.id, type: :check_user) - unless YAML['Discord']['CONTRIBUTORS'].include?(data.user.id) + unless CONFIG['Discord']['CONTRIBUTORS'].include?(data.user.id) data.edit_response(content: RESPONSE[12]) return end