Browse Source

Fixed crash isf command is empty

tBKwtWS 7 years ago
parent
commit
79c0cb86f4

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


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


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


+ 4 - 2
commands/admin.py

@@ -12,12 +12,14 @@ grey = "\x0314"
 
 def do_command(self, connection, event):
     cmdtype, trigger, command, replyto = CH.disect_command(self, event)
-    
+    if not command: # Do nothing if there is no command.
+        return
+        
     # Ignore channel commands from users that do not have at least voice in homechannel or operator status in target channel.
     if event.type == "pubmsg":   # It's a channel message.
         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) and not self.channels[event.target].is_owner(event.source.nick) and not self.channels[event.target].is_admin(event.source.nick) and not self.channels[event.target].is_oper(event.source.nick): # Does not have at least voiced status in homechannel or operator status in target channel.
             return
-    
+            
     if command == "cmd" or command == "commands":
         if cmdtype == "cmd":
             message = grey + "Admin: "

+ 8 - 4
commands/common.py

@@ -59,20 +59,24 @@ class CommandHelpers():
             return blue + self.cmdchar + command + reset + ", "
     
     def get_channelfunctions(self, channel):
-        channelfunctions = self.db.one("SELECT join_greeting, statistics_commands, games FROM channels WHERE name='" + channel + "' AND network='" + self.network + "'")
+        channelfunctions = self.db.one("SELECT autojoin, join_greeting, statistics_commands, games FROM channels WHERE name='" + channel + "' AND network='" + self.network + "'")
         if channelfunctions[0]:
+            autojoin = "on"
+        else:
+            autojoin = "off"
+        if channelfunctions[1]:
             joingreet = "on"
         else:
             joingreet = "off"
-        if channelfunctions[1]:
+        if channelfunctions[2]:
             statscmds = "on"
         else:
             statscmds = "off"
-        if channelfunctions[2]:
+        if channelfunctions[3]:
             games = "on"
         else:
             games = "off"
-        return ("join_greeting " + joingreet + ", statistics_commands " + statscmds + ", games " + games + ".")
+        return ("autojoin" + autojoin + ", join_greeting " + joingreet + ", statistics_commands " + statscmds + ", games " + games + ".")
         
     def is_channelfunction(self, value):
         if value not in ["join_greeting",  "statistics_commands",  "games"]:

+ 2 - 0
commands/games.py

@@ -13,6 +13,8 @@ grey = "\x0314"
 
 def do_command(self, connection, event):
     cmdtype, trigger, command, replyto = CH.disect_command(self, event)
+    if not command: # Do nothing if there is no command.
+        return
     
     if command == "cmd" or command == "commands":
         if cmdtype == "cmd":

+ 2 - 6
commands/public.py

@@ -12,12 +12,8 @@ grey = "\x0314"
 
 def do_command(self, connection, event):
     cmdtype, trigger, command, replyto = CH.disect_command(self, event)
-    
-    # Bot crashes once in a while when a user joins a channel, with "IndexError: list index out of range"  on "command.split()[0] == "joins"". 
-    try:
-        command.split()[0]
-    except:
-        return  # Stop, there is no command.
+    if not command: # Do nothing if there is no command.
+        return
     
     # The actual commands:
     if command == "test":

+ 1 - 0
rotbot.py

@@ -54,6 +54,7 @@ class PyRot(irc.bot.SingleServerIRCBot):
         print(event)
         if self.password:
             connection.privmsg("NickServ", "identify " + connection.nickname + " " + self.password) # Identify with NickServ.
+        self.db.all("SELECT name FROM channels WHERE network='" + self.network + "' AND autojoin=True")
         print("Joining " + self.homechannel)
         connection.join(self.homechannel)