|
@@ -76,6 +76,9 @@ class LocationBot(ircbot.SingleServerIRCBot):
|
|
|
self.__logins = bot.__logins
|
|
|
self.__reloading = True
|
|
|
|
|
|
+ self.__variables = frozenset(['nick', 'secret', 'masks', 'channels', 'timezone', 'location', 'latitude'])
|
|
|
+ self.__unsetable = self.__variables.difference(['nick', 'secret'])
|
|
|
+
|
|
|
def __admin(self, nickmask):
|
|
|
return _or(lambda admin: irclib.mask_matches(nickmask, admin), self.__admins)
|
|
|
|
|
@@ -230,8 +233,6 @@ class LocationBot(ircbot.SingleServerIRCBot):
|
|
|
if connection is not None:
|
|
|
return connection.privmsg(nick, 'failed to log in as "%s"' % login)
|
|
|
|
|
|
- return False
|
|
|
-
|
|
|
def __logout(self, connection, nick):
|
|
|
connection.privmsg(nick, 'logged out as "%s"' % self.__logins.pop(nick)[0])
|
|
|
|
|
@@ -264,15 +265,15 @@ class LocationBot(ircbot.SingleServerIRCBot):
|
|
|
_nick = arguments.split(None, 1)[0] if arguments else None
|
|
|
db, cursor = self.__db()
|
|
|
|
|
|
- cursor.execute('select nick, location, updated from locationbot.nick where location is not null' + (' and nick = %s' if _nick is not None else ''), (_nick,))
|
|
|
+ cursor.execute('select nick, location, updated from locationbot.nick where ' + ('nick = %s and ' if _nick is not None else '') + 'location is not null order by updated desc', (_nick,))
|
|
|
|
|
|
if cursor.rowcount == 0:
|
|
|
return connection.privmsg(nick, 'no location information for ' + ('"%s"' % _nick if _nick is not None else 'anybody'))
|
|
|
|
|
|
locations = cursor.fetchall()
|
|
|
|
|
|
- if login:
|
|
|
- cursor.execute('select timezone from locationbot.nick where timezone is not null and nick = %s', (login,))
|
|
|
+ if login is not None:
|
|
|
+ cursor.execute('select timezone from locationbot.nick where nick = %s and timezone is not null', (login,))
|
|
|
|
|
|
timezone = pytz.timezone(cursor.fetchone()[0]) if cursor.rowcount == 1 else pytz.utc
|
|
|
else:
|
|
@@ -286,6 +287,27 @@ class LocationBot(ircbot.SingleServerIRCBot):
|
|
|
def __unknown(self, connection, nick, command):
|
|
|
connection.privmsg(nick, 'unknown command ("!%s"); try "!help"' % command)
|
|
|
|
|
|
+ def __unknown_variable(self, connection, nick, variable):
|
|
|
+ connection.privmsg(nick, 'unknown variable ("%s")' % variable)
|
|
|
+
|
|
|
+ def __unset(self, connection, nick, login, arguments):
|
|
|
+ try:
|
|
|
+ variable = arguments.split(None, 1)[0]
|
|
|
+ except IndexError:
|
|
|
+ return self.__help(connection, nick, False, login, 'unset')
|
|
|
+
|
|
|
+ if variable not in self.__unsetable:
|
|
|
+ if variable in self.__variables:
|
|
|
+ return connection.privmsg(nick, 'variable ("%s") is not unsetable' % variable)
|
|
|
+
|
|
|
+ return self.__unknown_variable(connection, nick, variable)
|
|
|
+
|
|
|
+ db, cursor = self.__db()
|
|
|
+
|
|
|
+ cursor.execute('update locationbot.nick set ' + variable + ' = null' + (', updated = null' if variable == 'location' else '') + ' where nick = %s and ' + variable + ' is not null', (login,))
|
|
|
+ db.commit()
|
|
|
+ connection.privmsg(nick, 'variable ("' + variable + '") ' + ('' if cursor.rowcount == 1 else 'already ') + 'unset')
|
|
|
+
|
|
|
def __who(self, connection, nick):
|
|
|
connection.privmsg(nick, 'Login Nick Nick Mask')
|
|
|
|
|
@@ -361,6 +383,8 @@ class LocationBot(ircbot.SingleServerIRCBot):
|
|
|
self.__status(connection, nick, login, arguments)
|
|
|
elif login and command == 'logout':
|
|
|
self.__logout(connection, nick)
|
|
|
+ elif login and command == 'unset':
|
|
|
+ self.__unset(connection, nick, login, arguments)
|
|
|
elif admin and command == 'reload':
|
|
|
self.__reload(connection, nick)
|
|
|
elif admin and command == 'restart':
|