Parcourir la source

before refactoring of channelfunctions

tBKwtWS il y a 7 ans
Parent
commit
565b569013

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


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


+ 34 - 12
commands/admin.py

@@ -1,5 +1,6 @@
 from common import userstatus
 from commands.common import CommandHelpers as CH
+from commands.common import AdminHelpers as AH
 bold = "\x02"
 italic = "\x1D"
 underline = "\x1F"
@@ -206,52 +207,73 @@ def do_command(self, connection, event):
         if cmdtype == "help":    #Display help text. # Help code block first, as it is impossible to predict for what channel a later command is going to be issued. Rights filtering after help test.
             if len(command.split()) is not 1:
                 return
-            connection.privmsg(replyto, "Display or toggle the status channel functions. Channel, function and value optional.")
+            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")
         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 = CH.get_channelfunctions(self, event.target)
+                    message = AH.get_channelfunctions(self, event.target)
                     connection.privmsg(replyto, message)
             elif len(command.split()) == 2:   # One argument.
-                if command.split()[1] in self.channels: # Info requested on specific channel.
-                    message = CH.get_channelfunctions(self, command.split()[1])
+                if command.split()[1].lower() in self.channels.lower(): # 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.
-                    connection.privmsg(replyto, command.split()[1] + " is not a channel I inhabit. For help type " + blue + self.helpchar + "channelfunctions" + reset + ".")
+                    if not command.split()[1].lower() == "help":    # Not a help request.
+                        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.
                 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 CH.is_channelfunction(self, command.split()[1]):   # First argument is not a channelfunction.
-                        connection.privmsg(replyto, command.split()[1] + " is not a channel function. For help type " + blue + self.helpchar + "channelfunctions" + reset + ".")
-                        return
-                    if not command.split()[2].lower() in ["on",  "off"] and not command.split()[1].lower() == "aggressiveness":    # Second argument unsupported.
-                        connection.privmsg(replyto, "The value of this channel function can only be \"on\" or \"off\". For help type " + blue + self.helpchar + "channelfunctions" + reset + ".")
+                    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.
+                            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.
+                                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 + ".")
+                                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 + ".")
+                            return
                     if not userstatus.atleast_oper(self, event.source.nick, self.homechannel) and not userstatus.atleast_oper(self, event.source.nick, event.target):   # Does not have operator status or higher in target or home channel.
                         connection.privmsg(replyto, "Denied. You need to have at least operator status in " + red + event.target + reset + " or " + red + self.homechannel + reset + ".")
                         return
+                    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 + ".")
                     return
-                if not CH.is_channelfunction(self, command.split()[2]):  # Function does not exist.
+                if not AH.is_channelfunction(command.split()[2]):  # Function does not exist.
                     connection.privmsg(replyto, command.split()[2] + " is not a valid channel function. For a list help type: " + blue + self.cmdchar + "channelfunctions" + red + italic + "channel")
                     return
+                
                 if not command.split()[3].lower() in ["on", "off"] and not command.split()[2].lower() == "aggressiveness": # Third argument unsupported.
                     connection.privmsg(replyto, "The value of this channel function can only be \"on\" or \"off\". For help type " + blue + self.helpchar + "channelfunctions" + reset + ".")
                     return
                 if not userstatus.atleast_oper(self, event.source.nick, self.homechannel) and not userstatus.atleast_oper(self, event.source.nick, command.split()[1]):   # Does not have operator status or higher in target or home channel.
                     connection.privmsg(replyto, "Denied. You need to have at least operator status in " + red + event.target + reset + " or " + red + self.homechannel + reset + ".")
                     return
+                if command.split()[2].lower() == "autojoin" and command.split()[1] == self.homechannel:   # Chaning autojoin of homechannel.
+                    connection.action(replyto, "will always join it's homechannel " + red + self.homechannel + reset + ", regardless of the autojoin function.")
                 try:
                     self.db.run("UPDATE channels SET " + command.split()[2].lower() + "='" + command.split()[3].lower() + "' WHERE LOWER(name)=LOWER('" + command.split()[1] + "') AND network='" + self.network + "'")
                 except:
                     connection.privmsg(replyto, "Error, database record not updated.")
                     return
-            else:
+            else:   # Too many arguments.
                 connection.privmsg(replyto, "Too many arguments. For help type " + blue + self.helpchar + "channelfunctions" + reset + ".")

+ 35 - 5
commands/common.py

@@ -57,9 +57,10 @@ class CommandHelpers():
                 return blue + self.cmdchar + command + reset + ", "
         else:
             return blue + self.cmdchar + command + reset + ", "
-    
+
+class AdminHelpers():
     def get_channelfunctions(self, channel):
-        channelfunctions = self.db.one("SELECT autojoin, aggressiveness, join_greeting, statistics_commands, games FROM channels WHERE LOWER(name)=LOWER('" + channel + "') AND network='" + self.network + "'")
+        channelfunctions = self.db.one("SELECT autojoin, aggressiveness, join_greeting, statistics_commands, games, chat FROM channels WHERE LOWER(name)=LOWER('" + channel + "') AND network='" + self.network + "'")
         if channelfunctions[0]:
             autojoin = "on"
         else:
@@ -76,13 +77,42 @@ class CommandHelpers():
             games = "on"
         else:
             games = "off"""
-        return ("autojoin " + green + autojoin + reset + ", aggressiveness " + green + channelfunctions[1] + reset +  ", join_greeting " + green + joingreet + reset + ", statistics_commands " + green + statscmds + reset + ", games " + green + games + reset + ".")
+        if channelfunctions[5]:
+            chat = "on"
+        else:
+            chat = "off"""
+        return ("autojoin " + green + autojoin + reset + ", aggressiveness " + green + channelfunctions[1] + reset +  ", join_greeting " + green + joingreet + reset + ", statistics_commands " + green + statscmds + reset + ", games " + green + games + reset + ", chat " + green + chat + reset + ".")
         
-    def is_channelfunction(self, value):
-        if value not in ["autojoin", "join_greeting",  "statistics_commands",  "games", "aggressiveness"]:
+    def is_channelfunction(value):
+        if value.lower() in ["autojoin", "aggressiveness", "join_greeting",  "statistics_commands",  "games", "chat"]:
+            return True
+        else:
             return False
+    
+    def describe_channelfunction(function):
+        if function == "autojoin":
+            message = "Boolean. If the channel will be joined automaticly after connecting."
+        elif function == "aggressiveness":
+            message = "How to respond to kick, ban and mode events. Options: " + blue + "passive" + reset + ", " + blue + "defense_only" + reset + "."
+        elif function == "join_greeting":
+            message = ""
+        elif function == "statistics_commands":
+            message = ""
+        elif function == "games":
+            message = ""
+        elif function == "chat":
+            message = ""
         else:
+            message = ""
+        
+        return message
+    
+    def is_aggressiveness(value):
+        if value.lower() in ["passive", "defense_only"]:
             return True
+        else:
+            return False
+        
 
 class GameHelpers():
     def roll_dice(amount, type):

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


+ 7 - 2
common/networkservices.py

@@ -1,6 +1,11 @@
 class NickServ():
     def recover_nick(connection, password):
-        connection.privmsg("NickServ", "identify " + connection.nickname + " " + password) # Identify with NickServ.
-        connection.privmsg("NickServ", "recover " + connection.nickname + " " + password)  # Recover control of nickname via NickServ.
+        connection.privmsg("NickServ", "IDENTIFY " + connection.nickname + " " + password) # Identify with NickServ.
+        connection.privmsg("NickServ", "RECOVER " + connection.nickname + " " + password)  # Recover control of nickname via NickServ.
+        connection.privmsg("NickServ", "GHOST " + connection.nickname + " " + password)  # Recover control of nickname via NickServ, old style.
         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 unban(connection, channel, user):
+        connection.privmsg("ChanServ", "UNBAN " + channel + " " + user)
+

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


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


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


+ 24 - 6
events/on_kick.py

@@ -1,8 +1,19 @@
+from common.networkservices import ChanServ
+bold = "\x02"
+italic = "\x1D"
+underline = "\x1F"
+reverse = "\x16" 	# swap background and foreground colors ("reverse video")
+reset = "\x0F"
+blue = "\x0302"
+green = "\x0303"
+red = "\x0304"
+grey = "\x0314"
+
 def process_event(self, connection, event):
     kicker = event.source.nick
     channel = event.target
     kicked = event.arguments[0]
-    #reason = event.arguments[1]
+    reason = event.arguments[1]
     
     # 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.
@@ -22,8 +33,15 @@ def process_event(self, connection, event):
     
     # React.
     if kicked == connection.get_nickname(): # Bot was kicked.
-        if channel == self.homechannel: # From it's homechannel.
-            connection.join(self.homechannel)
-            return
-        #if self.db.one("SELECT aggressiveness FROM channels WHERE name='" + channel + "' AND network='" + self.network + "'") == "passive"):    # Passiev behaviour.
-            #return  # Do nothing.
+        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 + ".")

+ 6 - 1
events/on_pubmsg.py

@@ -3,6 +3,11 @@ 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 channelfunction chat if off.
+        chat = self.db.one("SELECT chat FROM channels WHERE name='" + event.target + "' AND network='" + self.network + "'")
+        if not chat:
+            return
         
         messages = [
             "Hello " + event.source.nick + ".", 
@@ -48,7 +53,7 @@ def process_event(self, connection, event):
             "rapes " + event.source.nick + ".", 
         ]
         
-        # REply with a random message or action.
+        # Reply with a random message or action.
         if random.randint(0, 1) == 0:
             connection.privmsg(event.target, random.choice(messages))
         else:

+ 0 - 2
rotbot.py

@@ -38,8 +38,6 @@ class PyRot(irc.bot.SingleServerIRCBot):
             sys.stderr.write(sys.exc_info()[1])
     
     # Events.
-    def on_all(self, connection, event):
-        print("ALL " + event)
     def on_nicknameinuse(self, connection, event):
         log.info("Nickname in use, attempting to recover: " + connection.nickname)
         connection.nick(connection.nickname + ''.join(random.choice(string.digits) for _ in range(3)))    # Take temporary nick. Without this recovering via NickServ won't work.