def on_privmsg(self, irc, prefix, params): user = prefix.split("!")[0] channel = params[0] msg = params[-1] m = re.findall("(https?://[^\s$]+)+", msg) if m: for url in m: u, created = URLLog.objects.get_or_create(url=url) if not u.first_nick: u.first_nick = user u.last_nick = user u.last_post = datetime.datetime.now() if u.counter > 0: irc.msg( channel, "OLD! This url was first posted {} ago by {} (Times posted: {})".format( timesince(u.first_post), u.first_nick, u.counter ), ) u.counter += 1 u.save()
def random_url(self): u = URLLog.objects.all() u = u[random.randint(0, u.count() - 1)] msg = "{url} first posted {time} ago by {nick} (Times posted: {count})".format( url=u.url, time=timesince(u.first_post), nick=u.first_nick, count=u.counter ) irc.msg(channel, msg)
def status(irc, source, msgtarget, args): size = subprocess.getoutput("ps -p $$ h -o size").strip() time = subprocess.getoutput("ps -p $$ h -o time").strip() up = irc.started rx = int(math.log(irc.rx,2)/10.0) tx = int(math.log(irc.tx,2)/10.0) formats = ["bytes", "KiB", "MiB", "GiB", "TiB"] txn = int(irc.tx / (1024 ** tx)) rxn = int(irc.rx / (1024 ** rx)) irc.msg(msgtarget, "This bot has been running for {}, is using {}KB of RAM, has used {} of CPU time, has sent {}{} of data, and received {}{} of data.".format( timesince(up), size, time, txn, formats[tx], rxn, formats[rx]))
def status(irc, source, msgtarget, args): size = subprocess.getoutput("ps -p $$ h -o size").strip() time = subprocess.getoutput("ps -p $$ h -o time").strip() up = irc.started rx = int(math.log(irc.rx, 2) / 10.0) tx = int(math.log(irc.tx, 2) / 10.0) formats = ["bytes", "KiB", "MiB", "GiB", "TiB"] txn = int(irc.tx / (1024**tx)) rxn = int(irc.rx / (1024**rx)) irc.msg( msgtarget, "This bot has been running for {}, is using {}KB of RAM, has used {} of CPU time, has sent {}{} of data, and received {}{} of data." .format(timesince(up), size, time, txn, formats[tx], rxn, formats[rx]))
def seen(irc, source, msgtarget, args): nick = args.split()[0] try: for nicks in irc.nicks.keys(): if nick.lower() == nicks.lower(): n = irc.nicks[nicks]["lastaction"] break try: #s = irc.nicks[nick]["lastaction"] s = n n = irc.nicks[nick] if s["chan"] == nick: return if s["action"] == "PRIVMSG": irc.msg(msgtarget, "{} ({}@{}) was last seen saying \"{}\" about {} ago in {}".format( nick, n["ident"], n["host"], s["args"].replace("", ""), timesince(s["time"]), s["chan"])) elif s["action"] == "JOIN": irc.msg(msgtarget, "{} ({}@{}) was seen joining {} about {} ago".format( nick, n["ident"], n["host"], s["chan"], timesince(s["time"]))) elif s["action"] == "PART": irc.msg(msgtarget, "{} ({}@{}) was seen parting {} about {} ago ({})".format( nick, n["ident"], n["host"], s["chan"], timesince(s["time"]), s["args"] or "")) elif s["action"] == "QUIT": irc.msg(msgtarget, "{} ({}@{}) was seen quitting about {} ago ({})".format( nick, n["ident"], n["host"], timesince(s["time"]), s["args"])) elif s["action"] == "KICK": irc.msg(msgtarget, "{} ({}@{}) was last seen kicked from {} about {} ago ({})".format( nick, n["ident"], n["host"], s["chan"], timesince(s["time"]), s["args"] )) except: if nick == irc.nick: irc.msg(msgtarget, "I'm right here!") else: irc.msg(msgtarget, "I don't know who that is") except KeyError: irc.msg(msgtarget, "I don't know who that is")
def FriendsActivityListView(request, username): activities = FriendsActivity.objects.all().order_by('-timestamp') activity_list = [] for activity in activities: activity_obj = {} activity_obj['type'] = activity.activity_type activity_obj['timestamp'] = timesince(activity.timestamp) if activity.actor: activity_obj['actor'] = activity.actor.name activity_obj['actor_id'] = activity.actor.id activity_obj['actor_photo'] = activity.actor.photo if activity.friend: activity_obj['friend'] = activity.friend.name activity_obj['friend_id'] = activity.friend.id activity_obj['friend_photo'] = activity.friend.photo if activity.restaurant: activity_obj['restaurant'] = activity.restaurant.name activity_obj['restaurant_id'] = activity.restaurant.id activity_obj['restaurant_photo'] = activity.restaurant.photo if activity.review: activity_obj['actor'] = activity.review.user.name activity_obj['actor_id'] = activity.review.user.id activity_obj['actor_photo'] = activity.review.user.photo activity_obj['restaurant'] = activity.review.restaurant.name activity_obj['restaurant_id'] = activity.review.restaurant.id activity_obj['restaurant_photo'] = activity.review.restaurant.photo activity_obj['review_id'] = activity.review.id activity_obj['photo'] = activity.review.photo activity_obj['rating'] = activity.review.rating if activity_obj['type'] == "achievement": activity_obj['foods'] = [{'food_photo': food.photo, 'food_id': food.id} for food in activity.actor.foods_liked.all()[:7]] activity_list.append(activity_obj) return HttpResponse(json.dumps(activity_list), content_type="application/json")
def __init__(self, verb, sub=None, obj=None, oth=None, date=None): super(Action, self).__init__() if date is None: date = datetime.utcnow() elif type(date) != datetime: date = datetime(date) self.verb = verb self.subject = sub self.obj = obj self.other = oth self.date = date self.description = u'%s did %s to %s %s%s%s ago' % ( self.subject, self.verb, self.obj, u"(%s) " % (self.other,) if self.other else '', u"at %s, " % (self.subject.whereami(),) if hasattr(self.subject, 'whereami') else '', timesince(self.date) )