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) )
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) )
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)))
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)))
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))
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)
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)))
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)))
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)
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))
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))
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)))
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
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)
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 )
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)))
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)) )
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")
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)
def _default_reply(self, msg): self._client.rtm_send_message(msg['channel'], to_utf8(HELP))
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
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))
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)))
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))