Added seen plugin
This commit is contained in:
parent
74a4129afd
commit
c1ddb10e06
|
@ -17,6 +17,7 @@
|
||||||
"nxy.plugins.kernel",
|
"nxy.plugins.kernel",
|
||||||
"nxy.plugins.mcmaniac",
|
"nxy.plugins.mcmaniac",
|
||||||
"nxy.plugins.quotes",
|
"nxy.plugins.quotes",
|
||||||
|
"nxy.plugins.seen",
|
||||||
"nxy.plugins.tell",
|
"nxy.plugins.tell",
|
||||||
"nxy.plugins.timer",
|
"nxy.plugins.timer",
|
||||||
"nxy.plugins.useless",
|
"nxy.plugins.useless",
|
||||||
|
|
44
nxy/plugins/seen.py
Normal file
44
nxy/plugins/seen.py
Normal file
|
@ -0,0 +1,44 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
import re
|
||||||
|
import irc3
|
||||||
|
|
||||||
|
from datetime import datetime
|
||||||
|
from docopt import Dict as DocOptDict
|
||||||
|
from irc3.plugins.command import command
|
||||||
|
from irc3.utils import IrcString
|
||||||
|
|
||||||
|
from . import DatabasePlugin
|
||||||
|
|
||||||
|
|
||||||
|
class Seen(DatabasePlugin):
|
||||||
|
requires = ['irc3.plugins.command',
|
||||||
|
'nxy.plugins.database']
|
||||||
|
|
||||||
|
@command(options_first=True)
|
||||||
|
def seen(self, mask: IrcString, channel: IrcString, args: DocOptDict):
|
||||||
|
"""Get last seen date and message for a nick.
|
||||||
|
|
||||||
|
%%seen [<nick>]
|
||||||
|
"""
|
||||||
|
nick = args.get('<nick>') or mask.nick
|
||||||
|
if nick == mask.nick:
|
||||||
|
return '{nick}, have you seen in the mirror?'.format(nick=nick)
|
||||||
|
self.cur.execute('select * from seens where nick = ?', [nick])
|
||||||
|
seen = self.cur.fetchone()
|
||||||
|
if not seen:
|
||||||
|
return 'I\'ve never seen {nick}'.format(nick=nick)
|
||||||
|
return '{nick} was last seen {delta} saying: {message}'.format(
|
||||||
|
nick=seen['nick'],
|
||||||
|
# TODO: relate string delta
|
||||||
|
delta=datetime.now() - seen['last_seen'],
|
||||||
|
message=re.sub(r'\x01ACTION (.*)\x01', r'\1', seen['message']),
|
||||||
|
)
|
||||||
|
|
||||||
|
@irc3.event(r'(?i)^:(?P<mask>\S+) PRIVMSG (?P<channel>\S+) :(?P<msg>.*)')
|
||||||
|
def save(self, mask: str, channel: str, msg: str):
|
||||||
|
nick = IrcString(mask).nick
|
||||||
|
if nick != self.bot.nick:
|
||||||
|
self.cur.execute('insert or replace into seens (nick, channel, '
|
||||||
|
'message, last_seen) values (?, ?, ?, ?)',
|
||||||
|
[nick, channel.lower(), msg, datetime.now()])
|
||||||
|
self.con.commit()
|
10
schema.sql
10
schema.sql
|
@ -29,3 +29,13 @@ create table if not exists tells (
|
||||||
created timestamp not null default current_timestamp,
|
created timestamp not null default current_timestamp,
|
||||||
unique (to_user, message)
|
unique (to_user, message)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
|
create table if not exists seens (
|
||||||
|
id integer primary key autoincrement,
|
||||||
|
nick text not null,
|
||||||
|
channel text not null,
|
||||||
|
message text not null,
|
||||||
|
last_seen timestamp not null,
|
||||||
|
unique (nick collate nocase) on conflict replace
|
||||||
|
);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user