Compare commits

...

2 Commits

Author SHA1 Message Date
randomuser 6dfe72a83a move duck testing logic to new method duck_test 2021-07-20 23:23:58 -05:00
randomuser b41d315056 add formatting functions 2021-07-20 23:18:31 -05:00
1 changed files with 10 additions and 4 deletions

14
main.py
View File

@ -30,16 +30,22 @@ class Server(BaseServer):
self.duckactive = True
self.duckactivetime = time.time()
await self.msgall(lang["duck"])
async def duck_test(self):
if self.messages > 1 and random.randint(0, 99) < 10: await self.new_duck()
async def misstime(self):
return format(time.time() - self.lastduck, '.2f')
async def coughttime(self):
return format(self.lastduck - self.duckactivetime, '.2f')
async def duck_action(self, user, chan):
if self.duckactive:
self.duckactive = False
self.messages = 0
self.lastduck = time.time()
await self.msgall(lang["duckcought"].format(user, chan, format(self.lastduck - self.duckactivetime, '.2f')))
await self.msgall(lang["duckcought"].format(user, chan, self.coughttime())))
elif self.lastduck != 0:
await self.msg(chan, lang["noduck"].format(format(time.time() - self.lastduck, '.2f')), user)
await self.msg(chan, lang["noduck"].format(self.coughttime())), user)
else:
await self.msg(chan, lang["noduckstart"].format(format(time.time() - self.lastduck, '.2f')), user)
await self.msg(chan, lang["noduckstart"], user)
async def line_read(self, line: Line):
print(f"{self.name} < {line.format()}")
if line.command == "001":
@ -56,7 +62,7 @@ class Server(BaseServer):
return
self.messages += 1
if self.messages > 1 and random.randint(0, 100) < 10: await self.new_duck()
self.duck_test()
elif line.command == "INVITE":
await self.send(build("JOIN", [line.params[1]]))
async def line_send(self, line: Line):