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

Logging to Discord channel #29

Merged
merged 16 commits into from
Jul 7, 2023
Merged

Logging to Discord channel #29

merged 16 commits into from
Jul 7, 2023

Conversation

Cheukting
Copy link
Contributor

part of #18 and #14 - only about logging successful registration and failed registration into dedicated Discord channel

Copy link
Contributor

@Kislovskiy Kislovskiy left a comment

Choose a reason for hiding this comment

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

Thank you @Cheukting
I have a few comments

pass


class AlreadyRegisteredError(BotError):
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe we can consider putting a bit more information for the error message here. Currently it's called in one place here:

def validate_key(key: str) -> bool:
if key in REGISTERED_SET:
raise AlreadyRegisteredError("Ticket already registered")
return True

and I think by adding:

class AlreadyRegisteredError(BotError):
    """Exception raised for registering a registered ticket."""
    def __init__(self, key, message="Ticket is already registered."):
        self.ticket_id = key
        self.message = message + f" Key: {self.key}"
        super().__init__(self.message)

we can add more debugger friendly error message like:

❌ : artem.kislovskiy encounter an error - AlreadyRegisteredError: Ticket already registered Ticket id: G0CFM-raquelindividual

However, we can find a better name for the key variable

Copy link
Contributor

Choose a reason for hiding this comment

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

another thought, maybe we can explicitly add a timestamp in the beginning of the error message, that way I know for sure when a certain event happened.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

RE: the code snippet works fine, thanks, I will add that. RE: the timestamp, I don't think it is needed as discord will log the time when receiving the message

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I will just modify the message that got passed in for now, do not see the point of holding the id in the Exception object for now, if needed in the future we can refactor

pass


class NotFoundError(BotError):
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm changing the logic to validate the ticket on Pretix. And I'll update this class there, not sure what would be the best error message here at the moment

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You can add as many errors as you like, they are all in the error.py

if error is None:
content = f"✅ : `{user_name}` registered as {[role.name for role in user.roles[1:]]}"
else:
content = f"❌ : `{user_name}` encounter an error - {error.__class__.__name__}: {error}"
Copy link
Contributor

Choose a reason for hiding this comment

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

I would maybe put \n instead of - if possible

❌ : artem.kislovskiy encounter an error
AlreadyRegisteredError: Ticket already registered Ticket id: G0CFM-raquelindividual

And maybe used smth like this:

❌ ERROR: user_name=artem.kislovskiy
AlreadyRegisteredError: Ticket already registered Ticket id: G0CFM-raquelindividual

But I'm totally fine to keep it as it is

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it's ok, just formatting things, I will add that (and an empty line if we do it with a multiline display) - I do not like the user_name= I am thinking if someone said they have a problem and you ask them the name, you just to though the message and seek for that name anyway, no need to make it more "code like"

user_name = user.name

if error is None:
content = f"✅ : `{user_name}` registered as {[role.name for role in user.roles[1:]]}"
Copy link
Contributor

Choose a reason for hiding this comment

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

What about we use the same pattern as in error, like:

✅ SUCCESS: user_name=artem.kislovskiy roles=['Speakers', 'Attendees', 'online_role', 'inperson_role', 'new role', 'Ops', 'Admin']

BTW, do you know why we are ignoring the very first roleuser.roles[1:]?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

RE: same reason as above, I prefer it to look more like a communication rather than code, for skipping the 1st role, it is @everyone and it is not needed - everyone gets them

@Cheukting
Copy link
Contributor Author

Ready to merge @Kislovskiy

@Cheukting Cheukting merged commit 467c520 into main Jul 7, 2023
2 checks passed
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.

None yet

2 participants