-
Notifications
You must be signed in to change notification settings - Fork 10
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
Polite 1.0 #32
base: beta
Are you sure you want to change the base?
Polite 1.0 #32
Conversation
I should have some time to test this locally next week since I already have a duplicate. |
unitbot.py
Outdated
processedMessage = unitconversion.process(message.content) | ||
polite = False | ||
if isinstance(message.channel, TextChannel): | ||
for member in message.channel.members: |
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.
You can actually get the roles of an message author directly without needing to iterate over all members. (possibly ten to hundreds of thousands in large servers, which might make a lot of API requests and noise)
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.
I thought that since the calls i used in potentially large loops were written in the API as properties rather than as async functions there wouldn't be excessive API calls; however, I could be wrong about that. I did see how you checked for imperial certified in the old version, and I liked it better.
However, I don't know how to use that same form of the API to get a Member
object for the bot itself, and the wording of the API specifications wasn't completely clear to me that if a Member
with the id
of the message.author
is contained in the message.channel.members
list a Member
object must be returned by message.author
, so while I was checking for the bot Member
object, I figured I could check for the user as well.
I realize now that such a guarantee probably exists.
However, after a bit of searching through the documentation for the API I still couldn't find how to directly get the roles of the bot itself, given the message object.
Also, from my experience with the discord.js
API, some degree of caching occurs between API requests? What degree, however, I do not know.
If we need a more efficient fix to this issue, I'll defer to someone who's better acquainted with the discord.py
API and focus on manipulating strings instead.
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.
@Randall-Scharpf try this one :)
ctx = await bot.get_context(message)
bot_member = ctx.guild.get_member(bot.user.id)
roles = bot_member.roles
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.
I implemented it! Take a look, when you get a chance, at the new code in this commit.
Beta to master (stable)
Fixes #30
As a warning, this hasn't been tested locally, but I am recommending merging to the beta branch for those tests so a duplicate bot does not need to be created, and the development version of the bot can simply be used to perform the said test. Additionally, I am relatively confident that I have correctly interpreted the API for this commit.