def ignore(self, bot, room, user, args): if len(args): reason = "Check your behavior." if len(args) > 1: reason = " ".join(args[1:]) victim = getUser(args[0]) if len(victim): victim = victim[0][0] if victim.get("banned", False): victim["banned"] = False db.users.update({"_id": victim["_id"]}, victim) return "{0} has been unbanned.".format(victim["nick"]) else: victim["banned"] = reason db.users.update({"_id": victim["_id"]}, victim) return "{0} has been banned.".format(victim["nick"]) else: return "Can't find a user by the name {0}".format(args[0]) else: banned = db.users.find({"banned": True}) outlist = ", ".join([u["nick"] for u in banned]) return "Banned Users: " + outlist
def remember(self, bot, room, user, args): if room is None: return "Can't remember private conversations!" if len(args) == 0: return "Remember what, exactly?" tuser = getUser(args[0], room) #print "tuser:"******" ".join(args[1:]) for u in tuser: query = {"user.id": u[0]["_id"], "room": room.info["_id"], "body": {"$regex": text, '$options': 'i'}, "command": False, 'date': {'$gt': datetime.datetime.now() - datetime.timedelta(hours=3)}} quote = db.db.history.find_one(query, sort=[("date", DESCENDING)]) print "query:", query #print "quote:", quote if quote: if quote['user']['id'] == user['_id']: return "Sorry, {0}, but you can't quote yourself! Try saying someone funnier and maybe someone else will remember you.".format(user['nick']) if "echo" in quote and quote['echo'] == True: return "Oh no! I have amnesia! I can't remember anything I've said!" if "remembered" in quote: return u"Sorry, {0}, I already knew about <{1}>: {2}".format(user["nick"], quote['user']["nick"], quote["body"]) else: quote["remembered"] = {"user": user["_id"], "nick": user["nick"], "time": datetime.datetime.now()} db.db.history.save(quote) return u"Ok, {0}, remembering <{1}>: {2}".format(user["nick"], quote['user']['nick'], quote["body"]) return "Sorry, {0}, I haven't heard anything like '{1}' by anyone named {2}.".format(user["nick"], text, args[0]) elif not tuser: return "Hrm, the name {0} doesn't ring any bells.".format(args[0]) else: return "Sorry, {0} isn't unique enough. Too many users matched!".format(args[0])
def sayQuotes(room, user, nick, segment, min=1, max=1): if max < min: max = min if max > 10: return "Too many, jerkwad!" query = {'remembered': {'$exists': True}} if nick is not None: nickq = {'user.nick': {'$regex': nick, '$options': 'i'}} ids = getUser(nick) if ids: idq = {'user.id': {'$in': map(lambda x: x[0]['_id'], ids)}} query['$or'] = [nickq, idq] else: query.update(nickq) if segment is not None: query['body'] = {'$regex': segment, '$options': 'i'} quotes = db.db.history.find(query) msg = None if quotes.count() == 0: msg = "I can't find any quotes" if nick is not None: msg += " for user {0}".format(nick) if segment is not None: msg += " with string '{0}'".format(segment) else: quotes = getSubset(quotes, min, max) lines = [] for quote in quotes: lines.append(u"<{0}>: {1}".format(quote['user']['nick'], quote['body'])) msg = '\n'.join(lines) return msg
def parseQuoteArgs(args, room): user = None segment = None min = None max = None if len(args) >= 3 and ((args[1] == "to") or (args[1] in [',','-',':'])): try: min = int(args[0]) max = int(args[2]) except: pass #f**k em. args = args[3:] elif len(args) > 0: try: spl = re.split("[,\-:]", args[0], 1) min = int(spl[0]) if len(spl) > 1: max = int(spl[1]) else: max = int(spl[0]) args = args[1:] except: pass #thats not a number. if len(args) > 0: if args[0] not in ['anyone', 'anybody', 'all', '*', '%']: tuser = getUser(args[0], room, special="quotes") if tuser: user = args[0] args = args[1:] else: args = args[1:] if len(args) > 0: segment = ' '.join(args) return user, segment, min, max