浏览代码

crash path

tBKwtWS 8 年之前
父节点
当前提交
4a1dbedc64
共有 3 个文件被更改,包括 20 次插入3 次删除
  1. 18 1
      commands/public.py
  2. 0 2
      events/on_join.py
  3. 2 0
      rotbot.py

+ 18 - 1
commands/public.py

@@ -12,6 +12,12 @@ grey = "\x0314"
 def do_command(self, connection, event):
 def do_command(self, connection, event):
     cmdtype, trigger, command, replyto = CH.disect_command(self, 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.
+    
     # The actual commands:
     # The actual commands:
     if command == "test":
     if command == "test":
         if cmdtype == "help":    #Display help text.
         if cmdtype == "help":    #Display help text.
@@ -24,7 +30,7 @@ def do_command(self, connection, event):
         if cmdtype == "help":    #Display help text.
         if cmdtype == "help":    #Display help text.
             connection.privmsg(replyto, "Displays a list of commands.")
             connection.privmsg(replyto, "Displays a list of commands.")
         elif cmdtype == "cmd":
         elif cmdtype == "cmd":
-            connection.privmsg(replyto, grey + "Commands: " + CH.ccc(self, "cmd") + CH.ccc(self, "help") + CH.ccc(self, "joins")[:-2] + ".")
+            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":
     elif command == "help":
         if cmdtype == "help":    #Display help text.
         if cmdtype == "help":    #Display help text.
@@ -88,3 +94,14 @@ def do_command(self, connection, event):
             except:
             except:
                     pass
                     pass
             connection.privmsg(replyto, "tBKwtWS Was wondering if this programming was sloppy. When you see this message, it was.")
             connection.privmsg(replyto, "tBKwtWS Was wondering if this programming was sloppy. When you see this message, it was.")
+    
+    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")
+        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.

+ 0 - 2
events/on_join.py

@@ -11,10 +11,8 @@ grey = "\x0314"
 def process_event(self, connection, event):
 def process_event(self, connection, event):
     # Add join event to database for statistics.
     # Add join event to database for statistics.
     if not self.db.one("SELECT id FROM channels WHERE name='" + event.target + "' AND network='" + self.network + "'"): # Channel does not exist in database.
     if not self.db.one("SELECT id FROM channels WHERE name='" + event.target + "' AND network='" + self.network + "'"): # Channel does not exist in database.
-        print("INFO Adding channel " + event.target + " to the database.")
         self.db.run("INSERT INTO channels (name, network) VALUES ('" + event.target + "', '" + self.network + "')")
         self.db.run("INSERT INTO channels (name, network) VALUES ('" + event.target + "', '" + self.network + "')")
     if not self.db.one("SELECT id FROM users WHERE name='" + event.source.nick + "' AND network='" + self.network + "'"):   # User does not exist in database.
     if not self.db.one("SELECT id FROM users WHERE name='" + event.source.nick + "' AND network='" + self.network + "'"):   # User does not exist in database.
-        print("INFO Adding user " + event.source.nick + " to the database.")
         self.db.run("INSERT INTO users (name, network) VALUES ('" + event.source.nick + "', '" + self.network + "')")
         self.db.run("INSERT INTO users (name, network) VALUES ('" + event.source.nick + "', '" + self.network + "')")
     if not self.db.one("SELECT id FROM joins WHERE channel='" + event.target + "' AND channel_network='" + self.network + "' AND \"user\"='" + event.source.nick + "' AND user_network='" + self.network + "'"):    # No record yet
     if not self.db.one("SELECT id FROM joins WHERE channel='" + event.target + "' AND channel_network='" + self.network + "' AND \"user\"='" + event.source.nick + "' AND user_network='" + self.network + "'"):    # No record yet
         self.db.run("INSERT INTO joins (channel, channel_network, \"user\", user_network, joins) VALUES ('" + event.target + "', '" + self.network + "', '" + event.source.nick + "', '" + self.network + "', 0)")
         self.db.run("INSERT INTO joins (channel, channel_network, \"user\", user_network, joins) VALUES ('" + event.target + "', '" + self.network + "', '" + event.source.nick + "', '" + self.network + "', 0)")

+ 2 - 0
rotbot.py

@@ -1,4 +1,6 @@
 #! /usr/bin/env python
 #! /usr/bin/env python
+#
+# Version 0.0a2 by tBKwtWS.
 
 
 import sys, random, string, ssl
 import sys, random, string, ssl
 import irc.bot, irc.strings
 import irc.bot, irc.strings