Bladeren bron

!geolocate command, plus some cleanup to other commands

tags/v0.1^2
Ben Kurtovic 12 jaren geleden
bovenliggende
commit
526151e031
12 gewijzigde bestanden met toevoegingen van 81 en 43 verwijderingen
  1. +0
    -14
      earwigbot/commands/_old.py
  2. +1
    -3
      earwigbot/commands/crypt.py
  3. +1
    -3
      earwigbot/commands/editcount.py
  4. +68
    -0
      earwigbot/commands/geolocate.py
  5. +1
    -1
      earwigbot/commands/langcode.py
  6. +0
    -8
      earwigbot/commands/link.py
  7. +1
    -3
      earwigbot/commands/registration.py
  8. +1
    -3
      earwigbot/commands/remind.py
  9. +2
    -1
      earwigbot/commands/replag.py
  10. +1
    -3
      earwigbot/commands/rights.py
  11. +1
    -3
      earwigbot/commands/threads.py
  12. +4
    -1
      earwigbot/config.py

+ 0
- 14
earwigbot/commands/_old.py Bestand weergeven

@@ -367,17 +367,3 @@ def parse(command, line, line2, nick, chan, host, auth, notice, say, reply, s):
reply("NotImplementedError", chan, nick)
elif action == "report":
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

+ 1
- 3
earwigbot/commands/crypt.py Bestand weergeven

@@ -33,9 +33,7 @@ class Command(BaseCommand):

def check(self, data):
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):
if data.command == "crypt":


+ 1
- 3
earwigbot/commands/editcount.py Bestand weergeven

@@ -31,9 +31,7 @@ class Command(BaseCommand):

def check(self, data):
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):
if not data.args:


+ 68
- 0
earwigbot/commands/geolocate.py Bestand weergeven

@@ -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)

+ 1
- 1
earwigbot/commands/langcode.py Bestand weergeven

@@ -45,7 +45,7 @@ class Command(BaseCommand):
if site["code"] == code:
name = site["name"]
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)
return



+ 0
- 8
earwigbot/commands/link.py Bestand weergeven

@@ -29,14 +29,6 @@ class Command(BaseCommand):
"""Convert a Wikipedia page name into a URL."""
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):
msg = data.msg



+ 1
- 3
earwigbot/commands/registration.py Bestand weergeven

@@ -31,9 +31,7 @@ class Command(BaseCommand):

def check(self, data):
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):
if not data.args:


+ 1
- 3
earwigbot/commands/remind.py Bestand weergeven

@@ -30,9 +30,7 @@ class Command(BaseCommand):
name = "remind"

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):
if not data.args:


+ 2
- 1
earwigbot/commands/replag.py Bestand weergeven

@@ -41,7 +41,8 @@ class Command(BaseCommand):

conn = oursql.connect(**args)
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)
replag = int(cursor.fetchall()[0][0])
conn.close()


+ 1
- 3
earwigbot/commands/rights.py Bestand weergeven

@@ -29,9 +29,7 @@ class Command(BaseCommand):

def check(self, data):
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):
if not data.args:


+ 1
- 3
earwigbot/commands/threads.py Bestand weergeven

@@ -32,9 +32,7 @@ class Command(BaseCommand):

def check(self, data):
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):
self.data = data


+ 4
- 1
earwigbot/config.py Bestand weergeven

@@ -273,7 +273,10 @@ class BotConfig(object):
>>> config.decrypt(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():
self._decrypt(node, nodes)



Laden…
Annuleren
Opslaan