-
Notifications
You must be signed in to change notification settings - Fork 66
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 action (webhook or bot token) #111
Add Discord action (webhook or bot token) #111
Conversation
create discordaction with webhook
Alternative to webhook-based actions, requires a bot token and channel ID in `__init__` parameters.
Pull Request Test Coverage Report for Build 160
💛 - Coveralls |
Looking at this, it implements a Discord bot way better and efficiently than my PR, #86, with no new dependencies at all. Good stuff! |
self.webhook = webhook | ||
if webhook is None: | ||
if token is None or channel_id is None: | ||
raise ValueError('Invalid arguments: requires either webhook or token+channel_id arguments') |
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.
👏 very nice
else: | ||
paste_dict = paste.to_dict() | ||
paste_dict["analyzer_name"] = analyzer_name | ||
text = self.template.safe_substitute(DictWrapper(paste_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.
I created a much better way on how to use templates in the most recent master branch. But no worries, I will fix this later on :)
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 belive this is Mxrk's work, inspired from TelegramAction
source code, so make the change there too :)
Tested webhook from @Mxrk and it works perfectly! But sadly I can't manage to get the bot part working. You write that you have not used "fresh" tokens, which means that you had a bot which connected via a library first and then you used that token? |
Yes, as someone in the gist you linked yesterday mentioned, some initialization might be required. I will try to generate some tokens for myself and try again, if I get it to work I will add the gateway ping in |
@Zeroji That would be epic. Maybe also check the status code returned from the post method and do a gateway ping again. |
@d-Rickyy-b I'll have to check status codes because apparently this is a "happens occasionally at random intervals" kind of thing. I can reproduce the issue with fresh tokens, unfortunately I can't establish a Gateway connection without adding websockets. I'll give this a small hour, and drop it if I can't put something together - the alternative will be to run the token through any "proper" discord lib at least once. EDIT: I don't want to hurt the compat - I believe current is 3.4+? |
Uses websockets to open a connection to Discord's Gateway, then sends the proper identification payload so that further requests are authorized. This code runs only if sending messages fails with code 40001.
Very nice!! Thanks for all the effort. ❤️ Sadly pastepwn is a multithreaded application and hence it runs into an error regarding a missing event loop.
So I just added loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop) And it seems to work just fine 🎉 . I am not sure what kind of side effects this brings in. Thank you so much. Gonna merge this. |
This includes commits from #85 which hasn't been merged yet.
Fixes #83 and expands on #85 by enabling users to have a
DiscordAction
with a custom bot token and channel ID, instead of just a webhook.Both ways work just fine on my machine, but I haven't tried using fresh tokens, let me know if you encounter authentication issues.