summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorschneefux <schneefux+commit@schneefux.xyz>2016-12-01 20:03:39 +0100
committerschneefux <schneefux+commit@schneefux.xyz>2016-12-01 20:03:39 +0100
commit8860360d1ccbaf089f40f7699580b5eceb4f2b8b (patch)
tree3c5bd07ef9c7dee0d6df040096c31c9f8fa3f6f8
parent30abc1e3489e652fdf0483d12040dabda69c8d72 (diff)
downloadVainbot-8860360d1ccbaf089f40f7699580b5eceb4f2b8b.tar.gz
Vainbot-8860360d1ccbaf089f40f7699580b5eceb4f2b8b.zip
be more accurate about game dates
-rw-r--r--main.py26
1 files changed, 12 insertions, 14 deletions
diff --git a/main.py b/main.py
index 7a7797d..07fb0d7 100644
--- a/main.py
+++ b/main.py
@@ -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"):