rewrite zaagmans - fixes #33 #41
+21
-22
@@ -3,6 +3,7 @@ from discord.ext import commands
|
||||
from urllib import request
|
||||
import json, requests
|
||||
import math
|
||||
from zoneinfo import ZoneInfo
|
||||
from datetime import datetime, timedelta
|
||||
import os
|
||||
import random
|
||||
@@ -17,6 +18,7 @@ class Shitpost(commands.Cog):
|
||||
self.bot = bot
|
||||
self.hdConImpatientEvents = []
|
||||
self.userAgent = 'Mozilla/5.0 (X11; Linux x86_64; rv:136.0) Gecko/20100101 Firefox/136.0'
|
||||
self.TIME_ZONE = ZoneInfo("Europe/Amsterdam")
|
||||
try:
|
||||
with open('black.txt') as zwart:
|
||||
self.zwarte_lijst = [line.rstrip('\n') for line in zwart]
|
||||
@@ -811,18 +813,26 @@ class Shitpost(commands.Cog):
|
||||
await ctx.channel.send(message)
|
||||
|
||||
def get_zaagmans(self):
|
||||
now = datetime.now()
|
||||
# Zaagmans komt steevast elke woensdag om 12 uur, berekend vanaf nu:
|
||||
noon_today = now.replace(hour=12, minute=0, second=0, microsecond=0)
|
||||
# dagen t/m woensdag (index 2), % 7 wraps als al geweest. vb zondag 6; (-4 % 7 = 3 dagen)
|
||||
zaagmans_o_clock = noon_today + timedelta(days=(2 - now.weekday()) % 7)
|
||||
if zaagmans_o_clock <= now: # als woensdag na 12:00
|
||||
zaagmans_o_clock += timedelta(days=7)
|
||||
now = datetime.now(self.TIME_ZONE)
|
||||
|
||||
if now.weekday() in (5, 6): # za, zo
|
||||
return "Ga weekend vieren of zo."
|
||||
|
||||
noon_today = now.replace(hour=12, minute=0, second=0, microsecond=0)
|
||||
if now.weekday() == 2 and now >= noon_today: # als woensdag na 12:00
|
||||
return "Zaagmans heeft de week doormidden gezaagd!"
|
||||
|
||||
# tijd tot volgende woensdag 12:00. % 7 wraps als al geweest die week. vb zondag 6; (-4 % 7 = 3 dagen)
|
||||
zaagmans_o_clock = noon_today + timedelta(days=(2 - now.weekday()) % 7)
|
||||
if zaagmans_o_clock <= now:
|
||||
zaagmans_o_clock += timedelta(days=7)
|
||||
time_til_zaagmans = zaagmans_o_clock - now
|
||||
|
||||
if time_til_zaagmans <= timedelta(hours=5):
|
||||
return "Zaagmans komt bijna, nog even geduld!" # I'm epsilon there!
|
||||
|
||||
whole_days = time_til_zaagmans.days
|
||||
extra_hours = time_til_zaagmans.seconds // 3600
|
||||
|
||||
day_suffix = ""
|
||||
if whole_days != 1:
|
||||
day_suffix = "en"
|
||||
@@ -833,24 +843,13 @@ class Shitpost(commands.Cog):
|
||||
else:
|
||||
time_to_wait = f"iets meer dan {whole_days} dag{day_suffix}"
|
||||
|
||||
if now.weekday() in (5, 6):
|
||||
return "Ga weekend vieren of zo."
|
||||
if now.weekday() == 2 and now >= noon_today:
|
||||
return "Zaagmans heeft de week doormidden gezaagd!"
|
||||
if now.weekday() in (3,4):
|
||||
if now.weekday() in (3,4): # do, vr
|
||||
return f"Zaagmans heeft de week doormidden gezaagd en komt pas weer over {time_to_wait}."
|
||||
if time_til_zaagmans <= timedelta(hours=5):
|
||||
return "Zaagmans komt bijna, nog even geduld!"
|
||||
else:
|
||||
else: # ma, di, wo tot 7:00
|
||||
return f"Helaas, meneer Zaagmans is nog niet langsgeweest om de week doormidden te zagen. Nog {time_to_wait} wachten."
|
||||
|
||||
@commands.command()
|
||||
async def zaagmans(self, ctx):
|
||||
"""Is zaagmans al langsgeweest? Is de week al doormidden. Wie weet."""
|
||||
gezaagd = self.get_zaagmans()
|
||||
message = ctx.author.mention + ": "
|
||||
if gezaagd:
|
||||
message += gezaagd
|
||||
else:
|
||||
message += "De waarheid over zaagmans is niet te doorgronden."
|
||||
message = ctx.author.mention + ": " + self.get_zaagmans()
|
||||
await ctx.channel.send(message)
|
||||
Reference in new issue
Block a user