Skip to content
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

Add support for role mentions on the bot's autogenerated managed roleid. #262

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

Ifiht
Copy link

@Ifiht Ifiht commented Jun 4, 2024

Summary

This is to address the discrepancy when a user types the bot's exact name, and discord translates it to a role mention due to the autogenerated managed role that's created when adding a bot with permissions > 0 to a server. Below is an example of the new behavior from an irb session:

3.1.4 :003 > bot.run :async
[INFO : websocket @ 2024-06-05 09:54:55.116] Discord using gateway protocol version: 9, requested: 9
 => nil
3.1.4 :004 > bot.mention(allow_role_mention: true) do |event|
3.1.4 :005 >     puts "THIS FIRES FOR USER & ROLE MENTIONS: #{event.content}"
3.1.4 :006 > end
 => #<Discordrb::Events::MentionEventHandler:0x000055742aa345c8 @attributes={:allow_role_mention=>true}, @block=#<Proc:0x000055742aa34a00 (irb):4>>
3.1.4 :007 > bot.mention() do |event|
3.1.4 :008 >     puts "THIS ONLY FIRES FOR USER MENTIONS: #{event.content}"
3.1.4 :009 > end
 => #<Discordrb::Events::MentionEventHandler:0x000055742ab280d8 @attributes={}, @block=#<Proc:0x000055742ab282b8 (irb):7>>
3.1.4 :010 >
3.1.4 :011 > 
THIS FIRES FOR USER & ROLE MENTIONS: <@1211423563475849236> user mention test
THIS ONLY FIRES FOR USER MENTIONS: <@1211423563475849236> user mention test
THIS FIRES FOR USER & ROLE MENTIONS: <@&1211432785353637999> role mention test

in the above test, I sent two messages to the bot, one with a role mention and the other with a user mention. The blocks passed demonstrate that only when :allow_role_mention == true will the event be raised upon role mentions.

All tests were run with bundle exec rspec spec and passed:

Finished in 0.27027 seconds (files took 0.38679 seconds to load)
430 examples, 0 failures, 3 pending

Changed

  • discordrb/events/message.rb
  • discordrb/bot.rb
  • discordrb/container.rb

additionally the gemspec was updated to include the role_mentions: flag, to avoid a no method error but otherwise function is exactly the same.

Fixed

You could say the bot.mention function has been "fixed"? Depends how you view this feature & support for Discord's managed roles.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant