From c84bf9114a16f1a435a737c514bc154e6085f8eb Mon Sep 17 00:00:00 2001 From: Ben Date: Mon, 19 Aug 2019 02:29:17 +0100 Subject: [PATCH] Ignore handler module --- houdini/handlers/play/ignore.py | 36 +++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/houdini/handlers/play/ignore.py b/houdini/handlers/play/ignore.py index e69de29..ef4e571 100644 --- a/houdini/handlers/play/ignore.py +++ b/houdini/handlers/play/ignore.py @@ -0,0 +1,36 @@ +from houdini import handlers +from houdini.handlers import XTPacket + +from houdini.data.penguin import Penguin +from houdini.data.buddy import IgnoreList + + +@handlers.handler(XTPacket('n', 'gn')) +@handlers.allow_once +async def handle_get_ignore_list(p): + ignore_query = IgnoreList.load(parent=Penguin.on(Penguin.id == IgnoreList.ignore_id)).where( + IgnoreList.penguin_id == p.data.id) + + async with p.server.db.transaction(): + ignore_list = ignore_query.gino.iterate() + ignores = [f'{ignore.ignore_id}|{ignore.parent.nickname}' async for ignore in ignore_list] + + await p.send_xt('gn', *ignores) + + +@handlers.handler(XTPacket('n', 'rn')) +async def handle_ignore_remove(p, ignored_id: int): + if ignored_id in p.data.ignore: + await p.data.ignore.delete(ignored_id) + await p.send_xt('rn', ignored_id) + + +@handlers.handler(XTPacket('n', 'an')) +async def handle_ignore_add(p, ignored_id: int): + if ignored_id not in p.data.ignore: + if ignored_id in p.server.penguins_by_id: + nickname = p.server.penguins_by_id[ignored_id].data.nickname + else: + nickname = await Penguin.select('nickname').where(Penguin.id == ignored_id).gino.scalar() + await p.data.ignore.set(ignored_id) + await p.send_xt('an', ignored_id, nickname)