magnumjec

aka.py version 2.0.4b

Apr 21st, 2021 (edited)
798
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 26.43 KB | None | 0 0
  1. #  znc-aka: A ZNC module to track users
  2. #  Copyright (C) 2016 Evan Magaliff
  3. #
  4. #  This program is free software; you can redistribute it and/or modify
  5. #  it under the terms of the GNU General Public License as published by
  6. #  the Free Software Foundation; either version 2 of the License, or
  7. #  (at your option) any later version.
  8. #
  9. #  This program is distributed in the hope that it will be useful,
  10. #  but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. #  GNU General Public License for more details.
  13. #
  14. #  You should have received a copy of the GNU General Public License along
  15. #  with this program; if not, write to the Free Software Foundation, Inc.,
  16. #  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  17.  
  18. # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
  19. #  Authors: Evan (MuffinMedic), Aww (AwwCookies)                          #
  20. #  Contributors: See CHANGELOG for specific contributions by users        #
  21. #  Desc: A ZNC module to track users                                      #
  22. # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
  23.  
  24. version = '2.0.4b'
  25. updated = "December 28, 2016"
  26.  
  27. import znc
  28. import os
  29. import datetime
  30. import time
  31. import re
  32. import sqlite3
  33. import requests
  34.  
  35. class aka(znc.Module):
  36.     module_types = [znc.CModInfo.UserModule]
  37.     description = "Tracks users, allowing tracing and history viewing of nicks, hosts, and channels"
  38.     wiki_page = "aka"
  39.  
  40.     def OnLoad(self, args, message):
  41.  
  42.         self.USER = self.GetUser().GetUserName()
  43.  
  44.         self.db_setup()
  45.  
  46.         return True
  47.  
  48.     def OnJoin(self, user, channel):
  49.         self.process_user(self.GetNetwork().GetName(), user.GetNick(), user.GetIdent(), user.GetHost(), channel.GetName())
  50.  
  51.     def OnNick(self, user, new_nick, channels):
  52.         for chan in channels:
  53.             self.process_user(self.GetNetwork().GetName(), new_nick, user.GetIdent(), user.GetHost(), chan.GetName())
  54.  
  55.     def OnPrivMsg(self, user, message):
  56.         self.process_seen(self.GetNetwork().GetName(), user.GetNick(), user.GetIdent(), user.GetHost(), 'PRIVMSG', message)
  57.  
  58.     def OnChanMsg(self, user, channel, message):
  59.         self.process_seen(self.GetNetwork().GetName(), user.GetNick(), user.GetIdent(), user.GetHost(), channel.GetName(), message)
  60.  
  61.     def OnChanAction(self, user, channel, message):
  62.         message = "* " + str(message).replace("'","''")
  63.         self.process_seen(self.GetNetwork().GetName(), user.GetNick(), user.GetIdent(), user.GetHost(), channel.GetName(), message)
  64.  
  65.     def OnUserJoin(self, channel, key):
  66.         self.PutIRC("WHO %s" % channel)
  67.  
  68.     def process_user(self, network, nick, ident, host, channel):
  69.         self.cur.execute("INSERT OR IGNORE INTO users (network, nick, ident, host, channel, time) VALUES (?, ?, ?, ?, ?, strftime('%s', 'now'));", (network.lower(), nick.lower(), ident.lower(), host.lower(), channel.lower()))
  70.         self.conn.commit()
  71.  
  72.     def process_seen(self, network, nick, ident, host, channel, message):
  73.         message = str(message).replace("'","''")
  74.         self.cur.execute("INSERT OR REPLACE INTO users (network, nick, ident, host, channel, message, time) VALUES (?, ?, ?, ?, ?, ?, strftime('%s', 'now'));", (network.lower(), nick.lower(), ident.lower(), host.lower(), channel.lower(), message))
  75.         self.conn.commit()
  76.  
  77.     def cmd_process(self, scope):
  78.         self.PutModule("Processing {}.".format(scope))
  79.         if scope == 'all':
  80.             nets = self.GetUser().GetNetworks()
  81.             for net in nets:
  82.                 chans = net.GetChans()
  83.                 for chan in chans:
  84.                     nicks = chan.GetNicks()
  85.                     for nick in nicks.items():
  86.                         self.process_user(net.GetName(), nick[1].GetNick(), nick[1].GetIdent(), nick[1].GetHost(), chan.GetName())
  87.         elif scope == 'network':
  88.             chans = self.GetNetwork().GetChans()
  89.             for chan in chans:
  90.                 nicks = chan.GetNicks()
  91.                 for nick in nicks.items():
  92.                     self.process_user(self.GetNetwork().GetName(), nick[1].GetNick(), nick[1].GetIdent(), nick[1].GetHost(), chan.GetName())
  93.         else:
  94.             nicks = self.GetNetwork().FindChan(scope).GetNicks()
  95.             for nick in nicks.items():
  96.                 self.process_user(self.GetNetwork().GetName(), nick[1].GetNick(), nick[1].GetIdent(), nick[1].GetHost(), scope)
  97.         self.PutModule("{} processed.".format(scope))
  98.  
  99.     def cmd_history(self, type, user, deep):
  100.         user_query = self.generate_user_query(type, user)
  101.         self.PutModule("Looking up \x02history\x02 for \x02{}\x02, please be patient...".format(user.lower()))
  102.         self.cur.execute("SELECT DISTINCT nick, host FROM users WHERE network = '{0}' AND ({1});".format(self.GetNetwork().GetName().lower(), re.sub(r'([\[\]])', '[\\1]', user_query)))
  103.         data = self.cur.fetchall()
  104.         nicks = set(); idents = set(); hosts = set();
  105.         if len(data) > 0:
  106.             for row in data:
  107.                 nicks.add("nick = '" + row[0] + "' OR"); hosts.add("host = '" + row[1] + "' OR");
  108.             self.cur.execute("SELECT DISTINCT nick, ident, host FROM users WHERE network = '{}' AND ({} {})".format(self.GetNetwork().GetName().lower(), ' '.join(nicks), ' '.join(hosts)[:-3]))
  109.             data = self.cur.fetchall()
  110.             nicks.clear(); hosts.clear()
  111.             for row in data:
  112.                 if deep:
  113.                     nicks.add(row[0]); idents.add(row[1]); hosts.add(row[2]);
  114.                     self.cur.execute("SELECT DISTINCT nick, ident, host FROM users WHERE network = '{0}' AND (nick GLOB '{1}' OR ident GLOB '{2}' OR host GLOB '{3}');".format(self.GetNetwork().GetName().lower(), re.sub(r'([\[\]])', '[\\1]', row[0]), re.sub(r'([\[\]])', '[\\1]', row[1]), re.sub(r'([\[\]])', '[\\1]', row[2])))
  115.                     data_inner = self.cur.fetchall()
  116.                     for row_inner in data_inner:
  117.                         nicks.add(row_inner[0]); idents.add(row_inner[1]); hosts.add(row_inner[2]);
  118.                 else:
  119.                     nicks.add(row[0]); idents.add(row[1]); hosts.add(row[2]);
  120.             self.display_results(nicks, idents, hosts)
  121.             self.PutModule("History for {} \x02complete\x02.".format(user.lower()))
  122.         else:
  123.             self.PutModule("No history found for \x02{}\x02".format(user.lower()))
  124.  
  125.     def display_results(self, nicks, idents, hosts):
  126.         nicks = sorted(list(nicks)); idents = sorted(list(idents)); hosts = sorted(list(hosts));
  127.         size = 100
  128.         index = 0
  129.         while(index < len(nicks)):
  130.             self.PutModule("\x02Nick(s):\x02 " + ', '.join(nicks[index:index+size]))
  131.             index += size
  132.         index = 0
  133.         while(index < len(idents)):
  134.             self.PutModule("\x02Ident(s):\x02 " + ', '.join(idents[index:index+size]))
  135.             index += size
  136.         index = 0
  137.         while(index < len(hosts)):
  138.             self.PutModule("\x02Host(s):\x02 " + ', '.join(hosts[index:index+size]))
  139.             index += size
  140.  
  141.     def cmd_seen(self, type, user, channel):
  142.         user_query = self.generate_user_query(type, user)
  143.         if channel:
  144.             self.cur.execute("SELECT nick, ident, host, channel, message, MAX(time) FROM (SELECT * from users WHERE message IS NOT NULL) WHERE network = '{0}' AND channel = '{1}' AND ({2});".format(self.GetNetwork().GetName().lower(), channel.lower(), re.sub(r'([\[\]])', '[\\1]', user_query)))
  145.         else:
  146.             self.cur.execute("SELECT nick, ident, host, channel, message, MAX(time) FROM (SELECT * from users WHERE message IS NOT NULL) WHERE network = '{0}' AND ({1});".format(self.GetNetwork().GetName().lower(), re.sub(r'([\[\]])', '[\\1]', user_query)))
  147.         data = self.cur.fetchone()
  148.         try:
  149.             self.PutModule("\x02{}\x02 ({}@{}) was last seen in \x02{}\x02 at \x02{}\x02 saying \"\x02{}\x02\".".format(data[0], data[1], data[2],data[3], datetime.datetime.fromtimestamp(int(data[5])).strftime('%Y-%m-%d %H:%M:%S'), data[4]))
  150.         except:
  151.             if channel:
  152.                 self.PutModule("\x02{}\x02 has \x02\x034not\x03\x02 been seen in \x02{}\x02.".format(user.lower(), channel.lower()))
  153.             else:
  154.                 self.PutModule("\x02{}\x02 has \x02\x034not\x03\x02 been seen.".format(user.lower()))
  155.  
  156.     def cmd_users(self, type, user):
  157.         user_query = self.generate_user_query(type, user)
  158.         self.cur.execute("SELECT DISTINCT nick, host, ident FROM users WHERE network = '{0}' AND ({1});".format(self.GetNetwork().GetName().lower(), re.sub(r'([\[\]])', '[\\1]', user_query)))
  159.         data = self.cur.fetchall()
  160.         chans = set()
  161.         for row in data:
  162.             chans.add(row[0])
  163.         self.PutModule("\x02{}\x02 has been seen in \x02channels\x02: {}".format(user.lower(), ', '.join(sorted(chans))))
  164.  
  165.     def cmd_channels(self, type, users):
  166.         chan_lists = []
  167.         for user in users:
  168.             user_query = self.generate_user_query(type, user)
  169.             chans = []
  170.             self.cur.execute("SELECT DISTINCT channel FROM users WHERE network = '{0}' AND ({1});".format(self.GetNetwork().GetName().lower(), re.sub(r'([\[\]])', '[\\1]', user_query)))
  171.             data = self.cur.fetchall()
  172.             for row in data:
  173.                 chans.append(row[0])
  174.             chan_lists.append(chans)
  175.         shared_chans = set(chan_lists[0])
  176.         for chan in chan_lists[1:]:
  177.             shared_chans.intersection_update(chan)
  178.         self.PutModule("Common \x02channels\x02 for \x02{}:\x02 {}".format(', '.join(users), ', '.join(sorted(shared_chans))))
  179.  
  180.     def cmd_users(self, channels):
  181.         nick_lists = []; ident_lists = []; host_lists = [];
  182.         for channel in channels:
  183.             nicks = []; idents = []; hosts = [];
  184.             self.cur.execute("SELECT DISTINCT nick, ident, host FROM users WHERE network = '{}' AND channel = '{}';".format(self.GetNetwork().GetName().lower(), channel.lower()))
  185.             data = self.cur.fetchall()
  186.             for row in data:
  187.                 nicks.append(row[0]); idents.append(row[1]); hosts.append(row[2]);
  188.             nick_lists.append(nicks); ident_lists.append(idents); host_lists.append(hosts);
  189.         nicks = set(nick_lists[0]); idents = set(ident_lists[0]); hosts = set(host_lists[0]);
  190.         for nick in nick_lists[1:]:
  191.             nicks.intersection_update(nick)
  192.         for ident in ident_lists[1:]:
  193.             idents.intersection_update(ident)
  194.         for host in host_lists[1:]:
  195.             hosts.intersection_update(host)
  196.         self.PutModule("Common \x02users\x02 for \x02{}:\x02".format(', '.join(channels)))
  197.         self.display_results(nicks, idents, hosts)
  198.  
  199.     def cmd_compare_users(self, type, users):
  200.         self.PutModule("Users compared.")
  201.  
  202.     def cmd_geo(self, type, user):
  203.         user_query = self.generate_user_query(type, user)
  204.  
  205.         ipv4 = '(?:[0-9]{1,3}(\.|\-)){3}[0-9]{1,3}'
  206.         ipv6 = '^((?:[0-9A-Fa-f]{1,4}))((?::[0-9A-Fa-f]{1,4}))*::((?:[0-9A-Fa-f]{1,4}))((?::[0-9A-Fa-f]{1,4}))*|((?:[0-9A-Fa-f]{1,4}))((?::[0-9A-Fa-f]{1,4})){7}$'
  207.         rdns = '^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\-]*[A-Za-z0-9])$'
  208.        
  209.         if (re.search(ipv6, str(user)) or re.search(ipv4, str(user)) or (re.search(rdns, str(user)) and '.' in str(user))):
  210.             host = user
  211.  
  212.         self.cur.execute("SELECT host, nick, ident FROM users WHERE network = '{0}' AND ({1}) ORDER BY time DESC;".format(self.GetNetwork().GetName().lower(), re.sub(r'([\[\]])', '[\\1]', user_query)))
  213.         data = self.cur.fetchall()
  214.         for row in data:
  215.             if (re.search(ipv6, str(row[0])) or re.search(ipv4, str(row[0])) or (re.search(rdns, str(row[0])) and '.' in str(row[0]))):
  216.                 host = row[0]
  217.                 nick = row[1]
  218.                 ident = row[2]
  219.                 break
  220.         try:
  221.             if re.search(ipv4, str(host)):
  222.                 ip = re.sub('[^\w.]',".",((re.search(ipv4, str(host))).group(0)))
  223.             elif re.search(ipv6, str(host)) or re.search(rdns, str(host)):
  224.                 ip = str(host)
  225.             url = 'http://ip-api.com/json/' + ip + '?fields=country,regionName,city,lat,lon,timezone,mobile,proxy,query,reverse,status,message'
  226.             loc = requests.get(url)
  227.             loc_json = loc.json()
  228.  
  229.             if loc_json["status"] != "fail":
  230.                 try:
  231.                     user = "\x02{}\x02 ({}@{})".format(nick.lower(), ident.lower(), host.lower())
  232.                 except:
  233.                     user = "\x02{}\x02 (no matching user)".format(user.lower())
  234.                 self.PutModule("{} is located in \x02{}, {}, {}\x02 ({}, {}) / Timezone: {} / Proxy: {} / Mobile: {} / IP: {} / rDNS: {}".format(user, loc_json["city"], loc_json["regionName"], loc_json["country"], loc_json["lat"], loc_json["lon"], loc_json["timezone"], loc_json["proxy"], loc_json["mobile"], loc_json["query"], loc_json["reverse"]))
  235.             else:
  236.                 self.PutModule("\x02\x034Unable to geolocate\x03\x02 user \x02{}\x02. (Reason: {})".format(user.lower(), loc_json["message"]))
  237.         except:
  238.             self.PutModule("\x02\x034No valid host\x03\x02 for user \x02{}\x02".format(user.lower()))
  239.  
  240.     def generate_user_query(self, type, user):
  241.         if type:
  242.             query = "{0} GLOB '{1}'".format(type, user.lower())
  243.         else:
  244.             query = "nick GLOB '{0}' OR ident GLOB '{0}' OR host GLOB '{0}'".format(user.lower())
  245.         return query
  246.  
  247.     def cmd_stats(self):
  248.         self.cur.execute("SELECT COUNT(DISTINCT nick), COUNT(DISTINCT ident), COUNT(DISTINCT host), COUNT(DISTINCT channel), COUNT(*) FROM users WHERE network = '{0}';".format(self.GetNetwork().GetName().lower()))
  249.         data = self.cur.fetchone()
  250.         self.PutModule("\x02Nick(s):\x02 {}".format(data[0]))
  251.         self.PutModule("\x02Ident(s):\x02 {}".format(data[1]))
  252.         self.PutModule("\x02Host(s):\x02 {}".format(data[2]))
  253.         self.PutModule("\x02Channel(s):\x02 {}".format(data[3]))
  254.         self.PutModule("\x02Size:\x02 {} MB".format(os.path.getsize(self.GetSavePath() + "/aka.db") >> 20))
  255.         self.PutModule("\x02Total Records:\x02 {}".format(data[4]))
  256.  
  257.     def cmd_who(self, scope):
  258.         if scope == 'all':
  259.             nets = self.GetUser().GetNetworks()
  260.             for net in nets:
  261.                 chans = net.GetChans()
  262.                 for chan in chans:
  263.                     self.PutIRC("WHO %s" % chan.GetName())
  264.         elif scope == 'network':
  265.             chans = self.GetNetwork().GetChans()
  266.             for chan in chans:
  267.                 self.PutIRC("WHO %s" % chan.GetName())
  268.         else:
  269.            self.PutIRC("WHO %s" % scope)
  270.         self.PutModule("{} WHO updates triggered. Please wait several minutes for ZNC to receive the updated data from the IRC server(s) and then run \x02process\x02 to add these updates to the database".format(scope))
  271.  
  272.     def cmd_about(self):
  273.         self.PutModule("\x02aka\x02 (Also Known As / nickhistory) ZNC module by MuffinMedic (Evan)")
  274.         self.PutModule("\x02Description:\x02 {}".format(self.description))
  275.         self.PutModule("\x02Version:\x02 {}".format(version))
  276.         self.PutModule("\x02Updated:\x02 {}".format(updated))
  277.         self.PutModule("\x02Documenation:\x02 http://wiki.znc.in/Aka")
  278.         self.PutModule("\x02Source:\x02 https://github.com/MuffinMedic/znc-aka")
  279.  
  280.     def cmd_rawquery(self, query):
  281.         try:
  282.             query = ' '.join(query)
  283.             count = 0
  284.             for row in self.cur.execute(query):
  285.                 self.PutModule(str(row))
  286.                 count += 1
  287.             self.conn.commit()
  288.             if self.cur.rowcount >= 0:
  289.                 self.PutModule('Query successful: %s rows affected' % self.cur.rowcount)
  290.             else:
  291.                 self.PutModule('%s records retrieved' % count)
  292.         except sqlite3.Error as e:
  293.             self.PutModule('Error: %s' % e)
  294.  
  295.     def cmd_import(self, network, file):
  296.         if os.path.exists(file):
  297.             self.old_conn = sqlite3.connect(file)
  298.             self.old_c = self.old_conn.cursor()
  299.             try:
  300.                 self.old_c.execute("SELECT nick, identity, host, channel, message, processed_time, added FROM users")
  301.                 old = True
  302.             except:
  303.                 self.old_c.execute("SELECT nick, ident, host, channel, message, time FROM users")
  304.                 old = False
  305.             data = self.old_c.fetchall()
  306.             count = 0
  307.             self.PutModule("Importing {}. Please be patient...".format(file))
  308.             if old:
  309.                 for row in data:
  310.                     if row[5]:
  311.                         self.cur.execute("INSERT OR IGNORE INTO users (network, nick, ident, host, channel, message, time) VALUES (LOWER(?), LOWER(?), LOWER(?), LOWER(?), LOWER(?), LOWER(?), LOWER(?));", (network, row[0], row[1], row[2], row[3], row[4], str(time.mktime((datetime.datetime.strptime(row[5].partition('.')[0], '%Y-%m-%d %H:%M:%S')).timetuple())).partition('.')[0]))
  312.                     elif row[6]:
  313.                         self.cur.execute("INSERT OR IGNORE INTO users (network, nick, ident, host, channel, message, time) VALUES (LOWER(?), LOWER(?), LOWER(?), LOWER(?), LOWER(?), LOWER(?), LOWER(?);", (network, row[0], row[1], row[2], row[3], row[4], str(time.mktime((datetime.datetime.strptime(row[6].partition('.')[0], '%Y-%m-%d %H:%M:%S')).timetuple())).partition('.')[0]))
  314.                     else:
  315.                         self.cur.execute("INSERT OR IGNORE INTO users (network, nick, ident, host, channel, message) VALUES (LOWER(?), LOWER(?), LOWER(?), LOWER(?), LOWER(?), LOWER(?));", (network, row[0], row[1], row[2], row[3], row[4]))
  316.                     count += 1
  317.             else:
  318.                 for row in data:
  319.                     if row[5]:
  320.                         self.cur.execute("INSERT OR IGNORE INTO users (network, nick, ident, host, channel, message, time) VALUES (LOWER(?), LOWER(?), LOWER(?), LOWER(?), LOWER(?), LOWER(?), LOWER(?));", (network, row[0], row[1], row[2], row[3], row[4], row[5]))
  321.                     else:
  322.                         self.cur.execute("INSERT OR IGNORE INTO users (network, nick, ident, host, channel, message) VALUES (LOWER(?), LOWER(?), LOWER(?), LOWER(?), LOWER(?), LOWER(?));", (network, row[0], row[1], row[2], row[3], row[4]))
  323.                     count += 1
  324.             self.conn.commit()
  325.             self.PutModule("Database imported. {} records processed.".format(count))
  326.         else:
  327.             self.PutModule("File {} does not exist. Skipping.".format(file))
  328.  
  329.     def db_setup(self):
  330.         self.conn = sqlite3.connect(self.GetSavePath() + "/aka.db")
  331.         self.cur = self.conn.cursor()
  332.         self.cur.execute("create table if not exists users (id INTEGER PRIMARY KEY, network TEXT, nick TEXT, ident TEXT, host TEXT, channel TEXT, message TEXT, time INTEGER, UNIQUE(network, nick, ident, host, channel));")
  333.         self.conn.commit()
  334.  
  335.         if 'HAS_RUN' not in self.nv:
  336.             nets = self.GetUser().GetNetworks()
  337.             for net in nets:
  338.                 file = self.GetUser().GetUserPath() + "/networks/" + net.GetName() + "/moddata/aka/aka." + net.GetName() + ".db"
  339.                 self.cmd_import(net.GetName(), file)
  340.             self.SetNV('HAS_RUN', "TRUE")
  341.  
  342.     def OnModCommand(self, command):
  343.         line = command.lower()
  344.         commands = line.split()
  345.         cmds = ["all", "history", "users", "channels", "sharedchans", "sharedusers", "seen", "geo", "process", "who", "rawquery", "import", "stats", "about", "help", "migrate"]
  346.         if commands[0] in cmds:
  347.             if "--type=" in line:
  348.                 type = (line.split('=')[1]).lower()
  349.                 if type != 'nick' and type != 'host' and type != 'ident':
  350.                     self.PutModule("Valid types are \x02nick\x02, \x02ident\x02, and \x02host\x02.")
  351.                     return znc.HALT
  352.                 else:
  353.                     del commands[-1]
  354.             else:
  355.                 type = None
  356.             if commands[0] == "all":
  357.                 try:
  358.                     self.PutModule("Getting \x02all\x02 for \x02{}\x02.".format(commands[1]))
  359.                     self.cmd_history(type, commands[1], False)
  360.                     self.cmd_channels(type, commands[1:])
  361.                     self.cmd_seen(type, commands[1], None)
  362.                     self.cmd_geo(type, commands[1])
  363.                     self.PutModule("All \x02complete\x02.")
  364.                 except:
  365.                     self.PutModule("You must specify a user.")
  366.             elif commands[0] == "history":
  367.                 try:
  368.                     if "--deep" in line:
  369.                         self.cmd_history(type, commands[1], True)
  370.                     else:
  371.                         self.cmd_history(type, commands[1], False)
  372.                 except:
  373.                     self.PutModule("You must specify a user.")
  374.             elif commands[0] == "users" or commands[0] == "channels" or commands[0] == "sharedchans" or commands[0] == "sharedusers":
  375.                 if commands[0] == 'channels' or commands[0] == 'sharedchans':
  376.                     try:
  377.                         self.cmd_channels(type, commands[1:])
  378.                     except:
  379.                         self.PutModule("You must specify at least one user.")
  380.                 elif commands[0] == 'users' or commands[0] == 'sharedusers':
  381.                     try:
  382.                         self.cmd_users(commands[1:])
  383.                     except:
  384.                         self.PutModule("You must specify at least one channel.")
  385.             elif commands[0] == "seen":
  386.                 try:
  387.                     try:
  388.                         self.cmd_seen(type, commands[1], commands[2])
  389.                     except:
  390.                         self.cmd_seen(type, commands[1], None)
  391.                 except:
  392.                     self.PutModule("You must specify a user and optional channel.")
  393.             elif commands[0] == "geo":
  394.                 try:
  395.                     self.cmd_geo(type, commands[1])
  396.                 except:
  397.                     self.PutModule("You must specify a user, host, or IP address.")
  398.             elif commands[0] == "process" or commands[0] == "who":
  399.                 try:
  400.                     if commands[0] == "process":
  401.                         self.cmd_process(commands[1])
  402.                     elif commands[0] == "who":
  403.                         self.cmd_who(commands[1])
  404.                 except:
  405.                     self.PutModule("Valid options: #channel, network, all")
  406.             elif commands[0] == "rawquery":
  407.                 try:
  408.                     self.cmd_rawquery(commands[1:])
  409.                 except:
  410.                     self.PutModule("You must specify a query.")
  411.             elif commands[0] == "import":
  412.                 self.cmd_import(commands[1], commands[2])
  413.                 '''
  414.                try:
  415.                    self.cmd_import(commands[1], commands[2])
  416.                except:
  417.                    self.PutModule("You must specify a network and file.")
  418.                '''
  419.             elif commands[0] == "stats":
  420.                 self.cmd_stats()
  421.             elif commands[0] == "about":
  422.                 self.cmd_about()
  423.             elif commands[0] == "help":
  424.                 self.cmd_help()
  425.         else:
  426.             self.PutModule("Invalid command. See \x02help\x02 for a list of available commands.")
  427.  
  428.     def cmd_help(self):
  429.         help = znc.CTable(250)
  430.         help.AddColumn("Command")
  431.         help.AddColumn("Arguments")
  432.         help.AddColumn("Description")
  433.         help.AddRow()
  434.         help.SetCell("Command", "all")
  435.         help.SetCell("Arguments", "<user> [--type=type] [--deep]")
  436.         help.SetCell("Description", "Get all information on a user (nick, ident, or host)")
  437.         help.AddRow()
  438.         help.SetCell("Command", "history")
  439.         help.SetCell("Arguments", "<user> [--type=type]")
  440.         help.SetCell("Description", "Show history for a user")
  441.         help.AddRow()
  442.         help.SetCell("Command", "users")
  443.         help.SetCell("Arguments", "<#channel 1> [<#channel 2>] ... [<channel #>]")
  444.         help.SetCell("Description", "Show common users between a list of channel(s)")
  445.         help.AddRow()
  446.         help.SetCell("Command", "channels")
  447.         help.SetCell("Arguments", "<user 1> [<user 2>] ... [<user #>] [--type=type]")
  448.         help.SetCell("Description", "Show common channels between a list of user(s) (nicks, idents, or hosts, including mixed)")
  449.         help.AddRow()
  450.         help.SetCell("Command", "seen")
  451.         help.SetCell("Arguments", "<user> [<#channel>] [--type=type]")
  452.         help.SetCell("Description", "Display last time user was seen speaking")
  453.         help.AddRow()
  454.         help.SetCell("Command", "geo")
  455.         help.SetCell("Arguments", "<user> [--type=type]")
  456.         help.SetCell("Description", "Geolocates user (nick, ident, host, IP, or domain)")
  457.         help.AddRow()
  458.         help.SetCell("Command", "who")
  459.         help.SetCell("Arguments", "<scope>")
  460.         help.SetCell("Description", "Update userdata on all users in the scope (#channel, network, or all)")
  461.         help.AddRow()
  462.         help.SetCell("Command", "process")
  463.         help.SetCell("Arguments", "<scope>")
  464.         help.SetCell("Description", "Add all current users in the scope (#channel, network, or all) to the database")
  465.         help.AddRow()
  466.         help.SetCell("Command", "rawquery")
  467.         help.SetCell("Arguments", "<query>")
  468.         help.SetCell("Description", "Run raw sqlite3 query and return results")
  469.         help.SetCell("Command", "import")
  470.         help.SetCell("Arguments", "<network> <file>")
  471.         help.SetCell("Description", "Import an existing database")
  472.         help.AddRow()
  473.         help.SetCell("Command", "about")
  474.         help.SetCell("Description", "Display information about aka")
  475.         help.AddRow()
  476.         help.SetCell("Command", "stats")
  477.         help.SetCell("Description", "Print data stats for the current network")
  478.         help.AddRow()
  479.         help.SetCell("Command", "help")
  480.         help.SetCell("Description", "Print help for using the module")
  481.         help.AddRow()
  482.         help.SetCell("Command", "NOTE")
  483.         help.SetCell("Arguments", "User Types")
  484.         help.SetCell("Description", "Valid user types are nick, ident, and host.")
  485.         help.SetCell("Command", "NOTE")
  486.         help.SetCell("Arguments", "Wildcard Searches")
  487.         help.SetCell("Description", "<user> supports * and ? GLOB wildcard syntax (combinable at start, middle, and end).")
  488.  
  489.         self.PutModule(help)
Advertisement
Add Comment
Please, Sign In to add comment