This commit is contained in:
+23
-13
@@ -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)
|
||||||
|
|
||||||
@commands.command(pass_context=True)
|
def get_kopieerpasta(self):
|
||||||
@asyncio.coroutine
|
|
||||||
def kopieerpasta(self, ctx):
|
|
||||||
"""Een willekeurige shitpost"""
|
|
||||||
rkopieerpasta = self.r.subreddit('kopieerpasta')
|
rkopieerpasta = self.r.subreddit('kopieerpasta')
|
||||||
post = rkopieerpasta.random()
|
post = rkopieerpasta.random()
|
||||||
|
|
||||||
# Subreddits kunnen de random functie uitzetten, dus dit is de fallback:
|
# Subreddits kunnen de random functie uitzetten, dus dit is de fallback:
|
||||||
if post == None:
|
if post == None:
|
||||||
post = rkopieerpasta.top('month', limit=250)
|
listing = list(rkopieerpasta.top('month', limit=250))
|
||||||
listing = list(post)
|
post = random.choice(listing)
|
||||||
random.shuffle(listing)
|
|
||||||
post = listing[0]
|
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:
|
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
|
||||||
|
|||||||
@@ -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)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user