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

Identify #101

Merged
merged 5 commits into from
Aug 11, 2019
Merged

Identify #101

merged 5 commits into from
Aug 11, 2019

Conversation

krofna
Copy link
Collaborator

@krofna krofna commented Aug 5, 2019

No description provided.

@@ -128,6 +129,7 @@ def _make_pages(users):
class Handles(commands.Cog):
def __init__(self, bot):
self.bot = bot
self.identify_map = dict()
Copy link
Collaborator

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])
Copy link
Collaborator

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?')
Copy link
Collaborator

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.


invoker = str(ctx.author)
problem = random.choice(cf_common.cache2.problem_cache.problems)
handle, name, url = (users[0].handle, problem.name, problem.url)
Copy link
Collaborator

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.

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)
Copy link
Collaborator

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].

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)
Copy link
Collaborator

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):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Docstring and usage?

@algmyr algmyr merged commit 39022e4 into master Aug 11, 2019
@krofna krofna deleted the identify branch August 18, 2019 21:05
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.

2 participants