mirror of https://github.com/Mikaela/Limnoria.git
Added some fixes; seen command works, and stats somewhat works.
This commit is contained in:
parent
dae47de713
commit
3da6310065
|
@ -45,6 +45,9 @@ import time
|
||||||
|
|
||||||
import sqlite
|
import sqlite
|
||||||
|
|
||||||
|
import debug
|
||||||
|
import ircdb
|
||||||
|
import ircmsgs
|
||||||
import privmsgs
|
import privmsgs
|
||||||
import ircutils
|
import ircutils
|
||||||
import callbacks
|
import callbacks
|
||||||
|
@ -81,16 +84,18 @@ class ChannelStats(callbacks.Privmsg, ChannelDBHandler):
|
||||||
kicks INTEGER,
|
kicks INTEGER,
|
||||||
kicked INTEGER,
|
kicked INTEGER,
|
||||||
modes INTEGER,
|
modes INTEGER,
|
||||||
topics INTEGER,
|
topics INTEGER
|
||||||
)""")
|
)""")
|
||||||
cursor.execute("""CREATE INDEX stats_username ON stats (username)""")
|
cursor.execute("""CREATE INDEX stats_username ON stats (username)""")
|
||||||
db.commit()
|
db.commit()
|
||||||
return db
|
return db
|
||||||
|
|
||||||
def doPrivmsg(self, irc, msg):
|
def doPrivmsg(self, irc, msg):
|
||||||
|
callbacks.Privmsg.doPrivmsg(self, irc, msg)
|
||||||
if ircutils.isChannel(msg.args[0]):
|
if ircutils.isChannel(msg.args[0]):
|
||||||
(channel, s) = msg.args
|
(channel, s) = msg.args
|
||||||
db = self.getDb(channel)
|
db = self.getDb(channel)
|
||||||
|
cursor = db.cursor()
|
||||||
try:
|
try:
|
||||||
name = ircdb.users.getUserName(msg.prefix)
|
name = ircdb.users.getUserName(msg.prefix)
|
||||||
except KeyError:
|
except KeyError:
|
||||||
|
@ -100,7 +105,7 @@ class ChannelStats(callbacks.Privmsg, ChannelDBHandler):
|
||||||
cursor.execute("""INSERT INTO stats VALUES (
|
cursor.execute("""INSERT INTO stats VALUES (
|
||||||
NULL, %s, %s, %s, %s, %s,
|
NULL, %s, %s, %s, %s, %s,
|
||||||
%s, %s, 1, %s,
|
%s, %s, 1, %s,
|
||||||
0, 0, 0, 0, 0 )""",
|
0, 0, 0, 0, 0, 0 )""",
|
||||||
name, int(time.time()), msg.args[1],
|
name, int(time.time()), msg.args[1],
|
||||||
len(smileyre.findall(s)),
|
len(smileyre.findall(s)),
|
||||||
len(frownre.findall(s)), len(s), len(s.split()),
|
len(frownre.findall(s)), len(s), len(s.split()),
|
||||||
|
@ -117,12 +122,12 @@ class ChannelStats(callbacks.Privmsg, ChannelDBHandler):
|
||||||
WHERE username=%s""",
|
WHERE username=%s""",
|
||||||
int(time.time()),
|
int(time.time()),
|
||||||
s,
|
s,
|
||||||
values.chars + len(s),
|
int(values.chars) + len(s),
|
||||||
values.words + len(s.split()),
|
int(values.words) + len(s.split()),
|
||||||
values.msgs + 1,
|
int(values.msgs) + 1,
|
||||||
values.actions + ircmsgs.isAction(msg),
|
int(values.actions) + ircmsgs.isAction(msg),
|
||||||
values.smileys + len(smileyre.findall(s)),
|
int(values.smileys) + len(smileyre.findall(s)),
|
||||||
values.frowns + len(frownre.findall(s)),
|
int(values.frowns) + len(frownre.findall(s)),
|
||||||
name)
|
name)
|
||||||
db.commit()
|
db.commit()
|
||||||
|
|
||||||
|
@ -220,7 +225,7 @@ class ChannelStats(callbacks.Privmsg, ChannelDBHandler):
|
||||||
"[<channel>] (if not sent on the channel itself) <nick>"
|
"[<channel>] (if not sent on the channel itself) <nick>"
|
||||||
channel = privmsgs.getChannel(msg, args)
|
channel = privmsgs.getChannel(msg, args)
|
||||||
name = privmsgs.getArgs(args)
|
name = privmsgs.getArgs(args)
|
||||||
if not irc.users.hasUser(name):
|
if not ircdb.users.hasUser(name):
|
||||||
hostmask = irc.state.nickToHostmask(name)
|
hostmask = irc.state.nickToHostmask(name)
|
||||||
try:
|
try:
|
||||||
name = irc.users.getUserName(hostmask)
|
name = irc.users.getUserName(hostmask)
|
||||||
|
@ -229,12 +234,13 @@ class ChannelStats(callbacks.Privmsg, ChannelDBHandler):
|
||||||
return
|
return
|
||||||
db = self.getDb(channel)
|
db = self.getDb(channel)
|
||||||
cursor = db.cursor()
|
cursor = db.cursor()
|
||||||
cursor.execute("""SELECT (last_seen, last_msg) FROM stats
|
cursor.execute("""SELECT last_seen, last_msg FROM stats
|
||||||
WHERE username=%s""", name)
|
WHERE username=%s""", name)
|
||||||
if cursor.rowcount == 0:
|
if cursor.rowcount == 0:
|
||||||
irc.reply(msg, 'I have no stats for that user.')
|
irc.reply(msg, 'I have no stats for that user.')
|
||||||
else:
|
else:
|
||||||
(seen, m) = cursor.fetchone()
|
(seen, m) = cursor.fetchone()
|
||||||
|
seen = int(seen)
|
||||||
ago = int(time.time()) - seen
|
ago = int(time.time()) - seen
|
||||||
days = ago / 86400
|
days = ago / 86400
|
||||||
ago %= 86400
|
ago %= 86400
|
||||||
|
@ -246,15 +252,15 @@ class ChannelStats(callbacks.Privmsg, ChannelDBHandler):
|
||||||
(days, days == 1 and ',' or 's,',
|
(days, days == 1 and ',' or 's,',
|
||||||
hours, hours == 1 and ',' or 's,',
|
hours, hours == 1 and ',' or 's,',
|
||||||
minutes, minutes == 1 and ',' or 's,',
|
minutes, minutes == 1 and ',' or 's,',
|
||||||
seconds, seconds == 1 and ',' or 's,')
|
seconds, seconds == 1 and ' ' or 's ')
|
||||||
irc.reply(msg, '%s was last seen here at %s saying %s' % \
|
irc.reply(msg, '%s was last seen here at %s saying %r' % \
|
||||||
(name, s, m))
|
(name, s, m))
|
||||||
|
|
||||||
def stats(self, irc, msg, args):
|
def stats(self, irc, msg, args):
|
||||||
"[<channel>] (if not sent in the channel itself) <nick>"
|
"[<channel>] (if not sent in the channel itself) <nick>"
|
||||||
channel = privmsgs.getChannel(msg, args)
|
channel = privmsgs.getChannel(msg, args)
|
||||||
name = privmsgs.getArgs(args)
|
name = privmsgs.getArgs(args)
|
||||||
if not irc.users.hasUser(name):
|
if not ircdb.users.hasUser(name):
|
||||||
hostmask = irc.state.nickToHostmask(name)
|
hostmask = irc.state.nickToHostmask(name)
|
||||||
try:
|
try:
|
||||||
name = irc.users.getUserName(hostmask)
|
name = irc.users.getUserName(hostmask)
|
||||||
|
@ -270,14 +276,14 @@ class ChannelStats(callbacks.Privmsg, ChannelDBHandler):
|
||||||
irc.reply(msg, 'I have no stats for that user.')
|
irc.reply(msg, 'I have no stats for that user.')
|
||||||
return
|
return
|
||||||
values = cursor.fetchone()
|
values = cursor.fetchone()
|
||||||
s = '%s has %s messages, with a total of %s chars, %s words, ' \
|
s = '%s has sent %s messages; a total of %s characters, %s words, ' \
|
||||||
'%s smileys, and %s frowns; %s of those messages were ACTIONs. ' \
|
'%s smileys, and %s frowns; %s of those messages were ACTIONs. ' \
|
||||||
'%s has joined %s times, parted %s times, kicked someone %s times'\
|
'%s has joined %s times, parted %s times, kicked someone %s times'\
|
||||||
' been kicked %s times, changed the topic %s times, ' \
|
' been kicked %s times, changed the topic %s times, ' \
|
||||||
'and changed the mode %s times.' % \
|
'and changed the mode %s times.' % \
|
||||||
(values.msgs, values.chars, values.words,
|
(name, values.msgs, values.chars, values.words,
|
||||||
values.smileys, values.frowns, values.actions,
|
values.smileys, values.frowns, values.actions,
|
||||||
values.joins, values.parts, values.kicks,
|
name, values.joins, values.parts, values.kicks,
|
||||||
values.kicked, values.topics,
|
values.kicked, values.topics,
|
||||||
values.modes)
|
values.modes)
|
||||||
irc.reply(msg, s)
|
irc.reply(msg, s)
|
||||||
|
|
Loading…
Reference in New Issue