From 5e7e6aa45cbe1e2a07d336ad482546705494676a Mon Sep 17 00:00:00 2001 From: schneefux Date: Fri, 9 Dec 2016 15:03:13 +0100 Subject: who can play: ask passively for games --- main.py | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/main.py b/main.py index 589c942..6e83a9d 100644 --- a/main.py +++ b/main.py @@ -47,7 +47,7 @@ async def get_user(id): }) return await get_user(id) -async def search_teammates(who, query): +async def search_teammates(who, query, notify=True): cal = parsedatetime.Calendar() if " for " in query or " until " in query: @@ -64,11 +64,12 @@ async def search_teammates(who, query): start = cal.parseDT(startstr)[0] end = cal.parseDT(endstr, sourceTime=start)[0] - db.playwithme.insert_one({ - "player": who.id, - "start": start, - "end": end - }) + if notify: + db.playwithme.insert_one({ + "player": who.id, + "start": start, + "end": end + }) log.info(who.name + " requested a game " + ", ".join([str(d) for d in (start, end)])) @@ -98,9 +99,12 @@ async def search_teammates(who, query): if not mention in players: players += [mention] if len(players) > 1: - return ", ".join(players) + " can play together at." + return ", ".join(players) + " can play together." else: - return "Nobody can play at that time. I will notify you if anyone wants to play between %s and %s. It is now %s." % (start.strftime("%H:%M"), end.strftime("%H:%M"), datetime.datetime.now().strftime("%H:%M")) + if notify: + return "Nobody can play at that time. I will notify you if anyone wants to play between %s and %s. It is now %s." % (start.strftime("%H:%M"), end.strftime("%H:%M"), datetime.datetime.now().strftime("%H:%M")) + else: + return "Nobody can play at that time." @cli.event async def on_message(message): @@ -114,14 +118,15 @@ async def on_message(message): if msg.startswith("?help"): await cli.send_message(message.channel, "Commands: ?help, ?ping, ?about") await cli.send_message(message.channel, " to find teammates.") + await cli.send_message(message.channel, " to see who registered for notifications.") await cli.send_message(message.channel, " to cancel.") - if msg.startswith("play with me") or msg.startswith("?play"): + if msg.startswith("play with me") or msg.startswith("who can play"): if msg.startswith("play with me"): when = message.content[len("play with me"):] else: - when = message.content[len("?play"):] - response = await search_teammates(message.author, when) + when = message.content[len("who can play"):] + response = await search_teammates(message.author, when, False) await cli.send_message(message.channel, response) if msg.startswith("don't play with me") or msg.startswith("dont play with me"): -- cgit v1.3.1