Testing/CI #21
+30
-36
@@ -648,49 +648,43 @@ class Shitpost(commands.Cog):
|
|||||||
return -1.0
|
return -1.0
|
||||||
|
|
||||||
return max(1.0, min(10.0, grade))
|
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)
|
@commands.command(pass_context=True)
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
def ktdm(self, ctx, *args):
|
def ktdm(self, ctx, *args):
|
||||||
'''Speel Kaarten Tegen De Mensheid! Genereer een kaart of geef zelf opties.
|
'''Speel Kaarten Tegen De Mensheid! Genereer een kaart of geef zelf opties.
|
||||||
Bijvoorbeeld: !ktdm <"1"><"2"><"3"> (aanbevolen 1 of 2, max 3)'''
|
Bijvoorbeeld: !ktdm <"1"><"2"><"3"> (aanbevolen 1 of 2, max 3)'''
|
||||||
random.shuffle(self.witte_lijst) # schudden voor gebruik
|
try:
|
||||||
zwarte_kaart = random.choice(self.zwarte_lijst).replace("___", "**{}**") # kies en maak het juiste format
|
yield from ctx.message.delete()
|
||||||
aantal_wit = zwarte_kaart.count("{}") # tel hoeveel witte kaarten er nodig zijn
|
except:
|
||||||
if aantal_wit == 0: # Soms staat er geen ___ in de kaart
|
print("No permission to delete message")
|
||||||
zwarte_kaart = zwarte_kaart + " **{}**"
|
resultaat = self.get_ktdm(args)
|
||||||
aantal_wit = 1
|
if resultaat:
|
||||||
arg_count = len(args)
|
yield from ctx.channel.send(f"{ctx.author.mention}\n{resultaat}")
|
||||||
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']))
|
|
||||||
else:
|
else:
|
||||||
print("Dit is een vreemd aantal witte kaarten: " + str(aantal_wit) + "\nDe boosdoener: " + zwarte_kaart)
|
yield from ctx.channel.send(f"{ctx.author.mention}\nIets ging niet helemaal lekker")
|
||||||
yield from ctx.channel.send("Arme " + random.choice(insult) + ", er is iets foutgegaan!")
|
|
||||||
yield from ctx.message.delete()
|
|
||||||
|
|
||||||
@commands.command(pass_context=True)
|
@commands.command(pass_context=True)
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
|
|||||||
+17
-1
@@ -45,4 +45,20 @@ class TestShitpost(unittest.TestCase):
|
|||||||
with self.subTest(msg="Watspelenwe activiteit does not return a string"):
|
with self.subTest(msg="Watspelenwe activiteit does not return a string"):
|
||||||
self.assertIsInstance(activiteit, str)
|
self.assertIsInstance(activiteit, str)
|
||||||
with self.subTest(msg="Watspelenwe reden does not return a string"):
|
with self.subTest(msg="Watspelenwe reden does not return a string"):
|
||||||
self.assertIsInstance(reden, str)
|
self.assertIsInstance(reden, str)
|
||||||
|
|
||||||
|
def test_ktdm(self):
|
||||||
|
with self.subTest():
|
||||||
|
wit = ["qwerty", "yuiop"]
|
||||||
|
kaart = self.cog.get_ktdm(wit)
|
||||||
|
self.assertIn(wit[0], kaart)
|
||||||
|
self.assertIn(wit[1], kaart)
|
||||||
|
with self.subTest():
|
||||||
|
wit = ["a", "b", "c", "d"]
|
||||||
|
kaart = self.cog.get_ktdm(wit)
|
||||||
|
self.assertEqual(kaart, None)
|
||||||
|
with self.subTest():
|
||||||
|
wit = ["a", "b", "c"]
|
||||||
|
self.cog.zwarte_lijst = ["___"]
|
||||||
|
kaart = self.cog.get_ktdm(wit)
|
||||||
|
self.assertEqual(kaart, None)
|
||||||
Reference in New Issue
Block a user