How to use the pastepwn.util.DictWrapper function in pastepwn

To help you get started, we’ve selected a few pastepwn examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github d-Rickyy-b / pastepwn / pastepwn / actions / discordaction.py View on Github external
def perform(self, paste, analyzer_name=None, matches=None):
        """Send a message via Discord to a specified channel, without checking for errors"""
        r = Request()
        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))

        if self.webhook is not None:
            # Send to a webhook (no authentication)
            url = self.webhook
        else:
            # Send through Discord bot API (header-based authentication)
            url = 'https://discordapp.com/api/channels/{0}/messages'.format(self.channel_id)
            r.headers = {'Authorization': 'Bot {}'.format(self.token)}

        res = r.post(url, {"content": text})
        if res == "":
            # If the response is empty, skip further execution
            return

        res = json.loads(res)
github d-Rickyy-b / pastepwn / pastepwn / util / templatingengine.py View on Github external
Returns a templated text with paste contents inserted into the template string
        Use ${key_name} in the template_string to insert paste contents into it
        :param paste: A paste which serves as the source for template filling
        :param analyzer_name: Name of the analyzer
        :param template_string: A template string describing how the variables should be filled in
        :return: Filled template
        """
        paste_dict = paste.to_dict()
        paste_dict["analyzer_name"] = analyzer_name

        # Fallback if the template string is empty or non existent
        if template_string is None or template_string == "":
            template_string = "New paste matched by analyzer '${analyzer_name}' - Link: ${full_url}"

        template = Template(template_string)
        text = template.safe_substitute(DictWrapper(paste_dict))
        return text