def who_command(self, message=None): if self.set_chat_and_user(message): arg = message.arg.strip() if arg in ["", "am i", "online"]: if arg == "am i": message.reply(messages.SYSTEM_MESSAGE % ("You are " + user_listing([self.sender]))) else: who = "\nOnline:\n" listeners = [ u for u in self.chat.listeners if xmpp.get_presence(u.address, message.to) ] who += user_listing(listeners) if arg != "online": offlines = [ u for u in self.chat.users if not xmpp.get_presence(u.address, message.to) ] who += "\n\nOffline:\n" who += user_listing(offlines) who += "\n\nOnline, but has muted this chat:\n" non_listeners = [ User.user(address) for address in self.chat.non_listeners if xmpp.get_presence(address, message.to) ] who += user_listing(non_listeners) message.reply(messages.SYSTEM_MESSAGE % who) else: message.reply(messages.HELP_MSG)
def set_chat_and_user(self, message): sender_address = message.sender.split('/')[0].lower() (self.chat, self.sender) = (get_chat(message), User.user(sender_address)) if user_in_chat(self.sender, self.chat): return True else: message.reply(messages.NO_ACCESS) logging.info("Denied access for address %s to chat %s" % (sender_address, self.chat)) return False
def pm_command(self, message=None): if self.set_chat_and_user(message): arg = message.arg.strip() space = arg.find(' ') to = arg[:space] msg = arg[space+1:] user = User.user(to) if user == None: user = User.user_from_nick(to) if user != None: xmpp.send_message(user.address, messages.PRIVATE_MESSAGE % (self.sender.nickname, msg), message.to) else: logging.info("Failed PM from '%s' to '%s' in channel '%s'." % (self.sender.nickname, to, self.chat)) message.reply(messages.SYSTEM_MESSAGE % "No such user")
def pm_command(self, message=None): if self.set_chat_and_user(message): arg = message.arg.strip() space = arg.find(' ') to = arg[:space] msg = arg[space + 1:] user = User.user(to) if user == None: user = User.user_from_nick(to) if user != None: xmpp.send_message( user.address, messages.PRIVATE_MESSAGE % (self.sender.nickname, msg), message.to) else: logging.info("Failed PM from '%s' to '%s' in channel '%s'." % (self.sender.nickname, to, self.chat)) message.reply(messages.SYSTEM_MESSAGE % "No such user")
def who_command(self, message=None): if self.set_chat_and_user(message): arg = message.arg.strip() if arg in ["", "am i", "online"]: if arg == "am i": message.reply(messages.SYSTEM_MESSAGE % ("You are " + user_listing([self.sender]))) else: who = "\nOnline:\n" listeners = [u for u in self.chat.listeners if xmpp.get_presence(u.address, message.to)] who += user_listing(listeners) if arg != "online": offlines = [u for u in self.chat.users if not xmpp.get_presence(u.address, message.to)] who += "\n\nOffline:\n" who += user_listing(offlines) who += "\n\nOnline, but has muted this chat:\n" non_listeners = [User.user(address) for address in self.chat.non_listeners if xmpp.get_presence(address, message.to)] who += user_listing(non_listeners) message.reply(messages.SYSTEM_MESSAGE % who) else: message.reply(messages.HELP_MSG)
def test_user_from_address(self): '''Get a user using the registered XMPP address''' self.assertEqual(self.user.key(), User.user(self.user.address).key())
def users(self): return [User.user(p) for p in self.participants if User.user(p)]
def get_chat_and_user(message): sender_address = message.sender.split('/')[0].lower() return get_chat(message), User.user(sender_address)