Files
stroopwafel/General.py
T
mark 074545f965
continuous-integration/drone/push Build is passing
Verwijder gif functie
Als het het niet doet en we het niet testen, dan moet het weg.
2022-12-04 15:10:26 +01:00

136 lines
4.3 KiB
Python

import asyncio
import discord
import sys, os
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
class General(commands.Cog):
"""Overal toegestaan."""
def __init__(self, bot):
self.bot = bot
self.voice_states = {}
self.muzak_url = 'https://hdcon-muzak.herokuapp.com'
self.r = praw.Reddit(
user_agent='StroopwafelBot',
client_secret=os.getenv("STROOP_REDDIT_SECRET"),
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
@commands.command()
@asyncio.coroutine
def huge(self, ctx, *, arg):
"""YUGE. Geeft een grote versie van de gegeven emoji terug. Werkt alleen voor custom emoji.
Bijvoorbeeld:
!huge :ancilla:
"""
id = re.search("\<\:([A-z]*)\:(\d*)\>", arg)
hugemoji = 'https://cdn.discordapp.com/emojis/' + id.group(2) + '.png'
em = discord.Embed(title=id.group(1), type='photo')
em.set_image(url=hugemoji)
try:
yield from ctx.message.delete()
except:
print("No permission to delete message")
yield from ctx.channel.send(ctx.author.mention, embed=em)
@commands.command()
@asyncio.coroutine
def tex(self, ctx, *, arg):
"""Geeft een mooi LaTeX plaatje terug.
Bijvoorbeeld:
!tex Je moeder is lelijk! $a^b b^c \\rightarrow d$
"""
preamble = "\\documentclass[10pt]{article}\\pagestyle{empty}\\usepackage[margin=1in]{geometry}\\usepackage{amsmath, amsfonts}\\begin{document}" #\\usepackage{CJKutf8}\\usepackage[T1]{fontenc}\\usepackage[english]{babel}
options = ["-T", "tight", "-z", "9", "--truecolor", "-D", "512"]
preview(r''+arg+'', viewer='file', filename='test.png', dvioptions=options, preamble=preamble)
#file = open('test.png', 'rb')
#yield from ctx.channel.send(file, filename ='test.png', content='')
try:
yield from ctx.message.delete()
except:
print("No permission to delete message")
yield from ctx.channel.send(ctx.author.mention, file=discord.File('test.png', 'tex.png'))
def get_aww_post(self):
raww = self.r.subreddit('aww+catloaf+tuckedinkitties+babyelephantgifs+babybigcatgifs+blep+holdmynip+gingerkitty+cathighfive+catsstandingup+catsareassholes+eyebleach')
listing = list(raww.top(time_filter='month'))
return random.choice(listing)
@commands.command(pass_context=True)
@asyncio.coroutine
def aww(self, ctx):
""" iets schattigs... """
post = self.get_aww_post()
try:
yield from ctx.message.delete()
except:
print("No permission to delete message")
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)
@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")
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.")
def get_playlist_json(self):
return requests.get(self.muzak_url + '/stroopwafel')
@commands.command(pass_context=True)
@asyncio.coroutine
def playlist(self, ctx):
"""HDcon2021 playlist"""
data = json.loads(self.get_playlist_json().content)
msg = 'Stemmen en nomineren kan hier: {}\n'.format(self.muzak_url)
msg += '*Er zijn al {} nummers genomineerd*\n'.format(data['stemCount'])
yield from ctx.channel.send(msg)
@commands.command(pass_context=True, hidden=True)
@asyncio.coroutine
def reboot(self, ctx, password=""):
""" Reboot.. """
if password == os.getenv("STROOP_RESET_PASSWORD"):
yield from ctx.channel.send("Rebooting.. brb!")
os.execv(sys.executable, ['python3'] + sys.argv)
else:
yield from ctx.channel.send(ctx.author.mention + " What's the magic word?")