Reviewed-on: #41 Reviewed-by: Mark Hoekveen <mark@hoekveen.net>
This commit was merged in pull request #41.
This commit is contained in:
commit
e184267eca
1 file changed
+38
-16
+38
-16
@@ -3,6 +3,7 @@ from discord.ext import commands
|
|||||||
from urllib import request
|
from urllib import request
|
||||||
import json, requests
|
import json, requests
|
||||||
import math
|
import math
|
||||||
|
from zoneinfo import ZoneInfo
|
||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
import os
|
import os
|
||||||
import random
|
import random
|
||||||
@@ -17,6 +18,7 @@ class Shitpost(commands.Cog):
|
|||||||
self.bot = bot
|
self.bot = bot
|
||||||
self.hdConImpatientEvents = []
|
self.hdConImpatientEvents = []
|
||||||
self.userAgent = 'Mozilla/5.0 (X11; Linux x86_64; rv:136.0) Gecko/20100101 Firefox/136.0'
|
self.userAgent = 'Mozilla/5.0 (X11; Linux x86_64; rv:136.0) Gecko/20100101 Firefox/136.0'
|
||||||
|
self.TIME_ZONE = ZoneInfo("Europe/Amsterdam")
|
||||||
try:
|
try:
|
||||||
with open('black.txt') as zwart:
|
with open('black.txt') as zwart:
|
||||||
self.zwarte_lijst = [line.rstrip('\n') for line in zwart]
|
self.zwarte_lijst = [line.rstrip('\n') for line in zwart]
|
||||||
@@ -811,23 +813,43 @@ class Shitpost(commands.Cog):
|
|||||||
await ctx.channel.send(message)
|
await ctx.channel.send(message)
|
||||||
|
|
||||||
def get_zaagmans(self):
|
def get_zaagmans(self):
|
||||||
zaagman_url = "http://iszaagmansallangsgeweest.nl/"
|
now = datetime.now(self.TIME_ZONE)
|
||||||
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
|
|
||||||
|
|
||||||
@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:
|
||||||
|
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):
|
async def zaagmans(self, ctx):
|
||||||
"""Is zaagmans al langsgeweest? Is de week al doormidden. Wie weet."""
|
"""Is zaagmans al langsgeweest? Is de week al doormidden. Wie weet."""
|
||||||
gezaagd = self.get_zaagmans()
|
message = ctx.author.mention + ": " + self.get_zaagmans()
|
||||||
message = ctx.author.mention + ": "
|
|
||||||
if gezaagd:
|
|
||||||
message += gezaagd
|
|
||||||
else:
|
|
||||||
message += "De waarheid over zaagmans is niet te doorgronden."
|
|
||||||
await ctx.channel.send(message)
|
await ctx.channel.send(message)
|
||||||
Reference in new issue
Block a user