| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121 |
- from commands.common import CommandHelpers as CH
- bold = "\x02"
- italic = "\x1D"
- underline = "\x1F"
- reverse = "\x16" # swap background and foreground colors ("reverse video")
- reset = "\x0F"
- blue = "\x0302"
- green = "\x0303"
- red = "\x0304"
- 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 not self.db.one("SELECT statistics_commands FROM channels WHERE name='" + event.target + "' AND network='" + self.network + "'") and not event.target == connection.get_nickname():
- return # Do noting if the games channel function is off and it's a channel message.
- 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")[:-2] + ".")
-
-
- elif command.split()[0] == "joins" or command.split()[0] == "kicks" or command.split()[0] == "messages":
- 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, grey + "Usage: " + blue + self.cmdchar + command.split()[0] + " " + reset + italic + "channel user")
- elif cmdtype == "cmd":
-
- # Parse user input
- user = event.source.nick
- channel = None
- channelonly= False
- if not connection.get_nickname() == event.target: # Channel message.
- channel = event.target
- if len(command.split()) == 1: # Command contains only !joins.
- user = event.source.nick
- elif len(command.split()) == 2: # Command has one argument.
- if command.split()[1] in self.channels:
- channel = command.split()[1]
- if connection.get_nickname() == event.target: # Private message.
- channelonly = True
- else:
- user = command.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]
- channel = command.split()[2]
- else: # Bot does inhabit requested channel.
- user = command.split()[2]
- channel = command.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
-
- if command.split()[0] == "joins":
- if channel: # User and channel.
- userstat = str(sum(self.db.all("SELECT " + command.split()[0] + " FROM " + command.split()[0] + " WHERE channel_network='" + self.network + "' AND LOWER(\"user\")=LOWER('" + user + "') AND user_network='" + self.network + "'")))
- userchannelstat = str(self.db.one("SELECT " + command.split()[0] + " FROM " + command.split()[0] + " WHERE LOWER(channel)=LOWER('" + channel + "') AND channel_network='" + self.network + "' AND LOWER(\"user\")=LOWER('" + user + "') AND user_network='" + self.network + "'"))
- channelstat = str(sum(self.db.all("SELECT " + command.split()[0] + " FROM " + command.split()[0] + " WHERE LOWER(channel)=LOWER('" + channel + "') AND channel_network='" + self.network + "' AND user_network='" + self.network + "'")))
- if userchannelstat == "None":
- userchannelstat = "0"
- if channelonly:
- connection.privmsg(replyto, red + channel + reset + " has " + green + channelstat + reset + " " + command.split()[0] + reset + " in total.")
- elif userstat == "0" and not channelonly: # No user joins on record.
- connection.action(replyto, "has no record of any joins by " + red + user + reset + " in " + red + channel + reset + ".")
- else: # User joins on record.
- connection.privmsg(replyto, red + user + reset + " has " + green + userstat + reset + " " + command.split()[0] + ". Of which " + green + userchannelstat + reset + " have been in " + red + channel + reset + ", that has " + green + channelstat + reset + " " + command.split()[0] + reset + " in total.")
- else: # Only user.
- userstat = str(sum(self.db.all("SELECT " + command.split()[0] + " FROM " + command.split()[0] + " WHERE channel_network='" + self.network + "' AND LOWER(\"user\")=LOWER('" + user + "') AND user_network='" + self.network + "'")))
- if userstat == "0": # No statistics on user.
- connection.action(replyto, "has no record of any joins by " + red + user + reset + ".")
- else: # Got statistics on user.
- connection.privmsg(replyto, red + user + reset + " has " + green + userstat + reset + " " + command.split()[0] + " in channels I monitor.")
- elif command.split()[0] == "kicks":
- if channel: # User and channel.
- try:
- givenkicks, receivedkicks = self.db.one("SELECT given, received FROM " + command.split()[0] + " WHERE LOWER(channel)=LOWER('" + channel + "') AND channel_network='" + self.network + "' AND LOWER(\"user\")=LOWER('" + user + "') AND user_network='" + self.network + "'")
- except:
- givenkicks = 0
- receivedkicks = 0
- if channelonly:
- connection.privmsg(replyto, red + channel + reset + " has " + green + channelstat + reset + " " + command.split()[0] + reset + " in total.")
- elif givenkicks == 0: # No kicks on record.
- connection.action(replyto, "has no record of any kicks for " + red + user + reset + " in " + red + channel + reset + ".")
- else: # Kciks on record.
- channelkicks = self.db.all("SELECT given FROM " + command.split()[0] + " WHERE LOWER(channel)=LOWER('" + channel + "') AND channel_network='" + self.network + "'")
- connection.privmsg(replyto, red + user + reset + " has kicked " + green + str(givenkicks) + reset + " and been kicked " + green + str(receivedkicks) + reset + " times in " + red + channel + reset + ", where were " + green + str(sum(channelkicks)) + reset + " kicks in total.")
- else: # Only user.
- userstat = self.db.all("SELECT given, received FROM kicks WHERE channel_network='" + self.network + "' AND LOWER(\"user\")=LOWER('" + user + "') AND user_network='" + self.network + "'")
- kicksgiven = 0
- kicksreceived = 0
- for record in userstat:
- kicksgiven += record[0]
- kicksreceived += record[1]
- if kicksgiven == 0 and kicksreceived == 0:
- connection.action(replyto, red + user + reset + " has no record of any kicks for " + red + user + reset + " in " + red + channel + reset + ".")
- else:
- connection.privmsg(replyto, red + user + reset + " has given " + green + str(kicksgiven) + reset + " and received " + green + str(kicksreceived) + reset + " kicks")
- elif command.split()[0] == "messages":
- if channel: # User and channel.
- pass
- else: # User only.
- pass
- # userstatfields = ()
- # userchannelstatfields = ()
- # channelstatfields = ()
- # userstatvalues = ()
- # userchannelstatvalues = ()
- # channelstatvalues = ()
- # userstatparameters = ()
- # userchannelstatparameters = ()
- # channelstatparameters = ()
|