def handle_message(self, msg, status): """Override this method to customize a handler. """ body = ensure_unicode(msg.Body) chat_id = get_chat_id(msg.Chat) if len(body) == 0: return False for name, cmd in self.commands.items(): if body == name: cmd(msg, chat_id) return True if self.troller_is_running.get(chat_id): response = self.alice.respond(body) if response: msg.Chat.SendMessage(response) return True else: return False else: return False
def handle_message(self, msg, status): """Override this method to customize a handler. """ # Skype API may give different encodings # on different platforms body = ensure_unicode(msg.Body) logger.debug("Tasks handler got: %s" % body) # Parse the chat message to commanding part and arguments words = body.split(" ") lower = body.lower() if len(words) == 0: return False # Parse argument for two part command names if len(words) >= 2: desc = " ".join(words[2:]) else: desc = None chat_id = get_chat_id(msg.Chat) # Check if we match any of our commands for name, cmd in self.commands.items(): if lower.startswith(name): cmd(msg, status, desc, chat_id) return True return False
def find_and_add(self, msg, uri): """ Find and add a history item. """ true_uri, title = self._get_uri_and_title(uri) logger.debug('Got {} (title: {})'.format(true_uri, title)) if not true_uri: return chat_id = get_chat_id(msg.Chat) history = self.histories.get(chat_id) if not history: history = utils.LastUpdatedOrderedDict() self.histories[chat_id] = history item = history.get(true_uri) if not item: self._add(history, true_uri, title, msg) return return self._match(item, msg, uri) and item
def threaded_run(): args.insert(0, unicode(self.path)) logger.debug("Running command line: %s" % " ".join(args)) env = os.environ.copy() env["SKYPE_USERNAME"] = username.encode("utf-8") env["SKYPE_FULLNAME"] = full_name.encode("utf-8") env["SKYPE_CHATNAME"] = chat_name.encode("utf-8") env["CHAT_ID"] = get_chat_id(msg.Chat) env["HTTP_HOST"] = settings.HTTP_HOST.encode("utf-8") env["HTTP_PORT"] = str(settings.HTTP_PORT).encode("utf-8") env["SHARED_SECRET"] = settings.SHARED_SECRET.encode("utf-8") env["SEVABOT_HOME"] = settings.SEVABOT_HOME.encode("utf-8") for i, server in enumerate(settings.QA_SERVERS): name = "QA_SERVER" + str(i) env[name] = server.encode("utf-8") env["VERSION_APPENDIX"] = settings.VERSION_APPENDIX.encode("utf-8") env["GIT_REPO"] = settings.GIT_REPO.encode("utf-8") process = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, shell=False, env=env) out = process.communicate()[0] # :E1103: *%s %r has no %r member (but some types could not be inferred)* # pylint: disable=E1103 return out.decode("utf-8")
def handle_message(self, msg, status): """ Print help text to chat. """ if status == 'SENT': return True body = ensure_unicode(msg.Body) lower = body.lower() words = re.split('(\s+|\n|,)', lower, flags=re.M) if len(words) < 2: return False if False==words[0].startswith(BOT_NAME): return False chat_id = get_chat_id(msg.Chat) # usrs = msg.Chat.Members # aUm = iter(usrs) # for i, x in enumerate(usrs): # msg.Chat.SendMessage(" - %s" % x.FullName) # Check if we match any of our commands for name, cmd in self.commands.items(): patern = re.compile(name) if patern.search(lower) != None: cmd(msg, chat_id) return True return False
def duarte_add(self, msg, status, args): chan = get_chat_id(msg.Chat) # Add if not there if not chan in self.channels: self.channels.append(chan) logger.info('[Duarte] Added new channel: '+ chan) return False
def cacheChats(self): """ Scan all chats on initial connect. """ logger.debug("Async cacheChats() -- this may take a while") self.chats = OrderedDict() # First get all fresh chats chats = [] for chat in self.skype.Chats: # filter chats older than 6 months if time.time() - chat.ActivityTimestamp > 3600 * 24 * 180: continue chats.append(chat) chats = sorted(chats, key=lambda c: c.ActivityTimestamp, reverse=True) for chat in chats: # Encode ids in b64 so they are easier to pass in URLs chat_id = get_chat_id(chat) self.chats[chat_id] = chat
def run(self, msg, args, callback): """ Run an external script asynchronously. Timeout with a message if the default threshold is reached. """ logger.debug("Executing module %s: %s" % (self.name, args)) # Not sure if this unicode on all platforms by default username = ensure_unicode(msg.Sender.Handle) full_name = ensure_unicode(msg.Sender.FullName) chat_name = ensure_unicode(msg.ChatName) chat_id = ensure_unicode(get_chat_id(msg.Chat)) #timeout(execute_module, name, args, callback, default=) def threaded_run(): args.insert(0, unicode(self.path)) logger.debug("Running command line: %s" % " ".join(args)) env = os.environ.copy() env["SKYPE_USERNAME"] = username.encode("utf-8") env["SKYPE_FULLNAME"] = full_name.encode("utf-8") env["SKYPE_CHATNAME"] = chat_name.encode("utf-8") env["SKYPE_CHATID"] = chat_id.encode("utf-8") process = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, shell=False, env=env) out = process.communicate()[0] # :E1103: *%s %r has no %r member (but some types could not be inferred)* # pylint: disable=E1103 return out.decode("utf-8") default = "Module %s timeouted in %d seconds" % (self.name, settings.TIMEOUT) thread = ExecutionManagedThread(threaded_run, default, settings.TIMEOUT, callback) thread.start()