-
-
Notifications
You must be signed in to change notification settings - Fork 306
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
Add discord notifications #107
base: develop
Are you sure you want to change the base?
Add discord notifications #107
Conversation
I think at this point we should refactor this somehow. |
also the package needs to be added to the requirements.txt, otherwise people will get errors when trying to use the bot. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
@@ -0,0 +1,42 @@ | |||
import logging | |||
from discordwebhook import Discord |
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.
Add package to requirements.txt
try: | ||
auth = yaml.load(file, Loader=yaml.FullLoader) | ||
discord_webhook_url = str(auth['discord_webhook_url']) | ||
valid_auth = True |
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.
module/class "private" variables should be marked with an underscore
_valid_auth
and _discord_webhook_url
|
||
config = load_config('config.yml') | ||
|
||
with open('auth/auth.yml') as file: |
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 whole block should be part of the DiscordHandler class.
I would suggest an init()
method to handle this initialization (not the constructor because its bad practice to handle File/IO stuff there IMO).
key = getattr(record, 'DISCORD') | ||
|
||
# unknown message key | ||
if not key in config['DISCORD']['NOTIFICATIONS']: |
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.
if not key in config['DISCORD']['NOTIFICATIONS']: | |
if key not in config['DISCORD']['NOTIFICATIONS']: |
@@ -30,6 +31,11 @@ | |||
except KeyError: | |||
pass | |||
|
|||
try: | |||
log_discord = config['DISCORD']['ENABLED'] |
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.
log_discord
should get initialized to false in the beginning (similar to log_to_console
), otherwise you will get an NameError if the value does not exist in the config.yaml file, as soon as you try to access it in the if-statement below
New feature to add Discord notifications (same way as the already implemented msgs to Telegram)
The user needs to provide the Discord's webhook url