4 Commits

Author SHA1 Message Date
mark e904451037 updates crypto module with newer async code
continuous-integration/drone/push Build is passing
2023-06-23 21:56:52 +02:00
mark cde205aad7 pollen klachtencijfer
continuous-integration/drone Build is passing
continuous-integration/drone/push Build is passing
2023-06-13 21:05:22 +02:00
mark 2e91781fad robustness of gpt calls
continuous-integration/drone/push Build is passing
2023-03-19 13:57:51 +01:00
jp 58ce3a8565 Merge pull request '10% kans op nieuwe GPT' (#24) from gpt into master
continuous-integration/drone/push Build is passing
Reviewed-on: #24
2023-03-18 23:42:06 +01:00
3 changed files with 38 additions and 13 deletions
+8 -3
View File
@@ -292,7 +292,9 @@ class Chatbot(commands.Cog):
if random.random() > 0.9: if random.random() > 0.9:
try: try:
# GPT request moet echt even in een non-blocking executortje, anders loopt de hele boel vast # 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: except:
pass # Door naar local call pass # Door naar local call
return self.getResponseForMessageLocal(wordsToRespondTo) return self.getResponseForMessageLocal(wordsToRespondTo)
@@ -303,8 +305,11 @@ class Chatbot(commands.Cog):
return req.json()["translations"][0]["text"] return req.json()["translations"][0]["text"]
def getResponseForMessageOnline(self, wordsToRespondTo): def getResponseForMessageOnline(self, wordsToRespondTo):
text = self.translateTo("en", " ".join(wordsToRespondTo)) prompt = " ".join(wordsToRespondTo)
req = requests.post('http://gpt.hoekveen.net/complete', json={"prompt": text, "max_tokens": 60}) 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()) print(req.json())
respons = req.json()["text"] respons = req.json()["text"]
respons = respons[0:respons.rfind(".")+1] # Alles weg na de laatste punt respons = respons[0:respons.rfind(".")+1] # Alles weg na de laatste punt
+8 -10
View File
@@ -197,8 +197,7 @@ class Cryptocoin(commands.Cog):
#user functions below #user functions below
@commands.command(pass_context=True) @commands.command(pass_context=True)
@asyncio.coroutine async def coinprice(self, ctx, coinId: str, currencyId: str="USD"):
def coinprice(self, ctx, coinId: str, currencyId: str="USD"):
"""Geeft de huidige prijs van de desbetreffende crypto currency """Geeft de huidige prijs van de desbetreffende crypto currency
Bijv: Bijv:
!coinprice BTC !coinprice BTC
@@ -211,20 +210,19 @@ class Cryptocoin(commands.Cog):
currencyId = currencyId.upper() currencyId = currencyId.upper()
if (currencyId not in allowedCurrencies): 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 return
price = self.getCoinPrice(coinId, currencyId) price = self.getCoinPrice(coinId, currencyId)
if (price == -1): 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 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) @commands.command(pass_context=True)
@asyncio.coroutine async def coinadvice(self, ctx, coinId: str=""):
def coinadvice(self, ctx, coinId: str=""):
"""Voor al uw adviezen in monopolygeld """Voor al uw adviezen in monopolygeld
Vraag Stroop's mening over een specifieke coin: Vraag Stroop's mening over een specifieke coin:
!coinadvice NLG !coinadvice NLG
@@ -237,7 +235,7 @@ class Cryptocoin(commands.Cog):
#Geen specieke coin? Doe random. #Geen specieke coin? Doe random.
if(coinId == ""): if(coinId == ""):
yield from ctx.channel.send( self.getRandomCoinAdvice() ) await ctx.channel.send( self.getRandomCoinAdvice() )
return return
coinId = coinId.upper() coinId = coinId.upper()
@@ -245,7 +243,7 @@ class Cryptocoin(commands.Cog):
growPercentage, coinStability, dummy = self.analyseCoin(coinId) growPercentage, coinStability, dummy = self.analyseCoin(coinId)
if (growPercentage == 0 and coinStability == 1.0): #aanname. anders moet je weer een extra call doen. 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 return
time.sleep(0.1) #don't overload the API time.sleep(0.1) #don't overload the API
@@ -302,5 +300,5 @@ class Cryptocoin(commands.Cog):
if (coinStability < 0.3): if (coinStability < 0.3):
message += "Denk ik?" message += "Denk ik?"
yield from ctx.channel.send(message) await ctx.channel.send(message)
+22
View File
@@ -98,3 +98,25 @@ class General(commands.Cog):
msg = 'Stemmen en nomineren kan hier: {}\n'.format(self.muzak_url) msg = 'Stemmen en nomineren kan hier: {}\n'.format(self.muzak_url)
msg += '*Er zijn al {} nummers genomineerd*\n'.format(data['stemCount']) msg += '*Er zijn al {} nummers genomineerd*\n'.format(data['stemCount'])
await ctx.channel.send(msg) 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?;", json.loads([x for x in response.text.splitlines() if "var options =" in x][0].partition("=")[2].strip(";, "))["data"]["csv"])[-1].strip(";"))
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')