Forráskód Böngészése

Minor fixes, added debug print messages to on_kick

tBKwtWS 7 éve
szülő
commit
3795f040f6
9 módosított fájl, 51 hozzáadás és 27 törlés
  1. 1 1
      .eric6project/pyRot.e4q
  2. 3 3
      .eric6project/pyRot.e6t
  3. 15 0
      events/common.py
  4. 19 7
      events/on_action.py
  5. 5 0
      events/on_kick.py
  6. 3 4
      events/on_mode.py
  7. 3 0
      events/on_nick.py
  8. 2 2
      rotbot.py
  9. 0 10
      test.py

+ 1 - 1
.eric6project/pyRot.e4q

@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <!DOCTYPE UserProject SYSTEM "UserProject-4.0.dtd">
 <!-- eric6 user project file for project pyRot -->
-<!-- Saved: 2018-01-27, 19:55:21 -->
+<!-- Saved: 2018-01-28, 18:31:01 -->
 <!-- Copyright (C) 2018 tBKwtWS,  -->
 <UserProject version="4.0"/>

+ 3 - 3
.eric6project/pyRot.e6t

@@ -1,13 +1,13 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <!DOCTYPE Tasks SYSTEM "Tasks-6.0.dtd">
 <!-- eric6 tasks file for project pyRot -->
-<!-- Saved: 2018-01-27, 22:56:10 -->
+<!-- Saved: 2018-01-28, 22:14:06 -->
 <Tasks version="6.0">
   <ProjectScanFilter></ProjectScanFilter>
-  <Task priority="1" completed="False" type="2" uid="{241fd9ce-7896-465b-ab1c-2dc0a9fa89ea}">
+  <Task priority="1" completed="False" type="2" uid="{f922ec46-05e3-43d1-9f41-2fefa8ce09d3}">
     <Summary>WARNING: &quot; + str(message))</Summary>
     <Description></Description>
-    <Created>2018-01-27, 22:56:07</Created>
+    <Created>2018-01-28, 22:14:03</Created>
     <Resource>
       <Filename>common/log.py</Filename>
       <Linenumber>8</Linenumber>

+ 15 - 0
events/common.py

@@ -69,3 +69,18 @@ class Aggressiveness():
              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, network, type, datetime, channel=False, lastact=False):
+        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 + "'")

+ 19 - 7
events/on_action.py

@@ -23,9 +23,13 @@ def process_event(self, connection, event):
     self.db.run("UPDATE \"users\" SET actions=actions+1 WHERE name='" + event.source.nick + "' AND network='" + self.network + "'") # Increment record.
 
     # Slap guard.
-    if not self.db.one("SELECT chat FROM channels WHERE name='" + event.target + "' AND network='" + self.network + "'"):
-        return  # Stop if chat channel function is off.
     if event.arguments[0].lower().startswith("slaps ") and not event.target == connection.get_nickname():   # Channel action that stats with "slaps ".
+        
+        # Stop if chat channel function is off.
+        if not self.db.one("SELECT chat FROM channels WHERE name='" + event.target + "' AND network='" + self.network + "'"):
+            return
+    
+        # Only protect the worty.
         if not userstatus.atleast_voiced(self, event.arguments[0].split(" ")[1], self.homechannel) and not userstatus.atleast_oper(self, event.arguments[0].split(" ")[1], self.homechannel): # Insufficient rights.
             return
         if userstatus.atleast_voiced(self, event.source.nick, self.homechannel):   # Slapper has atleast voice in home channel.
@@ -33,12 +37,20 @@ def process_event(self, connection, event):
                 return
             if self.channels[self.homechannel].is_owner(event.source.nick) and  self.channels[self.homechannel].is_owner(event.arguments[0].split(" ")[1]): # Slapper and slappee are owner.
                 return
-
+        # Respond.
         if " with a " in event.arguments[0]:
             if event.arguments[0].split(" with a ", maxsplit=1)[1]:
-                connection.action(event.target, "swiftly jumps in front of " + red + event.arguments[0].split(" ")[1] + reset + " to block the " + event.arguments[0].split(" with a ", maxsplit=1)[1])
-                return
+                if event.arguments[0].split(" ")[1].lower() == self.get_nickname(): # Bot slapped
+                    connection.action(event.target, "Takes the " + event.arguments[0].split(" with a ", maxsplit=1)[1] + " like a robot.")
+                else:
+                    connection.action(event.target, "swiftly jumps in front of " + red + event.arguments[0].split(" ")[1] + reset + " to block the " + event.arguments[0].split(" with a ", maxsplit=1)[1])
 
-            connection.action(event.target, "swiftly jumps in front of " + red + event.arguments[0].split(" ")[1] + reset + " to block the slap.")
+            elif event.arguments[0].split(" ")[1].lower() == self.get_nickname(): # Bot slapped
+                connection.action(event.target, "bites " + red + event.source.nick + reset + " furiously.")
+            else:
+                connection.action(event.target, "swiftly jumps in front of " + red + event.arguments[0].split(" ")[1] + reset + " to block the slap.")
         elif len(event.arguments[0].split(" ")) > 1:
-            connection.action(event.target, "swiftly jumps in front of " + red + event.arguments[0].split(" ")[1] + reset + " to block the slap.")
+            if event.arguments[0].split(" ")[1].lower() == self.get_nickname(): # Bot slapped
+                connection.action(event.target, "bites " + red + event.source.nick + reset + " furiously.")
+            else:
+                connection.action(event.target, "swiftly jumps in front of " + red + event.arguments[0].split(" ")[1] + reset + " to block the slap.")

+ 5 - 0
events/on_kick.py

@@ -51,6 +51,7 @@ def process_event(self, connection, event):
             connection.privmsg(self.homechannel, red + kicked + reset + " has been kicked from " + red + channel + reset + " by " + red + kicker + reset + ".")
     
     # React.
+    print("Reacting to kick")
     behaviour = self.db.one("SELECT aggressiveness FROM channels WHERE name='" + channel + "' AND network='" + self.network + "'")
     if behaviour == "passive":    # Passive behaviour.
         if kicked == connection.get_nickname() and channel == self.homechannel: # Bot was kicked from it's home channel.
@@ -96,11 +97,15 @@ def process_event(self, connection, event):
         
         
         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.
         if not userstatus.atleast_halfop(self, kicked, self.homechannel) or not kicked == connection.get_nickname():
+            print("Stop if offended is not atleast halfop and is not the bot itself")
             return  # Stop if offended is not atleast halfop and is not the bot itself.
         if userstatus.atleast_halfop(self, kicker, self.homechannel) and not self.channels[self.homechannel].is_owner(kicked):
+            print("Stop if offender is at least halfop in the home channel and the offended is not owner")
             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() + ".")

+ 3 - 4
events/on_mode.py

@@ -52,12 +52,11 @@ def process_event(self, connection, event):
         if event.source.nick == connection.get_nickname() or self.channels[self.homechannel].is_owner(event.source.nick):
             return
         
-        for protectee in self.protectees:
-            
-            # Stop if offender is atleast halfop in the home channel and offended is not owner.
+        # Stop if offender is atleast halfop in the home channel and offended is not owner.
             if userstatus.atleast_halfop(self, event.source.nick, self.homechannel) and not self.channels[self.homechannel].is_owner(protectee):
                 return
-            
+                
+        for protectee in self.protectees:
             if behaviour == "passive":    # Passive behaviour.
                 return
             elif behaviour == "defense_only":   # Defensive only behaviour.

+ 3 - 0
events/on_nick.py

@@ -1,5 +1,6 @@
 from common import log
 from common.networkservices import NickServ
+from events.common import Lastact
 
 def process_event(self, connection, event):
     
@@ -13,4 +14,6 @@ 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)
     

+ 2 - 2
rotbot.py

@@ -49,7 +49,7 @@ class PyRot(irc.bot.SingleServerIRCBot):
     
     def on_welcome(self, connection, event):
         events.on_welcome.process_event(self, connection, event)
-        
+    
     def on_error(self, connection, event):
         log.notice(event)
         connection.privmsg(self.homechannel, "ERROR: " + event)
@@ -177,7 +177,7 @@ def main():
     except:
         print("Invalid network ID.")
         sys.exit(1)
-    if not network:
+    if network == None:
         print("Invalid network ID.")
         sys.exit(1)
     

+ 0 - 10
test.py

@@ -1,10 +0,0 @@
-import threading
-
-def worker():
-    """thread worker function"""
-    print ('Worker')
-    return
-
-for i in range(5):
-    t = threading.Thread(target=worker)
-    t.start()