From 14a3c508c0ed5f5d8adab814d0bc75e74dcdc731 Mon Sep 17 00:00:00 2001 From: dynomite567 <17055345+dynomite567@users.noreply.github.com> Date: Thu, 3 Oct 2019 22:53:52 +0000 Subject: [PATCH 1/2] Added discordaction.py --- pastepwn/actions/discordaction.py | 53 +++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 pastepwn/actions/discordaction.py diff --git a/pastepwn/actions/discordaction.py b/pastepwn/actions/discordaction.py new file mode 100644 index 0000000..e2ec787 --- /dev/null +++ b/pastepwn/actions/discordaction.py @@ -0,0 +1,53 @@ +# -*- coding: utf-8 -*- +import logging +import re +import json +import discord +from string import Template + +from pastepwn.util import Request, DictWrapper +from .basicaction import BasicAction + + +class DiscordAction(BasicAction): + """Action to send a Discord message to a certain channel via a webhook""" + name = "DiscordAction" + + def __init__(self, webhook, token, channel, custom_payload=None, template=None): + super().__init__() + self.logger = logging.getLogger(__name__) + + self.webhook = webhook + self.token = token + self.channel = channel + self.custom_payload = custom_payload + if template is not None: + self.template = Template(template) + else: + self.template = None + + def perform(self, paste, analyzer_name=None): + """Send a message via a Discord bot or webhook to a specified channel, without checking for errors""" + r = Request() + if self.webhook is None: + client = discord.Client() + + @client.event + async def on_ready(): + msg = "New paste matched by analyzer '{0}' - Link: {1}".format(analyzer_name, paste.full_url) + channel = client.get_channel(self.channel) + await channel.send(msg) + await client.close() + + client.run(self.token) + else: + if self.template is None: + text = "New paste matched by analyzer '{0}' - Link: {1}".format(analyzer_name, paste.full_url) + else: + paste_dict = paste.to_dict() + paste_dict["analyzer_name"] = analyzer_name + text = self.template.safe_substitute(DictWrapper(paste_dict)) + + pasteJson = json.dumps( {"content":paste}) + + r.post(self.webhook, pasteJson) \ No newline at end of file From 2fa8f7f37195deddb9e2b101c3089acbe9aad252 Mon Sep 17 00:00:00 2001 From: dynomite567 <17055345+dynomite567@users.noreply.github.com> Date: Thu, 3 Oct 2019 22:54:46 +0000 Subject: [PATCH 2/2] Edited __init__.py and requirements.txt --- pastepwn/actions/__init__.py | 3 ++- requirements.txt | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/pastepwn/actions/__init__.py b/pastepwn/actions/__init__.py index da99b54..297d7bc 100644 --- a/pastepwn/actions/__init__.py +++ b/pastepwn/actions/__init__.py @@ -7,5 +7,6 @@ from .genericaction import GenericAction from .databaseaction import DatabaseAction from .savejsonaction import SaveJSONAction +from .discordaction import DiscordAction -__all__ = ('BasicAction', 'SaveFileAction', 'TelegramAction', 'LogAction', 'GenericAction', 'DatabaseAction', 'SaveJSONAction') +__all__ = ('BasicAction', 'SaveFileAction', 'TelegramAction', 'LogAction', 'GenericAction', 'DatabaseAction', 'SaveJSONAction', 'DiscordAction') diff --git a/requirements.txt b/requirements.txt index 15cbeaf..3865dcb 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,4 @@ pymongo mysql-connector-python requests +discord.py \ No newline at end of file