Ver código fonte

eric project, aggressiveness modes, no chat on commands

tBKwtWS 7 anos atrás
pai
commit
f459f5dc25

BIN
commands/__pycache__/admin.cpython-36.pyc


BIN
commands/__pycache__/common.cpython-36.pyc


+ 12 - 7
commands/admin.py

@@ -209,16 +209,18 @@ def do_command(self, connection, event):
                 return
             connection.privmsg(replyto, "Display or toggle the status channel functions. Channel, function and value optional. Get a description of a functio via the help argument.")
             connection.privmsg(replyto, grey + "Usage: " + blue + "!channelfunctions " + red + italic + "channel " + reset + italic + "function value")
-            connection.privmsg(replyto, grey + "Usage: " + blue + "!channelfunctions help" + italic + "function")
+            connection.privmsg(replyto, grey + "Usage: " + blue + "!channelfunctions describe " + reset + italic + "function")
         elif cmdtype == "cmd":
+            
             if len(command.split()) == 1:   # No arguments.
                 if event.target == connection.get_nickname():   # Command issued via PM.
                     connection.privmsg(replyto, "Nothing to display, Specify a channel.")
                 else:   # Command issued as channel message.
                     message = AH.get_channelfunctions(self, event.target)
                     connection.privmsg(replyto, message)
+            
             elif len(command.split()) == 2:   # One argument.
-                if command.split()[1].lower() in self.channels.lower(): # Info requested on specific channel.
+                if command.split()[1] in self.channels: # Info requested on specific channel.
                     message = AH.get_channelfunctions(self, command.split()[1])
                     connection.privmsg(replyto, message)
                 else:   # First argument is not a channel the bot inhabits.
@@ -226,24 +228,26 @@ def do_command(self, connection, event):
                         connection.privmsg(replyto, command.split()[1] + " is not a channel I inhabit. For help type " + blue + self.helpchar + "channelfunctions" + reset + ".")
                     else:   # Help request.
                         connection.privmsg(replyto, "Specify a channel function to get a description of. For help type " + blue + self.helpchar + "channelfunctions" + reset + ".")
+            
             elif len(command.split()) == 3: # Two arguments.
+                channel = event.target
                 if event.target == connection.get_nickname():   # Command issued via PM.
                     connection.privmsg(replyto, "One or three arguments required. For help type " + blue + self.helpchar + "channelfunctions" + reset + ".")
                 else:   # Command issued via channel.
                     if not AH.is_channelfunction(command.split()[1]):   # First argument is not a channelfunction.
-                        if not command.split()[1].lower() == "help":    # Not a help request.
+                        if not command.split()[1].lower() == "describe":    # Not a help request.
                             connection.privmsg(replyto, command.split()[1] + " is not a channel function. For help type " + blue + self.helpchar + "channelfunctions" + reset + ".")
                             return
-                        if not AH.is_channelhunction(self, command.split()[2]): # Second argument not a channel function.
+                        if not AH.is_channelfunction(command.split()[2]): # Second argument not a channel function.
                                 connection.privmsg(replyto, command.split()[2] + " is not a channel function.")
                                 return
                         connection.privmsg(replyto, AH.describe_channelfunction(command.split()[2]))
                         return
                     # Second argument unsupported.
                     if not command.split()[2].lower() in ["on",  "off"]:
-                        if not command.split()[1].lower() == "aggressiveness":
-                            if not AH.is_aggressiveness(command.split()[2]):    # Is not an aggressiveness setting.
-                                connection.privmsg(replyto, command.split()[2] + " is not an aggressiveness setting. For help type " + blue + self.helpchat + "channelfunctions" + reset + ".")
+                        if command.split()[1].lower() == "aggressiveness":
+                            if not AH.is_aggressiveness(command.split()[2].lower()):    # Is not an aggressiveness setting.
+                                connection.privmsg(replyto, command.split()[2] + " is not an aggressiveness setting. For help type " + blue + self.helpchar + "channelfunctions" + reset + ".")
                                 return
                         else:   # Channel function is not aggresiveness.
                             connection.privmsg(replyto, "The value of this channel function can only be \"on\" or \"off\". For help type " + blue + self.helpchar + "channelfunctions" + reset + ".")
@@ -254,6 +258,7 @@ def do_command(self, connection, event):
                     if command.split()[1].lower() == "autojoin" and event.target == self.homechannel:   # Chaning autojoin of homechannel.
                         connection.action(replyto, "will always join it's homechannel " + red + self.homechannel + reset + ", regardless of the autojoin function.")
                     self.db.run("UPDATE channels SET " + command.split()[1].lower() + "='" + command.split()[2].lower() + "' WHERE name='" + event.target + "' AND network='" + self.network + "'")
+            
             elif len(command.split()) == 4: # Three arguments.
                 if not command.split()[1] in self.channels: # Bot does not inhabit channel to be altered.
                     connection.privmsg(replyto, command.split()[1] + " is not a channel I inhabit. For help type " + blue + self.helpchar + "channelfunctions" + reset + ".")

+ 8 - 8
commands/common.py

@@ -91,24 +91,24 @@ class AdminHelpers():
     
     def describe_channelfunction(function):
         if function == "autojoin":
-            message = "Boolean. If the channel will be joined automaticly after connecting."
+            message = "Join the channel automaticly after connecting."
         elif function == "aggressiveness":
-            message = "How to respond to kick, ban and mode events. Options: " + blue + "passive" + reset + ", " + blue + "defense_only" + reset + "."
+            message = "How to respond to kick, ban and mode events. Options: " + blue + "passive" + reset + ", " + blue + "defense_only" + reset + ", " + blue + "equal_retalliation" + reset + ", " + blue + "battlebot" + reset + "."
         elif function == "join_greeting":
-            message = ""
+            message = "Greet users joining the channel on the first few joins, and later on large amounts."
         elif function == "statistics_commands":
-            message = ""
+            message = "Enable use of statistics commands."
         elif function == "games":
-            message = ""
+            message = "Enable use of game commands."
         elif function == "chat":
-            message = ""
+            message = "Respond to and initiate chat."
         else:
-            message = ""
+            message = "Sorry, this function has no description yet."
         
         return message
     
     def is_aggressiveness(value):
-        if value.lower() in ["passive", "defense_only"]:
+        if value.lower() in ["passive", "defense_only", "equal_retalliation", "battlebot"]:
             return True
         else:
             return False

BIN
common/__pycache__/networkservices.cpython-36.pyc


+ 15 - 0
common/networkservices.py

@@ -6,6 +6,21 @@ class NickServ():
         connection.nick(connection.nickname)    # Set original nickname. Should have happened during the nickServ recover, this fails when still connecting. So this creates a loop to successfully recover via NickServ.
 
 class ChanServ():
+    def ban(connection, channel, user, reason):
+        connection.privmsg("ChanServ", "BAN " + channel + " " + user + " " + reason)
+    
+    def tempban(connection, channel, user, duration, reason):
+        connection.privmsg("ChanServ", "BAN " + channel + " +" + duration + " " + user + " " + reason)
+    
     def unban(connection, channel, user):
         connection.privmsg("ChanServ", "UNBAN " + channel + " " + user)
+    
+    def akick_add(connection, channel, user):
+        connection.privmsg("ChanServ", "AKICK " + channel + " ADD " + user)
+        
+    def akick_del(connection, channel, user):
+        connection.privmsg("ChanServ", "AKICK " + channel + " DEL " + user)
+    
+    def kick(connection, channel, user, reason):
+        connection.privmsg("ChanServ", "KICK " + channel + " " + user + " " + reason)
 

BIN
events/__pycache__/on_kick.cpython-36.pyc


BIN
events/__pycache__/on_pubmsg.cpython-36.pyc


+ 66 - 13
events/on_kick.py

@@ -1,4 +1,5 @@
 from common.networkservices import ChanServ
+from common import userstatus
 bold = "\x02"
 italic = "\x1D"
 underline = "\x1F"
@@ -10,6 +11,7 @@ red = "\x0304"
 grey = "\x0314"
 
 def process_event(self, connection, event):
+    print(event)
     kicker = event.source.nick
     channel = event.target
     kicked = event.arguments[0]
@@ -31,17 +33,68 @@ def process_event(self, connection, event):
     self.db.run("UPDATE kicks SET given = given + 1 WHERE channel='" + channel + "'AND channel_network='" + self.network + "' AND \"user\"='" + kicker + "' AND user_network='" + self.network + "'")
     self.db.run("UPDATE kicks SET received = received + 1 WHERE channel='" + channel + "'AND channel_network='" + self.network + "' AND \"user\"='" + kicked + "' AND user_network='" + self.network + "'")
     
+    if not userstatus.atleast_halfop(self, kicked, self.homechannel) and not kicked == connection.get_nickname():   # Insufficient rights.
+        return
+    
+    # Report to home channel.
+    if not channel == self.homechannel: # Not from it's homechannel.
+        if reason:
+            connection.action(self.homechannel, "has been kicked from " + red + channel + reset + " by " + red + kicker + reset + ": " + green + reason)
+        else:
+            connection.action(self.homechannel, "has been kicked from " + red + channel + reset + " by " + red + kicker + reset + ".")
+    
     # React.
-    if kicked == connection.get_nickname(): # Bot was kicked.
-        if self.db.one("SELECT aggressiveness FROM channels WHERE name='" + channel + "' AND network='" + self.network + "'") == "passive":    # Passive behaviour.
-            if channel == self.homechannel: # From it's homechannel.
-                ChanServ.unban(connection, channel, kicked)
-                connection.privmsg("ChanServ", "UNBAN " + channel)
-                connection.join(self.homechannel)
-        
-        # Report to home channel.
-        if not channel == self.homechannel: # Not from it's homechannel.
-            if reason:
-                connection.action(self.homechannel, "has been kicked from " + red + channel + reset + " by " + red + kicker + reset + ": " + green + reason)
-            else:
-                connection.action(self.homechannel, "has been kicked from " + red + channel + reset + " by " + red + kicker + reset + ".")
+    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.
+            ChanServ.unban(connection, channel, kicked)
+            ChanServ.akick_del(connection, channel, kicked)
+            connection.privmsg("ChanServ", "UNBAN " + channel)
+            connection.join(self.homechannel)
+    elif behaviour == "defense_only":   # Defensive behaviour.
+        ChanServ.unban(connection, channel, kicked)
+        ChanServ.akick_del(connection, channel, kicked)
+        if kicked == connection.get_nickname() and channel == self.homechannel: # Bot was kicked from it's home channel.
+            connection.privmsg("ChanServ", "UNBAN " + channel)
+            connection.join(self.homechannel)
+    elif behaviour == "equal_retalliation":   # Equal retalitory behaviour.
+        ChanServ.unban(connection, channel, kicked)
+        ChanServ.akick_del(connection, channel, kicked)
+        
+        # Rejoin if bot was kicked from it's home channel.
+        if kicked == connection.get_nickname() and channel == self.homechannel:
+            connection.privmsg("ChanServ", "UNBAN " + channel)
+            connection.join(self.homechannel)
+        
+        # Stop if the offender is a bot operator and the offended is not the bot owner or if the 2 parties are both bot owner.
+        if userstatus.atleast_halfop(self, kicker, self.homechannel) and not self.channels[self.homechannel].isowner(kicked) or self.channels[self.homechannel].isowner(kicked) == self.channels[self.homechannel].isowner(kicker):
+            return
+        
+        # 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() + ".")
+    elif behaviour == "battlebot":   # Battlebot behaviour.
+        ChanServ.unban(connection, channel, kicked)
+        ChanServ.akick_del(connection, channel, kicked)
+        
+        # Rejoin if bot was kicked from it's home channel.
+        if kicked == connection.get_nickname() and channel == self.homechannel:
+            connection.privmsg("ChanServ", "UNBAN " + channel)
+            connection.join(self.homechannel)
+        
+        # Stop if the offender is a bot operator and the offended is not the bot owner or if the 2 parties are both bot owner.
+        if userstatus.atleast_halfop(self, kicker, self.homechannel) and not self.channels[self.homechannel].isowner(kicked) or self.channels[self.homechannel].isowner(kicked) == self.channels[self.homechannel].isowner(kicker):
+            return
+        
+        # Ban.
+        ChanServ.tempban(connection, channel, kicker, "Aggression channel function = equal_retalliation: " + kicked + " is an operator of " + connection.get_nickname() + ".")
+        print(event.source)
+        print(event.target)
+        connection.mode(channel, "+b " + event.source)
+        
+        #connection.mode(channel, "+e " + event.source)  # Protect 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() + ".")

+ 4 - 0
events/on_pubmsg.py

@@ -3,6 +3,10 @@ import random
 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
+        
+        # Stop if it's a command.
+        if event.arguments[0].startswith(self.cmdchar):
+            return
     
         # Stop if channelfunction chat if off.
         chat = self.db.one("SELECT chat FROM channels WHERE name='" + event.target + "' AND network='" + self.network + "'")

+ 59 - 0
pyRot.e4p

@@ -0,0 +1,59 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE Project SYSTEM "Project-5.1.dtd">
+<!-- eric project file for project pyRot -->
+<!-- Saved: 2018-01-25, 22:51:57 -->
+<!-- Copyright (C) 2018 tBKwtWS,  -->
+<Project version="5.1">
+  <Language>en_US</Language>
+  <Hash>e4efcb6f94c2972397bee40050ea12454672da34</Hash>
+  <ProgLanguage mixed="0">Python3</ProgLanguage>
+  <ProjectType>PyQt5</ProjectType>
+  <Description>RotBot</Description>
+  <Version>0.1</Version>
+  <Author>tBKwtWS</Author>
+  <Email></Email>
+  <Eol index="0"/>
+  <Sources>
+    <Source>__init__.py</Source>
+    <Source>commands/admin.py</Source>
+    <Source>commands/common.py</Source>
+    <Source>commands/games.py</Source>
+    <Source>commands/public.py</Source>
+    <Source>commands/statistics.py</Source>
+    <Source>common/log.py</Source>
+    <Source>common/networkservices.py</Source>
+    <Source>common/userstatus.py</Source>
+    <Source>events/on_join.py</Source>
+    <Source>events/on_kick.py</Source>
+    <Source>events/on_pubmsg.py</Source>
+    <Source>original_testbot.py</Source>
+    <Source>rotbot.py</Source>
+    <Source>test.py</Source>
+  </Sources>
+  <Forms/>
+  <Translations/>
+  <Resources/>
+  <Interfaces/>
+  <Others/>
+  <MainScript>rotbot.py</MainScript>
+  <Vcs>
+    <VcsType>None</VcsType>
+  </Vcs>
+  <FiletypeAssociations>
+    <FiletypeAssociation pattern="*.e4p" type="OTHERS"/>
+    <FiletypeAssociation pattern="*.idl" type="INTERFACES"/>
+    <FiletypeAssociation pattern="*.md" type="OTHERS"/>
+    <FiletypeAssociation pattern="*.py" type="SOURCES"/>
+    <FiletypeAssociation pattern="*.py3" type="SOURCES"/>
+    <FiletypeAssociation pattern="*.pyw" type="SOURCES"/>
+    <FiletypeAssociation pattern="*.pyw3" type="SOURCES"/>
+    <FiletypeAssociation pattern="*.qm" type="TRANSLATIONS"/>
+    <FiletypeAssociation pattern="*.qrc" type="RESOURCES"/>
+    <FiletypeAssociation pattern="*.rst" type="OTHERS"/>
+    <FiletypeAssociation pattern="*.ts" type="TRANSLATIONS"/>
+    <FiletypeAssociation pattern="*.txt" type="OTHERS"/>
+    <FiletypeAssociation pattern="*.ui" type="FORMS"/>
+    <FiletypeAssociation pattern="README" type="OTHERS"/>
+    <FiletypeAssociation pattern="README.*" type="OTHERS"/>
+  </FiletypeAssociations>
+</Project>

+ 14 - 10
rotbot.py

@@ -31,6 +31,7 @@ class PyRot(irc.bot.SingleServerIRCBot):
             factory = irc.connection.Factory(wrapper=ssl.wrap_socket)
         else:
             factory = irc.connection.Factory()
+        print("Starting pyRot, the third RotBot by tBkwtWS.")
         log.info("Connecting to " + host + ":" + str(port) + "/" + self.homechannel)
         try:
             irc.bot.SingleServerIRCBot.__init__(self, [(host, port)], nickname, username, connect_factory=factory)
@@ -63,27 +64,27 @@ class PyRot(irc.bot.SingleServerIRCBot):
             NickServ.recover_nick(connection, self.password)
     
     def on_join(self, connection, event):
-        print(event)
+        log.info(event)
         events.on_join.process_event(self, connection, event)
     
     def on_kick(self, connection, event):
-        print(event)
+        log.info(event)
         events.on_kick.process_event(self, connection, event)
     
     def on_mode(self, connection, event):
-        print(event)
+        log.info(event)
     
     def on_part(self, connection, event):
-        print(event)
+        log.info(event)
     
     def on_quit(self, connection, event):
-        print(event)
+        log.info(event)
     
     def on_invite(self, connection, event):
-        print(event)
+        log.info(event)
     
     def on_topic(self, connection, event):
-        print(event)
+        log.info(event)
 
     def on_pubmsg(self, connection,  event):
         commands.public.do_command(self, connection, event)
@@ -98,7 +99,7 @@ class PyRot(irc.bot.SingleServerIRCBot):
         events.on_pubmsg.process_event(self, connection, event)
     
     def on_pubnotice(self, connection, event):
-        print(event)
+        log.info(event)
     
     def on_privmsg(self, connection, event):
         log.info(event)
@@ -117,15 +118,17 @@ class PyRot(irc.bot.SingleServerIRCBot):
             connection.privmsg("NickServ", "identify " + connection.nickname + " " + connection.password) # Identify with NickServ.
     
     def on_action(self, connection, event):
-        print(event)
+        log.info(event)
     
     # DCC stuff from originalexample file.
     def on_dccmsg(self, c, e):
+        log.info(e)
         # non-chat DCC messages are raw bytes; decode as text
         text = e.arguments[0].decode('utf-8')
         c.privmsg("You said: " + text)
 
     def on_dccchat(self, c, e):
+        log.info(e)
         if len(e.arguments) != 2:
             return
         args = e.arguments[1].split()
@@ -146,7 +149,8 @@ def main():
         sys.exit(1)
     instance = sys.argv[1]  # Instance is the database network id.
     
-    db = Postgres("postgres://pyRot:4h8q(.@localhost/pyRot")    # Database.
+    # Database.
+    db = Postgres("postgres://pyRot:4h8q(.@localhost/pyRot")
     
     # Get network from database.
     try: