add stats command

This commit is contained in:
randomuser 2021-07-21 00:30:52 -05:00
parent e4f4621d1b
commit 4b4912fd3d
1 changed files with 13 additions and 1 deletions

14
main.py
View File

@ -4,6 +4,7 @@ import time
from db import DuckDB from db import DuckDB
from db import DuckEvent from db import DuckEvent
from db import DuckStats
from irctokens import build, Line from irctokens import build, Line
from ircrobots import Bot as BaseBot from ircrobots import Bot as BaseBot
@ -15,6 +16,7 @@ lang = {
"noduckstart": "there was no duck!", "noduckstart": "there was no duck!",
"duckcought": "duck has been cought by {} in channel {} in {} seconds!", "duckcought": "duck has been cought by {} in channel {} in {} seconds!",
"duck": "・゜゜・。。・゜゜\_o< QUACK!", "duck": "・゜゜・。。・゜゜\_o< QUACK!",
"stats": "{} has befriended {} ducks in {} different channels, having a befriend/loss ratio of {}.",
} }
class DuckLogic: class DuckLogic:
@ -72,11 +74,21 @@ class Server(BaseServer, DuckLogic):
print(line.params) print(line.params)
print(line.hostmask.nickname) print(line.hostmask.nickname)
if line.params[1][0] == '%': if line.params[1][0] == '%':
cmd = line.params[1][1:] cmd = line.params[1].split(' ')[0][1:]
chan = line.params[0] chan = line.params[0]
user = line.hostmask.nickname user = line.hostmask.nickname
args = line.params[1].split(' ')[1:]
if cmd == "bef": await self.duck_action(user, chan) if cmd == "bef": await self.duck_action(user, chan)
elif cmd == "trigger": await self.new_duck() elif cmd == "trigger": await self.new_duck()
elif cmd == "stats":
db = DuckDB(self.db)
stats = DuckStats(db)
await self.msg(chan, lang["stats"].format(
args[0],
stats.cought(args[0]),
stats.channels(args[0]),
format(stats.ratio(args[0]), ".2f")
), user)
return return
self.messages += 1 self.messages += 1