increase queue size, use NOTICE, ignore certain nicks

This commit is contained in:
dsc 2022-07-21 23:02:16 +02:00
parent da4fc61f56
commit d457a25c88

25
main.py
View file

@ -16,6 +16,7 @@ import aiohttp
from settings import *
IGNORE_NICKS = ["monerobux", "denise"]
TASK_QUEUE = asyncio.Queue()
TASK_AUTHORS = {}
FONT = ImageFont.truetype('font-bold.ttf', 22)
@ -44,6 +45,13 @@ class Task:
self.term = term
self.dt = dt
@property
def term_short(self):
max_len = 60
if len(self.term) <= max_len:
return self.term
return self.term[:max_len] + ".."
async def process_images(self, images: List[JpegImageFile]) -> JpegImageFile:
if len(images) <= 0:
raise Exception("Not enough images")
@ -154,6 +162,8 @@ def reconnect(**kwargs):
async def message_received(nick, target, message, **kwargs):
if nick == IRC_NICK:
return
if nick in IGNORE_NICKS:
return
if target == IRC_NICK:
target = nick
if target not in IRC_CHANNELS:
@ -185,15 +195,15 @@ async def handle_msg(nick, msg, target, now: float):
return _err(target, f"longer query required.")
TASK_AUTHORS.setdefault(nick, 0)
if TASK_AUTHORS[nick] >= 3:
err = f"{nick}: you already queued 3 thingies, patient!!11"
bot.send("PRIVMSG", target=target, message=err)
if TASK_AUTHORS[nick] >= 4:
err = f"{nick}: you already queued 4 thingies, patient!!11"
bot.send("NOTICE", target=target, message=err)
return
TASK_AUTHORS[nick] += 1
task = Task(channel=target, author=nick, term=msg, dt=int(now))
await TASK_QUEUE.put(task)
bot.send("PRIVMSG", target=target, message=f"{nick}: generating...")
bot.send("NOTICE", target=target, message=f"generating...")
async def main():
@ -205,10 +215,7 @@ async def main():
TASK_AUTHORS[task_author] -= 1
def _err(_task, err):
term = _task.term
if len(term) >= 12:
term = _task.term[:12] + ".."
return bot.send("PRIVMSG", target=_task.channel, message=f"{_task.author}: Error \"{term}\"; {err}")
return bot.send("PRIVMSG", target=_task.channel, message=f"{_task.author}: Error \"{_task.term_short}\"; {err}")
# main loop
while True:
@ -245,7 +252,7 @@ async def main():
_lower_author_task_count(task.author)
completed_secs = int((datetime.now() - now).total_seconds())
bot.send("PRIVMSG", target=task.channel, message=f"{url} \"{task.term}\" (total: {completed_secs}s, {task.author}) ")
bot.send("NOTICE", target=task.channel, message=f"{url} \"{task.term_short}\" (total: {completed_secs}s, {task.author}) ")
await asyncio.sleep(10)
loop = asyncio.get_event_loop()