def thread(self, user, args): statuses = {"admins": [], "online": [], "offline": [], "away": [], "idle": [], "busy": []} for sid in self.parent.getRoster(): i = utils.getjid(sid) name = utils.getnickname(i) if name == iMan.config.server.username: continue if not utils.isonline(self.parent, sid): # statuses['offline'].append('(%s)' % name) continue jid_status = self.parent.getJidStatus(sid) for who, (status, display) in jid_status.iteritems(): if "@" not in unicode(who): continue if utils.isbanned(who): name = "#%s" % name continue if utils.isactive(self.parent, who): if utils.isadmin(who): name = "@%s" % name # statuses['admins'].append(name) elif utils.ismod(who): name = "%" + "%s" % name # statuses['admins'].append(name) statuses["online"].append(name) break # Anyone not "available". elif utils.isaway(self.parent, who): if status in [u"away", u"xa"]: name = "-%s" % name statuses["idle"].append(name) elif status == u"dnd": name = "!%s" % name statuses["busy"].append(name) break # Setup the header with a header for total number of users. reply = "Users (%s):\n" total = 0 for status, users in statuses.iteritems(): if not users: continue reply += "%s (%s): %s\n" % (status, len(users), " ".join(users)) total += len(users) # Tack on the total number of users. reply = reply % total self.parent.sendto(user, reply)
def thread(self, user, args, whisper): if not args: raise const.CommandHelp args = args.split(' ', 1) cmd, message = args[0], args[1:] cmd = cmd.lower() username = utils.getname(user).lower() if cmd == 'get': if username in iMan.mail: letters = iMan.mail[username].items() # Only take the top letter. sender, message = letters[0] self.parent.sendto(user, "%s says '%s'" % (sender, message)) self.parent.sendto( user, "You have %s more letter%s." % ((len(letters) - 1) or 'no', ((len(letters) - 1) != 1 and 's') or '' ) ) del iMan.mail[username][sender] if not iMan.mail[username]: del iMan.mail[username] else: self.parent.sendto(user, "I have no letters for you.") elif cmd == 'check': letters = len(iMan.mail.get(username, [])) self.parent.sendto( user, 'I have %s letter%s for you.' % ( letters or 'no', (letters != 1 and 's') or '' ) ) else: if not message: raise const.CommandHelp, "Missing message" target = cmd.lower() if target == iMan.config.server.displayname.lower(): self.parent.sendto(user, "Why do you need to send me mail?") return elif target not in iMan.roster: self.parent.sendto(user, "I don't know %s and, therefore, " "can't send him a letter." % cmd) else: iMan.mail[target][utils.getname(user)] = ' '.join(message) target_jid = utils.getjid(target) if self.parent.was_whispered and \ utils.isonline(self.parent, target_jid): self.parent.sendto(target_jid, '%s has mailed you a message. ' 'Please use "/w iPal !mail get" to ' 'retrive it.' % utils.getname(user)) self.parent.sendto(user, "I've notified %s about your " "message." % target) else: self.parent.sendto(user, "I have mailed your message to %s. " "He will notified it when he logs in." % cmd) iMan.mail.save()