mirror of
https://github.com/oddluck/limnoria-plugins.git
synced 2025-04-29 15:01:11 -05:00
add update command. geolocate nicks in channel
This commit is contained in:
parent
fb1c23b0dd
commit
bc60f8c019
@ -34,35 +34,36 @@ class Geo(callbacks.Plugin):
|
|||||||
if exception.errno != errno.EEXIST:
|
if exception.errno != errno.EEXIST:
|
||||||
raise
|
raise
|
||||||
|
|
||||||
# **********************************************************************
|
def geo(self, irc, msg, args, stuff):
|
||||||
|
"""[<ip> | <hostname>] [nick]
|
||||||
def geo( self, irc, msgs, args, stuff):
|
Geolocation of an ip, hostname, or nick. Nick must be in channel.
|
||||||
"""[<ip> | <hostname>]
|
|
||||||
Geolocation of an ip or host.
|
|
||||||
"""
|
"""
|
||||||
if stuff.lower()=='update':
|
channel = msg.args[0]
|
||||||
irc.reply('Updating data file...')
|
|
||||||
self.update()
|
|
||||||
irc.reply('Update finished.')
|
|
||||||
return
|
|
||||||
try:
|
try:
|
||||||
reader = geoip2.database.Reader('%s%sgeo%sGeoLite2-City.mmdb' % (conf.supybot.directories.data(), os.sep, os.sep))
|
reader = geoip2.database.Reader('%s%sgeo%sGeoLite2-City.mmdb' % (conf.supybot.directories.data(), os.sep, os.sep))
|
||||||
except:
|
except:
|
||||||
irc.reply("Error: GeoLite2-City database not found, attempting to update...")
|
irc.reply("Error: GeoLite2-City database not found, attempting to update...")
|
||||||
try:
|
try:
|
||||||
self.update()
|
self.do_update()
|
||||||
irc.reply('Update finished.')
|
irc.reply('Update finished.')
|
||||||
except:
|
except:
|
||||||
irc.reply("Update failed.")
|
irc.reply("Update failed.")
|
||||||
return
|
return
|
||||||
if not utils.net.isIP(stuff):
|
if stuff.lower() in (nick.lower() for nick in list(irc.state.channels[channel].users)):
|
||||||
|
try:
|
||||||
|
stuff = irc.state.nickToHostmask(stuff).split('@')[1]
|
||||||
|
ip = socket.gethostbyname(stuff)
|
||||||
|
except:
|
||||||
|
irc.reply("Invalid hostname {0}".format(stuff))
|
||||||
|
return
|
||||||
|
elif not utils.net.isIP(stuff):
|
||||||
try:
|
try:
|
||||||
ip = socket.gethostbyname(stuff)
|
ip = socket.gethostbyname(stuff)
|
||||||
except:
|
except:
|
||||||
irc.reply("Invalid Hostname.")
|
irc.reply("Invalid nick/hostname {0}".format(stuff))
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
ip = stuff
|
irc.reply("invalid nick or hostname/ip {0}".format(stuff))
|
||||||
res = reader.city(ip)
|
res = reader.city(ip)
|
||||||
if res:
|
if res:
|
||||||
irc.reply('%s, %s, %s' % (res.city.name, res.subdivisions.most_specific.name, res.country.name ))
|
irc.reply('%s, %s, %s' % (res.city.name, res.subdivisions.most_specific.name, res.country.name ))
|
||||||
@ -70,7 +71,20 @@ class Geo(callbacks.Plugin):
|
|||||||
irc.reply("No results found")
|
irc.reply("No results found")
|
||||||
geo = wrap(geo, ['text'])
|
geo = wrap(geo, ['text'])
|
||||||
|
|
||||||
def update(self):
|
def update(self, irc, msg, args):
|
||||||
|
"""
|
||||||
|
Update geoip database
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
irc.reply('Updating data file...')
|
||||||
|
self.do_update()
|
||||||
|
irc.reply('Update finished.')
|
||||||
|
except:
|
||||||
|
irc.reply("Update failed.")
|
||||||
|
return
|
||||||
|
update = wrap(update)
|
||||||
|
|
||||||
|
def do_update(self):
|
||||||
"""update the geo files"""
|
"""update the geo files"""
|
||||||
now=int(time.time())
|
now=int(time.time())
|
||||||
try:
|
try:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user