Skip to content

Commit

Permalink
Merge eac498a into 641afb3
Browse files Browse the repository at this point in the history
  • Loading branch information
dynomite567 committed Oct 4, 2019
2 parents 641afb3 + eac498a commit d35e53b
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 1 deletion.
3 changes: 2 additions & 1 deletion pastepwn/actions/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
53 changes: 53 additions & 0 deletions pastepwn/actions/discordaction.py
Original file line number Diff line number Diff line change
@@ -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, token, channel, webhook=None, 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)
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
pymongo
mysql-connector-python
requests
discord.py

0 comments on commit d35e53b

Please sign in to comment.