rewrite zaagmans - fixes #33 #41
+38
-16
@@ -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,23 +813,43 @@ class Shitpost(commands.Cog):
|
||||
await ctx.channel.send(message)
|
||||
|
||||
def get_zaagmans(self):
|
||||
zaagman_url = "http://iszaagmansallangsgeweest.nl/"
|
||||
headers = {
|
||||
'User-Agent': self.userAgent,
|
||||
}
|
||||
zreq = requests.get(zaagman_url, headers=headers)
|
||||
if zreq:
|
||||
return zreq.text.partition("<h1>")[2].partition("</h1>")[0]
|
||||
else:
|
||||
return None
|
||||
now = datetime.now(self.TIME_ZONE)
|
||||
|
||||
@commands.command(pass_context=True)
|
||||
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"
|
||||
if whole_days == 0:
|
||||
time_to_wait = "minder dan 1 dag"
|
||||
elif extra_hours >= 12:
|
||||
|
mark marked this conversation as resolved
|
||||
time_to_wait = f"iets minder dan {whole_days + 1} dagen"
|
||||
else:
|
||||
time_to_wait = f"iets meer dan {whole_days} dag{day_suffix}"
|
||||
|
||||
if now.weekday() in (3,4): # do, vr
|
||||
return f"Zaagmans heeft de week doormidden gezaagd en komt pas weer over {time_to_wait}."
|
||||
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
time_to_waitheb je alleen hier nodig, dus die hele if-chain hierboven waar je hem berekent kan ook hier, zodat je hem niet berekent als je hem niet nodig hebt.vond het leesbaarder om alle output bij elkaar te hebben, maar snap het punt. in de laatste commit aangepast.