tBKwtWS пре 8 година
родитељ
комит
b1c868c34c
6 измењених фајлова са 48 додато и 27 уклоњено
  1. 5 1
      commands/public.py
  2. 5 0
      common/do_everything_to.py
  3. 18 9
      events/common.py
  4. 6 0
      events/on_join.py
  5. 13 15
      events/on_kick.py
  6. 1 2
      events/on_nick.py

+ 5 - 1
commands/public.py

@@ -46,7 +46,6 @@ def do_command(self, connection, event):
             connection.privmsg(replyto, "Replace the " + italic + "! " + reset + "prefix of any comand with " + italic + self.helpchar + " " + reset + "for help with a specific command. Request the command list with: " + blue + "!cmd")
             connection.privmsg(replyto, grey + "Example: " + reset + blue + self.helpchar + "help")
     
-    
     elif command.split()[0] == "stopgreet":
         if cmdtype == "help":    #Display help text.
             if len(command.split()) is not 1:
@@ -119,3 +118,8 @@ def do_command(self, connection, event):
                 self.db.run("UPDATE joins SET stopgreet='" + str(stopgreet) + "' WHERE LOWER(\"user\")=LOWER('" + user + "') AND user_network='" + self.network + "' AND lower(channel)=LOWER('" + channel + "') AND channel_network='" + self.network + "'")
             except:
                 connection.privmsg(replyto, "Failed to update database.")
+    
+    elif command.split()[0] == "seen":
+        pass
+        # last_act_type's: nick, join, kick, kicked,
+        

+ 5 - 0
common/do_everything_to.py

@@ -2,6 +2,7 @@ from common.networkservices import ChanServ
 
 def join(self, connection, channel, key=False):
     connection.privmsg("ChanServ", "UNBAN")
+    connection.privmsg("ChanServ", "UNBAN " + channel)
     ChanServ.unban(connection, channel, connection.get_nickname())
     ChanServ.akick_del(connection, channel, connection.get_nickname())
     ChanServ.invite(connection, channel)
@@ -27,3 +28,7 @@ def ban(connection, channel, user, mask, reason):
 def kick(connection, channel, user, reason):
     ChanServ.kick(connection, channel, user, reason)
     connection.kick(channel, user, reason)
+
+def bankick(connection, channel, user, reason):
+    ban(connection, channel, user, reason)
+    kick(connection, channel, user, reason)

+ 18 - 9
events/common.py

@@ -1,4 +1,5 @@
 import random
+from datetime import datetime
 from common import userstatus
 
 class Protectees():
@@ -72,16 +73,24 @@ class Aggressiveness():
             return "Aggression channel function = " + behaviour + ": " + protectee + " is atlast halfop in " + self.homechannel + "."
 
 class Lastact():
-    def update(self, name, network, type, datetime, channel=False, lastact=False):
+    def update(self, name, network, 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.
         
         # Update record.
-        if channel and lastact:
-            self.db.run("UPDATE users SET (last_act_type, last_act_datetime, last_act_channel, last_act_channel-network, last_act) = ('" + type + "', '" + datetime + "', '" + channel + "', '" + network + "', '" + lastact + "') WHERE \"user\"='" + name + "' AND network='" + network + "'")
-        elif channel:
-            self.db.run("UPDATE users SET (last_act_type, last_act_datetime, last_act_channel, last_act_channel-network, last_act) = ('" + type + "', '" + datetime + "', '" + channel + "', '" + network + "', NULL) WHERE \"user\"='" + name + "' AND network='" + network + "'")
-        elif lastact:
-            self.db.run("UPDATE users SET (last_act_type, last_act_datetime, last_act_channel, last_act_channel-network, last_act) = ('" + type + "', '" + datetime + "', NULL, '" + network + "', '" + lastact + "') WHERE \"user\"='" + name + "' AND network='" + network + "'")
-        else:
-            self.db.run("UPDATE users SET (last_act_type, last_act_datetime, last_act_channel, last_act_channel-network, last_act) = ('" + type + "', '" + datetime + "', NULL, '" + network + "', NULL) WHERE \"user\"='" + name + "' AND network='" + network + "'")
+        fields = "last_act_type, last_act_datetime"
+        values = "'" + type + "', '" + str(datetime.now()) + "'"
+        if channel:
+            fields = fields + ", last_act_channel"
+            values = values + ", '" + channel + "'"
+        if lastact:
+            fields = fields + ", last_act"
+            values = values + ", '" + lastact + "'"
+        if auxiliary:
+            fields = fields + ", auxiliary"
+            values = values + ", '" + auxiliary + "'"
+        self.db.run("UPDATE users SET (" + fields + ") = (" + values + ") WHERE name='" + name + "' AND network='" + network + "'")
+        
+        

+ 6 - 0
events/on_join.py

@@ -1,3 +1,5 @@
+from events.common import Lastact
+
 bold = "\x02"
 italic = "\x1D"
 underline = "\x1F"
@@ -9,6 +11,10 @@ red = "\x0304"
 grey = "\x0314"
 
 def process_event(self, connection, event):
+    
+    # Update last act.
+    Lastact.update(self, event.source.nick, self.network, "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.
         self.db.run("INSERT INTO channels (name, network) VALUES ('" + event.target + "', '" + self.network + "')")

+ 13 - 15
events/on_kick.py

@@ -1,6 +1,6 @@
 from common.networkservices import ChanServ
 from common import userstatus, do_everything_to
-from events.common import Aggressiveness
+from events.common import Aggressiveness, Lastact
 
 bold = "\x02"
 italic = "\x1D"
@@ -18,6 +18,14 @@ def process_event(self, connection, event):
     kicked = event.arguments[0]
     reason = event.arguments[1]
     
+    # 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)
+    else:
+        Lastact.update(self, kicker, self.network, "kick", channel=channel, lastact=kicked)
+        Lastact.update(self, kicked, self.network, "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.
         self.db.run("INSERT INTO \"users\" (name, network) VALUES ('" + kicker + "', '" + self.network + "')")  # Create user record.
@@ -66,7 +74,6 @@ def process_event(self, connection, event):
             connection.privmsg("ChanServ", "UNBAN " + channel)
             do_everything_to.join(self, connection, channel)
     elif behaviour == "equal_retalliation":   # Equal retalitory behaviour.
-        ChanServ.unban(connection, channel, kicked)
         ChanServ.akick_del(connection, channel, kicked)
         
         # Rejoin if bot was kicked.
@@ -74,7 +81,6 @@ def process_event(self, connection, event):
             connection.privmsg("ChanServ", "UNBAN " + channel)
             do_everything_to.join(self, connection, self.homechannel)
         
-        
         if event.source.nick == connection.get_nickname() or self.channels[self.homechannel].is_owner(kicker):
             return  # Stop if offender is bot or owner.
         if not userstatus.atleast_halfop(self, kicked, self.homechannel) or not kicked == connection.get_nickname():
@@ -87,15 +93,13 @@ def process_event(self, connection, event):
     
     # Battlebot behaviour.
     elif behaviour == "battlebot":
-        ChanServ.unban(connection, channel, kicked)
         ChanServ.akick_del(connection, channel, kicked)
         
         # Rejoin if bot was kicked.
         if kicked == connection.get_nickname():
-            connection.privmsg("ChanServ", "UNBAN " + channel)
+            print("Rejoining " + channel)
             do_everything_to.join(self, connection, self.homechannel)
         
-        
         if event.source.nick == connection.get_nickname() or self.channels[self.homechannel].is_owner(kicker):
             print("Stop if offender is bot or owner")
             return  # Stop if offender is bot or owner.
@@ -107,13 +111,7 @@ def process_event(self, connection, event):
             return  # Stop if offender is at least halfop in the home channel and the offended is not owner.
         print("Kickbanning")
 
-        # Ban.
-        ChanServ.tempban(connection, channel, kicker, "1h", "Aggression channel function = equal_retalliation: " + kicked + " is an operator of " + connection.get_nickname() + ".")
-        connection.mode(channel, "+b " + event.source)
-        
-        connection.mode(channel, "+e " + event.source)  # Excempt operator.
+        ChanServ.tempban(connection, channel, kicker, "1h", "Aggression channel function = equal_retalliation: " + kicked)
+        connection.mode(channel, "+e " + kicked)  # Excempt operator.
         ChanServ.akick_add(connection, channel, kicker) # Add kicker to ChanServs autokick.
-        
-        # Kick.
-        ChanServ.kick(connection, channel, kicker, "Aggression channel function = equal_retalliation: " + kicked + " is an operator of " + connection.get_nickname() + ".")
-        connection.kick(channel, kicker, "Aggression channel function = equal_retalliation: " + kicked + " is an operator of " + connection.get_nickname() + ".")
+        do_everything_to.bankick(connection, channel, kicker, "Aggression channel function = equal_retalliation: " + kicked)

+ 1 - 2
events/on_nick.py

@@ -15,6 +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", datetime, channel=False, lastact=False)
-#   Lastact.update(self, name, self.network, type, datetime, channel=False, lastact=False)
+    Lastact.update(self, event.source.nick, self.network, "nick", lastact=event.target)