En refactor, want hoe het stond was niet heel testbaar
This commit is contained in:
+30
-36
@@ -648,49 +648,43 @@ class Shitpost(commands.Cog):
|
||||
return -1.0
|
||||
|
||||
return max(1.0, min(10.0, grade))
|
||||
|
||||
def get_ktdm(self, wit = []):
|
||||
if not wit:
|
||||
zwarte_kaart = random.choice(self.zwarte_lijst)
|
||||
aantal_wit = zwarte_kaart.count("___")
|
||||
if aantal_wit == 0: # Soms staat er geen ___ in de kaart
|
||||
zwarte_kaart = zwarte_kaart + " ___"
|
||||
aantal_wit = 1
|
||||
wit = random.sample(self.witte_lijst, k=aantal_wit)
|
||||
else:
|
||||
if len(wit) > 3:
|
||||
return None
|
||||
zwarte_kaart = None
|
||||
random.shuffle(self.zwarte_lijst)
|
||||
for zwart in self.zwarte_lijst:
|
||||
if zwart.count("___") == len(wit):
|
||||
zwarte_kaart = zwart
|
||||
break
|
||||
if not zwarte_kaart:
|
||||
return None
|
||||
|
||||
return zwarte_kaart.replace("___", "**{}**").format(*wit)
|
||||
|
||||
@commands.command(pass_context=True)
|
||||
@asyncio.coroutine
|
||||
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)'''
|
||||
random.shuffle(self.witte_lijst) # schudden voor gebruik
|
||||
zwarte_kaart = random.choice(self.zwarte_lijst).replace("___", "**{}**") # kies en maak het juiste format
|
||||
aantal_wit = zwarte_kaart.count("{}") # tel hoeveel witte kaarten er nodig zijn
|
||||
if aantal_wit == 0: # Soms staat er geen ___ in de kaart
|
||||
zwarte_kaart = zwarte_kaart + " **{}**"
|
||||
aantal_wit = 1
|
||||
arg_count = len(args)
|
||||
if arg_count > 3:
|
||||
yield from ctx.channel.send(ctx.author.mention + ", " + random.choice(insult) + ", 3 is het maximum.")
|
||||
elif arg_count > 0:
|
||||
for elem in args:
|
||||
self.witte_lijst.append(elem)
|
||||
|
||||
if arg_count != 0: # Indien extra args gegeven
|
||||
while arg_count != aantal_wit: # Match het aantal args aan het aantal dat nodig is
|
||||
zwarte_kaart = random.choice(self.zwarte_lijst).replace("___", "**{}**")
|
||||
aantal_wit = zwarte_kaart.count("{}")
|
||||
|
||||
wit={} # maak dynamisch dict aan met de witte kaarten die ingevuld worden
|
||||
for x in range(aantal_wit, 0, -1):
|
||||
key = "wit" + str(x)
|
||||
wit[key] = self.witte_lijst.pop()
|
||||
|
||||
# Dit gedeelte print de zwarte kaart mooi af
|
||||
if aantal_wit == 1:
|
||||
print(zwarte_kaart.format(wit['wit1']))
|
||||
yield from ctx.channel.send(ctx.author.mention + "\n" + zwarte_kaart.format(wit['wit1']))
|
||||
elif aantal_wit == 2:
|
||||
print(zwarte_kaart.format(wit['wit1'],wit['wit2']))
|
||||
yield from ctx.channel.send(ctx.author.mention + "\n" + zwarte_kaart.format(wit['wit1'],wit['wit2']))
|
||||
elif aantal_wit == 3:
|
||||
print(zwarte_kaart.format(wit['wit1'],wit['wit2'],wit['wit3']))
|
||||
yield from ctx.channel.send(ctx.author.mention + "\n" + zwarte_kaart.format(wit['wit1'],wit['wit2'],wit['wit3']))
|
||||
try:
|
||||
yield from 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}")
|
||||
else:
|
||||
print("Dit is een vreemd aantal witte kaarten: " + str(aantal_wit) + "\nDe boosdoener: " + zwarte_kaart)
|
||||
yield from ctx.channel.send("Arme " + random.choice(insult) + ", er is iets foutgegaan!")
|
||||
yield from ctx.message.delete()
|
||||
yield from ctx.channel.send(f"{ctx.author.mention}\nIets ging niet helemaal lekker")
|
||||
|
||||
@commands.command(pass_context=True)
|
||||
@asyncio.coroutine
|
||||
|
||||
Reference in New Issue
Block a user