Replaces asyncio coroutines with native async

Replaces @asyncio.coroutine decorator with async
Replaces yield from with await
This commit is contained in:
2022-12-18 02:03:46 +01:00
parent ad2324d53c
commit f8db215b31
4 changed files with 124 additions and 163 deletions
+60 -81
View File
@@ -1,4 +1,3 @@
import asyncio
import discord
from discord.ext import commands
from urllib import request
@@ -43,8 +42,7 @@ class Shitpost(commands.Cog):
warnings.simplefilter("ignore")
@commands.command(pass_context=True, hidden=False)
@asyncio.coroutine
def ishetalhdcon(self, ctx):
async def ishetalhdcon(self, ctx):
"""Hoe lang nog tot Hoestende Draken Con 2022?
Gebruik: !ishetalhdcon
"""
@@ -61,7 +59,7 @@ class Shitpost(commands.Cog):
Message = "HD Con 2022 is vandaag alweer afgelopen... F"
if Distance.days < 0:
yield from ctx.channel.send(ctx.author.mention + ' ' + str(Message))
await ctx.channel.send(ctx.author.mention + ' ' + str(Message))
return
NachtjesSlapen = Distance.days + 1
@@ -90,23 +88,23 @@ class Shitpost(commands.Cog):
return #fuck it.
if eventsMinutesAgoSameAuthor > 0:
if eventsMinutesAgoSameAuthor > 2:
yield from ctx.channel.send("...")
await ctx.channel.send("...")
return
yield from ctx.channel.send("Dat vroeg je net ook al, " + ctx.author.mention + "!")
await ctx.channel.send("Dat vroeg je net ook al, " + ctx.author.mention + "!")
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 *= random.random()
if impatientFactor > 100:
yield from ctx.channel.send("Nee!")
await ctx.channel.send("Nee!")
return
elif impatientFactor > 15 and eventsMinutesAgo > 0:
Message = "Dat hebben jullie net gevraagd."
elif impatientFactor > 9:
Message = "Nee."
yield from ctx.channel.send(ctx.author.mention + ' ' + str(Message))
await ctx.channel.send(ctx.author.mention + ' ' + str(Message))
def zalgofy(self, sentence, factor = 4):
random.seed(datetime.now().timestamp())
@@ -119,8 +117,7 @@ class Shitpost(commands.Cog):
return message
@commands.command(pass_context=True, hidden=False)
@asyncio.coroutine
def zalgo(self, ctx, *, arg):
async def zalgo(self, ctx, *, arg):
"""z̴̬̘͇̗͇̦̤̩̜͜ą̷̟̯̪̩̣̭̭͇̹l̴̗͓̟̠̤̳̗͉̠ͅg̵̜͎̪̞̫͎͈͉͉͍o̵̧̧͇̱̱̜̮͉͉̳ ̴̨̡͖̘̪̭̖͖̘̝h̸̭̰̫̲̺̹̻̜͕ͅe̴̢̘̪̱̱̩̠̣̘̱ ̴̡̢̲̞̙̝̮̻̻͇c̶̡̢̺͙̮̗̲̹̱̱o̷̢̡̺̘͈͎̫̬͔̤m̷͕͍͍̥͖̻̲̞̝ͅe̷̱̟͕̥͕̞̜̫̳̙s̷̨͍̼̝̙̩̥̰̠ͅ
h̷̦̰̣̗̭͕̩͓͈̠i̶̗̰̹̤̖͙̰̹͙̹j̸̧̜̬̬̜̹͔̰̫͜ ̶̧͉͔̠̻͈̜̳̥̭k̸̯̳̠̼̙̗̘̳͜ͅǫ̵̝̱̩͎̫͈̣̪̦m̶̺̙̟̫͔͈̭̖̱ͅt̶̜̠̟͙̞̠̗̗̥ͅ ̸̢̹̜͉͙̩̬̖ͅͅh̷̯̮̘̭͈̜̺͎̳̯i̴̩̯̼̱͇̟̫̻̘̖j̵̪̤̦͖̮̜̦̼̺̮ ̶̧͇̭̞̮̩̼͚̮ͅḵ̴̢̨̢͉͉͖̹̬̺o̵̢̪̥̻͙͕̫̥̗͜m̶̧̡͔̠̺͖̝̳̪ͅt̷̢̮̭̜̥̠̼̫͍̯
d̷̢̪͍͓̭̣̼̠͎̠e̴̡̢̩̱͙̻̥̯͎͜ ̵̲̪͖̖͖͍͈͎̮̼ļ̴̯̗̝̦͍͍͖̰͜i̶̡̘̟̳̖͙͕͔̺͜ȩ̸̤͎̣͖͔̭͔̫̯v̷͔̺͖̖̞̙̘̖̠͓e̶̲͍̮̳͎̗̳̞̹͔ ̸̡̬̫͎͎̝͍̤̯ͅg̴̨̞̻͙̠̰͖͖̝ͅǫ̴̘̥͇̙̖͈͍̹̥e̵̥͇̫̱̬̝̥̲̞̜d̷͈͙̝͍͔̘͕̼̜̦e̴̡̯̦͉͙̪̭͕̻̝
@@ -130,10 +127,10 @@ class Shitpost(commands.Cog):
"""
message = self.zalgofy(arg)
try:
yield from ctx.message.delete()
await ctx.message.delete()
except:
print("No permission to delete message")
yield from ctx.channel.send(str(message))
await ctx.channel.send(str(message))
def get_corona_message(self):
response = requests.get('https://covid.ourworldindata.org/data/latest/owid-covid-latest.json')
@@ -151,18 +148,16 @@ class Shitpost(commands.Cog):
return None
@commands.command(pass_context=True, hidden=False)
@asyncio.coroutine
def corona(self, ctx):
async def corona(self, ctx):
try:
yield from ctx.message.delete()
await ctx.message.delete()
except:
print("No permission to delete message")
message = self.get_corona_message()
yield from ctx.channel.send(ctx.author.mention + ' ' + str(message))
await ctx.channel.send(ctx.author.mention + ' ' + str(message))
@commands.command(pass_context=True, hidden=False)
@asyncio.coroutine
def viertwintig(self, ctx):
async def viertwintig(self, ctx):
"""Hoe lang nog tot 420?
Gebruik: !viertwintig
"""
@@ -188,11 +183,10 @@ class Shitpost(commands.Cog):
seconds = secondsLeft - minutes * 60
Message += "Nog " + str(days) + " dagen, " + str(hours) + " uur, " + str(minutes) + " minuten en " + str(seconds) + " seconden tot 420!!"
yield from ctx.channel.send(ctx.author.mention + ' ' + str(Message))
await ctx.channel.send(ctx.author.mention + ' ' + str(Message))
@commands.command(pass_context=True, hidden=False)
@asyncio.coroutine
def iselderscrolls6aluit(self, ctx):
async def iselderscrolls6aluit(self, ctx):
"""Hoe lang nog tot Elder Scrolls 6? 11-11-11? 20-20-20?
Gebruik: !iselderscrolls6aluit
"""
@@ -203,15 +197,14 @@ class Shitpost(commands.Cog):
else:
Message = "Nee. :frowning2: Nog even geduld..."
yield from ctx.channel.send(ctx.author.mention + ' ' + str(Message))
await ctx.channel.send(ctx.author.mention + ' ' + str(Message))
def get_giet_het_oan(self):
# Alsof we ooit nog een elfstedentocht gaan krijgen.
return "nee"
@commands.command(pass_context=True, hidden=False)
@asyncio.coroutine
def giethetaloan(self, ctx):
async def giethetaloan(self, ctx):
"""Giet het al oan?
Ja of Nee.. kom op nou.
"""
@@ -225,7 +218,7 @@ class Shitpost(commands.Cog):
else:
if 'nee' in answer:
reactie += 'Nee helaas..'
yield from ctx.channel.send(ctx.author.mention + ' ' + reactie)
await ctx.channel.send(ctx.author.mention + ' ' + reactie)
def get_inspiration(self):
inspiration = requests.get(url='http://inspirobot.me/api?generate=true')
@@ -235,8 +228,7 @@ class Shitpost(commands.Cog):
@commands.command(pass_context=True, hidden=False)
@asyncio.coroutine
def inspire(self, ctx):
async def inspire(self, ctx):
"""Laat je inspireren
Bijvoorbeeld:
!inspire
@@ -246,12 +238,12 @@ class Shitpost(commands.Cog):
em = discord.Embed(title='Uw wijze woorden:', type='photo')
em.set_image(url=inspo)
try:
yield from ctx.message.delete()
await ctx.message.delete()
except:
print("No permission to delete message")
yield from ctx.channel.send(ctx.author.mention, embed=em)
await ctx.channel.send(ctx.author.mention, embed=em)
else:
yield from ctx.channel.send(ctx.author.mention + ' helaas, geen quote gevonden.')
await ctx.channel.send(ctx.author.mention + ' helaas, geen quote gevonden.')
def get_imgflip_embed(self, template: str, boven: str, onder: str, extra_options: dict = None):
params = dict(
@@ -273,49 +265,46 @@ class Shitpost(commands.Cog):
@commands.command(pass_context=True, hidden=True)
@asyncio.coroutine
def tering(self, ctx, boven: str, onder: str):
async def tering(self, ctx, boven: str, onder: str):
"""Vanavond gaan we helemaal naar de tering
Bijvoorbeeld:
!tering \"Vanavond\" \"gaan we helemaal naar de tering\"
"""
em = self.get_imgflip_embed(self.imgflips['tering'], boven, onder)
try:
yield from ctx.message.delete()
await ctx.message.delete()
except:
print("No permission to delete message")
if em:
yield from ctx.channel.send(ctx.author.mention, embed=em)
await ctx.channel.send(ctx.author.mention, embed=em)
@commands.command(pass_context=True, hidden=True)
@asyncio.coroutine
def mark(self, ctx, boven: str, onder: str):
async def mark(self, ctx, boven: str, onder: str):
"""Maakt een mark meem.
Bijvoorbeeld:
!mark \"je moeder\" \"is een hoer\"
"""
em = self.get_imgflip_embed(self.imgflips['mark'], boven, onder)
try:
yield from ctx.message.delete()
await ctx.message.delete()
except:
print("No permission to delete message")
if em:
yield from ctx.channel.send(ctx.author.mention, embed=em)
await ctx.channel.send(ctx.author.mention, embed=em)
@commands.command(pass_context=True, hidden=True)
@asyncio.coroutine
def eriku(self, ctx, boven: str, onder: str):
async def eriku(self, ctx, boven: str, onder: str):
"""Maakt een erik meem.
Bijvoorbeeld:
!eriku \"je moeder\" \"is een hoer\"
"""
em = self.get_imgflip_embed(self.imgflips['eriku'], boven, onder)
try:
yield from ctx.message.delete()
await ctx.message.delete()
except:
print("No permission to delete message")
if em:
yield from ctx.channel.send(ctx.author.mention, embed=em)
await ctx.channel.send(ctx.author.mention, embed=em)
def get_tegeltje(self, tekst, auteur):
params = {
@@ -341,43 +330,39 @@ class Shitpost(commands.Cog):
return self.get_imgflip_embed(self.imgflips['tegeltje'], "", "", params)
@commands.command(pass_context=True, hidden=True)
@asyncio.coroutine
def tegeltje(self, ctx, tekst: str, auteur: str=" "):
async def tegeltje(self, ctx, tekst: str, auteur: str=" "):
"""Maak een mooi tegeltje met volkswijsheid
Bijvoorbeeld:
!tegeltje \"Oost west, 420 best\" \"Lourens\"
"""
em = get_tegeltje(tekst, auteur)
try:
yield from ctx.message.delete()
await ctx.message.delete()
except:
print("No permission to delete message")
if em:
yield from ctx.channel.send(ctx.author.mention, embed=em)
await ctx.channel.send(ctx.author.mention, embed=em)
@commands.command(pass_context=True, hidden=True)
@asyncio.coroutine
def zout(self, ctx, boven: str, onder: str):
async def zout(self, ctx, boven: str, onder: str):
"""Maakt een martijn-zout meem.
Bijvoorbeeld:
!zout \"je moeder\" \"is een hoer\"
"""
em = self.get_imgflip_embed(self.imgflips['zout'], boven, onder)
try:
yield from ctx.message.delete()
await ctx.message.delete()
except:
print("No permission to delete message")
if em:
yield from ctx.channel.send(ctx.author.mention, embed=em)
await ctx.channel.send(ctx.author.mention, embed=em)
@commands.command(pass_context=True, hidden=True)
@asyncio.coroutine
def nihao(self,ctx):
yield from ctx.channel.send("kankerlauw")
async def nihao(self,ctx):
await ctx.channel.send("kankerlauw")
@commands.command(pass_context=True)
@asyncio.coroutine
def tijd(self, ctx, *args):
async def tijd(self, ctx, *args):
"""Vertelt je hoe laat het is..
Misschien geeft het ook wel een leuke meem terug.
Wie weet.
@@ -398,13 +383,13 @@ class Shitpost(commands.Cog):
elif os.path.isfile(filepng):
filepath = filepng
try:
yield from ctx.message.delete()
await ctx.message.delete()
except:
print("No permission to delete message")
if filepath != '':
yield from ctx.channel.send(ctx.author.mention + ' Het is nu ' + datetime.now().strftime('%H:%M'), file=discord.File(filepath, 'tijd.png'))
await ctx.channel.send(ctx.author.mention + ' Het is nu ' + datetime.now().strftime('%H:%M'), file=discord.File(filepath, 'tijd.png'))
else:
yield from ctx.channel.send(ctx.author.mention + ' Het is nu ' + datetime.now().strftime('%H:%M'))
await ctx.channel.send(ctx.author.mention + ' Het is nu ' + datetime.now().strftime('%H:%M'))
def get_dice_roll(self, nrOfDice, dieType, modifier=None):
if nrOfDice > 99 or dieType > 9999 or dieType < 2 or (modifier and abs(modifier) > 9999):
@@ -447,8 +432,7 @@ class Shitpost(commands.Cog):
return (numDice, die, modifier)
@commands.command(pass_context=True)
@asyncio.coroutine
def roll(self, ctx, *, dice):
async def roll(self, ctx, *, dice):
"""Roll een dobbelsteen. Of een paar. Bijvoorbeeld:
!roll 4d20
!roll 1d6 + 5
@@ -456,9 +440,9 @@ class Shitpost(commands.Cog):
(nrOfDice, dieType, modifier) = self.get_dice_parameters(dice)
message = self.get_dice_roll(nrOfDice, dieType, modifier)
if message:
yield from ctx.channel.send(message)
await ctx.channel.send(message)
else:
yield from ctx.channel.send("Die roll vind ik echt een beetje te mal..")
await ctx.channel.send("Die roll vind ik echt een beetje te mal..")
def get_weerbericht(self, wData, verbose=None):
if not wData:
@@ -519,8 +503,7 @@ class Shitpost(commands.Cog):
return None
@commands.command(pass_context=True)
@asyncio.coroutine
def weer(self, ctx, location="Leiden", verbose=None):
async def weer(self, ctx, location="Leiden", verbose=None):
"""Vertelt je het weer.
Omdat je te lui bent om naar buiten te kijken.
Oant Moarn!
@@ -530,7 +513,7 @@ class Shitpost(commands.Cog):
message = self.get_weerbericht(wData, verbose)
if not wData or not message:
message = "Weer ophalen niet gelukt. Probeer het later nogmaals.."
yield from ctx.channel.send(message)
await ctx.channel.send(message)
#returns a nice weather icon. Sometimes the API uses non-documented icons, so we return something else
def getWeatherIconTranslation(self, iconKey):
@@ -610,27 +593,25 @@ class Shitpost(commands.Cog):
return zwarte_kaart.replace("___", "**{}**").format(*wit)
@commands.command(pass_context=True)
@asyncio.coroutine
def ktdm(self, ctx, *args):
async def ktdm(self, ctx, *args):
'''Speel Kaarten Tegen De Mensheid! Genereer een kaart of geef zelf opties.
Bijvoorbeeld: !ktdm <"1"><"2"><"3"> (aanbevolen 1 of 2, max 3)'''
try:
yield from ctx.message.delete()
await ctx.message.delete()
except:
print("No permission to delete message")
resultaat = self.get_ktdm(args)
if resultaat:
yield from ctx.channel.send(f"{ctx.author.mention}\n{resultaat}")
await ctx.channel.send(f"{ctx.author.mention}\n{resultaat}")
else:
yield from ctx.channel.send(f"{ctx.author.mention}\nIets ging niet helemaal lekker")
await ctx.channel.send(f"{ctx.author.mention}\nIets ging niet helemaal lekker")
@commands.command(pass_context=True)
@asyncio.coroutine
def beledig(self, ctx, member:discord.User):
async def beledig(self, ctx, member:discord.User):
'''Je vindt iemand stom maar je hebt geen inspiratie? Beledig al je vriendjes met deze handige beledig-i-fier!
Bijvoorbeeld: !beledig @jemoeder'''
yield from ctx.channel.send(member.mention+ ", " + ctx.author.mention + " vindt jou een " + random.choice(self.insult) + "! :angry:")
yield from ctx.message.delete()
await ctx.channel.send(member.mention+ ", " + ctx.author.mention + " vindt jou een " + random.choice(self.insult) + "! :angry:")
await ctx.message.delete()
def get_watspelenwe_cal(self):
"""Geeft een paar terug, met de titel en omschrijving van het eerstvolgende event uit de kalender"""
@@ -749,8 +730,7 @@ class Shitpost(commands.Cog):
return message
@commands.command(pass_context=True)
@asyncio.coroutine
def watspelenwe(self, ctx):
async def watspelenwe(self, ctx):
"""Stroop weet wat we spelen op vrijdag.
Geeft elke week een pseudo-random antwoord.
Geseed op weeknummer + jaar.
@@ -764,10 +744,10 @@ class Shitpost(commands.Cog):
message += ". En wilt iemand even aan Mark vragen of hij de kalender bijhoudt?"
try:
yield from ctx.message.delete()
await ctx.message.delete()
except:
print("No permission to delete message")
yield from ctx.channel.send(message)
await ctx.channel.send(message)
def get_review_string(self, topic = ""):
if topic == "":
@@ -819,10 +799,9 @@ class Shitpost(commands.Cog):
return message
@commands.command(pass_context=True)
@asyncio.coroutine
def review(self, ctx, *args):
async def review(self, ctx, *args):
"""Stroop heeft (bijna) overal een mening over. Vraag het hem!
"""
topic = " ".join(args)
message = self.get_review_string(topic)
yield from ctx.channel.send(message)
await ctx.channel.send(message)