Skip to content

Commit

Permalink
Switch to YAML files.
Browse files Browse the repository at this point in the history
  • Loading branch information
Droid00000 committed Nov 14, 2024
1 parent f0bc128 commit 25673d1
Show file tree
Hide file tree
Showing 14 changed files with 30 additions and 46 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ travis.yml
.DS_Store?

# Credentials
config.yaml
config.yml
File renamed without changes.
2 changes: 0 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ gem 'rufus-scheduler'

gem 'tzinfo-data'

gem 'require_all'

gem 'sequel'

gem 'pg'
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
27 changes: 8 additions & 19 deletions core.rb
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -39,6 +30,4 @@
bot.include! ManualPinArchiver
bot.include! ModerationCommands

at_exit { bot.stop }

bot.run
File renamed without changes.
2 changes: 1 addition & 1 deletion src/frost/admin/status.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions src/frost/admin/utilities.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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}```")
Expand Down
2 changes: 1 addition & 1 deletion src/frost/affections/punch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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|
Expand Down
3 changes: 1 addition & 2 deletions src/frost/commands/commands.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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]) }

Expand Down
20 changes: 10 additions & 10 deletions src/frost/data/constants.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
Expand Down
5 changes: 2 additions & 3 deletions src/frost/data/functions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

require 'json'
require 'time'
require 'YAML-rb'
require 'net/http'
require 'discordrb'
require 'data/embeds'
Expand Down Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions src/frost/data/schema.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/frost/snow/steal.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 25673d1

Please sign in to comment.