Skip to content

Commit

Permalink
fix: assorted module bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
anna328p committed Oct 29, 2023
1 parent 17de3e8 commit 588362e
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 32 deletions.
2 changes: 1 addition & 1 deletion modules/colors.rb
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ def self.randomize_color_roles(server, &)
} do |event|
next embed t('no_perms') unless event.author.permission?(:manage_roles)

randomize_color_roles(server) { event.send_embed('', _1) }
randomize_color_roles(event.server) { event.send_embed('', _1) }
end

##
Expand Down
2 changes: 2 additions & 0 deletions modules/fun.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@
# Fun commmands
module Fun
extend Discordrb::Commands::CommandContainer

# :(
end
22 changes: 12 additions & 10 deletions modules/help.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,32 +72,34 @@ def self.command_field(cmd)
}
end

def self.embed_full
def self.embed_with_fields
embed do |m|
m.title = t('help.list-title')
m.fields = available_commands.map { command_field(_1) }
end
end

def self.embed_compact
names = available_commands.map(&:name)

short_desc = names.map { "`#{prefixed(_1)}`" }.join(', ')

long_desc =
names

Check warning on line 88 in modules/help.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.
.map { "`#{prefixed(_1)}` - #{t("descriptions.#{_1}")}" }

Check warning on line 89 in modules/help.rb

View check run for this annotation

Check Run Reporter / Lint / lint

com.puppycrawl.tools.checkstyle.Layout/MultilineMethodCallIndentation

com.puppycrawl.tools.checkstyle.Layout/MultilineMethodCallIndentation: Layout/MultilineMethodCallIndentation: Use 2 (not 0) spaces for indenting an expression in an assignment spanning multiple lines.
.join("\n")

Check warning on line 90 in modules/help.rb

View check run for this annotation

Check Run Reporter / Lint / lint

com.puppycrawl.tools.checkstyle.Layout/MultilineMethodCallIndentation

com.puppycrawl.tools.checkstyle.Layout/MultilineMethodCallIndentation: Layout/MultilineMethodCallIndentation: Use 2 (not 0) spaces for indenting an expression in an assignment spanning multiple lines.

embed do |m|
m.title = t('help.list-title')

m.description = \
available_commands
.map { |cmd| prefixed(cmd.name) }
.then { |names| <<~DESC }
```
#{names.join("\n")}
```
DESC
m.description = long_desc.size < 4096 ? long_desc : short_desc
end
end

def self.show_all_help
case available_commands.length
when 0..25
embed_full
embed_with_fields
else
embed_compact
end
Expand Down
26 changes: 13 additions & 13 deletions modules/polls.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,21 +85,21 @@ def self.poll_allowed?(event, channel)

nil
end
end

QBot.bot.reaction_add do |event|
footer_text = event.message.embeds.first&.footer&.text
if footer_text&.include?('type:poll') \
|| footer_text&.include?('poll:') \
&& event.user.id != event.bot.bot_user.id
matches = footer_text.match(/opts:(\d+)/) \
|| footer_text.match(/poll:(\d+)/)
num = matches && matches[1]&.to_i
reaction_add do |event|
footer_text = event.message.embeds.first&.footer&.text
if footer_text&.include?('type:poll') \
|| footer_text&.include?('poll:') \

Check warning on line 92 in modules/polls.rb

View check run for this annotation

Check Run Reporter / Lint / lint

com.puppycrawl.tools.checkstyle.Lint/AmbiguousOperatorPrecedence

com.puppycrawl.tools.checkstyle.Lint/AmbiguousOperatorPrecedence: Lint/AmbiguousOperatorPrecedence: Wrap expressions with varying precedence with parentheses to avoid ambiguity.
&& event.user.id != event.bot.bot_user.id
matches = footer_text.match(/opts:(\d+)/) \
|| footer_text.match(/poll:(\d+)/)
num = matches && matches[1]&.to_i

last = num || 9
numbers = [*1..last].map { to_emoji _1 }
last = num || 9
numbers = [*1..last].map { to_emoji _1 }

numbers.include?(event.emoji.name) || \
event.message.delete_reaction(event.user, event.emoji)
numbers.include?(event.emoji.name) || \
event.message.delete_reaction(event.user, event.emoji)
end
end
end
16 changes: 8 additions & 8 deletions modules/tio.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,16 @@ def self.get_codespans(text)

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

QBot.bot.reaction_add(emoji: '❌') do |event|
if (ftext = event.message.embeds.first&.footer&.text) \
&& ftext.start_with?('tio:') \
&& event.user.id != event.bot.bot_user.id
matches = ftext.match(/tio:(\d+)/)
reaction_add(emoji: '❌') do |event|
if (ftext = event.message.embeds.first&.footer&.text) \
&& ftext.start_with?('tio:') \
&& event.user.id != event.bot.bot_user.id
matches = ftext.match(/tio:(\d+)/)

id = matches && matches[1]&.to_i
id = matches && matches[1]&.to_i

event.message.delete if event.user.id == id
event.message.delete if event.user.id == id
end
end
end

0 comments on commit 588362e

Please sign in to comment.