示例#1
0
 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)
示例#2
0
 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
示例#3
0
 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
示例#4
0
 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")
示例#5
0
 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")
示例#6
0
 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)
示例#7
0
文件: user_tests.py 项目: PEZ/MooTalk
 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())
示例#8
0
文件: chat.py 项目: PEZ/MooTalk
 def users(self):
     return [User.user(p) for p in self.participants if User.user(p)]
示例#9
0
def get_chat_and_user(message):
    sender_address = message.sender.split('/')[0].lower()
    return get_chat(message), User.user(sender_address)
示例#10
0
def get_chat_and_user(message):
    sender_address = message.sender.split('/')[0].lower()
    return get_chat(message), User.user(sender_address)
示例#11
0
文件: chat.py 项目: PEZ/MooTalk
 def users(self):
     return [User.user(p) for p in self.participants if User.user(p)]