Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ module ARConfig
DatabaseTasks.db_dir = File.join(__dir__, *%w[lib qbot db])
DatabaseTasks.root = __dir__

DatabaseTasks.migrations_paths = \
DatabaseTasks.migrations_paths =
File.join(__dir__, *%w[lib qbot db migrate])

DatabaseTasks.database_configuration = { development: db_config }
Expand Down
16 changes: 6 additions & 10 deletions lib/qbot/arch_repos.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,10 @@ def clear
end
end

IndexEntry = Data.define(:name, :description) do
IndexEntry = Data.define(:name, :description) {
alias_method :id, :name
alias_method :name_tok, :name
end
}

Package = Struct.new(
'Package',
Expand Down Expand Up @@ -123,10 +123,10 @@ class DB
private def parse_desc(desc)
field_re = /(?>%(\w+)%\n)((?:[^\n]+\n)+)/m

options = \
options =
desc
.enum_for(:scan, field_re)
.each_with_object({}) { |(k, v), pkg|
.enum_for(:scan, field_re)
.each_with_object({}) { |(k, v), pkg|
pkg[k.downcase.to_sym] = v.strip
}

Expand All @@ -140,11 +140,7 @@ class DB
end

private def parse_tar(tar)
tar
.lazy
.filter { tar_entry_pred _1 }
.map { parse_desc(_1.read) }
.force
tar.lazy.filter { tar_entry_pred _1 }.map { parse_desc(_1.read) }.force
end

def populate_data(io)
Expand Down
3 changes: 1 addition & 2 deletions lib/qbot/aur.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
url = "https://aur.archlinux.org/packages-meta-ext-v1.json.gz"

'https://aur.archlinux.org/packages-meta-ext-v1.json.gz'
22 changes: 16 additions & 6 deletions lib/qbot/breaking_wrap.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,22 @@ def self.breaking_word_wrap(text, *args)
options = args.extract_options!
options[:line_width] = args[0] || 80 unless args.blank?
options.reverse_merge!(line_width: 80)
text = text.split(' ').collect do |word|
word.length > options[:line_width] ? word.gsub(/(.{1,#{options[:line_width]}})/, '\\1 ') : word
end * ' '
text.split("\n").collect do |line|
line.length > options[:line_width] ? line.gsub(/(.{1,#{options[:line_width]}})(\s+|$)/, "\\1\n").strip : line
end * "\n"
text = text.split(' ').collect { |word|
if word.length > options[:line_width]
word.gsub(/(.{1,#{options[:line_width]}})/, '\\1 ')
else
word
end
} * ' '
text.split("\n").collect { |line|
if line.length > options[:line_width]
line.gsub(
/(.{1,#{options[:line_width]}})(\s+|$)/, "\\1\n"
).strip
else
line
end
} * "\n"
end
# rubocop: enable Metrics/AbcSize
end
4 changes: 2 additions & 2 deletions lib/qbot/db/concerns/configurable/option.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module Configurable
class Option
attr_reader :root, :name, :type, :path, :default

def initialize(root, name, type, default: nil, &block)
def initialize(root, name, type, default: nil, &)
@root = root
@name = name
@path = [*root, name]
Expand All @@ -19,7 +19,7 @@ def initialize(root, name, type, default: nil, &block)

@hooks = Hash.new { |h, k| h[k] = [] }

instance_eval(&block) if block_given?
instance_eval(&) if block_given?
end

def add_hook(type, &hook)
Expand Down
2 changes: 1 addition & 1 deletion lib/qbot/db/concerns/configurable/option_types.rb
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def format_value(value)
if @format
Kernel.format(FORMATS[@format], value)
else
super(value)
super
end
end

Expand Down
3 changes: 1 addition & 2 deletions lib/qbot/db/migrate/20230424_create_delayed_jobs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,10 @@ def self.up
table.timestamps null: true
end

add_index :delayed_jobs, [:priority, :run_at], name: "delayed_jobs_priority"
add_index :delayed_jobs, %i[priority run_at], name: 'delayed_jobs_priority'
end

def self.down
drop_table :delayed_jobs
end
end

4 changes: 1 addition & 3 deletions lib/qbot/db/models/note.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ def self.page_index_valid?(index, ...)
end

def self.find_random!(query)
where(name: query.downcase)
.order('RANDOM()')
.take!
where(name: query.downcase).order('RANDOM()').take!
end

scope :page, ->(index, size: PAGE_SIZE) { limit(size).offset(index * size) }
Expand Down
4 changes: 2 additions & 2 deletions lib/qbot/db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ def self.define_schema
end

add_index :delayed_jobs,
%i[priority run_at],
name: 'delayed_jobs_priority'
%i[priority run_at],
name: 'delayed_jobs_priority'

add_index :server_configs, :server_id, unique: true
add_index :user_configs, :user_id, unique: true
Expand Down
6 changes: 1 addition & 5 deletions lib/qbot/global_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,7 @@ def self.parse_from_hash(hash)
end

def self.read_from_file(path)
yaml = YAML.load_file(
path,
aliases: true,
symbolize_names: true
)
yaml = YAML.load_file(path, aliases: true, symbolize_names: true)

raise 'Invalid config path' unless yaml

Expand Down
3 changes: 2 additions & 1 deletion lib/qbot/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ def log_embed(event, channel, user, extra)
m.title = 'Command execution'

m.fields = [
{ name: 'Command', value: event.message.to_s.truncate(1024), inline: true },
{ name: 'Command', value: event.message.to_s.truncate(1024),
inline: true },
{ name: 'User ID', value: user.id, inline: true }
]

Expand Down
3 changes: 2 additions & 1 deletion lib/qbot/hooks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ class CommandBot

# rubocop: disable Style/OptionalBooleanParameter

def execute_command(name, event, arguments, chained = false, check_permissions = true)
def execute_command(name, event, arguments, chained = false,
check_permissions = true)
# Set the user's locale for response strings
uc_lang = UserConfig.for(event.user.id)[:language].to_sym
I18n.locale = uc_lang
Expand Down
9 changes: 4 additions & 5 deletions lib/qbot/init.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ def self.init_log

def self.print_logo(version)
logo = File.read File.join(__dir__, *%w[.. .. share logo.txt])
puts "\n#{logo.chomp} #{Paint["version #{version}", :italic, :bright, :gray]}\n\n"
puts "\n#{logo.chomp} #{Paint["version #{version}", :italic, :bright,
:gray]}\n\n"

@log.info "starting up qbot, version #{version}"
end
Expand All @@ -45,9 +46,7 @@ def self.init_config
end

def self.init_delayed_jobs
@worker = Delayed::Worker.new(
exit_on_complete: false
)
@worker = Delayed::Worker.new(exit_on_complete: false)

@worker_thread = Thread.new do
@worker.start
Expand Down Expand Up @@ -116,7 +115,7 @@ def self.run!
@bot.sync
end
# rubocop: enable Metrics/MethodLength, Metrics/AbcSize

def self.stop
@worker.stop
@scheduler.shutdown(:wait)
Expand Down
6 changes: 3 additions & 3 deletions lib/qbot/options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,21 @@ def define_options(parser)

def config_option(parser)
parser.on('-c', '--config <file>', String,
"Specify location of the config file (default #{@config_path})") do |path|
"Specify location of the config file (default #{@config_path})") do |path|
@config_path = path
end
end

def state_dir_option(parser)
parser.on('-s', '--state-dir <directory>', String,
'Set the directory where state, such as databases, will be stored') do |dir|
'Set the directory where state, such as databases, will be stored') do |dir|
@state_dir = dir
end
end

def console_option(parser)
parser.on('-n', '--no-console',
'Do not start the qbot console') do |_nc|
'Do not start the qbot console') do |_nc|
@no_console = true
end
end
Expand Down
9 changes: 6 additions & 3 deletions lib/qbot/patches.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ module Events
module Respondable
def respond_wrapped(content, tts: false, embed: nil, attachments: nil,
allowed_mentions: nil, message_reference: nil, components: nil)
send_message(content, tts, embed, attachments, allowed_mentions, message_reference, components)
send_message(content, tts, embed, attachments, allowed_mentions,
message_reference, components)
end
end
# rubocop: enable Metrics/ParameterLists
Expand All @@ -37,9 +38,11 @@ module CommandEventIntercept
# rubocop: disable Style/OptionalBooleanParameter
def call(event, arguments, chained = false, check_permissions = true)
# rubocop:enable Style/OptionalBooleanParameter
return if event.author.bot_account && !(QBot.config.bot_id_allowlist.include? event.author.id)
if event.author.bot_account && !(QBot.config.bot_id_allowlist.include? event.author.id)
return
end

super(event, arguments, chained, check_permissions)
super
end
end

Expand Down
4 changes: 2 additions & 2 deletions lib/qbot/sitelenpona.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ def self.gen_markup(text, options)
PANGO
end

def self.draw_text(text, options = nil, **kwargs)
options ||= DrawOptions.new(**kwargs)
def self.draw_text(text, options = nil, **)
options ||= DrawOptions.new(**)

markup = gen_markup(text, options)
image = generate_image(markup, options)
Expand Down
4 changes: 2 additions & 2 deletions lib/qbot/xkcd.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
class XKCD
def self.random_id
URI.open('https://dynamic.xkcd.com/random/comic/', allow_redirections: :all)
.base_uri.to_s
.split('/').last.to_i
.base_uri.to_s
.split('/').last.to_i
end

def self.parse_info(io) = JSON.parse(io.read).symbolize_keys
Expand Down
5 changes: 2 additions & 3 deletions modules/admin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,15 @@

ServerConfig.extend_schema do
column_option :prefix,
TString.new(min_size: 1, max_size: 32),
default: QBot.config.default_prefix
TString.new(min_size: 1, max_size: 32),
default: QBot.config.default_prefix

column_option :log_channel_id, TSnowflake.new(format: :channel) do
on_save do |_, value, event, *|
new_channel = event.bot.channel(value)

foreign = new_channel.server != event.server
raise ArgumentError, t('cfg.log-channel.set.other-server') if foreign

rescue Discordrb::Errors::UnknownChannel
# UnknownChannel raised for invalid channel IDs
embed t('cfg.log-channel.set.invalid-id', new_id)
Expand Down
11 changes: 5 additions & 6 deletions modules/admin/config_ui.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ def self.option_fields(cfg, option)

def self.option_help(cfg, option)
embed do |m|
m.title = t('cfg.help.option.title', option.localized_name, option.ui_path)
m.title = t('cfg.help.option.title', option.localized_name,
option.ui_path)
m.description = option.description

m.fields = option_fields(cfg, option)
Expand Down Expand Up @@ -97,9 +98,7 @@ def self.option_set_success_embed(option, val, clear: false)
m.title = t('cfg.set.success.title', option.ui_path) unless clear
m.title = t('cfg.set.success.clear-title', option.ui_path) if clear

m.fields = [
{ name: t('cfg.set.success.new-value'), value: val_text }
]
m.fields = [{ name: t('cfg.set.success.new-value'), value: val_text }]

m.footer = cfg_footer
end
Expand All @@ -121,13 +120,13 @@ def self.option_clear(cfg, option, *)
option_set_success_embed(option, val, clear: true)
end

def self.option_op(cfg, option, cmd, *args)
def self.option_op(cfg, option, cmd, *)
verbs = %w[set clear reset]
verb = verbs.abbrev[cmd]

case verb
when 'set'
option_set(cfg, option, *args)
option_set(cfg, option, *)
when 'clear', 'reset'
option_clear(cfg, option)
else
Expand Down
11 changes: 5 additions & 6 deletions modules/colors.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
option :use_bare_colors, TBoolean.new, default: false

option :auto_assign_colors,
TEnum.new(%w[on_join on_screening_pass never]),
default: 'on_join'
TEnum.new(%w[on_join on_screening_pass never]),
default: 'on_join'
end

# rubocop: disable Metrics/ModuleLength
Expand Down Expand Up @@ -54,7 +54,7 @@ def self.assign_color_role(member, new_role)
max_args: 1
} do |event, target|
is_valid = Colors.hex_code?(target)
next embed t('colors.closest.invalid-hex', target) unless is_valid
next embed t('colors.closest.invalid-hex', target) unless is_valid

closest = ColorRole.find_closest_on(server, target)
embed t('colors.closest.found', closest.hex_code)
Expand Down Expand Up @@ -161,8 +161,7 @@ def initialize(old_count)
end

def show_role_delete!(role, index)
message = \
t('colors.ccr.deleted', index, @old_count, role.name)
message = t('colors.ccr.deleted', index, @old_count, role.name)

@embeds[:deleting][:description] += "#{message}\n"

Expand All @@ -183,7 +182,7 @@ def begin_create_stage!(count)
end

def show_role_create!(role, index)
message = \
message =
t('colors.ccr.created', index, @new_count, role.mention, role.hex_code)

@embeds[:creating][:description] += "#{message}\n"
Expand Down
4 changes: 2 additions & 2 deletions modules/help.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ def self.embed_compact

long_desc =
names
.map { "`#{prefixed(_1)}` - #{t("descriptions.#{_1}")}" }
.join("\n")
.map { "`#{prefixed(_1)}` - #{t("descriptions.#{_1}")}" }
.join("\n")

embed do |m|
m.title = t('help.list-title')
Expand Down
1 change: 0 additions & 1 deletion modules/notes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,6 @@ def self.format_notes_page(notes)

note.destroy!
embed t('notes.del.success', note.name, note.id)

rescue ActiveRecord::RecordNotFound
embed t('notes.del.not-found', id)
end
Expand Down
Loading