import random from datetime import datetime from common import queries from common import userstatus class Protectees(): def update(self, nick, user, host): if nick in self.protectees: # On record. if userstatus.atleast_halfop(self, user, self.homechannel) or nick == self.connection.get_nickname(): # Update. Is atleast halfop or bot itself. self.protectees[nick].update({'ident': nick + "!" + user + "@" + host}) else: # Delete. del self.protectees[nick] else: # Append. if userstatus.atleast_halfop(self, user, self.homechannel) or nick == self.connection.get_nickname(): # Update. Is atleast halfop or bot itself. self.protectees[nick] = {'ident': nick + "!" + user + "@" + host} class Replyto(): def name(connection, event): messages = [ "Hello " + event.source.nick + ".", "How are you today " + event.source.nick + "?", "Piss off " + event.source.nick + "!", event.source.nick + ", what are you botherring me for?", "Go bother someone else...", "Is life treating you fair?", "What's up?", "Why are you talking to me?", "I'm not talking to you!", "What have you been up to?", "How is life?", "What do you want from me?", event.source.nick + ", why are you bothering me?", event.source.nick + ", when will you stop talking about me?", event.source.nick + " I hate you!", "Get bent!", "Go and cut yourself.", "Do you think i care about you?", "Stop nickalerting me " + event.source.nick + ", you wanker!", ] actions = [ "hides!", "dies.", "runs away.", "is ignoring that.", "is not feeling like caring.", "is away", "will be ignoring that.", "is faggaliciouz!! <333", "likes you! <3", "looks the other way...", "does a little dance with " + event.source.nick + ".", "makes a little love.", "get's down tonight.", "thinks SAM Broadcaster sucks raw cocks in hell!", "is secretly in love with " + event.source.nick + ".", "tosses " + event.source.nick + "'s salad.", "tortures " + event.source.nick + " horribly!", "is smelling like tuna when looking at " + event.source.nick + ".", "sniffing armpits.. Eew! Smells like " + event.source.nick + ".", "rapes " + event.source.nick + ".", ] # Reply with a random message or action. if random.randint(0, 1) == 0: connection.privmsg(event.target, random.choice(messages)) else: connection.action(event.target, random.choice(actions)) class Aggressiveness(): def retalliation_reason(self, connection, protectee, behaviour): if protectee == connection.get_nickname(): # Bot itself. return "Aggression channel function = " + behaviour + ": Self defense." else: return "Aggression channel function = " + behaviour + ": " + protectee + " is atlast halfop in " + self.homechannel + "." class Lastact(): def update(self, name, type, channel=False, lastact=False, auxiliary=False): # Create records if not present. queries.create_ifnot_onrecord(self, name) # Update record. fields = "last_act_type, last_act_datetime, last_act_channel, last_act, last_act_auxiliary" values = "'" + type + "', '" + str(datetime.now()) + "'" arguments = () if channel: values += ", '" + channel + "'" else: values += ", NULL" if lastact: values += ", %s" arguments += lastact, else: values += ", NULL" if auxiliary: values += ", %s" arguments += auxiliary, else: values += ", NULL" self.db.run("UPDATE users SET (" + fields + ") = (" + values + ") WHERE name='" + name + "' AND network='" + self.network + "'", arguments) # Set user back from away, if user is active. if type not in ["nick", "kick", "part", "quit"]: self.db.run("UPDATE users SET away=FALSE WHERE name='" + name + "' AND network='" + self.network + "'") class MessageStatistics(): def update(self, event, type): type = type + "s" queries.create_ifnot_onrecord(self, event.source.nick) if not self.db.one("SELECT id FROM messages WHERE LOWER(channel)=LOWER('" + event.target + "') AND channel_network='" + self.network + "' AND LOWER(\"user\")=LOWER('" + event.source.nick + "') AND user_network='" + self.network + "'"): # Not on record. self.db.run("INSERT INTO messages (channel, channel_network, \"user\", user_network) VALUES ('" + event.target + "', '" + self.network + "', '" + event.source.nick + "', '" + self.network + "')") # Create record. self.db.run("UPDATE messages SET " + type + "=" + type + "+1, " + type + "_words=" + type + "_words+" + str(len(event.arguments[0].split())) + ", " + type + "_characters=" + type + "_characters+" + str(len(event.arguments[0])) + " WHERE LOWER(channel)=LOWER('" + event.target + "') AND channel_network='" + self.network + "' AND LOWER(\"user\")=LOWER('" + event.source.nick + "') AND user_network='" + self.network + "'") # Increment record.