Prechádzať zdrojové kódy

saving last_act to db

tBKwtWS 7 rokov pred
rodič
commit
f8e6d16ccf

+ 1 - 2
commands/public.py

@@ -121,5 +121,4 @@ def do_command(self, connection, event):
     
     elif command.split()[0] == "seen":
         pass
-        # last_act_type's: nick, join, kick, kicked,
-        
+        # last_act_type's: nick, join, kick, kicked, mode, part, quit, topic, msg, notice, action

+ 4 - 4
events/common.py

@@ -73,11 +73,11 @@ class Aggressiveness():
             return "Aggression channel function = " + behaviour + ": " + protectee + " is atlast halfop in " + self.homechannel + "."
 
 class Lastact():
-    def update(self, name, network, type, channel=False, lastact=False, auxiliary=False):
+    def update(self, name, type, channel=False, lastact=False, auxiliary=False):
         
         # Create records if not present.
-        if not self.db.one("SELECT id FROM users WHERE name='" + name + "' AND network='" + network + "'"):  # Not on record.
-            self.db.run("INSERT INTO users (name, network) VALUES ('" + name + "', '" + network + "')")  # Create record.
+        if not self.db.one("SELECT id FROM users WHERE name='" + name + "' AND network='" + self.network + "'"):  # Not on record.
+            self.db.run("INSERT INTO users (name, network) VALUES ('" + name + "', '" + self.network + "')")  # Create record.
         
         # Update record.
         fields = "last_act_type, last_act_datetime"
@@ -91,6 +91,6 @@ class Lastact():
         if auxiliary:
             fields = fields + ", auxiliary"
             values = values + ", '" + auxiliary + "'"
-        self.db.run("UPDATE users SET (" + fields + ") = (" + values + ") WHERE name='" + name + "' AND network='" + network + "'")
+        self.db.run("UPDATE users SET (" + fields + ") = (" + values + ") WHERE name='" + name + "' AND network='" + self.network + "'")
         
         

+ 12 - 6
events/on_action.py

@@ -1,5 +1,5 @@
 from common import userstatus
-from events.common import Replyto
+from events.common import Replyto, Lastact
 
 bold = "\x02"
 italic = "\x1D"
@@ -12,7 +12,16 @@ red = "\x0304"
 grey = "\x0314"
 
 def process_event(self, connection, event):
-    if connection.get_nickname().lower() in event.arguments[0].lower() and event.source.nick is not connection.get_nickname(): # Bot's name was mentioned
+    # Update last act.
+    Lastact.update(self, event.source.nick, "action", channel=event.target, lastact=event.arguments[0])
+    
+    # Save statistic to database.
+    if not self.db.one("SELECT id FROM \"users\" WHERE name='" + event.source.nick + "' AND network='" + self.network + "'"):    # Not on record.
+        self.db.run("INSERT INTO \"users\" (name, network) VALUES ('" + event.source.nick + "', '" + self.network + "')")   # Create record.
+    self.db.run("UPDATE \"users\" SET actions=actions+1 WHERE name='" + event.source.nick + "' AND network='" + self.network + "'") # Increment record.
+    
+    # Respond to own name.
+    if connection.get_nickname().lower() in event.arguments[0].lower() and event.source.nick is not connection.get_nickname(): # Bot's name was mentioned,not by the bot itself.
         
         # Stop if channelfunction chat if off.
         if not self.db.one("SELECT chat FROM channels WHERE name='" + event.target + "' AND network='" + self.network + "'"):
@@ -24,10 +33,7 @@ def process_event(self, connection, event):
         
         Replyto.name(connection, event)
     
-    # Save statistic to database.
-    if not self.db.one("SELECT id FROM \"users\" WHERE name='" + event.source.nick + "' AND network='" + self.network + "'"):    # Not on record.
-        self.db.run("INSERT INTO \"users\" (name, network) VALUES ('" + event.source.nick + "', '" + self.network + "')")   # Create record.
-    self.db.run("UPDATE \"users\" SET actions=actions+1 WHERE name='" + event.source.nick + "' AND network='" + self.network + "'") # Increment record.
+    
 
     # Slap guard.
     if event.arguments[0].lower().startswith("slaps ") and not event.target == connection.get_nickname():   # Channel action that stats with "slaps ".

+ 1 - 1
events/on_join.py

@@ -13,7 +13,7 @@ grey = "\x0314"
 def process_event(self, connection, event):
     
     # Update last act.
-    Lastact.update(self, event.source.nick, self.network, "join", channel=event.target)
+    Lastact.update(self, event.source.nick, "join", channel=event.target)
     
     # Add join event to database for statistics.
     if not self.db.one("SELECT id FROM channels WHERE name='" + event.target + "' AND network='" + self.network + "'"): # Channel does not exist in database.

+ 4 - 4
events/on_kick.py

@@ -20,11 +20,11 @@ def process_event(self, connection, event):
     
     # Update last act.
     if reason:
-        Lastact.update(self, kicker, self.network, "kick", channel=channel, lastact=kicked, auxiliary=reason)
-        Lastact.update(self, kicked, self.network, "kicked", channel=channel, lastact=kicked, auxiliary=reason)
+        Lastact.update(self, kicker, "kick", channel=channel, lastact=kicked, auxiliary=reason)
+        Lastact.update(self, kicked, "kicked", channel=channel, lastact=kicked, auxiliary=reason)
     else:
-        Lastact.update(self, kicker, self.network, "kick", channel=channel, lastact=kicked)
-        Lastact.update(self, kicked, self.network, "kicked", channel=channel, lastact=kicked)
+        Lastact.update(self, kicker, "kick", channel=channel, lastact=kicked)
+        Lastact.update(self, kicked, "kicked", channel=channel, lastact=kicked)
     
     # Create user records if they don't exist.
     if not self.db.one("SELECT id FROM users WHERE name='" + kicker + "' AND network='" + self.network + "'"):   # Kicker does not have a user record.

+ 4 - 1
events/on_mode.py

@@ -2,7 +2,7 @@ import fnmatch
 from irc.modes import parse_channel_modes
 from common.networkservices import ChanServ
 from common import do_everything_to, userstatus
-from events.common import Aggressiveness
+from events.common import Aggressiveness, Lastact
 
 bold = "\x02"
 italic = "\x1D"
@@ -21,6 +21,9 @@ def process_event(self, connection, event):
         if any(mode in event.arguments[0][-1:] for mode in ("q", "a", "o", "h")):  # Atleast halfop.
             connection.who(event.arguments[1])  # Get whorepy to update protectees.
     
+    # Update last act.
+    Lastact.update(self, event.source.nick, "mode", auxiliary=event.target)
+    
     # React.
     modes = parse_channel_modes(" ".join(event.arguments))
     behaviour = self.db.one("SELECT aggressiveness FROM channels WHERE name='" + event.target + "' AND network='" + self.network + "'")

+ 1 - 1
events/on_nick.py

@@ -15,5 +15,5 @@ def process_event(self, connection, event):
         connection.who(event.target)    # Get whorepy to add new nick to protectees.
     
     # Update last act.
-    Lastact.update(self, event.source.nick, self.network, "nick", lastact=event.target)
+    Lastact.update(self, event.source.nick, "nick", lastact=event.target)
     

+ 11 - 5
events/on_pubmsg.py

@@ -1,7 +1,16 @@
 import datetime
-from events.common import Replyto
+from events.common import Replyto,  Lastact
 
 def process_event(self, connection, event):
+    
+    # Update last act.
+    Lastact.update(self, event.source.nick, "msg", channel=event.target, lastact=event.arguments[0])
+    
+    # Save statistic to database.
+    if not self.db.one("SELECT id FROM \"users\" WHERE name='" + event.source.nick + "' AND network='" + self.network + "'"):    # Not on record.
+        self.db.run("INSERT INTO \"users\" (name, network) VALUES ('" + event.source.nick + "', '" + self.network + "')")   # Create record.
+    self.db.run("UPDATE \"users\" SET messages=messages+1 WHERE name='" + event.source.nick + "' AND network='" + self.network + "'") # Increment record.
+    
     if connection.get_nickname().lower() in event.arguments[0].lower() and event.source.nick is not connection.get_nickname(): # Bot's name was mentioned
         if event.arguments[0].startswith(self.cmdchar):
             return  # Stop if it's a command.
@@ -27,7 +36,4 @@ def process_event(self, connection, event):
         
         connection.privmsg(event.target, event.arguments[0] + event.arguments[0][:1])
     
-    # Save statistic to database.
-    if not self.db.one("SELECT id FROM \"users\" WHERE name='" + event.source.nick + "' AND network='" + self.network + "'"):    # Not on record.
-        self.db.run("INSERT INTO \"users\" (name, network) VALUES ('" + event.source.nick + "', '" + self.network + "')")   # Create record.
-    self.db.run("UPDATE \"users\" SET messages=messages+1 WHERE name='" + event.source.nick + "' AND network='" + self.network + "'") # Increment record.
+    

+ 14 - 0
rotbot.py

@@ -8,6 +8,7 @@ import commands.public, commands.admin, commands.games, commands.statistics
 import events.on_welcome, events.on_join, events.on_kick, events.on_mode, events.on_pubmsg, events.on_action, events.on_whoreply, events.on_nick
 from common import log
 from common.networkservices import NickServ
+from events.common import Lastact
 
 bold = "\x02"
 italic = "\x1D"
@@ -71,12 +72,18 @@ class PyRot(irc.bot.SingleServerIRCBot):
         # Update protectees
         if event.target == self.homechannel and event.source.nick in self.protectees:    # Protectee parted home channel.
             del self.protectees[event.source.nick] # Delete from protectees.
+        
+        # Update last act.
+        Lastact.update(self, event.source.nick, "part", channel=event.target, lastact=event.arguments[0])
     
     def on_quit(self, connection, event):
         
         # Update protectees
         if event.source.nick in self.protectees:    # Protectee parted home channel.
             del self.protectees[event.source.nick] # Delete from protectees.
+        
+        # Update last act.
+        Lastact.update(self, event.source.nick, "quit", lastact=event.arguments[0])
     
     def on_invite(self, connection, event):
         log.info(event)
@@ -85,6 +92,9 @@ class PyRot(irc.bot.SingleServerIRCBot):
     
     def on_topic(self, connection, event):
         log.info(event)
+        
+        # Update last act.
+        Lastact.update(self, event.source.nick, "topic", channel=event.target, lastact=event.arguments[0])
 
     def on_pubmsg(self, connection,  event):
         commands.public.do_command(self, connection, event)
@@ -102,10 +112,14 @@ class PyRot(irc.bot.SingleServerIRCBot):
     
     def on_pubnotice(self, connection, event):
         log.info(event)
+        
         # Save statistic to database.
         if not self.db.one("SELECT id FROM \"users\" WHERE name='" + event.source.nick + "' AND network='" + self.network + "'"):    # Not on record.
             self.db.run("INSERT INTO \"users\" (name, network) VALUES ('" + event.source.nick + "', '" + self.network + "')")   # Create record.
         self.db.run("UPDATE \"users\" SET messages=messages+1 WHERE name='" + event.source.nick + "' AND network='" + self.network + "'") # Increment record.
+        
+        # Update last act.
+        Lastact.update(self, event.source.nick, "notice", channel=event.target, lastact=event.arguments[0])
     
     def on_privnotice(self,  connection,  event):
         log.info(event)