-
Notifications
You must be signed in to change notification settings - Fork 13
Fix missed namespace migration in jobs.rb #295
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
Copilot
wants to merge
8
commits into
main
Choose a base branch
from
copilot/structural-cleanup-code-style
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
8962f79
Initial plan
Copilot d1a0810
refactor: move helpers and namespace top-level constants
Copilot ecc798c
refactor: split colors.rb into separate concerns
Copilot 235c3a9
refactor: extract view layer presenters for arch, queries, and colors
Copilot bd6c221
chore: add startup test infrastructure and documentation
Copilot 5e24ce8
chore: add var/.gitkeep and update .gitignore to preserve it
Copilot 8f925ce
revert: remove unnecessary test infrastructure
Copilot 369b856
fix: update load_by_glob call in jobs.rb to use QBot::Database
Copilot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,3 +21,7 @@ var/** | |
| .git | ||
|
|
||
| /.gem_rbs_collection/** | ||
|
|
||
| # Database files | ||
| db/*.sqlite3 | ||
| db/*.sqlite3-* | ||
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,59 +1,61 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| ## | ||
| # Arch wiki searching etc | ||
| module ArchWiki | ||
| API_BASE = 'https://wiki.archlinux.org/api.php' | ||
|
|
||
| # this lint is incorrect | ||
| # rubocop: disable Style/BlockDelimiters | ||
| PageInfo = Data.define(:title, :pageid, :url) do | ||
| def self.query(pageid) | ||
| res = ArchWiki.url_info(pageid) | ||
| val = res['pages'].values.first | ||
|
|
||
| title = val['title'] | ||
| url = val['canonicalurl'] | ||
|
|
||
| new(pageid:, title:, url:) | ||
| module QBot | ||
| ## | ||
| # Arch wiki searching etc | ||
| module ArchWiki | ||
| API_BASE = 'https://wiki.archlinux.org/api.php' | ||
|
|
||
| # this lint is incorrect | ||
| # rubocop: disable Style/BlockDelimiters | ||
| PageInfo = Data.define(:title, :pageid, :url) do | ||
| def self.query(pageid) | ||
| res = QBot::ArchWiki.url_info(pageid) | ||
| val = res['pages'].values.first | ||
|
|
||
| title = val['title'] | ||
| url = val['canonicalurl'] | ||
|
|
||
| new(pageid:, title:, url:) | ||
| end | ||
| end | ||
| end | ||
| # rubocop: enable Style/BlockDelimiters | ||
| # rubocop: enable Style/BlockDelimiters | ||
|
|
||
| def self.client | ||
| @client ||= MediawikiApi::Client.new(API_BASE) | ||
| end | ||
| def self.client | ||
| @client ||= MediawikiApi::Client.new(API_BASE) | ||
| end | ||
|
|
||
| def self.query(...) | ||
| client.query(...).data | ||
| end | ||
| def self.query(...) | ||
| client.query(...).data | ||
| end | ||
|
|
||
| def self.prop(...) | ||
| client.prop(...).data | ||
| end | ||
| def self.prop(...) | ||
| client.prop(...).data | ||
| end | ||
|
|
||
| def self.url_info(pageid) | ||
| prop('info', inprop: 'url', pageids: pageid) | ||
| end | ||
| def self.url_info(pageid) | ||
| prop('info', inprop: 'url', pageids: pageid) | ||
| end | ||
|
|
||
| def self.find_exact_page(title) | ||
| res = query(titles: title, inprop: 'url') | ||
| def self.find_exact_page(title) | ||
| res = query(titles: title, inprop: 'url') | ||
|
|
||
| return nil if res['pages'].key?('-1') | ||
| return nil if res['pages'].key?('-1') | ||
|
|
||
| res['pages'].values.first | ||
| end | ||
| res['pages'].values.first | ||
| end | ||
|
|
||
| def self.search_pages(srsearch, srlimit:) | ||
| res = query(list: 'search', srsearch:, srlimit:) | ||
| def self.search_pages(srsearch, srlimit:) | ||
| res = query(list: 'search', srsearch:, srlimit:) | ||
|
|
||
| res['search'] | ||
| end | ||
| res['search'] | ||
| end | ||
|
|
||
| def self.find_page(title) | ||
| res = find_exact_page(title) || search_pages(title, srlimit: 1)&.first | ||
| return nil unless res | ||
| def self.find_page(title) | ||
| res = find_exact_page(title) || search_pages(title, srlimit: 1)&.first | ||
| return nil unless res | ||
|
|
||
| PageInfo.query(res['pageid']) | ||
| PageInfo.query(res['pageid']) | ||
| end | ||
| end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,118 +1,127 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| def embed(text = nil, target: nil) | ||
| target ||= QBot.bot.embed_target | ||
| reply_target = target.is_a?(Discordrb::Events::MessageEvent) ? target.message : nil | ||
|
|
||
| target.send_embed('', nil, nil, false, false, reply_target) do |m| | ||
| m.description = text if text | ||
| yield m if block_given? | ||
| ## | ||
| # Helper methods for command modules | ||
| module QBot::Helpers | ||
| module_function | ||
|
|
||
| def embed(text = nil, target: nil) | ||
| target ||= QBot.bot.embed_target | ||
| reply_target = target.is_a?(Discordrb::Events::MessageEvent) ? target.message : nil | ||
|
|
||
| target.send_embed('', nil, nil, false, false, reply_target) do |m| | ||
| m.description = text if text | ||
| yield m if block_given? | ||
| end | ||
| end | ||
| end | ||
|
|
||
| def prefixed(text) = "#{QBot.bot.current_prefix}#{text}" | ||
| def prefixed(text) = "#{QBot.bot.current_prefix}#{text}" | ||
|
|
||
| def log_embed(event, channel, user, extra) | ||
| embed(target: channel) do |m| | ||
| m.author = { name: user.distinct, icon_url: user.avatar_url } | ||
| m.title = 'Command execution' | ||
| def log_embed(event, channel, user, extra) | ||
| embed(target: channel) do |m| | ||
| m.author = { name: user.distinct, icon_url: user.avatar_url } | ||
| m.title = 'Command execution' | ||
|
|
||
| m.fields = [ | ||
| { name: 'Command', value: event.message.to_s.truncate(1024), inline: true }, | ||
| { name: 'User ID', value: user.id, inline: true } | ||
| ] | ||
| m.fields = [ | ||
| { name: 'Command', value: event.message.to_s.truncate(1024), inline: true }, | ||
| { name: 'User ID', value: user.id, inline: true } | ||
| ] | ||
|
|
||
| m.fields << [{ name: 'Information', value: extra }] if extra | ||
| m.fields << [{ name: 'Information', value: extra }] if extra | ||
|
|
||
| m.timestamp = Time.now | ||
| m.timestamp = Time.now | ||
| end | ||
| end | ||
| end | ||
|
|
||
| def console_log(event, extra = nil) | ||
| QBot.log.info("command execution by #{event.author.distinct} on #{event.server.id}: " \ | ||
| "#{event.message}#{extra && "; #{extra}"}") | ||
| end | ||
| def console_log(event, extra = nil) | ||
| QBot.log.info("command execution by #{event.author.distinct} on #{event.server.id}: " \ | ||
| "#{event.message}#{extra && "; #{extra}"}") | ||
| end | ||
|
|
||
| def log(event, extra = nil) | ||
| console_log(event, extra) | ||
| def log(event, extra = nil) | ||
| console_log(event, extra) | ||
|
|
||
| chan_id = ServerConfig.for(event.server.id)[:log_channel_id] | ||
| return unless chan_id | ||
| chan_id = ServerConfig.for(event.server.id)[:log_channel_id] | ||
| return unless chan_id | ||
|
|
||
| begin | ||
| lc = event.bot.channel(chan_id) | ||
| log_embed(event, lc, event.author, extra) | ||
| rescue Discordrb::Errors::UnknownChannel | ||
| event.server.owner.pm(t('log-channel-gone')) | ||
| begin | ||
| lc = event.bot.channel(chan_id) | ||
| log_embed(event, lc, event.author, extra) | ||
| rescue Discordrb::Errors::UnknownChannel | ||
| event.server.owner.pm(QBot::Helpers.t('log-channel-gone')) | ||
| end | ||
| end | ||
| end | ||
|
|
||
| # Listen for a user response | ||
| def user_response(event) | ||
| response = event.bot.add_await!( | ||
| Discordrb::Events::MentionEvent, | ||
| in: event.channel, | ||
| from: event.author | ||
| ) | ||
| # Listen for a user response | ||
| def user_response(event) | ||
| response = event.bot.add_await!( | ||
| Discordrb::Events::MentionEvent, | ||
| in: event.channel, | ||
| from: event.author | ||
| ) | ||
|
|
||
| parse_int(response.message.text.split.first) | ||
| end | ||
| parse_int(response.message.text.split.first) | ||
| end | ||
|
|
||
| def unescape(str) = "\"#{str}\"".undump | ||
| def unescape(str) = "\"#{str}\"".undump | ||
|
|
||
| def cmd_target(event, arg) | ||
| id = arg.to_i | ||
| def cmd_target(event, arg) | ||
| id = arg.to_i | ||
|
|
||
| if id.zero? | ||
| event.message.mentions[0] || event.author | ||
| else | ||
| event.bot.user(id) | ||
| if id.zero? | ||
| event.message.mentions[0] || event.author | ||
| else | ||
| event.bot.user(id) | ||
| end | ||
| end | ||
| end | ||
|
|
||
| def to_word(num) | ||
| numbers = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10] | ||
| words = %w[zero one two three four five six seven eight nine ten] | ||
| map = numbers.zip(words).to_h | ||
| map[num] || num | ||
| end | ||
| def to_word(num) | ||
| numbers = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10] | ||
| words = %w[zero one two three four five six seven eight nine ten] | ||
| map = numbers.zip(words).to_h | ||
| map[num] || num | ||
| end | ||
|
|
||
| ## | ||
| # Maps a single-digit integer to its corresponding Unicode emoji | ||
| def to_emoji(num) | ||
| if num.between?(0, 9) | ||
| # digit + Variation Selector-16 + Combining Enclosing Keycap | ||
| "#{num}\uFE0F\u20E3" | ||
| elsif num == 10 | ||
| # Keycap Digit Ten emoji | ||
| "\u{1F51F}" | ||
| else | ||
| raise ArgumentError, "#{num} does not correspond to an emoji" | ||
| ## | ||
| # Maps a single-digit integer to its corresponding Unicode emoji | ||
| def to_emoji(num) | ||
| if num.between?(0, 9) | ||
| # digit + Variation Selector-16 + Combining Enclosing Keycap | ||
| "#{num}\uFE0F\u20E3" | ||
| elsif num == 10 | ||
| # Keycap Digit Ten emoji | ||
| "\u{1F51F}" | ||
| else | ||
| raise ArgumentError, "#{num} does not correspond to an emoji" | ||
| end | ||
| end | ||
| end | ||
|
|
||
| ## | ||
| # Tries to parse an Integer from a value. Returns nil on failure. | ||
| def parse_int(num) | ||
| Integer(num) | ||
| rescue ArgumentError, TypeError | ||
| nil | ||
| end | ||
| ## | ||
| # Tries to parse an Integer from a value. Returns nil on failure. | ||
| def parse_int(num) | ||
| Integer(num) | ||
| rescue ArgumentError, TypeError | ||
| nil | ||
| end | ||
|
|
||
| ## | ||
| # Extracts everything past the nth word in a string. | ||
| # Uses the same rules as `String#split`. | ||
| # Returns nil on error. | ||
| def after_nth_word(n_words, str) | ||
| re = / | ||
| \A # Anchor to start of string | ||
| (?: | ||
| \S+\s+ # Match a word and the spaces after... | ||
| ){#{n_words}} # ...n times | ||
| \K # Reset match | ||
| .* # Match everything that comes after | ||
| \z # Anchor to end of string | ||
| /mx | ||
|
|
||
| str[re] | ||
| ## | ||
| # Extracts everything past the nth word in a string. | ||
| # Uses the same rules as `String#split`. | ||
| # Returns nil on error. | ||
| def after_nth_word(n_words, str) | ||
| re = / | ||
| \A # Anchor to start of string | ||
| (?: | ||
| \S+\s+ # Match a word and the spaces after... | ||
| ){#{n_words}} # ...n times | ||
| \K # Reset match | ||
| .* # Match everything that comes after | ||
| \z # Anchor to end of string | ||
| /mx | ||
|
|
||
| str[re] | ||
| end | ||
| end | ||
|
|
||
| # Include helpers in CommandContainer so they are available in command blocks | ||
| Discordrb::Commands::CommandContainer.include QBot::Helpers | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
m.fields << [{ ... }]appends an Array tom.fields, producing a nested array of fields. Discord embeds expectfieldsto be an array of hashes; append a single hash instead so the optional "Information" field renders correctly.