Browse Source

seen command

tBKwtWS 7 years ago
parent
commit
6e22f29ac1
6 changed files with 124 additions and 31 deletions
  1. 6 5
      commands/admin.py
  2. 4 5
      commands/public.py
  3. 96 6
      commands/statistics.py
  4. 15 12
      events/common.py
  5. 2 2
      events/on_kick.py
  6. 1 1
      events/on_mode.py

+ 6 - 5
commands/admin.py

@@ -1,6 +1,7 @@
 from common import userstatus, do_everything_to
 from commands.common import CommandHelpers as CH
 from commands.common import AdminHelpers as AH
+
 bold = "\x02"
 italic = "\x1D"
 underline = "\x1F"
@@ -30,8 +31,8 @@ def do_command(self, connection, event):
                 message += CH.ccc(self, "join", {"homechan": "oper",  "chan": None}, event)
             if CH.ccc(self, "part", {"homechan": "oper",  "chan": None}, event):
                 message += CH.ccc(self, "part", {"homechan": "oper",  "chan": None}, event)
-            if CH.ccc(self, "die",  {"homechan": "admin",  "chan": None}, event):
-                message += CH.ccc(self, "die",  {"homechan": "admin",  "chan": None}, event)
+            if CH.ccc(self, "quit",  {"homechan": "admin",  "chan": None}, event):
+                message += CH.ccc(self, "quit",  {"homechan": "admin",  "chan": None}, event)
             if CH.ccc(self, "reconnect", {"homechan": "oper",  "chan": None}, event):
                 message += CH.ccc(self, "reconnect", {"homechan": "oper",  "chan": None}, event)
             if CH.ccc(self, "recovernick",  {"homechan": "oper",  "chan": None}, event):
@@ -44,15 +45,15 @@ def do_command(self, connection, event):
                 return
             connection.privmsg(replyto, message[:-2] + ".")
     
-    elif command.split()[0] == "die":
+    elif command.split()[0] == "quit":
         if not userstatus.atleast_admin(self, event.source.nick, self.homechannel): #Insufficient rights.
             connection.privmsg(replyto, "Denied, you need to have admin (super 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, "Kill " + connection.get_nickname() + ". Optionally with reason.")
-            connection.privmsg(replyto,  grey + "Usage: " + blue + "!die " + reset + italic + "reason")
+            connection.privmsg(replyto, "Disconnect and terminate " + connection.get_nickname() + ". Optionally with reason.")
+            connection.privmsg(replyto,  grey + "Usage: " + blue + "!quit " + reset + italic + "reason")
         elif cmdtype == "cmd":
             if len(command.split()) == 1:
                 self.die(msg = "Killed by " + event.source.nick)

+ 4 - 5
commands/public.py

@@ -35,7 +35,10 @@ def do_command(self, connection, event):
                 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, "stopgreet")[:-2] + ".")
+            if not event.target == connection.get_nickname() and not self.db.one("SELECT join_greeting FROM channels WHERE name='" + event.target + "' AND network='" + self.network + "'"):
+                connection.privmsg(replyto, grey + "Commands: " + CH.ccc(self, "cmd") + CH.ccc(self, "help")[:-2] + ".")
+            else:
+                connection.privmsg(replyto, grey + "Commands: " + CH.ccc(self, "cmd") + CH.ccc(self, "help") + CH.ccc(self, "stopgreet")[:-2] + ".")
     
     elif command == "help":
         if cmdtype == "help":    #Display help text.
@@ -118,7 +121,3 @@ def do_command(self, connection, event):
                 self.db.run("UPDATE joins SET stopgreet='" + str(stopgreet) + "' WHERE LOWER(\"user\")=LOWER('" + user + "') AND user_network='" + self.network + "' AND lower(channel)=LOWER('" + channel + "') AND channel_network='" + self.network + "'")
             except:
                 connection.privmsg(replyto, "Failed to update database.")
-    
-    elif command.split()[0] == "seen":
-        pass
-        # last_act_type's: nick, join, kick, kicked, mode, part, quit, topic, msg, notice, action

+ 96 - 6
commands/statistics.py

@@ -1,3 +1,4 @@
+from datetime import datetime
 from commands.common import CommandHelpers as CH, StatisticsHelpers
 
 bold = "\x02"
@@ -19,14 +20,14 @@ def do_command(self, connection, event):
 
     if command == "cmd" or command == "commands":
         if cmdtype == "cmd":
-            connection.privmsg(replyto, grey + "Statistics commands: " + CH.ccc(self, "joins") + CH.ccc(self, "kicks") + CH.ccc(self, "messages") + CH.ccc(self, "actions") + CH.ccc(self, "notices")[:-2] + ".")
+            connection.privmsg(replyto, grey + "Statistics commands: " + CH.ccc(self, "seen") + CH.ccc(self, "joins") + CH.ccc(self, "kicks") + CH.ccc(self, "messages") + CH.ccc(self, "actions") + CH.ccc(self, "notices")[:-2] + ".")
     
     
     elif command.split()[0] == "joins" or command.split()[0] == "kicks" or command.split()[0] == "messages" or command.split()[0] == "actions" or command.split()[0] == "notices":
         if cmdtype == "help":    #Display help text.
             if len(command.split()) is not 1:
                 return
-            connection.privmsg(replyto, "Display amount of " + command.split()[0] + " of user and or channel. Channel and user optional.")
+            connection.privmsg(replyto, "Display amount of " + command.split()[0] + " of user and channel. Channel and user optional.")
             connection.privmsg(replyto, grey + "Usage: " + blue + self.cmdchar + command.split()[0] + " " + reset + italic + "channel user")
         elif cmdtype == "cmd":
             
@@ -44,18 +45,18 @@ def do_command(self, connection, event):
                     if connection.get_nickname() == event.target:   # Private message.
                         channelonly = True
                 else:
-                    user = command.split()[1]
+                    user = trigger.split()[1]
             elif len(command.split()) == 3: # Command has two arguments.
                 if not command.split()[1] in self.channels: # Bot does not inhabit requested channel.
                     if not command.split()[2] in self.channels: # User did not revert channel and user in command syntax.
                         connection.action(replyto, "does not inhabit " + red + command.split()[1] + reset + ".")
                         return
                     else:   # User reverted user and channel in command syntax.
-                        user = command.split()[1]
+                        user = trigger.split()[1]
                         channel = command.split()[2]
                 else: # Bot does inhabit requested channel.
-                    user = command.split()[2]
-                    channel = command.split()[1]
+                    user = trigger.split()[2]
+                    channel = trigger.split()[1]
             elif len(command.split()) < 5:  # To many arguments
                 connection.privmsg(replyto, "To many arguments. For help type " + blue + self.helpchar + "joins" + reset + ".")
                 return
@@ -127,3 +128,92 @@ def do_command(self, connection, event):
                         messages, words, characters = StatisticsHelpers.add_message_stats(chanstat)
                         message += " Total in " + red + channel + " " + green + str(messages) + reset + " " + blue + command.split()[0] + reset + ", " + green + str(words) + reset + " wrd, " + green + str(characters) + reset + " chr." 
                 connection.privmsg(replyto, message)
+    
+    elif command.split()[0] == "seen":
+        if cmdtype == "help":    #Display help text.
+            if len(command.split()) is not 1:
+                return
+            connection.privmsg(replyto, "Report the last sighting of a user.")
+            connection.privmsg(replyto, grey + "Usage: " + blue + self.cmdchar + command.split()[0] + " " + reset + italic + "user")
+        elif cmdtype == "cmd":
+        
+            if len(command.split()) == 1:
+                connection.privmsg(replyto, "I asm seeing you right now. For help type " + blue + self.helpchar + reset + ".")
+            elif len(command.split()) == 2:
+                if not self.db.one("SELECT last_act_type FROM users WHERE LOWER(name)='" + command.split()[1] + "' AND network='" + self.network + "'"):
+                    print("SELECT last_act_type FROM users WHERE LOWER(name)='" + command.split()[1] + "' AND network='" + self.network + "'")
+                    print(self.db.one("SELECT last_act_type FROM users WHERE LOWER(name)='" + command.split()[1] + "' AND network='" + self.network + "'"))
+                    connection.action(replyto, "has never seen " + red + command.split()[1] + reset + ".")
+                else:
+                    record = self.db.one("SELECT last_act_type, last_act_datetime, last_act_channel, last_act, last_act_auxiliary FROM users WHERE LOWER(name)='" + command.split()[1] + "' AND network='" + self.network + "'")
+                    action = "last saw " + red + trigger.split()[1] + reset + " "
+                    print(record)
+                    if record[0] == "nick":
+                        action += "changing nickname to " + red + record[3]
+                    elif record[0] == "join":
+                        action += "joining " + red + record[2]
+                    elif record[0] == "kick":
+                        if record[4]:
+                            action += "kicking " + red + record[4] + reset + " for " + green + record[3]
+                        else:
+                            action += "kicking " + red + record[3]
+                    elif record[0] == "kicked":
+                        if record[4]:
+                            action += "being kicked by " + red + record[3] + reset + " for " + green + record[4]
+                        else:
+                            action += "being kicked by " + red + record[3]
+                    elif record[0] == "mode":
+                        action += "changing modes on " + red + record[3]
+                    elif record[0] == "part":
+                        action += "parting " + red + record[2]
+                        if record[3]:
+                            action += reset + " for " + record[3]
+                    elif record[0] == "quit":
+                        action += "disconnecting"
+                        if record[3]:
+                            action += " due to " + green + record[3]
+                    elif record[0] == "topic":
+                        action += "changing the topic of " + red + record[2] + reset + " to " + green + record[3]
+                    elif record[0] == "msg":
+                        action += "posting " + green + record[3] + reset + " to " + red + record[2]
+                    elif record[0] == "notice":
+                        action += "posting the notice " + green + record[3] + " to " + red + record[2]
+                    elif record[0] == "action":
+                        action += green + record[3] + reset + " in " + red + record[2]
+                    else:
+                        connection.privmsg(replyto, "Last stored action unsupported by command code.")
+                        return
+                    action += reset + ", "
+                    print(datetime.now() - record[1])
+                    differential = datetime.now() - record[1]
+                    if differential.seconds < 5:    # Less then 5 seconds.
+                        action += blue + "right now."
+                    elif differential.seconds < 20: # Less then 20 seconds.
+                        action += blue + "just now."
+                    elif differential.seconds < 60: # Less then a minute.
+                        action += green + str(differential.seconds) + blue + " seconds " + reset + "ago."
+                    elif differential.seconds == 60: # 1 minute.
+                        action += green + "1 " + blue + "minute " + reset + "ago."
+                    elif int(differential.seconds / 60) < 60:   # Less then an hour.
+                        action += green + str(int(differential.seconds / 60)) + " minutes " + reset + "ago."
+                    elif int(differential.seconds / 60) ==  60: # 1 hour.
+                        action += green + "1 " + blue + "hour " + reset + "ago."
+                    elif int(differential.seconds / 3600) < 24 : # Less then a day.
+                        remaining_seconds = int(differential.seconds - int(differential.seconds / 3600) * 3600)
+                        action += green + str(int(differential.seconds / 3600)) + blue + " hours" + reset + " and " + str(int(remaining_seconds / 60)) + " minutes ago."
+                    elif int(differential.seconds / 3600) == 24 : # 1 day.
+                        action += green + "1 " + blue + "day " + reset + "ago."
+                    elif differential.days < 7: # Less then a week.
+                        remaining = differential - datetime.timedelta(days=differential.days)
+                        action += green + str(differential.days) + blue + " days " + reset + "and " + str(int(remaining.seconds / 3600)) + " hours ago."
+                    elif differential.days < 365:   # Less then a year.
+                        action += green + str(differential.days) + blue + " days " + reset + "ago."
+                    elif differential.days < 365:   # Less then 5 years.
+                        remaining_days = int(int(differential.days / 365) * 365)
+                        remaining = differential - datetime.timedelta(days=remaining_days)
+                        action += green + str(int(differential.days / 365)) + blue + " years " + reset + "and " + str(remaining.days) + " days."
+                    else:   # More then 5 years.
+                        action += green + str(int(differential.days / 365)) + blue + " years ago."
+                    connection.action(replyto, action)
+            else:   # Too many arguments.
+                connection.privmsg(replyto, "Too many arguments. For help type " + blue + self.helpchar + "seen" + reset + ".")

+ 15 - 12
events/common.py

@@ -79,22 +79,25 @@ class Lastact():
         if not self.db.one("SELECT id FROM users WHERE name='" + name + "' AND network='" + self.network + "'"):  # Not on record.
             self.db.run("INSERT INTO users (name, network) VALUES ('" + name + "', '" + self.network + "')")  # Create record.
         
-        # Update record.
-        fields = "last_act_type, last_act_datetime"
+          # Update record.
+        fields = "last_act_type, last_act_datetime, last_act_channel, last_act, last_act_auxiliary"
         values = "'" + type + "', '" + str(datetime.now()) + "'"
-        parameters = ()
+        arguments = ()
         if channel:
-            fields = fields + ", last_act_channel"
-            values = values + ", '" + channel + "'"
+            values += ", '" + channel + "'"
+        else:
+            values += ", NULL"
         if lastact:
-            fields = fields + ", last_act"
-            values = values + ", %s"
-            parameters = (lastact, )
+            values += ", %s"
+            arguments += lastact, 
+        else:
+            values += ", NULL"
         if auxiliary:
-            fields = fields + ", last_act_auxiliary"
-            values = values + ", %s"
-            parameters = parameters + (auxiliary, )
-        self.db.run("UPDATE users SET (" + fields + ") = (" + values + ") WHERE name='" + name + "' AND network='" + self.network + "'", parameters)
+            values += ", %s"
+            arguments += auxiliary, 
+        else:
+            values += ", NULL"
+        self.db.run("UPDATE users SET (" + fields + ") = (" + values + ") WHERE name='" + name + "' AND network='" + self.network + "'", arguments)
 
 class MessageStatistics():
     def update(self, event, type):

+ 2 - 2
events/on_kick.py

@@ -23,10 +23,10 @@ def process_event(self, connection, event):
     # Update last act.
     if reason:
         Lastact.update(self, kicker, "kick", channel=channel, lastact=kicked, auxiliary=reason)
-        Lastact.update(self, kicked, "kicked", channel=channel, lastact=kicked, auxiliary=reason)
+        Lastact.update(self, kicked, "kicked", channel=channel, lastact=kicker, auxiliary=reason)
     else:
         Lastact.update(self, kicker, "kick", channel=channel, lastact=kicked)
-        Lastact.update(self, kicked, "kicked", channel=channel, lastact=kicked)
+        Lastact.update(self, kicked, "kicked", channel=channel, lastact=kicker)
     
     # 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.

+ 1 - 1
events/on_mode.py

@@ -23,7 +23,7 @@ def process_event(self, connection, event):
             connection.who(event.arguments[1])  # Get whorepy to update protectees.
     
     # Update last act.
-    Lastact.update(self, event.source.nick, "mode", auxiliary=event.target)
+    Lastact.update(self, event.source.nick, "mode", lastact=event.target)
     
     # React.
     modes = parse_channel_modes(" ".join(event.arguments))