-
Notifications
You must be signed in to change notification settings - Fork 4
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
Roleboard #46
base: master
Are you sure you want to change the base?
Roleboard #46
Conversation
…role to an existing one
## To make a commit, type your commit message and press CTRL-ENTER. To cancel ## the commit, close the window. To sign off on the commit, press CTRL-S. ## ## You may also reference or close a GitHub issue with this commit. To do so, ## type `#` followed by the `tab` key. You will be shown a list of issues ## related to the current repo. You may also type `owner/repo#` plus the `tab` ## key to reference an issue in a different GitHub repo. rolecall/UI Specification | 9 ++++++++- rolecall/sample.png | Bin 287260 -> 0 bytes 2 files changed, 8 insertions(+), 1 deletion(-)
…D strings instead of channel objects
…constructed as desired
rolecall/rolecall.py
Outdated
next_key = self.reaction_user_queue.pop() | ||
reaction = self.reaction_queue.pop(next_key) | ||
await self.process_event(reaction) | ||
await asyncio.sleep(0.0001) |
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.
can probably wait longer than this 😬
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.
updated ridiculous sleep time to a less ridiculous 0.1 seconds as of commit 34af3cf
rolecall/rolecall.py
Outdated
@@ -101,73 +46,166 @@ class RoleCall: | |||
def __init__(self, bot): | |||
self.bot = bot | |||
self.settings = dataIO.load_json(SETTINGS_PATH) | |||
self.reaction_queue = {} | |||
self.reaction_user_queue = set() | |||
self.queue_processor_task = bot.loop.create_task(self.queue_processor()) |
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.
to be nice and tidy, you might want to __unload
this task as well
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.
implemented in commit 336c2f1
rolecall/rolecall.py
Outdated
# chosen role board | ||
try: | ||
await self.post_role(entry) | ||
except Exception as e: |
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.
be careful with catch-all try/excepts
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.
solved with commit be67606
rolecall/rolecall.py
Outdated
try: | ||
await self.create_or_edit_role_channel(server, role_object, role_channel) | ||
except Exception as e: | ||
print(e) |
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.
be careful with catch-all try/excepts.
also, to be nice to your users, you might want to use Red's logger instead of printing the exception directly to the console
rolecall/rolecall.py
Outdated
settings = self.settings[server.id] | ||
# retrieve channel mentions in the command message | ||
channels = ctx.message.raw_channel_mentions | ||
if len(channels) == 2: |
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.
this and your raw_role_mentions has incorrect logic.
[p]rolecall add chan1 "test @role1 #chan2 #chan3" role2 :eyes: chan4
will cause the mentions in the message to be used instead of the role and channel in the actual argument
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.
applied correct logic as of 47f7037
rolecall/rolecall.py
Outdated
async def rolecall_add(self, ctx, channel: discord.Channel, | ||
content_or_message_id: str, role: str, | ||
emoji: str, | ||
private_channel: str = None, |
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.
once we use this for awhile, let's come up with a simpler more memorable command signature
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.
we definitely should 🤒
|
||
server_id = entry.server.id | ||
roleboard_id = entry.roleboard_channel.id | ||
message_id = entry.content_or_message_id |
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.
for sanity, you should probably add a separate attribute for message id in Entry
which is either None
or the message id and pull from that.
async def roleboard_channel(self, ctx, channel: discord.Channel=None): | ||
"""Set the roleboard for this server. | ||
@rolecall.command(pass_context=True, name="add", no_pm=True) | ||
async def rolecall_add(self, ctx, channel: discord.Channel, |
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.
anybody can use this command
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.
fixed with commit 2b9b585
rolecall/rolecall.py
Outdated
|
||
@commands.group(pass_context=True, no_pm=True) | ||
async def roleboard(self, ctx): | ||
"""change roleboard settings""" | ||
async def rolecall(self, ctx): |
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.
we should probably add more entry management before we publish.
doesn't need to be in-depth.
@jasperdanan also noticed #48 and #47 |
rolecall/rolecall.py
Outdated
@@ -52,7 +53,8 @@ def __init__(self, bot): | |||
|
|||
def _record_entry(self, entry: Entry): | |||
""" record entry to settings file """ | |||
|
|||
if type(entry.emoji) is discord.Emoji: |
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.
please use isinstance
instead
https://docs.quantifiedcode.com/python-anti-patterns/readability/do_not_compare_types_use_isinstance.html
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.
used isinstance
as of 707ad4b
…message content and they are mistaken to be arguments
…ole to two different emojis
message_id = entry.content_or_message_id | ||
keyring = self.settings[server_id][roleboard_id][message_id] | ||
for emoji,role in keyring.items(): | ||
if entry.role.id == role['ROLE_ID']: |
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.
do you make sure 1 role can only have 1 entry?
rolecall/rolecall.py
Outdated
|
||
# check if channel was mentioned | ||
if private_channel is None: | ||
pass | ||
else: |
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.
can we do if private_channel is not None: do_things()
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.
I think I prefer it this way instead of using double negatives that may be mildly confusing to some people, or to me when I'm sleepy :3
rolecall/rolecall.py
Outdated
@@ -333,7 +380,7 @@ def _get_object_by_name(self, otype, server, name, ignore_case=True): | |||
""" returns object if it exists, otherwise create the object """ | |||
if object_type == "role": # for roles | |||
role = discord.utils.get(server.roles, name=object_name) | |||
try: # try in case role = None | |||
try: # try in case role = None |
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.
ok?
please don't blindly commit ;)
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.
this is what fixed the spamming problem for me. lol jk
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.
fixed redundant indentation as of 37d82d4
rolecall/rolecall.py
Outdated
role_object = discord.utils.get(server.roles, id=potential_role_id) | ||
else: | ||
role_object = await self.get_or_create("role", role, server) |
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.
whhhhhat?
you're getting or creating a role, but then if it already exists, you're deleting the role and then trying to get it again?
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.
No. Check if the passed argument contains a role id(AKA a role mention) and if it does, delete the role that was created earlier and just get the role associated with the id found
…unctional since the bot would be powerless
…oid discrepancies
potential_role_id = nums_found[0] | ||
if potential_role_id in [r.id for r in server.roles]: | ||
role_object = discord.utils.get(server.roles, id=potential_role_id) | ||
|
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.
this doesn't return anything
Merge Rolecall v2 to master for publishing