Updated seen plugin to pgsql
This commit is contained in:
parent
d1911ca4f2
commit
4a0a24e38a
|
@ -15,31 +15,35 @@ class Seen(DatabasePlugin):
|
||||||
requires = ['irc3.plugins.command',
|
requires = ['irc3.plugins.command',
|
||||||
'nxy.plugins.database']
|
'nxy.plugins.database']
|
||||||
|
|
||||||
@command(options_first=True)
|
@command
|
||||||
def seen(self, mask: IrcString, channel: IrcString, args: DocOptDict):
|
def seen(self, mask: IrcString, target: IrcString, args: DocOptDict):
|
||||||
"""Get last seen date and message for a nick.
|
"""Get last seen date and message for a nick.
|
||||||
|
|
||||||
%%seen [<nick>]
|
%%seen [<nick>]
|
||||||
"""
|
"""
|
||||||
nick = args.get('<nick>') or mask.nick
|
nick = args.get('<nick>') or mask.nick
|
||||||
|
|
||||||
if nick == mask.nick:
|
if nick == mask.nick:
|
||||||
return '{nick}, have you seen in the mirror?'.format(nick=nick)
|
return '{nick}, have you seen in the mirror?'.format(nick=nick)
|
||||||
self.cur.execute('select * from seens where nick = ?', [nick])
|
|
||||||
|
self.cur.execute('select * from seens where nick = %s', [nick])
|
||||||
seen = self.cur.fetchone()
|
seen = self.cur.fetchone()
|
||||||
|
|
||||||
if not seen:
|
if not seen:
|
||||||
return 'I\'ve never seen {nick}'.format(nick=nick)
|
return 'I\'ve never seen {nick}'.format(nick=nick)
|
||||||
|
|
||||||
return '{nick} was last seen {delta} saying: {message}'.format(
|
return '{nick} was last seen {delta} saying: {message}'.format(
|
||||||
nick=seen['nick'],
|
nick=seen['nick'],
|
||||||
# TODO: relate string delta
|
# TODO: relative string delta
|
||||||
delta=datetime.now() - seen['last_seen'],
|
delta=datetime.now() - seen['seen_at'],
|
||||||
message=re.sub(r'\x01ACTION (.*)\x01', r'/me \1', seen['message']),
|
message=re.sub(r'\x01ACTION (.*)\x01', r'/me \1', seen['message']),
|
||||||
)
|
)
|
||||||
|
|
||||||
@irc3.event(r'(?i)^:(?P<mask>\S+) PRIVMSG (?P<channel>\S+) :(?P<msg>.*)')
|
@irc3.event(r'(?i)^:(?P<mask>\S+) PRIVMSG (?P<target>\S+) :(?P<msg>.*)')
|
||||||
def save(self, mask: str, channel: str, msg: str):
|
def save(self, mask: str, target: str, msg: str):
|
||||||
nick = IrcString(mask).nick
|
values = [IrcString(mask).nick, target.lower(), msg, datetime.now()]
|
||||||
if nick != self.bot.nick:
|
self.cur.execute('''insert into seens (nick, channel, message,
|
||||||
self.cur.execute('insert into seens (nick, channel, message, '
|
seen_at) values (%s, %s, %s, %s) on conflict (nick) do update set
|
||||||
'last_seen) values (?, ?, ?, ?)',
|
channel = excluded.channel, seen_at = excluded.seen_at,
|
||||||
[nick, channel.lower(), msg, datetime.now()])
|
message = excluded.message''', values)
|
||||||
self.con.commit()
|
self.con.commit()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user