| @@ -367,17 +367,3 @@ def parse(command, line, line2, nick, chan, host, auth, notice, say, reply, s): | |||||
| reply("NotImplementedError", chan, nick) | reply("NotImplementedError", chan, nick) | ||||
| elif action == "report": | elif action == "report": | ||||
| reply("NotImplementedError", chan, nick) | reply("NotImplementedError", chan, nick) | ||||
| if command == "lookup" or command == "ip": | |||||
| try: | |||||
| hexIP = line2[4] | |||||
| except Exception: | |||||
| reply("Please specify a hex IP address.", chan, nick) | |||||
| return | |||||
| hexes = [hexIP[:2], hexIP[2:4], hexIP[4:6], hexIP[6:8]] | |||||
| hashes = [] | |||||
| for hexHash in hexes: | |||||
| newHex = int(hexHash, 16) | |||||
| hashes.append(newHex) | |||||
| normalizedIP = "%s.%s.%s.%s" % (hashes[0], hashes[1], hashes[2], hashes[3]) | |||||
| reply(normalizedIP, chan, nick) | |||||
| return | |||||
| @@ -33,9 +33,7 @@ class Command(BaseCommand): | |||||
| def check(self, data): | def check(self, data): | ||||
| commands = ["crypt", "hash", "encrypt", "decrypt"] | commands = ["crypt", "hash", "encrypt", "decrypt"] | ||||
| if data.is_command and data.command in commands: | |||||
| return True | |||||
| return False | |||||
| return data.is_command and data.command in commands | |||||
| def process(self, data): | def process(self, data): | ||||
| if data.command == "crypt": | if data.command == "crypt": | ||||
| @@ -31,9 +31,7 @@ class Command(BaseCommand): | |||||
| def check(self, data): | def check(self, data): | ||||
| commands = ["ec", "editcount"] | commands = ["ec", "editcount"] | ||||
| if data.is_command and data.command in commands: | |||||
| return True | |||||
| return False | |||||
| return data.is_command and data.command in commands | |||||
| def process(self, data): | def process(self, data): | ||||
| if not data.args: | if not data.args: | ||||
| @@ -0,0 +1,68 @@ | |||||
| # -*- coding: utf-8 -*- | |||||
| # | |||||
| # Copyright (C) 2009-2012 by Ben Kurtovic <ben.kurtovic@verizon.net> | |||||
| # | |||||
| # Permission is hereby granted, free of charge, to any person obtaining a copy | |||||
| # of this software and associated documentation files (the "Software"), to deal | |||||
| # in the Software without restriction, including without limitation the rights | |||||
| # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |||||
| # copies of the Software, and to permit persons to whom the Software is | |||||
| # furnished to do so, subject to the following conditions: | |||||
| # | |||||
| # The above copyright notice and this permission notice shall be included in | |||||
| # all copies or substantial portions of the Software. | |||||
| # | |||||
| # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |||||
| # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |||||
| # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |||||
| # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |||||
| # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |||||
| # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | |||||
| # SOFTWARE. | |||||
| import json | |||||
| import urllib2 | |||||
| from earwigbot.commands import BaseCommand | |||||
| class Command(BaseCommand): | |||||
| """Geolocate an IP address (via http://ipinfodb.com/).""" | |||||
| name = "geolocate" | |||||
| def check(self, data): | |||||
| commands = ["geolocate", "locate", "geo", "ip"] | |||||
| return data.is_command and data.command in commands | |||||
| def process(self, data): | |||||
| if not data.args: | |||||
| self.reply(data, "please specify an IP to lookup.") | |||||
| return | |||||
| try: | |||||
| key = config.tasks[self.name]["apiKey"] | |||||
| except KeyError: | |||||
| msg = 'I need an API key for http://ipinfodb.com/ stored as \x0303config.tasks["{0}"]["apiKey"]\x0301.' | |||||
| log = 'Need an API key for http://ipinfodb.com/ stored as config.tasks["{0}"]["apiKey"]' | |||||
| self.reply(data, msg.format(self.name) + ".") | |||||
| self.logger.error(log.format(self.name)) | |||||
| return | |||||
| address = data.args[0] | |||||
| url = "http://api.ipinfodb.com/v3/ip-city/?key={0}&ip={1}&format=json" | |||||
| query = urllib2.urlopen(url.format(key, address)).read() | |||||
| res = json.loads(query) | |||||
| try: | |||||
| country = res["countryName"] | |||||
| region = res["regionName"] | |||||
| city = res["cityName"] | |||||
| latitude = res["latitude"] | |||||
| longitude = res["longitude"] | |||||
| utcoffset = res["timeZone"] | |||||
| except KeyError: | |||||
| self.reply(data, "IP \x0302{0}\x0301 not found.".format(address)) | |||||
| return | |||||
| msg = "{0}, {1}, {2} ({3}, {4}), UTC {5}" | |||||
| geo = msg.format(country, region, city, latitude, longitude, utcoffset) | |||||
| self.reply(data, geo) | |||||
| @@ -45,7 +45,7 @@ class Command(BaseCommand): | |||||
| if site["code"] == code: | if site["code"] == code: | ||||
| name = site["name"] | name = site["name"] | ||||
| sites = ", ".join([s["url"] for s in site["site"]]) | sites = ", ".join([s["url"] for s in site["site"]]) | ||||
| msg = "\x0302{0}\x0302 is {1} ({2})".format(code, name, sites) | |||||
| msg = "\x0302{0}\x0301 is {1} ({2})".format(code, name, sites) | |||||
| self.reply(data, msg) | self.reply(data, msg) | ||||
| return | return | ||||
| @@ -29,14 +29,6 @@ class Command(BaseCommand): | |||||
| """Convert a Wikipedia page name into a URL.""" | """Convert a Wikipedia page name into a URL.""" | ||||
| name = "link" | name = "link" | ||||
| def check(self, data): | |||||
| # if ((data.is_command and data.command == "link") or | |||||
| # (("[[" in data.msg and "]]" in data.msg) or | |||||
| # ("{{" in data.msg and "}}" in data.msg))): | |||||
| if data.is_command and data.command == "link": | |||||
| return True | |||||
| return False | |||||
| def process(self, data): | def process(self, data): | ||||
| msg = data.msg | msg = data.msg | ||||
| @@ -31,9 +31,7 @@ class Command(BaseCommand): | |||||
| def check(self, data): | def check(self, data): | ||||
| commands = ["registration", "reg", "age"] | commands = ["registration", "reg", "age"] | ||||
| if data.is_command and data.command in commands: | |||||
| return True | |||||
| return False | |||||
| return data.is_command and data.command in commands | |||||
| def process(self, data): | def process(self, data): | ||||
| if not data.args: | if not data.args: | ||||
| @@ -30,9 +30,7 @@ class Command(BaseCommand): | |||||
| name = "remind" | name = "remind" | ||||
| def check(self, data): | def check(self, data): | ||||
| if data.is_command and data.command in ["remind", "reminder"]: | |||||
| return True | |||||
| return False | |||||
| return data.is_command and data.command in ["remind", "reminder"] | |||||
| def process(self, data): | def process(self, data): | ||||
| if not data.args: | if not data.args: | ||||
| @@ -41,7 +41,8 @@ class Command(BaseCommand): | |||||
| conn = oursql.connect(**args) | conn = oursql.connect(**args) | ||||
| with conn.cursor() as cursor: | with conn.cursor() as cursor: | ||||
| query = "SELECT UNIX_TIMESTAMP() - UNIX_TIMESTAMP(rc_timestamp) FROM recentchanges ORDER BY rc_timestamp DESC LIMIT 1" | |||||
| query = """SELECT UNIX_TIMESTAMP() - UNIX_TIMESTAMP(rc_timestamp) | |||||
| FROM recentchanges ORDER BY rc_timestamp DESC LIMIT 1""" | |||||
| cursor.execute(query) | cursor.execute(query) | ||||
| replag = int(cursor.fetchall()[0][0]) | replag = int(cursor.fetchall()[0][0]) | ||||
| conn.close() | conn.close() | ||||
| @@ -29,9 +29,7 @@ class Command(BaseCommand): | |||||
| def check(self, data): | def check(self, data): | ||||
| commands = ["rights", "groups", "permissions", "privileges"] | commands = ["rights", "groups", "permissions", "privileges"] | ||||
| if data.is_command and data.command in commands: | |||||
| return True | |||||
| return False | |||||
| return data.is_command and data.command in commands | |||||
| def process(self, data): | def process(self, data): | ||||
| if not data.args: | if not data.args: | ||||
| @@ -32,9 +32,7 @@ class Command(BaseCommand): | |||||
| def check(self, data): | def check(self, data): | ||||
| commands = ["tasks", "task", "threads", "tasklist"] | commands = ["tasks", "task", "threads", "tasklist"] | ||||
| if data.is_command and data.command in commands: | |||||
| return True | |||||
| return False | |||||
| return data.is_command and data.command in commands | |||||
| def process(self, data): | def process(self, data): | ||||
| self.data = data | self.data = data | ||||
| @@ -273,7 +273,10 @@ class BotConfig(object): | |||||
| >>> config.decrypt(config.irc, "frontend", "nickservPassword") | >>> config.decrypt(config.irc, "frontend", "nickservPassword") | ||||
| # decrypts config.irc["frontend"]["nickservPassword"] | # decrypts config.irc["frontend"]["nickservPassword"] | ||||
| """ | """ | ||||
| self._decryptable_nodes.append((node, nodes)) | |||||
| signature = (node, nodes) | |||||
| if signature in self._decryptable_nodes: | |||||
| return # Already decrypted | |||||
| self._decryptable_nodes.append(signature) | |||||
| if self.is_encrypted(): | if self.is_encrypted(): | ||||
| self._decrypt(node, nodes) | self._decrypt(node, nodes) | ||||