Browse Source

stopgreet & part

tBKwtWS 7 năm trước cách đây
mục cha
commit
c89ad441c8

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


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


+ 50 - 4
commands/admin.py

@@ -1,3 +1,4 @@
+from common import userstatus
 from commands.common import CommandHelpers as CH
 bold = "\x02"
 italic = "\x1D"
@@ -19,7 +20,15 @@ def do_command(self, connection, event):
     
     if command == "cmd" or command == "commands":
         if cmdtype == "cmd":
-            connection.privmsg(replyto, grey + "Admin: " + CH.ccc(self, "channelfunctions",  {"homechan": "oper", "chan": "oper"}, event) + CH.ccc(self, "join", {"homechan": "oper",  "chan": None}, event) + CH.ccc(self, "die",  {"homechan": "admin",  "chan": None}, event) + CH.ccc(self, "reconnect", {"homechan": "oper",  "chan": None}, event) + CH.ccc(self, "recovernick",  {"homechan": "oper",  "chan": None}, event)+ CH.ccc(self, "msg",  {"homechan": "oper",  "chan": "oper"}, event) + CH.ccc(self, "act", {"homechan": "oper",  "chan": "oper"}, event)[:-2] + ".")
+            connection.privmsg(replyto, grey + "Admin: "
+           + CH.ccc(self, "channelfunctions",  {"homechan": "oper", "chan": "oper"}, event)
+           + CH.ccc(self, "join", {"homechan": "oper",  "chan": None}, event)
+           + CH.ccc(self, "part", {"homechan": "oper",  "chan": None}, event)
+           + CH.ccc(self, "die",  {"homechan": "admin",  "chan": None}, event)
+           + CH.ccc(self, "reconnect", {"homechan": "oper",  "chan": None}, event)
+           + CH.ccc(self, "recovernick",  {"homechan": "oper",  "chan": None}, event)
+           + CH.ccc(self, "msg",  {"homechan": "oper",  "chan": "oper"}, event)
+           + CH.ccc(self, "act", {"homechan": "oper",  "chan": "oper"}, event)[:-2] + ".")
     
     elif command.split()[0] == "channelfunctions":
         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.
@@ -76,14 +85,14 @@ def do_command(self, connection, event):
                 connection.privmsg(replyto, "Too many arguments. For help type " + blue + self.helpchar + "channelfunctions" + reset + ".")
     
     elif command.split()[0] == "join":
-        if not self.channels[self.homechannel].is_owner(event.source.nick) and not self.channels[self.homechannel].is_admin(event.source.nick) and not self.channels[self.homechannel].is_oper(event.source.nick):
-            connection.privmsg(replyto, "Denied, you need to have admin (super operator) status or higher in " + red + self.homechannel  + reset + ".")
+        if not userstatus.atleast_oper(self, event.source.nick, self.homechannel):
+            connection.privmsg(replyto, "Denied, you need to have operator status or higher in " + red + self.homechannel  + reset + ".")
             return
         if cmdtype == "help":    #Display help text.
             if len(command.split()) is not 1:
                 return
             connection.privmsg(replyto, "Make " + connection.get_nickname() + " join a channel. Password optional.")
-            connection.privmsg(replyto, grey + "Usage: " + blue + "!join " + red + italic + "channel " + reset + italic + "password")
+            connection.privmsg(replyto, grey + "Usage: " + blue + self.cmdchar + "join " + red + italic + "channel " + reset + italic + "password")
         elif cmdtype == "cmd":
             try:
                 channel = command.split()[1]
@@ -98,6 +107,43 @@ def do_command(self, connection, event):
             print(channel + " | " + key)
             connection.join(channel, key=key)
     
+    elif command.split()[0] == "part":
+        if cmdtype == "help":    #Display help text.
+            if len(command.split()) is not 1:
+                return
+            connection.privmsg(replyto, "Make " + connection.get_nickname() + " part a channel. Reason optional.")
+            connection.privmsg(replyto, grey + "Usage: " + blue + self.cmdchar + "join " + red + italic + "channel " + reset + italic + "password")
+        elif cmdtype == "cmd":
+            
+            if self.channels[self.homechannel].is_owner(event.source.nick) or self.channels[self.homechannel].is_admin(event.source.nick) or self.channels[self.homechannel].is_oper(event.source.nick):    # Is at least operator in home channel.
+                homeadmin = True
+            
+            try:
+                if self.channels[event.target].is_owner(event.source.nick) or self.channels[event.target].is_admin(event.source.nick) or self.channels[event.target].is_oper(event.source.nick):
+                    targetadmin = True
+            except:
+                pass
+            
+            if len(command.split()) == 1:   # No arguments.
+                if event.target in self.channels:   # It's a channel message.
+                    if not homeadmin and not targetadmin:   # Insufficient rights:
+                        connection.privmsg(replyto, "Denied. You need to have at least operator status in " + red + self.homechan + reset + " or " + red + event.target + reset + ".")
+                        return
+                    connection.part(event.target, event.source.nick)
+                else:   # It's a PM.
+                    connection.privmsg(replyto, "Specify a channel to part. For help type " + blue + self.helpchar + "part" + reset + ".")
+            elif len(command.split()) > 1:   # Arguments
+                if command.split()[1] not in self.channels: # First argument is not a channel the bot inhabits.
+                    connection.action(replyto, "does not inhabit " + red + command.split()[1] + reset + ". For help type " + blue + self.helpchar + "part" + reset + ".")
+                    return
+                if not homeadmin and not self.channels[command.split()[1]].is_owner(event.source.nick) and not self.channels[command.split()[1]].is_admin(event.source.nick) and not self.channels[command.split()[1]].is_oper(event.source.nick):  # Insufficient rights.
+                    connection.privmsg(replyto, "Denied. You need to have at least operator status in " + red + self.homechan + reset + " or " + red + command.split()[1] + reset + ".")
+                    return
+                try:
+                    connection.part(command.split()[1], command.split(maxsplit=2)[2])
+                except:
+                    connection.part(command.split()[1], event.source.nick)
+    
     elif command.split()[0] == "die":
         if not self.channels[self.homechannel].is_owner(event.source.nick) and not self.channels[self.homechannel].is_admin(event.source.nick):
             connection.privmsg(replyto, "Denied, you need to have admin (super operator) status or higher in " + red + self.homechannel  + reset + ".")

+ 79 - 7
commands/public.py

@@ -1,3 +1,4 @@
+from common import userstatus
 from commands.common import CommandHelpers as CH
 bold = "\x02"
 italic = "\x1D"
@@ -21,6 +22,8 @@ def do_command(self, connection, event):
     # The actual commands:
     if command == "test":
         if cmdtype == "help":    #Display help text.
+            if len(command.split()) is not 1:
+                return
             connection.privmsg(replyto, "Strictly for testing purposes only!")
         elif cmdtype == "cmd":
             
@@ -28,12 +31,16 @@ def do_command(self, connection, event):
             
     elif command == "cmd" or command == "commands":
         if cmdtype == "help":    #Display help text.
+            if len(command.split()) is not 1:
+                return
             connection.privmsg(replyto, "Displays a list of commands.")
         elif cmdtype == "cmd":
             connection.privmsg(replyto, grey + "Commands: " + CH.ccc(self, "cmd") + CH.ccc(self, "help") + CH.ccc(self, "joins") + CH.ccc(self, "stopgreet")[:-2] + ".")
     
     elif command == "help":
         if cmdtype == "help":    #Display help text.
+            if len(command.split()) is not 1:
+                return
             connection.privmsg(replyto, "Explains how to get help on any specific command and hints the user to the commandlist.")
         elif cmdtype == "cmd":
             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")
@@ -42,6 +49,8 @@ def do_command(self, connection, event):
     
     elif command.split()[0] == "joins":
         if cmdtype == "help":    #Display help text.
+            if len(command.split()) is not 1:
+                return
             connection.privmsg(replyto, "Display amount of joins of user and or channel. Channel and user optional.")
             connection.privmsg(replyto, grey + "Usage: " + blue + "!joins " + reset + italic + "channel user")
         elif cmdtype == "cmd":
@@ -97,11 +106,74 @@ def do_command(self, connection, event):
     
     elif command.split()[0] == "stopgreet":
         if cmdtype == "help":    #Display help text.
-            connection.privmsg(replyto, "Stops the bot from greeting you or a specific user. Channel and user optional.")
-            connection.privmsg(replyto, grey + "Usage: " + blue + "!stopgreet " + red + italic + "channel user")
+            if len(command.split()) is not 1:
+                return
+            connection.privmsg(replyto, "Stops the bot from greeting you or a specific user. Channel, user and option to resume optional.")
+            connection.privmsg(replyto, grey + "Usage: " + blue + "!stopgreet " + red + italic + "resume channel user")
         elif cmdtype == "cmd":
-            if len(command.splt()) == 1:    # No arguments.
-                if self.db.one("SELECT id FROM")
-            if len(command.splt()) == 2:    # One argument.
-            if len(command.splt()) == 3:    # Two arguments.
-            if len(command.splt()) < 3:    # Too many arguments.
+            
+            if len(command.split()) == 1:    # No arguments.
+                if event.target == connection.get_nickname():   # PM.
+                    connection.privmsg(replyto, "Specify at least a channel. For help type " + blue + self.helpchar + "stopgreet" + reset + ".")
+                    return
+                user = event.source.nick
+                channel = event.target
+            
+            # Check for resume variation of command.
+            resume = False
+            try:
+                if command.split()[1] == "resume":
+                    resume = True
+                    command = command.split(' ', 1)[1]  # Remove the resume argument. Which makes the following logic easier.
+            except:
+                pass
+                
+            if len(command.split()) == 2:    # One argument.
+                if command.split()[1] not in self.channels: # Argument is not a channel the bot inhabits.
+                    if event.target == connection.get_nickname():   # PM.
+                        connection.action(replyto, "does not inhabit " + red + command.split()[1] + reset + ".")
+                        return
+                    # Channel message
+                    if not userstatus.atleast_halfop(self, event.source.nick, self.homechannel) and not userstatus.atleast_halfop(self, event.source.nick, event.target):  # Insufficient rights.
+                        connection.privmsg(replyto, "Denied. You need to have at least halfop status in " + red + self.homechannel + reset + " or " + red + event.target + reset + ".")
+                        return
+                    # Stopgreet for x user in current channel
+                    user = command.split()[1]
+                    channel = event.target
+                else:   # Bot inhabit channel.
+                    user = event.source.nick
+                    channel = command.split()[1]
+            if len(command.split()) == 3:    # Two arguments.
+                if command.split()[1] not in self.channels: # Bot does not inhabit channel.
+                    connection.action(replyto, "does not inhabit " + red + command.split()[1] + reset + ".")
+                    return
+                if not userstatus.atleast_halfop(self, event.source.nick, self.homechannel) and not userstatus.atleast_halfop(self, event.source.nick, command.split()[1]):  # Insufficient rights.
+                    connection.privmsg(replyto, "Denied. You need to have at least halfop status in " + red + self.homechannel + reset + " or " + red + command.split()[1] + reset + ".")
+                    return
+                user = command.split()[2]
+                channel = command.split()[1]
+            if len(command.split()) > 3:    # Too many arguments.
+                connection.privmsg(replyto, "Too many arguments. For help type " + blue + self.helpchar + "stopgreet" + reset + ".")
+                return
+            
+            # Check for database record.
+            result = self.db.one("SELECT id, stopgreet FROM joins WHERE \"user\"='" + user + "' AND user_network='" + self.network + "' AND channel='" + channel + "' AND channel_network='" + self.network + "'")
+            if not result:  # No record in database.
+                connection.action(replyto, "has not yet had the pleasure of greeting " + red + user + reset + " in " + red + channel + reset + ".")
+                return
+            
+            if resume:
+                stopgreet = False
+                message = "has already every intention to greet "
+            else:
+                stopgreet = True
+                message = "has already stopped greeting "
+            if result[1] == stopgreet:
+                connection.action(replyto, message + red + user + reset + " in " + red + channel + reset + ".")
+                return
+            print(str(stopgreet) + str(user) + str(channel))
+            #try:
+            print("UPDATE joins SET stopgreet='" + str(stopgreet) + "' WHERE \"user\"='" + user + "' AND user_network='" + self.network + "' AND channel='" + channel + "' AND channel_network='" + self.network + "'")
+            self.db.run("UPDATE joins SET stopgreet='" + str(stopgreet) + "' WHERE \"user\"='" + user + "' AND user_network='" + self.network + "' AND channel='" + channel + "' AND channel_network='" + self.network + "'")
+            #except:
+                #connection.privmsg(replyto, "Failed to update database.")

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


+ 15 - 0
common/userstatus.py

@@ -0,0 +1,15 @@
+def atleast_oper(self, user, channel):
+    if channel not in self.channels:
+        return False
+    if self.channels[channel].is_owner(user) or self.channels[channel].is_admin(user) or self.channels[channel].is_oper(user):
+        return True
+    else:
+        return False
+
+def  atleast_halfop(self, user, channel):
+    if channel not in self.channels:
+        return False
+    if self.channels[channel].is_owner(user) or self.channels[channel].is_admin(user) or self.channels[channel].is_oper(user) or self.channels[channel].is_halfop(user):
+        return True
+    else:
+        return False

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