-
Notifications
You must be signed in to change notification settings - Fork 201
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
Identify #101
Conversation
tle/cogs/handles.py
Outdated
@@ -128,6 +129,7 @@ def _make_pages(users): | |||
class Handles(commands.Cog): | |||
def __init__(self, bot): | |||
self.bot = bot | |||
self.identify_map = dict() |
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.
Style-wise {}
is nicer.
users = await cf.user.info(handles=[handle]) | ||
user = users[0] | ||
await self._set(ctx, member, users[0]) |
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 this a typical case where you would write a decorator, but this is fine.
users = await cf.user.info(handles=[handle]) | ||
await self._set(ctx, ctx.author, users[0]) | ||
else: | ||
await ctx.send(f'Sorry `{invoker}`, can you try 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.
General note: We probably should write a function that escapes usernames so we actually print the correct thing. Something that prepends *_`
with a backslash would do the job.
tle/cogs/handles.py
Outdated
|
||
invoker = str(ctx.author) | ||
problem = random.choice(cf_common.cache2.problem_cache.problems) | ||
handle, name, url = (users[0].handle, problem.name, problem.url) |
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 feels a bit superfluous considering most of these are just used once. Just write them in-place, the names are obvious enough and not too long.
tle/cogs/handles.py
Outdated
handle, prob, url = self.identify_map[invoker] | ||
subs = await cf.user.status(handle=handle, count=5) | ||
if any(sub.problem.name == prob and sub.verdict == 'COMPILATION_ERROR' for sub in subs): | ||
self.identify_map.pop(invoker) |
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.
The general wisdom for removing things from dicts in python is to use value = D.pop(key)
if you want to capture the value, otherwise just do del D[key]
.
tle/cogs/handles.py
Outdated
invoker = str(ctx.author) | ||
problem = random.choice(cf_common.cache2.problem_cache.problems) | ||
handle, name, url = (users[0].handle, problem.name, problem.url) | ||
self.identify_map[invoker] = (handle, name, url) |
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 need to store the url? It's not used for anything right now afaik.
@@ -163,6 +168,35 @@ def __init__(self, bot): | |||
raise HandleCogError(f'Role for rank `{user.rank.title}` not present in the server') | |||
await self.update_member_rank_role(member, roles[0]) | |||
|
|||
@handle.command(brief='Identify yourself') | |||
async def identify(self, ctx, handle: str): |
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.
Docstring and usage?
No description provided.