| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111 |
- from common import log
- 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 command == "cmd" or command == "commands":
- if cmdtype == "help": #Display help text.
- if len(command.split()) is not 1:
- return
- connection.privmsg(replyto, "Displays a list of commands.")
- elif cmdtype == "cmd":
- connection.privmsg(replyto, grey + "Statistics commands: " + CH.ccc(self, "joins") + CH.ccc(self, "kicks")[:-2] + ".")
-
-
- elif command.split()[0] == "joins" or command.split()[0] == "kicks":
- 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
- 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]
- 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
-
- try:
- if user and channel:
- if command.split()[0] == "joins":
- userstat = str(sum(self.db.all("SELECT " + command.split()[0].lower() + " FROM " + command.split()[0].lower() + " WHERE channel_network='" + self.network + "' AND LOWER(\"user\")=LOWER('" + user + "') AND user_network='" + self.network + "'")))
- userchannelstat = str(self.db.one("SELECT " + command.split()[0].lower() + " FROM " + command.split()[0].lower() + " 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].lower() + " FROM " + command.split()[0].lower() + " WHERE LOWER(channel)=LOWER('" + channel + "') AND channel_network='" + self.network + "' AND user_network='" + self.network + "'")))
- if userchannelstat == "None":
- userchannelstat = "0"
- 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.")
- elif command.split()[0] == "kicks":
- try:
- givenkicks, receivedkicks = self.db.one("SELECT given, received FROM " + command.split()[0].lower() + " 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
- channelkicks = self.db.all("SELECT given FROM " + command.split()[0].lower() + " 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.")
- return
- except:
- pass
- try:
- if user:
- if command.split()[0] == "joins":
- 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 == "[]":
- userstat = "[0]"
- connection.privmsg(replyto, red + user + reset + " has " + green + userstat + reset + " " + command.split()[0] + " in channels I monitor.")
- elif command.split()[0] == "kicks":
- 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]
- print(record)
- print(userstat)
- connection.privmsg(replyto, red + user + reset + " has given " + green + str(kicksgiven) + reset + " and received " + green + str(kicksreceived) + reset + " kicks")
- return
- except:
- pass
- try:
- if channel: # This situation should not occur anymore.
- 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 command.split()[0] == "joins":
- connection.privmsg(replyto, red + channel + reset + " has been " + command.split()[0][:-1] + "ed " + green + channelstat + reset + " times.")
- elif command.split()[0] == "kicks":
- connection.privmsg(replyto, "There have been " + green + channelstat + reset + " kicks in " + red + command.split()[0] + reset + ".")
- return
- except:
- pass
- log.error("No situation applied on statistics.py")
|