Explorar o código

several minor improvements

tBKwtWS %!s(int64=8) %!d(string=hai) anos
pai
achega
c298eb2d94
Modificáronse 4 ficheiros con 26 adicións e 14 borrados
  1. 10 6
      irc/bot.py
  2. 1 6
      irc/commands/public.py
  3. 1 1
      irc/commands/statistics.py
  4. 14 1
      irc/events/common.py

+ 10 - 6
irc/bot.py

@@ -9,7 +9,7 @@ import commands.public, commands.admin, commands.games, commands.statistics
 import events.on_welcome, events.on_join, events.on_kick, events.on_mode, events.on_pubmsg, events.on_action, events.on_whoreply, events.on_nick
 from common import log
 from common.networkservices import NickServ
-from events.common import Lastact, MessageStatistics
+from events.common import Lastact, MessageStatistics, Inform
 
 bold = "\x02"
 italic = "\x1D"
@@ -32,7 +32,7 @@ class PyRot(irc.bot.SingleServerIRCBot):
         self.protectees = {}
         self.channelkeys = {}
         
-        print("Starting pyRot, the third RotBot by tBkwtWS.")
+        log.info("Starting pyRot, the third RotBot by tBkwtWS.")
         log.info("Connecting to " + host + ":" + str(port) + "/" + self.homechannel)
         
         if usessl:
@@ -58,6 +58,7 @@ class PyRot(irc.bot.SingleServerIRCBot):
     def on_error(self, connection, event):
         log.notice(str(event))
         connection.privmsg(self.homechannel, "ERROR: " + str(event))
+        Inform.owners(self, connection, "Received error from server: " + str(event))
     
     def on_nick(self, connection, event):
         events.on_nick.process_event(self, connection, event)
@@ -74,7 +75,7 @@ class PyRot(irc.bot.SingleServerIRCBot):
     def on_part(self, connection, event):
         log.info(event)
         
-        # Update protectees
+        # Update protectees.
         if event.target == self.homechannel and event.source.nick in self.protectees:    # Protectee parted home channel.
             del self.protectees[event.source.nick] # Delete from protectees.
         
@@ -87,7 +88,7 @@ class PyRot(irc.bot.SingleServerIRCBot):
     def on_quit(self, connection, event):
         log.info(event)
         
-        # Update protectees
+        # Update protectees.
         if event.source.nick in self.protectees:    # Protectee parted home channel.
             del self.protectees[event.source.nick] # Delete from protectees.
         
@@ -100,7 +101,7 @@ class PyRot(irc.bot.SingleServerIRCBot):
     def on_invite(self, connection, event):
         log.notice(event)
         if event.target == connection.get_nickname(): # Bot invited.
-            connection.privmsg(self.homechannel, "Received invite to " + red + event.arguments[0] + reset + " from " + red + event.source.nick + reset + ".")
+            Inform.operators(self, connection, "Received invitation to " + red + event.arguments[0] + reset + " from " + red + event.source.nick + reset + ".")
     
     def on_topic(self, connection, event):
         log.info(event)
@@ -121,6 +122,7 @@ class PyRot(irc.bot.SingleServerIRCBot):
         commands.admin.do_command(self, connection, event)
         commands.statistics.do_command(self, connection, event)
         commands.games.do_command(self, connection, event)
+        Inform.operators(self, connection, "PM from " + red + red + event.source.nick + grey + ": " + reset + event.arguments[0] + ".")
     
     def on_pubnotice(self, connection, event):
         log.info(event)
@@ -144,6 +146,7 @@ class PyRot(irc.bot.SingleServerIRCBot):
                 connection.join(event.arguments[0].split(' ')[3], event.arguments[0].split(' ')[5][:-1])
         except:
             pass
+        Inform.owners(self, connection, "PM from " + red + red + event.source.nick + grey + ": " + reset + event.arguments[0] + ".")
     
     def on_action(self, connection, event):
         events.on_action.process_event(self, connection, event)
@@ -162,8 +165,9 @@ class PyRot(irc.bot.SingleServerIRCBot):
     def on_yourebannedcreep(self, connection, event):
         log.warning(event)
     
-    def on_youwillbebanned(selfself, connection, event):
+    def on_youwillbebanned(self, connection, event):
         log.warning(event)
+        Inform.operators(self, connection, "I will be banned " + red + event.arguments[0] + reset + " from " + red + event.source)
     
     
     # DCC stuff from originalexample file.

+ 1 - 6
irc/commands/public.py

@@ -29,13 +29,8 @@ def do_command(self, connection, event):
                 return
             connection.privmsg(replyto, "Strictly for testing purposes only!")
         elif cmdtype == "cmd":
-            
             connection.privmsg(replyto, str(self.channels[self.homechannel].owners()))
-            if event.target == connection.get_nickname():   # PM
-                connection.privmsg(replyto, event)
-            else:   # Channel message.
-                connection.privmsg(replyto, str(self.channels[event.target]))
-            
+    
     elif command == "cmd" or command == "cmds" or command == "commands":
         if cmdtype == "help":    #Display help text.
             if len(command.split()) is not 1:

+ 1 - 1
irc/commands/statistics.py

@@ -115,7 +115,7 @@ def do_command(self, connection, event):
                         connection.privmsg(replyto, red + user + reset + " has given " + green + str(kicksgiven) + reset + " and received " + green + str(kicksreceived) + reset + " kicks")
             elif command.split()[0] == "messages" or command.split()[0] == "actions" or command.split()[0] == "notices":
                 userstat = self.db.all("SELECT " + command.split()[0] + ", " + command.split()[0] + "_words, " + command.split()[0] + "_characters FROM messages WHERE LOWER(\"user\")=LOWER('" + user + "') AND user_network='" + self.network + "'")
-                print(userstat[0])
+
                 userrecord = False
                 for record in userstat:
                     if not record[0] == 0:

+ 14 - 1
irc/events/common.py

@@ -94,5 +94,18 @@ class MessageStatistics():
         queries.create_ifnot_onrecord(self, "channels", event.target)
         queries.create_ifnot_onrecord(self, "users", event.source.nick)
         if not self.db.one("SELECT channel, \"user\" FROM messages WHERE LOWER(channel)=LOWER(%s) AND channel_network=%s AND LOWER(\"user\")=LOWER(%s) AND user_network=%s", (event.target, self.network, event.source.nick, self.network, )):  # Not on record.
-            self.db.run("INSERT INTO messages (channel, channel_network, \"user\", user_network) VALUES ('" + event.target + "', '" + self.network + "', '" + event.source.nick + "', '" + self.network + "')")   # Create record.
+            self.db.run("INSERT INTO messages (channel, channel_network, \"user\", user_network) VALUES (%s, %s, %s, %s)", (event.target, self.network, event.source.nick, self.network , ))   # Create record.
         self.db.run("UPDATE messages SET " + type + "=" + type + "+1, " + type + "_words=" + type + "_words+" + str(len(event.arguments[0].split())) + ", " + type + "_characters=" + type + "_characters+" + str(len(event.arguments[0])) + " WHERE LOWER(channel)=LOWER('" + event.target + "') AND channel_network='" + self.network + "' AND LOWER(\"user\")=LOWER('" + event.source.nick + "') AND user_network='" + self.network + "'")   # Increment record.
+
+class Inform():
+    def owners(self, connection, message):
+        for owner in self.channels[self.homechannel].owners():
+            connection.privmsg(owner, message)
+    
+    def operators(self, connection, message):
+        for user in self.channels[self.homechannel].owners():
+            connection.privmsg(user, message)
+        for user in self.channels[self.homechannel].admins():
+            connection.privmsg(user, message)
+        for user in self.channels[self.homechannel].operators():
+            connection.privmsg(user, message)