Testing/CI #21

Merged
jp merged 40 commits from testing into master 2022-12-11 16:27:22 +01:00
2 changed files with 31 additions and 14 deletions
Showing only changes of commit 009d64ef16 - Show all commits
+24 -14
View File
@@ -5,6 +5,7 @@ import praw
import random import random
import re import re
import json, requests import json, requests
import warnings
from discord.ext import commands from discord.ext import commands
from sympy import latex, symbols, preview, Symbol #for LaTeX images from sympy import latex, symbols, preview, Symbol #for LaTeX images
import youtube_dl import youtube_dl
@@ -22,6 +23,7 @@ class General(commands.Cog):
client_id=os.getenv("STROOP_REDDIT_ID") client_id=os.getenv("STROOP_REDDIT_ID")
) )
self.r.read_only = True self.r.read_only = True
warnings.simplefilter("ignore")
def __check(self, ctx): #Todo: Is dit het porno kanaal? def __check(self, ctx): #Todo: Is dit het porno kanaal?
return True return True
@@ -77,30 +79,38 @@ class General(commands.Cog):
print("No permission to delete message") print("No permission to delete message")
yield from ctx.channel.send(ctx.author.mention + ' ' + post.url) yield from ctx.channel.send(ctx.author.mention + ' ' + post.url)
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:
listing = list(rkopieerpasta.top('month', limit=250))
post = random.choice(listing)
return post
@commands.command(pass_context=True) @commands.command(pass_context=True)
@asyncio.coroutine @asyncio.coroutine
def kopieerpasta(self, ctx): def kopieerpasta(self, ctx):
"""Een willekeurige shitpost""" """Een willekeurige shitpost"""
rkopieerpasta = self.r.subreddit('kopieerpasta') post = self.get_kopieerpasta()
post = rkopieerpasta.random() print(post.url)
ATTEMPTS = 10
# Subreddits kunnen de random functie uitzetten, dus dit is de fallback: a = 0
if post == None: while len(post.selftext + post.title) >= 1990 and a < ATTEMPTS:
post = rkopieerpasta.top('month', limit=250) post = self.get_kopieerpasta()
listing = list(post) print(post.url)
random.shuffle(listing) a += 1
post = listing[0]
try: try:
yield from ctx.message.delete() yield from ctx.message.delete()
except: except:
print("No permission to delete message") print("No permission to delete message")
# Er is een 2000 karakter limiet wat met sommige pastas overschreden kan worden. if len(post.selftext + post.title) < 1990:
# 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:
yield from ctx.channel.send('**'+post.title+'**```'+post.selftext+'```') 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) @commands.command(pass_context=True)
@asyncio.coroutine @asyncio.coroutine
+7
View File
@@ -35,3 +35,10 @@ class TestGeneral(unittest.TestCase):
self.skipTest("PRAW Reddit instance failed to create") self.skipTest("PRAW Reddit instance failed to create")
post = self.cog.get_aww_post() post = self.cog.get_aww_post()
self.assertIsInstance(post.url, str) 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)