예제 #1
0
    def _export(self, message):
        """export [<alias name(s)] - exports all aliases - or the specified aliases - to paste.ee, \
        and returns a link"""
        if len(message.ParameterList) > 1:
            # filter the alias dictionary by the listed aliases
            params = [alias.lower() for alias in message.ParameterList[1:]]
            aliases = {
                alias: self.aliases[alias]
                for alias in self.aliases if alias in params
            }
            aliasHelp = {
                alias: self.aliasHelpDict[alias]
                for alias in self.aliasHelpDict if alias in params
            }

            if len(aliases) == 0:
                return IRCResponse(
                    ResponseType.Say,
                    u"I don't have any of the aliases listed for export",
                    message.ReplyTo)
        else:
            aliases = self.aliases
            aliasHelp = self.aliasHelpDict

            if len(aliases) == 0:
                return IRCResponse(ResponseType.Say,
                                   u"There are no aliases for me to export!",
                                   message.ReplyTo)

        addCommands = [
            u"{}alias add {} {}".format(self.bot.commandChar, name,
                                        u" ".join(command))
            for name, command in aliases.iteritems()
        ]
        helpCommands = [
            u"{}alias help {} {}".format(self.bot.commandChar, name, helpText)
            for name, helpText in aliasHelp.iteritems()
        ]

        export = u"{}\n\n{}".format(u"\n".join(sorted(addCommands)),
                                    u"\n".join(sorted(helpCommands)))

        url = WebUtils.pasteEE(
            export,
            u"Exported {} aliases for {}".format(self.bot.nickname,
                                                 cmdArgs.server), 60)
        return IRCResponse(
            ResponseType.Say,
            u"Exported {} aliases and {} help texts to {}".format(
                len(addCommands), len(helpCommands), url), message.ReplyTo)
예제 #2
0
    def execute(self, response):
        """
        @type response: IRCResponse
        """
        limit = 700  # chars
        expire = 10  # minutes
        if len(response.Response) > limit:
            replaced = WebUtils.pasteEE(
                response.Response,
                u'Response longer than {0} chars intended for {1}'.format(
                    limit, response.Target), expire)

            response.Response = u'Response too long, pasted here instead: {0} (Expires in {1} minutes)'.format(
                replaced, expire)
        return response
예제 #3
0
    def execute(self, response):
        """
        @type response: IRCResponse
        """
        limit = 700  # chars
        expire = 10  # minutes
        if len(response.Response) > limit:
            replaced = WebUtils.pasteEE(response.Response,
                                        u'Response longer than {0} chars intended for {1}'.format(limit,
                                                                                                  response.Target),
                                        expire)

            response.Response = u'Response too long, pasted here instead: {0} (Expires in {1} minutes)'.format(replaced,
                                                                                                               expire)
        return response
예제 #4
0
    def _export(self, message):
        """export [<alias name(s)] - exports all aliases - or the specified aliases - to paste.ee, \
        and returns a link"""
        if len(message.ParameterList) > 1:
            # filter the alias dictionary by the listed aliases
            params = [alias.lower() for alias in message.ParameterList[1:]]
            aliases = {alias: self.aliases[alias]
                       for alias in self.aliases
                       if alias in params}
            aliasHelp = {alias: self.aliasHelpDict[alias]
                         for alias in self.aliasHelpDict
                         if alias in params}

            if len(aliases) == 0:
                return IRCResponse(ResponseType.Say,
                                   u"I don't have any of the aliases listed for export",
                                   message.ReplyTo)
        else:
            aliases = self.aliases
            aliasHelp = self.aliasHelpDict

            if len(aliases) == 0:
                return IRCResponse(ResponseType.Say,
                                   u"There are no aliases for me to export!",
                                   message.ReplyTo)

        addCommands = [u"{}alias add {} {}".format(self.bot.commandChar,
                                                   name, u" ".join(command))
                       for name, command in aliases.iteritems()]
        helpCommands = [u"{}alias help {} {}".format(self.bot.commandChar,
                                                     name, helpText)
                        for name, helpText in aliasHelp.iteritems()]

        export = u"{}\n\n{}".format(u"\n".join(sorted(addCommands)),
                                    u"\n".join(sorted(helpCommands)))

        url = WebUtils.pasteEE(export,
                               u"Exported {} aliases for {}".format(self.bot.nickname, cmdArgs.server),
                               60)
        return IRCResponse(ResponseType.Say,
                           u"Exported {} aliases and {} help texts to {}".format(len(addCommands),
                                                                                 len(helpCommands),
                                                                                 url),
                           message.ReplyTo)