From d4aebc915d803fc54211e9aa22f0d2415935a677 Mon Sep 17 00:00:00 2001 From: schneefux Date: Fri, 9 Dec 2016 14:57:31 +0100 Subject: consider all timing cases --- main.py | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/main.py b/main.py index 813e7ab..589c942 100644 --- a/main.py +++ b/main.py @@ -73,14 +73,34 @@ async def search_teammates(who, query): log.info(who.name + " requested a game " + ", ".join([str(d) for d in (start, end)])) players = [] - for teammate in db.playwithme.find({"end": {"$gt": start, "$lt": end}}): + query = { + "$or": [ + { + "start": { + "$gt": start, + "$lt": end + } + }, + { + "end": { + "$gt": start, + "$lt": end + } + }, + { + "start": {"$lt": start}, + "end": {"$gt": end} + } + ] + } + for teammate in db.playwithme.find(query): mention = (await get_user(teammate["player"]))["mention"] if not mention in players: players += [mention] if len(players) > 1: - return ", ".join(players) + " can play together at %s. It is now %s." % (start.strftime("%H:%M"), datetime.datetime.now().strftime("%H:%M")) + return ", ".join(players) + " can play together at." else: - return "Nobody can play at that time. I will notify you if anyone can play between %s and %s. It is now %s." % (start.strftime("%H:%M"), end.strftime("%H:%M"), datetime.datetime.now().strftime("%H:%M")) + 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")) @cli.event async def on_message(message): -- cgit v1.3.1