Skip to content

Commit

Permalink
fix: misc fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
anna328p committed Dec 26, 2023
1 parent e693b67 commit da85ed4
Show file tree
Hide file tree
Showing 14 changed files with 391 additions and 282 deletions.
13 changes: 11 additions & 2 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,21 @@ AllCops:
NewCops: enable
ActiveSupportExtensionsEnabled: true

Layout/LineLength:
Max: 80
Layout/ArgumentAlignment:
EnforcedStyle: with_fixed_indentation

Layout/EndAlignment:
EnforcedStyleAlignWith: variable

Layout/FirstArgumentIndentation:
EnforcedStyle: consistent

Layout/FirstArrayElementIndentation:
EnforcedStyle: consistent

Layout/LineLength:
Max: 80

Layout/MultilineMethodCallIndentation:
EnforcedStyle: indented

Expand Down
4 changes: 1 addition & 3 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ gem 'rake'
# Base
gem 'discordrb', github: 'shardlab/discordrb', branch: 'main'
# dirty hack to fix bundix problems
gem 'discordrb-webhooks',
github: 'anna328p/discordrb',
branch: 'main'
gem 'discordrb-webhooks', github: 'anna328p/discordrb', branch: 'main'

gem 'rbnacl'

Expand Down
11 changes: 11 additions & 0 deletions bin/console
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

require_relative '../lib/qbot'

QBot.init_log
QBot.parse_options(ARGV)
QBot.init_config
QBot::Database.init_db

binding.irb

Check warning on line 11 in bin/console

View check run for this annotation

Check Run Reporter / Lint / lint

com.puppycrawl.tools.checkstyle.Lint/Debugger

com.puppycrawl.tools.checkstyle.Lint/Debugger: Lint/Debugger: Remove debugger entry point `binding.irb`.
23 changes: 13 additions & 10 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,8 @@ rec {
in
genAttrs systems.flakeExposed;

qbotPkgArgs = pkgs: rec {
mkQBotArgs = pkgs: rec {
ruby = pkgs.ruby_3_2;
bundler = pkgs.bundler.override { inherit ruby; };
bundix = pkgs.bundix.override { inherit bundler; };

# TODO: remove once nixpkgs#272969 is merged
rustc = rust-overlay.packages.${pkgs.system}.rust;
Expand All @@ -47,7 +45,14 @@ rec {
config.allowUnfree = true;
};

qbot = pkgs.callPackage ./. (qbotPkgArgs pkgs);
qbotArgs = mkQBotArgs pkgs;

inherit (qbotArgs) ruby;

bundler = pkgs.bundler.override { inherit ruby; };
bundix = pkgs.bundix.override { inherit bundler; };

qbot = pkgs.callPackage ./. qbotArgs;
};

# withCommon : (Dict Any -> Dict Any) -> Dict (Dict Any)
Expand All @@ -56,14 +61,14 @@ rec {
in {
overlays = rec {
qbot = final: prev: {
qbot = final.callPackage ./. (qbotPkgArgs final);
qbot = final.callPackage ./. (mkQBotArgs final);
};

default = qbot;
};

nixosModules = rec {
qbot = import ./module.nix { inherit nixConfig; };
qbot = import nix/module.nix { inherit nixConfig; };
default = qbot;
};

Expand All @@ -83,14 +88,12 @@ rec {
});

apps = withCommon (env: let
inherit (env) pkgs;

pkgArgs = qbotPkgArgs pkgs;
inherit (env) pkgs bundler bundix;

update-deps = pkgs.writeShellApplication {
name = "update-deps";

runtimeInputs = [ pkgArgs.bundler pkgArgs.bundix ];
runtimeInputs = [ bundler bundix ];

text = ''
rm -f Gemfile.lock
Expand Down
1 change: 0 additions & 1 deletion lib/qbot.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
require_relative 'qbot/db_config'
require_relative 'qbot/db'
require_relative 'qbot/jobs'
require_relative 'qbot/index_models'
require_relative 'qbot/i18n'
require_relative 'qbot/helpers'
require_relative 'qbot/colorlib'
Expand Down
2 changes: 2 additions & 0 deletions lib/qbot/aur.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
url = "https://aur.archlinux.org/packages-meta-ext-v1.json.gz"

Check warning on line 1 in lib/qbot/aur.rb

View check run for this annotation

Check Run Reporter / Lint / lint

com.puppycrawl.tools.checkstyle.Lint/UselessAssignment

com.puppycrawl.tools.checkstyle.Lint/UselessAssignment: Lint/UselessAssignment: Useless assignment to variable - `url`.

Check warning on line 1 in lib/qbot/aur.rb

View check run for this annotation

Check Run Reporter / Lint / lint

com.puppycrawl.tools.checkstyle.Style/FrozenStringLiteralComment

com.puppycrawl.tools.checkstyle.Style/FrozenStringLiteralComment: Style/FrozenStringLiteralComment: Missing frozen string literal comment.

Check warning on line 1 in lib/qbot/aur.rb

View check run for this annotation

Check Run Reporter / Lint / lint

com.puppycrawl.tools.checkstyle.Style/StringLiterals

com.puppycrawl.tools.checkstyle.Style/StringLiterals: Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols.

Check warning on line 2 in lib/qbot/aur.rb

View check run for this annotation

Check Run Reporter / Lint / lint

com.puppycrawl.tools.checkstyle.Layout/TrailingEmptyLines

com.puppycrawl.tools.checkstyle.Layout/TrailingEmptyLines: Layout/TrailingEmptyLines: 1 trailing blank lines detected.
2 changes: 0 additions & 2 deletions lib/qbot/db/concerns/configurable/option_types.rb
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,6 @@ def initialize(format: nil)
end

def format_value(value)
return t('types.empty') unless value

if @format
Kernel.format(FORMATS[@format], value)
else
Expand Down
11 changes: 10 additions & 1 deletion modules/colors.rb
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,12 @@ def self.create_color_roles(server, lightness, radius, count, &)
rescue ActiveRecord::RecordNotFound
embed t('colors.extra-roles.del.not-found', role.mention)
end
end
# rubocop: enable Metrics/ModuleLength

## Event container for the Colors module
module ColorsEvents
extend Discordrb::EventContainer

# Color roles on join

Expand Down Expand Up @@ -341,4 +347,7 @@ def give_random_color(server, user)
nil
end
end
# rubocop: enable Metrics/ModuleLength

module Colors

Check warning on line 351 in modules/colors.rb

View check run for this annotation

Check Run Reporter / Lint / lint

com.puppycrawl.tools.checkstyle.Style/Documentation

com.puppycrawl.tools.checkstyle.Style/Documentation: Style/Documentation: Missing top-level documentation comment for `module Colors`.
include! ColorsEvents
end
8 changes: 8 additions & 0 deletions modules/polls.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ def self.poll_allowed?(event, channel)

nil
end
end

module PollsEvents

Check warning on line 90 in modules/polls.rb

View check run for this annotation

Check Run Reporter / Lint / lint

com.puppycrawl.tools.checkstyle.Style/Documentation

com.puppycrawl.tools.checkstyle.Style/Documentation: Style/Documentation: Missing top-level documentation comment for `module PollsEvents`.
extend Discordrb::EventContainer

reaction_add do |event|
footer_text = event.message.embeds.first&.footer&.text
Expand All @@ -103,3 +107,7 @@ def self.poll_allowed?(event, channel)
end
end
end

module Polls

Check warning on line 111 in modules/polls.rb

View check run for this annotation

Check Run Reporter / Lint / lint

com.puppycrawl.tools.checkstyle.Style/Documentation

com.puppycrawl.tools.checkstyle.Style/Documentation: Style/Documentation: Missing top-level documentation comment for `module Polls`.
include! PollsEvents
end
8 changes: 8 additions & 0 deletions modules/tio.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ def self.get_codespans(text)

embed langs.keys.join(', ').truncate(2048)
end
end

module TioEvents

Check warning on line 59 in modules/tio.rb

View check run for this annotation

Check Run Reporter / Lint / lint

com.puppycrawl.tools.checkstyle.Style/Documentation

com.puppycrawl.tools.checkstyle.Style/Documentation: Style/Documentation: Missing top-level documentation comment for `module TioEvents`.
extend Discordrb::EventContainer

reaction_add(emoji: '❌') do |event|
if (ftext = event.message.embeds.first&.footer&.text) \
Expand All @@ -67,3 +71,7 @@ def self.get_codespans(text)
end
end
end

module Tio

Check warning on line 75 in modules/tio.rb

View check run for this annotation

Check Run Reporter / Lint / lint

com.puppycrawl.tools.checkstyle.Style/Documentation

com.puppycrawl.tools.checkstyle.Style/Documentation: Style/Documentation: Missing top-level documentation comment for `module Tio`.
include! TioEvents
end
File renamed without changes.
14 changes: 7 additions & 7 deletions scripts/compare_locales.rb
Original file line number Diff line number Diff line change
Expand Up @@ -122,33 +122,33 @@ def val(node)
# Filter for method calls
next unless node.type == :send

line = node.loc.line
col = node.loc.column
loc = KeyLoc.new(path:, line: node.loc.line, col: node.loc.column)

case node.children
# Find invocations of t()
in [_, :t, key, *]
list << KeyLoc.new(path:, line:, col:, key: val(key))
loc.key = val(key)

# Find all bot commands
in [_, :command, name, *]
list << KeyLoc.new(path:, line:, col:, key: "descriptions.#{val name}")
loc.key = "descriptions.#{val(name)}"

# Find list of locales
in [[[:const, _, :I18n], :config], :available_locales=, [*, locales]]
list << KeyLoc.new(path:, line:, col:, key: "locales.#{val name}")
loc.key = "locales.#{val(name)}"

else next
end

list << loc
}
}.inject(:+)

# print translations used in code, but not present in the base file.

puts Paint["Translations missing from #{base_name}:", :yellow, :bright]

key_groups = \
key_matches
key_groups = key_matches

Check warning on line 151 in scripts/compare_locales.rb

View check run for this annotation

Check Run Reporter / Lint / lint

com.puppycrawl.tools.checkstyle.Layout/RedundantLineBreak

com.puppycrawl.tools.checkstyle.Layout/RedundantLineBreak: Layout/RedundantLineBreak: Redundant line break detected.
.reject { base_flat.keys.include? _1.key }
.group_by(&:key)

Expand Down
63 changes: 56 additions & 7 deletions share/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,19 @@ en:
userconfig: 'Configure user settings that apply across servers'

listsnippets: 'Lists available snippets'
snippet: 'Posts a snippet'
getsnippet: 'Finds a snippet by name, and posts its text'
snippets: 'Manages snippets'

color: 'Sets your user color role'
closestcolor: 'Gives you the closest color, by hex code'
listcolors: 'Lists colors available on the server'
createcolorroles: 'Creates color roles'
gencolors: 'Creates a set of color roles'
randcolors: 'Randomizes colors for all users'

extracolorroles: 'Lists extra color roles'
addextracolorrole: 'Adds an existing role as an extra color role'
delextracolorrole: 'Removes an extra color role'

query: 'Adds a query to the list of queries'
openqueries: 'Lists open queries'
closequery: 'Closes a query by ID'
Expand All @@ -36,6 +41,8 @@ en:
invite: 'Sends a link to invite the bot to your server'
voicekick: 'Move a user to the AFK channel or given channel'

slowmode: 'Sets the slowmode delay for the current channel'

archwiki: 'Searches the Arch wiki'
packagesearch: 'Searches for a package in the Arch repositories'
package: 'Shows info for a given package'
Expand All @@ -44,7 +51,7 @@ en:

poll: 'Sets up a poll in a channel'

figlet: 'Converts some text into ASCII art'
figlet: 'Converts text into ASCII art'

nimi: 'Queries definitions for a toki pona word'
tpo: 'Queries usage data for a toki pona word from tokipona.org'
Expand All @@ -55,21 +62,35 @@ en:
listnotes: 'Lists all notes for this server'
noteid: 'Finds a note by ID'
delnote: 'Deletes a note'
exportnotes: "Uploads a JSON file containing all of this server's notes"

bottom: 'Converts text in Unicode to the [Bottom](https://github.com/bottom-software-foundation/spec) emoji encoding'
regress: 'Converts text in the [Bottom](https://github.com/bottom-software-foundation/spec) emoji encoding to Unicode'

ipa: 'Converts phonetic transcriptions from [X-SAMPA](https://en.wikipedia.org/wiki/X-SAMPA) to [IPA](https://en.wikipedia.org/wiki/International_Phonetic_Alphabet)'

sp: 'Renders Toki Pona text in the _sitelen pona_ alphabet'
sppreview: 'Renders some Toki Pona text in all available _sitelen pona_ typefaces'

tio: 'Runs some code using the service [Try It Online](https://tio.run)'
tiolangs: 'Lists all programming languages available on [Try It Online](https://tio.run)'

admin:
eval:
nope: 'nope'

arch:
wiki:
no-results: 'No results found'
no-results: 'No results found.'

ps:
no-results: 'No results found'
no-results: 'No results found.'
title: 'Search results for `%s`'
result-footer: 'version **%s** | built **%s** | [web link](%s)'

package:
not-found: '❔ Package not found.'

url: 'Upstream URL'
license: 'License'
csize: 'Size'
Expand Down Expand Up @@ -113,7 +134,7 @@ en:

creating: '🎨 Creating %d new color roles'
created: '`(%d/%d)` Created role %s with color `%s`.'
success: '✅ Created %s roles.'
success: '✅ Created %d roles.'

rc:
begin: '🔄 Randomizing colors for %s users.'
Expand Down Expand Up @@ -150,14 +171,38 @@ en:
no-perms: 'You do not have permission to delete query #%s.'

snippets:
help: >-
You can append the following verbs to this command:
- `list`, `show`: See the list of all snippets.
- `set`, `edit`: Given a name and text, create a new snippet by that name or set the value of an existing snippet.
- `remove`, `rm`, `delete`: Given a name, remove the snippet by that name, if it exists.
- `property`: Set properties of snippets.
edit:
success: 'Successfully edited snippet `%s`.'
not-found: 'Could not find a snippet with name `%s`.'

remove:
success: 'Successfully removed snippet `%s`, if it existed.'

prop:
help: >-
The following properties are available: `%s`.
To set a property, append the property, the name of the snippet to modify, and the new value;
for example, `snippet property embed foo true`.
success: 'Successfully set property `%s` of snippet `%s` to `%s`.'

list:
none-found: 'No available snippets.'
title: 'Available snippets'

snippet:
not-found: 'Snippet not found.'

notes:
add:
invalid-args: '⚠️ Invalid arguments given.'
success: 'Note **`%s`** (`#%s`) added successfully.'
failure: "⚠️ **Note could not be saved due to these errors:**\n%s."
get:
Expand All @@ -178,7 +223,8 @@ en:
attrib:
title: 'toki pona data sources'
text: >-
toki pona was created by Sonja Lang. the pu dictionary is in the public domain.
toki pona was created by Sonja Lang.
the dictionary in _Toki Pona: The Language of Good_, known as _pu_, is in the public domain.
tokipona.org data was gathered by Sonja Lang and can be found at %s.
other data was taken from ilo Salana, which is in the public domain.
Expand Down Expand Up @@ -230,6 +276,7 @@ en:
channel: 'channel IDs'
user: 'user IDs'
role: 'role IDs'
bare: 'any IDs'
enum:
name: 'selection'
desc: 'fixed set of choices'
Expand Down Expand Up @@ -312,3 +359,5 @@ en:

fun:
ping: 'I got pinged :o'

nyi: 'This feature is not yet implemented.'
Loading

0 comments on commit da85ed4

Please sign in to comment.