Пример #1
0
 def upload_file(self, fname, fpath, initial_comment=''):
     self._client.upload_file(
         self._body['id'],
         to_utf8(fname),
         to_utf8(fpath),
         to_utf8(initial_comment)
     )
Пример #2
0
 def upload_file(self, fname, fpath, initial_comment=''):
     self._client.upload_file(
         self._body['id'],
         to_utf8(fname),
         to_utf8(fpath),
         to_utf8(initial_comment)
     )
Пример #3
0
 def upload_content(self, fname, content, initial_comment=''):
     self._client.upload_content(
         self._body['id'],
         to_utf8(fname),
         to_utf8(content),
         to_utf8(initial_comment)
     )
Пример #4
0
 def _not_in_username_reply(self, username, msg):
     msg_reply = [
         u'`I am sorry "%s", I am not permitted to talk with you`' %
         username
     ]
     self._client.rtm_send_message(msg['channel'],
                                   '\n'.join(to_utf8(msg_reply)))
Пример #5
0
    def _default_reply(self, msg):
        default_reply = [
            u'`Unrecognized command "%s", Type Help for Help`' % msg['text']
        ]

        self._client.rtm_send_message(msg['channel'],
                                     '\n'.join(to_utf8(default_reply)))
Пример #6
0
    def _default_reply(self, msg):
        default_reply = [
            u'`Unrecognized command "%s", Type Help for Help`' % msg['text']
        ]

        self._client.rtm_send_message(msg['channel'],
                                      '\n'.join(to_utf8(default_reply)))
Пример #7
0
    def send(self, text):
        """
            Send a reply using RTM API

            (This function doesn't supports formatted message
            when using a bot integration)
        """
        self._client.rtm_send_message(self._body['channel'], to_utf8(text))
Пример #8
0
 def upload_file(self, channel, fname, fpath, comment, thread_ts=None):
     channel = self._channelify(channel)
     fname = fname or to_utf8(os.path.basename(fpath))
     return self.webapi.files.upload(fpath,
                                     channels=channel,
                                     filename=fname,
                                     initial_comment=comment,
                                     thread_ts=thread_ts)
Пример #9
0
    def send(self, text):
        """
            Send a reply using RTM API

            (This function doesn't supports formatted message
            when using a bot integration)
        """
        self._client.rtm_send_message(self._body['channel'], to_utf8(text))
Пример #10
0
    def _default_reply(self, msg):
        default_reply = [
            u'Bad command "%s", You can ask me one of the following questions:\n' % msg['text'],
        ]
        default_reply += [u'    • `%s`' % str(p.pattern) for p in self._plugins.commands['respond_to'].iterkeys()]

        self._client.rtm_send_message(msg['channel'],
                                     '\n'.join(to_utf8(default_reply)))
Пример #11
0
    def _default_reply(self, msg):
        default_reply = [
            u'Bad command "%s", You can ask me one of the following questions:\n' % msg['text'],
        ]
        default_reply += [u'    • `{}`'.format(p.pattern) for p in self._plugins.commands['respond_to'].iterkeys()]

        self._client.rtm_send_message(msg['channel'],
                                     '\n'.join(to_utf8(default_reply)))
Пример #12
0
    def send_webapi(self, text, attachments=None):
        """
            Send a reply using Web API

            (This function supports formatted message
            when using a bot integration)
        """
        self._client.send_message(
            self._body['channel'], to_utf8(text), attachments=attachments)
Пример #13
0
 def _default_reply(self, msg):
     if 'text' in msg:
         logger.info("Responding to unrecogized command '%s'" % msg['text'])
         #default_reply = [
         #u'Bad command "%s", You can ask me one of the following questions:\n' % msg['text'],
         #]
         #default_reply += [u'    • `{}`'.format(p.pattern) for p in self._plugins.commands['respond_to'].iterkeys()]
     default_reply = "Oops, I'm not set up to answer that"
     self._client.rtm_send_message(msg['channel'], to_utf8(default_reply))
Пример #14
0
 def _default_reply(self, msg):
   if 'text' in msg:
     logger.info("Responding to unrecogized command '%s'" %msg['text'])
     #default_reply = [
         #u'Bad command "%s", You can ask me one of the following questions:\n' % msg['text'],
     #]
     #default_reply += [u'    • `{}`'.format(p.pattern) for p in self._plugins.commands['respond_to'].iterkeys()]
   default_reply = "Oops, I'm not set up to answer that"
   self._client.rtm_send_message(msg['channel'], to_utf8(default_reply))
Пример #15
0
 def _default_reply(self, msg):
     default_reply = [
         u'Bad command "%s", You can ask me one of the following questions:\n' % msg['text'],
     ]
     default_reply += [u'    • `{0}` {1}'.format(p.pattern, v.__doc__ or "")
                       for p, v in iteritems(self._plugins.commands['respond_to'])]
         
     self._client.rtm_send_message(msg['channel'],
                                   '\n'.join(to_utf8(default_reply)))
Пример #16
0
    def get_plugins(self, category, text):
        has_matching_plugin = False
        for matcher in self.commands[category]:
            m = matcher.search(text)
            if m:
                has_matching_plugin = True
                yield self.commands[category][matcher], to_utf8(m.groups())

        if not has_matching_plugin:
            yield None, None
Пример #17
0
    def send_webapi(self, text, attachments=None):
        """
            Send a reply using Web API

            (This function supports formatted message
            when using a bot integration)
        """
        self._client.send_message(self._body['channel'],
                                  to_utf8(text),
                                  attachments=attachments)
Пример #18
0
    def reply_upload_file(self, fname, fpath, initial_comment='', in_thread=None):
        """
            Upload the file and send it as a reply
            If the message was send in a thread, answer in a thread per default.
        """
        if in_thread is None:
            in_thread = 'thread_ts' in self.body

        if in_thread:
            thread_ts = self.thread_ts
        else:
            thread_ts = None
        self._client.upload_file(
            self._body['channel'],
            to_utf8(fname),
            to_utf8(fpath),
            to_utf8(initial_comment),
            thread_ts=thread_ts
        )
Пример #19
0
    def get_plugins(self, category, text):
        has_matching_plugin = False
        for matcher in self.commands[category]:
            m = matcher.search(text)
            if m:
                has_matching_plugin = True
                yield self.commands[category][matcher], to_utf8(m.groups())

        if not has_matching_plugin:
            yield None, None
Пример #20
0
    def _default_reply(self, msg):
        default_reply = [
            u'Bad command "%s", You can ask me one of the following questsion:\n'
            % msg['text'],
        ]
        default_reply += [
            u'    • %s' % str(f.__name__)
            for f in self._plugins.commands.itervalues()
        ]

        self._client.rtm_send_message(msg['channel'],
                                      '\n'.join(to_utf8(default_reply)))
Пример #21
0
    def _default_reply(self, msg):
        default_reply = [
            u"That doesn't make sense to me. But, then again, you are very small. \n "
            u'You can ask me one of the following questions:\n',
        ]
        default_reply += [u'    • `{0}` {1}'.format(p.pattern, v.__doc__ or "")
                          for p, v in iteritems(self._plugins.commands['respond_to'])]

        self._client.rtm_send_message(
            msg['channel'],
            '\n'.join(to_utf8(default_reply))
        )
Пример #22
0
def help_commands(message):
    if message.is_approved("any"):
        coms = PluginsManager.commands['respond_to']
        default_reply = [
            'You can ask me one of the following questions:\n',
        ]
        default_reply += ['{0} {1}'.format(p[1]
                                                   , v.__doc__ or "")
                          for p, v in iteritems(coms)]

        default_reply = '\n'.join(to_utf8(default_reply))
        message.upload_snippet(str(default_reply), "Commands")
Пример #23
0
 def upload_file(self, channel, fname, fpath, comment):
     fname = fname or to_utf8(os.path.basename(fpath))
     self.webapi.files.upload(fpath,
                              channels=channel,
                              filename=fname,
                              initial_comment=comment)
Пример #24
0
 def _default_reply(self, msg):
     self._client.rtm_send_message(msg['channel'], to_utf8(HELP))
Пример #25
0
 def get_plugin(self, text):
     for matcher in self.commands:
         m = matcher.match(text)
         if m:
             return self.commands[matcher], to_utf8(m.groups())
     return None, None
Пример #26
0
 def upload_file(self, channel, fname, fpath, comment):
     fname = fname or to_utf8(os.path.basename(fpath))
     self.webapi.files.upload(fpath,
                              channels=channel,
                              filename=fname,
                              initial_comment=comment)
Пример #27
0
 def reply(self, text):
     chan = self._body['channel']
     if chan.startswith('C') or chan.startswith('G'):
         text = self._gen_at_message(text)
     self._client.rtm_send_message(
         self._body['channel'], to_utf8(text))
Пример #28
0
 def _not_in_username_reply(self,username,msg):
     msg_reply = [
       u'`I am sorry "%s", I am not permitted to talk with you`' %username
     ]
     self._client.rtm_send_message(msg['channel'],'\n'.join(to_utf8(msg_reply)))
Пример #29
0
 def reply(self, text):
     chan = self._body['channel']
     if chan.startswith('C'):
         text = self._gen_at_message(text)
     self._client.rtm_send_message(self._body['channel'], to_utf8(text))