diff options
Diffstat (limited to 'main.py')
| -rw-r--r-- | main.py | 26 |
1 files changed, 12 insertions, 14 deletions
@@ -52,7 +52,6 @@ async def get_user(id): async def search_teammates(who, query): now = datetime.datetime.utcnow() cal = parsedatetime.Calendar() - cal.inc(now) isrange = " for " in query or " until " in query if isrange: @@ -69,22 +68,22 @@ async def search_teammates(who, query): start, end, calnow = [cal.parseDT(d)[0] for d in (startstr, endstr, "now")] db.playwithme.insert_one({ - "player": who, + "player": who.id, "start": start, "end": end }) - print(who + " requested a game " + ", ".join([str(d) for d in (start, end)])) + print(who.name + " requested a game " + ", ".join([str(d) for d in (start, end)])) - if start == calnow: - players = [] - for teammate in db.playwithme.find({"start": {"$lt": now}, "end": {"$gt": now}}): - mention = (await get_user(teammate["player"]))["mention"] - if not mention in players: - players += [mention] - if len(players) > 1: - return ", ".join(players) + " can play together." - return "Nobody can play right now. I will notify you." + players = [] + for teammate in db.playwithme.find({"start": {"$lt": start}, "end": {"$gt": start}}): + 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." % (start.strftime("%H:%M")) + else: + return "Nobody can play at that time. I will notify you if anyone can play between %s and %s." % (start.strftime("%H:%M"), end.strftime("%H:%M")) @cli.event async def on_message(message): @@ -101,9 +100,8 @@ async def on_message(message): await cli.send_message(message.channel, "Cancel your search with <don't play with me>.") if msg.startswith("play with me"): - player = message.author.id when = message.content[len("play with me"):] - response = await search_teammates(player, when) + response = await search_teammates(message.author, when) await cli.send_message(message.channel, response) if msg.startswith("don't play with me"): |
