mirror of
https://git.wownero.com/dsc/craiyon-irc.git
synced 2024-08-15 01:03:24 +00:00
increase queue size, use NOTICE, ignore certain nicks
This commit is contained in:
parent
da4fc61f56
commit
d457a25c88
1 changed files with 16 additions and 9 deletions
25
main.py
25
main.py
|
@ -16,6 +16,7 @@ import aiohttp
|
||||||
|
|
||||||
from settings import *
|
from settings import *
|
||||||
|
|
||||||
|
IGNORE_NICKS = ["monerobux", "denise"]
|
||||||
TASK_QUEUE = asyncio.Queue()
|
TASK_QUEUE = asyncio.Queue()
|
||||||
TASK_AUTHORS = {}
|
TASK_AUTHORS = {}
|
||||||
FONT = ImageFont.truetype('font-bold.ttf', 22)
|
FONT = ImageFont.truetype('font-bold.ttf', 22)
|
||||||
|
@ -44,6 +45,13 @@ class Task:
|
||||||
self.term = term
|
self.term = term
|
||||||
self.dt = dt
|
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:
|
async def process_images(self, images: List[JpegImageFile]) -> JpegImageFile:
|
||||||
if len(images) <= 0:
|
if len(images) <= 0:
|
||||||
raise Exception("Not enough images")
|
raise Exception("Not enough images")
|
||||||
|
@ -154,6 +162,8 @@ def reconnect(**kwargs):
|
||||||
async def message_received(nick, target, message, **kwargs):
|
async def message_received(nick, target, message, **kwargs):
|
||||||
if nick == IRC_NICK:
|
if nick == IRC_NICK:
|
||||||
return
|
return
|
||||||
|
if nick in IGNORE_NICKS:
|
||||||
|
return
|
||||||
if target == IRC_NICK:
|
if target == IRC_NICK:
|
||||||
target = nick
|
target = nick
|
||||||
if target not in IRC_CHANNELS:
|
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.")
|
return _err(target, f"longer query required.")
|
||||||
|
|
||||||
TASK_AUTHORS.setdefault(nick, 0)
|
TASK_AUTHORS.setdefault(nick, 0)
|
||||||
if TASK_AUTHORS[nick] >= 3:
|
if TASK_AUTHORS[nick] >= 4:
|
||||||
err = f"{nick}: you already queued 3 thingies, patient!!11"
|
err = f"{nick}: you already queued 4 thingies, patient!!11"
|
||||||
bot.send("PRIVMSG", target=target, message=err)
|
bot.send("NOTICE", target=target, message=err)
|
||||||
return
|
return
|
||||||
|
|
||||||
TASK_AUTHORS[nick] += 1
|
TASK_AUTHORS[nick] += 1
|
||||||
task = Task(channel=target, author=nick, term=msg, dt=int(now))
|
task = Task(channel=target, author=nick, term=msg, dt=int(now))
|
||||||
await TASK_QUEUE.put(task)
|
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():
|
async def main():
|
||||||
|
@ -205,10 +215,7 @@ async def main():
|
||||||
TASK_AUTHORS[task_author] -= 1
|
TASK_AUTHORS[task_author] -= 1
|
||||||
|
|
||||||
def _err(_task, err):
|
def _err(_task, err):
|
||||||
term = _task.term
|
return bot.send("PRIVMSG", target=_task.channel, message=f"{_task.author}: Error \"{_task.term_short}\"; {err}")
|
||||||
if len(term) >= 12:
|
|
||||||
term = _task.term[:12] + ".."
|
|
||||||
return bot.send("PRIVMSG", target=_task.channel, message=f"{_task.author}: Error \"{term}\"; {err}")
|
|
||||||
|
|
||||||
# main loop
|
# main loop
|
||||||
while True:
|
while True:
|
||||||
|
@ -245,7 +252,7 @@ async def main():
|
||||||
_lower_author_task_count(task.author)
|
_lower_author_task_count(task.author)
|
||||||
|
|
||||||
completed_secs = int((datetime.now() - now).total_seconds())
|
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)
|
await asyncio.sleep(10)
|
||||||
|
|
||||||
loop = asyncio.get_event_loop()
|
loop = asyncio.get_event_loop()
|
||||||
|
|
Loading…
Reference in a new issue