Test voor kopieerpasta
continuous-integration/drone/push Build is passing

This commit is contained in:
2022-12-02 21:50:20 +01:00
parent 54b3dfd290
commit 009d64ef16
2 changed files with 31 additions and 14 deletions
+23 -13
View File
@@ -5,6 +5,7 @@ import praw
import random
import re
import json, requests
import warnings
from discord.ext import commands
from sympy import latex, symbols, preview, Symbol #for LaTeX images
import youtube_dl
@@ -22,6 +23,7 @@ class General(commands.Cog):
client_id=os.getenv("STROOP_REDDIT_ID")
)
self.r.read_only = True
warnings.simplefilter("ignore")
def __check(self, ctx): #Todo: Is dit het porno kanaal?
return True
@@ -77,30 +79,38 @@ class General(commands.Cog):
print("No permission to delete message")
yield from ctx.channel.send(ctx.author.mention + ' ' + post.url)
@commands.command(pass_context=True)
@asyncio.coroutine
def kopieerpasta(self, ctx):
"""Een willekeurige shitpost"""
def get_kopieerpasta(self):
rkopieerpasta = self.r.subreddit('kopieerpasta')
post = rkopieerpasta.random()
# Subreddits kunnen de random functie uitzetten, dus dit is de fallback:
if post == None:
post = rkopieerpasta.top('month', limit=250)
listing = list(post)
random.shuffle(listing)
post = listing[0]
listing = list(rkopieerpasta.top('month', limit=250))
post = random.choice(listing)
return post
@commands.command(pass_context=True)
@asyncio.coroutine
def kopieerpasta(self, ctx):
"""Een willekeurige shitpost"""
post = self.get_kopieerpasta()
print(post.url)
ATTEMPTS = 10
a = 0
while len(post.selftext + post.title) >= 1990 and a < ATTEMPTS:
post = self.get_kopieerpasta()
print(post.url)
a += 1
try:
yield from ctx.message.delete()
except:
print("No permission to delete message")
# Er is een 2000 karakter limiet wat met sommige pastas overschreden kan worden.
# eigenlijk willen we het dan opnieuw proberen maar dat is lastiger, dus maar gewoon berichtje.
if (len(post.selftext)+len(post.title)) >= 1990:
yield from ctx.channel.send('Sorry, kopieerpasta te lang. Probeer het maar opnieuw .')
else:
if len(post.selftext + post.title) < 1990:
yield from ctx.channel.send('**'+post.title+'**```'+post.selftext+'```')
else:
yield from ctx.channel.send("Geen kopieerpasta voor jou vandaag.")
@commands.command(pass_context=True)
@asyncio.coroutine
+7
View File
@@ -35,3 +35,10 @@ class TestGeneral(unittest.TestCase):
self.skipTest("PRAW Reddit instance failed to create")
post = self.cog.get_aww_post()
self.assertIsInstance(post.url, str)
def test_kopieerpasta(self):
if not isinstance(self.cog.r, praw.Reddit):
self.skipTest("PRAW Reddit instance failed to create")
post = self.cog.get_kopieerpasta()
self.assertIsInstance(post.url, str)