Compare commits
30 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| b3efbaa291 | |||
| 896bc3afd7 | |||
| 99513b16d4 | |||
| cc7a5f2f28 | |||
| c919386fcb | |||
| 9d00b319aa | |||
| 3b9ac14719 | |||
| d6bc6327a2 | |||
| 916a45715b | |||
| 3f5fc17833 | |||
| 29da1d218b | |||
| 07d22768fe | |||
| 392e19f4b3 | |||
| 9852f21ef7 | |||
| 41c2dc17d1 | |||
| d1a699ee46 | |||
| acbe8c6110 | |||
| a53598b2c3 | |||
| be6380d6b8 | |||
| 527164a040 | |||
| f76f7a48c9 | |||
| a2319f0fac | |||
| a4ca645e3e | |||
| acb9df8616 | |||
| 1f848861e3 | |||
| ecc3ae8853 | |||
| e904451037 | |||
| cde205aad7 | |||
| 2e91781fad | |||
| 58ce3a8565 |
+1
-1
@@ -3,7 +3,7 @@ name: default
|
||||
|
||||
steps:
|
||||
- name: test
|
||||
image: python:3.11
|
||||
image: python:3.13
|
||||
environment:
|
||||
STROOP_DISCORD_TOKEN:
|
||||
from_secret: STROOP_DISCORD_TOKEN
|
||||
|
||||
+65
-6
@@ -5,6 +5,8 @@ import random
|
||||
import requests
|
||||
import asyncio
|
||||
import os
|
||||
import feedparser
|
||||
import json
|
||||
from datetime import datetime
|
||||
import re
|
||||
|
||||
@@ -18,6 +20,8 @@ class Chatbot(commands.Cog):
|
||||
self.START_OF_MESSAGE = "<SOM>"
|
||||
self.pmLast = datetime(2018, 1, 1, 1, 1, 1)
|
||||
self.pmCount = 0
|
||||
self.nosLast = datetime(2018, 1, 1, 1, 1, 1)
|
||||
self.nosPosts = []
|
||||
try:
|
||||
np.load('markov_dict.npy', allow_pickle=True)
|
||||
except FileNotFoundError:
|
||||
@@ -46,7 +50,6 @@ class Chatbot(commands.Cog):
|
||||
"Hoi",
|
||||
"hmm?",
|
||||
"JA WAT?",
|
||||
"Godve...Godver-fucking-domme! Wie de fuck heeft me zojuist gepingt? Wie de fuck heeft de ballen om mij te pingen?! Als ik jou vind hè, ik ram je helemaal de tyfus in. Ik ga je kapot maken. Welke breincel in jouw hoofd dacht dat het grappig was om mij te pingen? Noem jij dat 'grappig'? Ik zal je godverdomme iets laten zien wat grappig is, ja. Ik neuk je moeder zo hard dat ze van me gaat houden, godverdomme. Dat krijg je er van als je me pingt, vuile teringleijer. Jouw soort mag wat mij betreft uitsterven. Weet je, ik ga je helemaal geen aandacht meer geven. Je mag de tering krijgen, en daar blijft het bij. Kutjong.",
|
||||
self.getResponseForMessageLocal("stroopwafel")
|
||||
]
|
||||
try:
|
||||
@@ -222,6 +225,11 @@ class Chatbot(commands.Cog):
|
||||
pass # Dit is een commando. Negeer.
|
||||
elif "```" in messageContent:
|
||||
pass # Daar zit een codeblok in. Negeer.
|
||||
elif "http" in messageContent and "nos" in messageContent:
|
||||
# NOS link
|
||||
nosIds = re.findall(r'\d+', messageContent)
|
||||
if nosIds:
|
||||
self.nosPosts.append(nosIds[0])
|
||||
elif messageContent[0:7] == "http://" or messageContent[0:8] == "https://":
|
||||
pass # Een link. Negeer. TODO: post af en toe een random link die geen repost is
|
||||
else:
|
||||
@@ -288,11 +296,13 @@ class Chatbot(commands.Cog):
|
||||
await message.channel.send(response)
|
||||
|
||||
#Gets a response
|
||||
async def getResponseForMessage(self, wordsToRespondTo):
|
||||
if random.random() > 0.9:
|
||||
async def getResponseForMessage(self, wordsToRespondTo, gptChance=0.1):
|
||||
if random.random() < 1-gptChance:
|
||||
try:
|
||||
# GPT request moet echt even in een non-blocking executortje, anders loopt de hele boel vast
|
||||
return await self.bot.loop.run_in_executor(None,self.getResponseForMessageOnline, wordsToRespondTo)
|
||||
response = await self.bot.loop.run_in_executor(None,self.getResponseForMessageOnline, wordsToRespondTo)
|
||||
if response:
|
||||
return response # Anders door naar local
|
||||
except:
|
||||
pass # Door naar local call
|
||||
return self.getResponseForMessageLocal(wordsToRespondTo)
|
||||
@@ -303,8 +313,11 @@ class Chatbot(commands.Cog):
|
||||
return req.json()["translations"][0]["text"]
|
||||
|
||||
def getResponseForMessageOnline(self, wordsToRespondTo):
|
||||
text = self.translateTo("en", " ".join(wordsToRespondTo))
|
||||
req = requests.post('http://gpt.hoekveen.net/complete', json={"prompt": text, "max_tokens": 60})
|
||||
prompt = " ".join(wordsToRespondTo)
|
||||
if not prompt:
|
||||
prompt = self.getResponseForMessageLocal([])
|
||||
text = self.translateTo("en", prompt)
|
||||
req = requests.post('http://gpt.hoekveen.net/complete', json={"prompt": text, "max_tokens": 80})
|
||||
print(req.json())
|
||||
respons = req.json()["text"]
|
||||
respons = respons[0:respons.rfind(".")+1] # Alles weg na de laatste punt
|
||||
@@ -469,3 +482,49 @@ class Chatbot(commands.Cog):
|
||||
await ctx.channel.send(message)
|
||||
except:
|
||||
pass
|
||||
|
||||
@commands.command(pass_context=True)
|
||||
async def nos(self, ctx, categorie=None):
|
||||
"""Een leuk NOS artikel. Hoef je het zelf niet meer op te zoeken.
|
||||
Mag optioneel een categorie aangeven:
|
||||
algemeen binnenland buitenland politiek economie opmerkelijk koningshuis cultuurenmedia tech """
|
||||
try:
|
||||
await ctx.message.delete()
|
||||
except:
|
||||
pass
|
||||
diff = datetime.now() - self.nosLast
|
||||
self.nosLast = datetime.now()
|
||||
if diff.days <= 0 and diff.seconds <= 300:
|
||||
await ctx.channel.send(f"Kappen nou {ctx.author.mention}")
|
||||
return
|
||||
opties = [
|
||||
"algemeen",
|
||||
"binnenland",
|
||||
"buitenland",
|
||||
"politiek",
|
||||
"economie",
|
||||
"opmerkelijk",
|
||||
"koningshuis",
|
||||
"cultuurenmedia",
|
||||
"tech"
|
||||
]
|
||||
artikel = None
|
||||
tries = 0
|
||||
while artikel is None:
|
||||
tries += 1
|
||||
if not categorie:
|
||||
categorie = random.choice(opties)
|
||||
categorie = categorie.lower()
|
||||
if categorie in opties:
|
||||
artikelen = feedparser.parse("https://feeds.nos.nl/nosnieuws" + categorie).entries
|
||||
artikel = random.choice(artikelen)
|
||||
#print(json.dumps(artikel, indent=4))
|
||||
nosId = re.findall(r'\d+', artikel.id)[0]
|
||||
if nosId not in self.nosPosts:
|
||||
self.nosPosts.append(nosId)
|
||||
response = await self.getResponseForMessage(artikel.title, gptChance=0.5)
|
||||
elif tries > 100:
|
||||
print("Oneindige loop voorkomen. Damn.")
|
||||
else:
|
||||
artikel = None
|
||||
await ctx.channel.send(response + '\n' + artikel.link)
|
||||
|
||||
+8
-10
@@ -197,8 +197,7 @@ class Cryptocoin(commands.Cog):
|
||||
#user functions below
|
||||
|
||||
@commands.command(pass_context=True)
|
||||
@asyncio.coroutine
|
||||
def coinprice(self, ctx, coinId: str, currencyId: str="USD"):
|
||||
async def coinprice(self, ctx, coinId: str, currencyId: str="USD"):
|
||||
"""Geeft de huidige prijs van de desbetreffende crypto currency
|
||||
Bijv:
|
||||
!coinprice BTC
|
||||
@@ -211,20 +210,19 @@ class Cryptocoin(commands.Cog):
|
||||
currencyId = currencyId.upper()
|
||||
|
||||
if (currencyId not in allowedCurrencies):
|
||||
yield from ctx.channel.send("Valuta " + currencyId + " ken ik niet. :disappointed: ")
|
||||
await ctx.channel.send("Valuta " + currencyId + " ken ik niet. :disappointed: ")
|
||||
return
|
||||
|
||||
price = self.getCoinPrice(coinId, currencyId)
|
||||
|
||||
if (price == -1):
|
||||
yield from ctx.channel.send("Die cryptocoin ken ik niet... :frowning2: ")
|
||||
await ctx.channel.send("Die cryptocoin ken ik niet... :frowning2: ")
|
||||
return
|
||||
|
||||
yield from ctx.channel.send(coinId + " is nu " + str(price) + " " + currencyId + " waard.")
|
||||
await ctx.channel.send(coinId + " is nu " + str(price) + " " + currencyId + " waard.")
|
||||
|
||||
@commands.command(pass_context=True)
|
||||
@asyncio.coroutine
|
||||
def coinadvice(self, ctx, coinId: str=""):
|
||||
async def coinadvice(self, ctx, coinId: str=""):
|
||||
"""Voor al uw adviezen in monopolygeld
|
||||
Vraag Stroop's mening over een specifieke coin:
|
||||
!coinadvice NLG
|
||||
@@ -237,7 +235,7 @@ class Cryptocoin(commands.Cog):
|
||||
|
||||
#Geen specieke coin? Doe random.
|
||||
if(coinId == ""):
|
||||
yield from ctx.channel.send( self.getRandomCoinAdvice() )
|
||||
await ctx.channel.send( self.getRandomCoinAdvice() )
|
||||
return
|
||||
|
||||
coinId = coinId.upper()
|
||||
@@ -245,7 +243,7 @@ class Cryptocoin(commands.Cog):
|
||||
growPercentage, coinStability, dummy = self.analyseCoin(coinId)
|
||||
|
||||
if (growPercentage == 0 and coinStability == 1.0): #aanname. anders moet je weer een extra call doen.
|
||||
yield from ctx.channel.send("Die cryptocoin ken ik niet... :frowning2: ")
|
||||
await ctx.channel.send("Die cryptocoin ken ik niet... :frowning2: ")
|
||||
return
|
||||
|
||||
time.sleep(0.1) #don't overload the API
|
||||
@@ -302,5 +300,5 @@ class Cryptocoin(commands.Cog):
|
||||
if (coinStability < 0.3):
|
||||
message += "Denk ik?"
|
||||
|
||||
yield from ctx.channel.send(message)
|
||||
await ctx.channel.send(message)
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
FROM python:3.11
|
||||
FROM python:3.13
|
||||
|
||||
WORKDIR /opt/stroopwafel
|
||||
|
||||
|
||||
+43
-7
@@ -5,6 +5,7 @@ import random
|
||||
import re
|
||||
import json, requests
|
||||
import warnings
|
||||
from datetime import timedelta, datetime, timezone
|
||||
from discord.ext import commands
|
||||
|
||||
class General(commands.Cog):
|
||||
@@ -12,7 +13,7 @@ class General(commands.Cog):
|
||||
|
||||
def __init__(self, bot):
|
||||
self.bot = bot
|
||||
self.muzak_url = 'https://hdcon-muzak.herokuapp.com'
|
||||
self.muzak_url = 'http://muzak.hoekveen.net:8001'
|
||||
self.r = praw.Reddit(
|
||||
user_agent='StroopwafelBot',
|
||||
client_secret=os.getenv("STROOP_REDDIT_SECRET"),
|
||||
@@ -22,7 +23,7 @@ class General(commands.Cog):
|
||||
warnings.simplefilter("ignore")
|
||||
|
||||
def get_emoji_embed(self, tag: str):
|
||||
emoji = re.search(".*\<\:([A-z]*)\:(\d*)\>.*", tag)
|
||||
emoji = re.search(r'.*\<\:([A-z]*)\:(\d*)\>.*', tag)
|
||||
embed = discord.Embed(title=emoji.group(1), type='photo')
|
||||
hugemoji = 'https://cdn.discordapp.com/emojis/' + emoji.group(2) + '.png'
|
||||
embed.set_image(url=hugemoji)
|
||||
@@ -58,19 +59,25 @@ class General(commands.Cog):
|
||||
|
||||
def get_kopieerpasta(self):
|
||||
rkopieerpasta = self.r.subreddit('kopieerpasta')
|
||||
try:
|
||||
post = rkopieerpasta.random()
|
||||
|
||||
# Subreddits kunnen de random functie uitzetten, dus dit is de fallback:
|
||||
if post == None:
|
||||
listing = list(rkopieerpasta.top('month', limit=250))
|
||||
listing = list(rkopieerpasta.top(time_filter='month', limit=250))
|
||||
post = random.choice(listing)
|
||||
|
||||
return post
|
||||
except:
|
||||
return None
|
||||
|
||||
@commands.command(pass_context=True)
|
||||
async def kopieerpasta(self, ctx):
|
||||
"""Een willekeurige shitpost"""
|
||||
post = self.get_kopieerpasta()
|
||||
if not post:
|
||||
await ctx.channel.send("Geen kopieerpasta voor jou vandaag.")
|
||||
return
|
||||
print(post.url)
|
||||
ATTEMPTS = 10
|
||||
a = 0
|
||||
@@ -92,9 +99,38 @@ class General(commands.Cog):
|
||||
return requests.get(self.muzak_url + '/stroopwafel')
|
||||
|
||||
@commands.command(pass_context=True)
|
||||
async def playlist(self, ctx):
|
||||
"""HDcon2021 playlist"""
|
||||
async def muzak(self, ctx):
|
||||
"""HD muzak playlist"""
|
||||
data = json.loads(self.get_playlist_json().content)
|
||||
msg = 'Stemmen en nomineren kan hier: {}\n'.format(self.muzak_url)
|
||||
msg += '*Er zijn al {} nummers genomineerd*\n'.format(data['stemCount'])
|
||||
msg = ""
|
||||
open = datetime.fromisoformat(data['openDate'])
|
||||
nom = datetime.fromisoformat(data['deadlineNominations'])
|
||||
vote = datetime.fromisoformat(data['deadlineVoting'])
|
||||
today = datetime.now(tz=timezone(timedelta(hours=2)))
|
||||
if open > today:
|
||||
msg = "Muwat?"
|
||||
else:
|
||||
msg += f"Stemmen en nomineren kan hier: https://muzak.hoekveen.net/ \n"
|
||||
msg += f"*Er zijn al {data['stemCount']} nummers genomineerd!*\n"
|
||||
await ctx.channel.send(msg)
|
||||
|
||||
@commands.command(pass_context=True)
|
||||
async def pollen(self, ctx):
|
||||
"Hoe veel last van pollen kun je verwachten?"
|
||||
poll = 'https://app.everviz.com/embed/apyvera/' # Thanks hooikoortsradar
|
||||
response = requests.get(poll)
|
||||
if response:
|
||||
# one-liner want eet stront
|
||||
cijfer = float(re.findall(r";\d\.?\d?\n", json.loads([x for x in response.text.splitlines() if "var options =" in x][0].partition("=")[2].strip(";, "))["data"]["csv"])[-1].strip(";\n"))
|
||||
msg = ""
|
||||
if cijfer < 3:
|
||||
msg = f"Nou, het lijkt goed te gaan. Recentelijk gaven mensen hun klachten maar een {cijfer}. Lekker!"
|
||||
elif cijfer < 6:
|
||||
msg = f"Het lijkt allemaal mee te vallen. Men gaf hun klachten een {cijfer} deze week. Moet te doen zijn."
|
||||
elif cijfer < 7.5:
|
||||
msg = f"Ai. Het gaat lekker met de pollen, maar het ergste moet nog komen of is al geweest. Klachtencijfer van {cijfer}; Sterkte alvast."
|
||||
else:
|
||||
msg = f"Balen dit. Klachtencijfer van {cijfer}, dus bekijk het maar. Joe."
|
||||
await ctx.channel.send(ctx.author.mention + ' ' + msg)
|
||||
else:
|
||||
await ctx.channel.send(ctx.author.mention + ' Er lijkt even geen klachtencijfer beschikbaar te zijn. Probeer het later nog eens')
|
||||
|
||||
+22
-15
@@ -16,6 +16,7 @@ class Shitpost(commands.Cog):
|
||||
def __init__(self, bot):
|
||||
self.bot = bot
|
||||
self.hdConImpatientEvents = []
|
||||
self.userAgent = 'Mozilla/5.0 (X11; Linux x86_64; rv:136.0) Gecko/20100101 Firefox/136.0'
|
||||
try:
|
||||
with open('black.txt') as zwart:
|
||||
self.zwarte_lijst = [line.rstrip('\n') for line in zwart]
|
||||
@@ -40,33 +41,36 @@ class Shitpost(commands.Cog):
|
||||
'zout': '116231806'
|
||||
}
|
||||
warnings.simplefilter("ignore")
|
||||
datestring = os.getenv('STROOP_HDCON_DATE') or None
|
||||
self.HdConDate = None
|
||||
if datestring:
|
||||
self.HdConDate = datetime.fromisoformat(datestring)
|
||||
|
||||
@commands.command(pass_context=True, hidden=False)
|
||||
async def ishetalhdcon(self, ctx):
|
||||
"""Hoe lang nog tot Hoestende Draken Con 2022?
|
||||
"""Hoe lang nog tot Hoestende Draken Con dit jaar? Of is het pas volgend jaar?
|
||||
Gebruik: !ishetalhdcon
|
||||
"""
|
||||
|
||||
Now = datetime.now()
|
||||
HdConDate = datetime(2022, 10, 14, 4, 0, 1) #om 4 uur lig je toch wel al op bed?
|
||||
Distance = HdConDate - Now
|
||||
Message = Message = "HD Con 2022 is al voorbij. HD Con 2023 zal in 2023 plaatsvinden."
|
||||
Message = f"Geen HD Con! >:|"
|
||||
if self.HdConDate:
|
||||
Message = f"HD Con {self.HdConDate.year} "
|
||||
Distance = self.HdConDate - Now
|
||||
if Distance.days == -1:
|
||||
Message = "HD Con 2022 begint vandaag! HYPE!"
|
||||
Message += "begint vandaag! HYPE!"
|
||||
elif Distance.days < 0 and Distance.days > -4:
|
||||
Message = "HD Con 2022 is nu bezig!!"
|
||||
Message += "is nu bezig!!"
|
||||
elif Distance.days == -4:
|
||||
Message = "HD Con 2022 is vandaag alweer afgelopen... F"
|
||||
Message += "is vandaag afgelopen :(\nWe hebben gelachen, we hebben gehuild. Het was gezellig. Volgend jaar bij mij."
|
||||
else: # distance < -4
|
||||
Message += f"is geweest. HD Con {self.HdConDate.year+1} zal komen."
|
||||
|
||||
if Distance.days < 0:
|
||||
await ctx.channel.send(ctx.author.mention + ' ' + str(Message))
|
||||
return
|
||||
|
||||
NachtjesSlapen = Distance.days + 1
|
||||
if NachtjesSlapen == 1:
|
||||
Message = "Nog " + str(NachtjesSlapen) + " nachtje slapen..."
|
||||
else:
|
||||
Message = "Nog " + str(NachtjesSlapen) + " nachtjes slapen..."
|
||||
Message = f"Nog {NachtjesSlapen} nachtje{'s' if NachtjesSlapen > 1 else ''} slapen..."
|
||||
|
||||
#Hou bij hoe vaak dit wordt gevraagd:
|
||||
eventsMinutesAgo = 0;
|
||||
@@ -94,14 +98,14 @@ class Shitpost(commands.Cog):
|
||||
return
|
||||
#Hoe vaker er wordt gevraagd, hoe ongeduldiger de antwoorden:
|
||||
if not "DMChannel" in type(ctx.channel).__name__: #ignore personal chats
|
||||
impatientFactor = 10 + eventsMinutesAgo*25 + eventsLastDays*10;
|
||||
impatientFactor = 10 + eventsMinutesAgo*25 + min(10, eventsLastDays)*2;
|
||||
impatientFactor *= random.random()
|
||||
if impatientFactor > 100:
|
||||
await ctx.channel.send("Nee!")
|
||||
return
|
||||
elif impatientFactor > 15 and eventsMinutesAgo > 0:
|
||||
Message = "Dat hebben jullie net gevraagd."
|
||||
elif impatientFactor > 9:
|
||||
elif impatientFactor > 12:
|
||||
Message = "Nee."
|
||||
|
||||
await ctx.channel.send(ctx.author.mention + ' ' + str(Message))
|
||||
@@ -808,7 +812,10 @@ class Shitpost(commands.Cog):
|
||||
|
||||
def get_zaagmans(self):
|
||||
zaagman_url = "http://iszaagmansallangsgeweest.nl/"
|
||||
zreq = requests.get(zaagman_url)
|
||||
headers = {
|
||||
'User-Agent': self.userAgent,
|
||||
}
|
||||
zreq = requests.get(zaagman_url, headers=headers)
|
||||
if zreq:
|
||||
return zreq.text.partition("<h1>")[2].partition("</h1>")[0]
|
||||
else:
|
||||
|
||||
@@ -14,3 +14,4 @@ STROOP_IMGFLIP_PASSWORD=
|
||||
STROOP_RESET_PASSWORD=
|
||||
STROOP_CHANNEL_SHITPOST=
|
||||
STROOP_CHANNEL_BELANGRIJK=
|
||||
STROOP_HDCON_DATE=2025-12-01
|
||||
@@ -3,3 +3,6 @@ discord.py
|
||||
praw
|
||||
numpy
|
||||
python-dotenv
|
||||
feedparser
|
||||
audioop-lts
|
||||
vobject
|
||||
|
||||
+1
-1
@@ -41,9 +41,9 @@ class TestGeneral(unittest.TestCase):
|
||||
if not isinstance(self.cog.r, praw.Reddit):
|
||||
self.skipTest("PRAW Reddit instance failed to create")
|
||||
post = self.cog.get_kopieerpasta()
|
||||
if post:
|
||||
self.assertIsInstance(post.url, str)
|
||||
|
||||
def test_huge(self):
|
||||
embed = self.cog.get_emoji_embed("<:test:123456789>")
|
||||
self.assertIsInstance(embed, discord.Embed)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user