Compare commits

...

7 Commits

2 changed files with 37 additions and 18 deletions

8
db.py
View File

@ -77,4 +77,10 @@ class DuckStats:
return self.countstatus(nick, "M")
def ratio(self, nick):
return (self.cought(nick) / self.missed(nick)) * 100
return self.cought(nick) / self.missed(nick)
def channels(self, nick):
channels = set()
for i in self.db.db:
if i.nick == nick: channels.add(i.channel)
return len(channels)

47
main.py
View File

@ -4,6 +4,7 @@ import time
from db import DuckDB
from db import DuckEvent
from db import DuckStats
from irctokens import build, Line
from ircrobots import Bot as BaseBot
@ -15,23 +16,10 @@ lang = {
"noduckstart": "there was no duck!",
"duckcought": "duck has been cought by {} in channel {} in {} seconds!",
"duck": "・゜゜・。。・゜゜\_o< QUACK!",
"stats": "{} has befriended {} ducks in {} different channels, having a befriend/loss ratio of {}.",
}
class Server(BaseServer):
messages = 0
duckactive = False
duckactivetime = 0
lastduck = 0
db = "duckdb"
async def msg(self, chan, msg, usr=None):
if usr != None:
await self.send(build("PRIVMSG", [chan, usr + ": " + msg]))
else: await self.send(build("PRIVMSG", [chan, msg]))
async def msgall(self, msg):
[await self.msg(channel, msg) for channel in self.channels]
class DuckLogic:
async def new_duck(self):
self.messages = 0
self.duckactive = True
@ -63,6 +51,21 @@ class Server(BaseServer):
db.add("M", user, time.time(), -1, chan)
db.write(self.db)
class Server(BaseServer, DuckLogic):
messages = 0
duckactive = False
duckactivetime = 0
lastduck = 0
db = "duckdb"
async def msg(self, chan, msg, usr=None):
if usr != None:
await self.send(build("PRIVMSG", [chan, usr + ": " + msg]))
else: await self.send(build("PRIVMSG", [chan, msg]))
async def msgall(self, msg):
[await self.msg(channel, msg) for channel in self.channels]
async def line_read(self, line: Line):
print(f"{self.name} < {line.format()}")
if line.command == "001":
@ -71,11 +74,21 @@ class Server(BaseServer):
print(line.params)
print(line.hostmask.nickname)
if line.params[1][0] == '%':
cmd = line.params[1][1:]
cmd = line.params[1].split(' ')[0][1:]
chan = line.params[0]
user = line.hostmask.nickname
args = line.params[1].split(' ')[1:]
if cmd == "bef": await self.duck_action(user, chan)
if 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]), ".3f")
), user)
return
self.messages += 1