commit ce3df4699348d3f428bf0dcb8d3fa9dbf01ceace Author: Mark Date: Fri Jun 2 18:05:21 2017 +0200 initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..541f92c --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +# Add any directories, files, or patterns you don't want to be tracked by version control \ No newline at end of file diff --git a/General.py b/General.py new file mode 100644 index 0000000..1c3c90a --- /dev/null +++ b/General.py @@ -0,0 +1,27 @@ +import asyncio +import discord +from discord.ext import commands +from sympy import latex, symbols, preview, Symbol #for LaTeX images + +class General(object): + """Overal toegestaan.""" + + def __init__(self, bot): + self.bot = bot + self.voice_states = {} + def __check(self, ctx): #Todo: Is dit het porno kanaal? + return True + @commands.command(pass_context=True) + @asyncio.coroutine + def tex(self, ctx, mathstring): + """Geeft een mooi LaTeX plaatje terug. + Encapsuleer uw string in mooie \" + Bijvoorbeeld: + !tex "a^b b^c \rightarrow d" + """ + preamble = "\\documentclass[10pt]{article}\\pagestyle{empty}\\usepackage[margin=1in]{geometry}\\usepackage[T1]{fontenc}\\usepackage{CJKutf8}\\usepackage[english]{babel}\\usepackage{amsmath, amsfonts}\\begin{document}" + options = ["-T", "tight", "-z", "9", "--truecolor", "-D", "512"] + preview(r'$$'+mathstring+'$$', viewer='file', filename='test.png', dvioptions=options, preamble=preamble) + file = open('test.png', 'rb') + yield from self.bot.upload(file, filename ='test.png', content='Nerd!') + diff --git a/Music.py b/Music.py new file mode 100644 index 0000000..54b08d5 --- /dev/null +++ b/Music.py @@ -0,0 +1,240 @@ +import asyncio +import discord +from discord.ext import commands + +class VoiceEntry: + def __init__(self, message, player): + self.requester = message.author + self.channel = message.channel + self.player = player + + def __str__(self): + fmt = '*{0.title}* verzocht door {1.display_name}' + duration = self.player.duration + if duration: + fmt = fmt + ' [{0[0]}m {0[1]}s]'.format(divmod(duration, 60)) + return fmt.format(self.player, self.requester) + +class VoiceState: + def __init__(self, bot): + self.current = None + self.voice = None + self.bot = bot + self.play_next_song = asyncio.Event() + self.songs = asyncio.Queue() + self.skip_votes = set() # a set of user_ids that voted + self.audio_player = self.bot.loop.create_task(self.audio_player_task()) + + def is_playing(self): + if self.voice is None or self.current is None: + return False + + player = self.current.player + return not player.is_done() + + @property + def player(self): + return self.current.player + + def skip(self): + self.skip_votes.clear() + if self.is_playing(): + self.player.stop() + + def toggle_next(self): + self.bot.loop.call_soon_threadsafe(self.play_next_song.set) + + @asyncio.coroutine + def audio_player_task(self): + while True: + self.play_next_song.clear() + self.current = yield from self.songs.get() + yield from self.bot.send_message(self.current.channel, 'U luistert naar: ' + str(self.current)) + self.current.player.start() + yield from self.play_next_song.wait() + + + +if not discord.opus.is_loaded(): + # the 'opus' library here is opus.dll on windows + # or libopus.so on linux in the current directory + # you should replace this with the location the + # opus library is located in and with the proper filename. + # note that on windows this DLL is automatically provided for you + discord.opus.load_opus('opus') + +class Music: + """Play that funky music white boy. + """ + def __init__(self, bot): + self.bot = bot + self.voice_states = {} + + def __check(self, ctx): + return True + + def get_voice_state(self, server): + state = self.voice_states.get(server.id) + if state is None: + state = VoiceState(self.bot) + self.voice_states[server.id] = state + + return state + @asyncio.coroutine + def create_voice_client(self, channel): + voice = yield from self.bot.join_voice_channel(channel) + state = self.get_voice_state(channel.server) + state.voice = voice + + def __unload(self): + for state in self.voice_states.values(): + try: + state.audio_player.cancel() + if state.voice: + self.bot.loop.create_task(state.voice.disconnect()) + except: + pass + + @commands.command(pass_context=True, no_pm=True) + @asyncio.coroutine + def join(self, ctx, *, channel : discord.Channel): + """Verplaats stroopie naar een bepaald kanaal.""" + try: + yield from self.create_voice_client(channel) + except discord.ClientException: + yield from self.bot.say('Already in a voice channel...') + except discord.InvalidArgument: + yield from self.bot.say('This is not a voice channel...') + else: + yield from self.bot.say('Ready to play audio in ' + channel.name) + + @commands.command(pass_context=True, no_pm=True) + @asyncio.coroutine + def summon(self, ctx): + """Roep stroopie naar jouw kanaal toe..""" + summoned_channel = ctx.message.author.voice_channel + if summoned_channel is None: + yield from self.bot.say('You are not in a voice channel.') + return False + + state = self.get_voice_state(ctx.message.server) + if state.voice is None: + state.voice = yield from self.bot.join_voice_channel(summoned_channel) + else: + yield from state.voice.move_to(summoned_channel) + + return True + + @commands.command(pass_context=True, no_pm=True) + @asyncio.coroutine + def play(self, ctx, *, song : str): + """Zet een liedje in de queue + """ + state = self.get_voice_state(ctx.message.server) + opts = { + 'default_search': 'auto', + 'quiet': True, + 'no-check-certificate': True, + } + + if state.voice is None: + success = yield from ctx.invoke(self.summon) + if not success: + return + + try: + player = yield from state.voice.create_ytdl_player(song, ytdl_options=opts, after=state.toggle_next) + except Exception as e: + fmt = 'Error: ```py\n{}: {}\n```' + yield from self.bot.send_message(ctx.message.channel, fmt.format(type(e).__name__, e)) + else: + player.volume = 0.6 + entry = VoiceEntry(ctx.message, player) + yield from self.bot.say('In de queue: ' + str(entry)) + yield from state.songs.put(entry) + + @commands.command(pass_context=True, no_pm=True) + @asyncio.coroutine + def volume(self, ctx, value : int): + """zet het volume. 1-100""" + + state = self.get_voice_state(ctx.message.server) + if state.is_playing(): + player = state.player + player.volume = value / 100 + yield from self.bot.say('Zet het volume op {:.0%}'.format(player.volume)) + + @commands.command(pass_context=True, no_pm=True) + @asyncio.coroutine + def pause(self, ctx): + """Pauzeer het huidige liedje""" + state = self.get_voice_state(ctx.message.server) + if state.is_playing(): + player = state.player + player.pause() + + @commands.command(pass_context=True, no_pm=True) + @asyncio.coroutine + def resume(self, ctx): + """onpauzeer.""" + state = self.get_voice_state(ctx.message.server) + if state.is_playing(): + player = state.player + player.resume() + + @commands.command(pass_context=True, no_pm=True) + @asyncio.coroutine + def stop(self, ctx): + """Kappen nou. Stoppen met spelen, gaat uit het kanaal en leegt de queue. + """ + server = ctx.message.server + state = self.get_voice_state(server) + + if state.is_playing(): + player = state.player + player.stop() + + try: + state.audio_player.cancel() + del self.voice_states[server.id] + yield from state.voice.disconnect() + except: + pass + + @commands.command(pass_context=True, no_pm=True) + @asyncio.coroutine + def skip(self, ctx): + """skipperdepip + """ + + state = self.get_voice_state(ctx.message.server) + if not state.is_playing(): + yield from self.bot.say('Not playing any music right now...') + return + + voter = ctx.message.author + if voter == state.current.requester: + yield from self.bot.say('Requester requested skipping song...') + state.skip() + elif voter.id not in state.skip_votes: + state.skip_votes.add(voter.id) + total_votes = len(state.skip_votes) + if total_votes >= 3: + yield from self.bot.say('Skip vote passed, skipping song...') + state.skip() + else: + yield from self.bot.say('Skip vote added, currently at [{}/3]'.format(total_votes)) + else: + yield from self.bot.say('You have already voted to skip this song.') + + @commands.command(pass_context=True, no_pm=True) + @asyncio.coroutine + def playing(self, ctx): + """Info over het huidige liedje.""" + + state = self.get_voice_state(ctx.message.server) + if state.current is None: + yield from self.bot.say('Not playing anything.') + else: + skip_count = len(state.skip_votes) + yield from self.bot.say('Now playing {} [skips: {}/3]'.format(state.current, skip_count)) diff --git a/Porno.py b/Porno.py new file mode 100644 index 0000000..614e85c --- /dev/null +++ b/Porno.py @@ -0,0 +1,36 @@ +import asyncio +import discord +from discord.ext import commands +import os +from random import randint + +class Porno(object): + """Porno commando's. Jij weet wat er aan is.""" + + def __init__(self, bot): + self.bot = bot + self.voice_states = {} + self.fileIndex = {} + def __check(self, ctx): #Todo: Is dit het porno kanaal? + return True + + def randomJpgFromFolder(self, dir): + if dir not in self.fileIndex.keys(): + self.fileIndex[dir] = [] #empty list + for dirname, dirnames, filenames in os.walk('./'+ dir): + for filename in filenames: + if filename.endswith('.jpg'): + self.fileIndex[dir].append(os.path.join(dirname, filename)) + #now we should have an index for the selected folder, but it might still be empty (i.e. empty folder given) + if self.fileIndex[dir]: + return self.fileIndex[dir][randint(0,len(self.fileIndex[dir])-1)] #get a random element from the newly created index + else: + return 'default file here' + + @commands.command(pass_context=True) + @asyncio.coroutine + def ancilla(self, ctx): + """ :-) """ + filepath = self.randomJpgFromFolder('ancilla'); + file = open(filepath, 'rb') + yield from self.bot.upload(file, filename = filepath, content='Alsjeblieft!') \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..39af52c --- /dev/null +++ b/README.md @@ -0,0 +1,29 @@ +# README # + +This README would normally document whatever steps are necessary to get your application up and running. + +### What is this repository for? ### + +* Quick summary +* Version +* [Learn Markdown](https://bitbucket.org/tutorials/markdowndemo) + +### How do I get set up? ### + +* Summary of set up +* Configuration +* Dependencies +* Database configuration +* How to run tests +* Deployment instructions + +### Contribution guidelines ### + +* Writing tests +* Code review +* Other guidelines + +### Who do I talk to? ### + +* Repo owner or admin +* Other community or team contact \ No newline at end of file diff --git a/Shitpost.py b/Shitpost.py new file mode 100644 index 0000000..b3096e2 --- /dev/null +++ b/Shitpost.py @@ -0,0 +1,72 @@ +import asyncio +import discord +from discord.ext import commands +from urllib import request +import json, requests +from datetime import datetime +import sys +import os + +class Shitpost(object): + """Schijtpaal commando's. Alleen bruikbaar in de daarvoor toegewezen schijtpaal kanalen.""" + + def __init__(self, bot): + self.bot = bot + self.voice_states = {} + def __check(self, ctx): #Todo: Is dit het shitpost kanaal? + return True + + @commands.command(pass_context=True) + @asyncio.coroutine + def eriku(self, ctx, boven: str, onder: str): + """Maakt een erik meem. + Bijvoorbeeld: + @Stroopwafel eriku \"je moeder\" \"is een hoer\" + """ + params = dict( + template_id = '93296473', #de eriku + username = 'Stroopwafel', + password = 'ruyter118', + text0 = boven, + text1 = onder + ) + self.bot.say("deed ik het ding?") + resp = requests.get(url='https://api.imgflip.com/caption_image', params=params) + #todo check for success + photourl = resp.json()['data']['url'] + em = discord.Embed(title='De Eriku heeft gesproken. Prijs hem!', type='photo') + em.set_image(url=photourl) + yield from self.bot.say(embed=em) + + @commands.command(pass_context=True, hidden=True) + @asyncio.coroutine + def nihao(self,ctx): + yield from self.bot.say("Kankerlauw") + + @commands.command(pass_context=True) + @asyncio.coroutine + def tijd(self, ctx, *args): + """Vertelt je hoe laat het is.. + Misschien geeft het ook wel een leuke meem terug. + Wie weet. + Probeer het eens op verschillende tijdstippen + """ + + time=datetime.now().strftime('%H%M') + for argument in args: + time = argument + filepath = '' + #filejpg = './tijd/' + time + '.jpg' + #filepng = './tijd/' + time + '.png' + filejpg = os.path.join('tijd', time) + '.jpg' + filepng = os.path.join('tijd', time) + '.png' + if os.path.isfile(filejpg): + filepath = filejpg + elif os.path.isfile(filepng): + filepath = filepng + + if filepath is not '': + file = open(filepath, 'rb') + yield from self.bot.upload(file, filename = filepath) + else: + yield from self.bot.say('Het is nu ' + datetime.now().strftime('%H:%M')) \ No newline at end of file diff --git a/Stroopwafel.py b/Stroopwafel.py new file mode 100644 index 0000000..33c9622 --- /dev/null +++ b/Stroopwafel.py @@ -0,0 +1,20 @@ +import asyncio +import discord +import Music +import Porno +import Shitpost +import General +from discord.ext import commands + +bot = commands.Bot(command_prefix=commands.when_mentioned_or('!'), description='Stroopwafel. Shitpost bot extraordinaire.', pm_help=True) +bot.add_cog(Music.Music(bot)) +bot.add_cog(Shitpost.Shitpost(bot)) +bot.add_cog(Porno.Porno(bot)) +bot.add_cog(General.General(bot)) + +@bot.event +@asyncio.coroutine +def on_ready(): + print('Logged in as:\n{0} (ID: {0.id})'.format(bot.user)) + +bot.run('MjczODc1ODM1NzIxNzQ0Mzg1.C2p7EA._tTMtYEsaUuTv_RtOifGhNX9QZ4') \ No newline at end of file diff --git a/Stroopwafel.pyproj b/Stroopwafel.pyproj new file mode 100644 index 0000000..0ce4001 --- /dev/null +++ b/Stroopwafel.pyproj @@ -0,0 +1,59 @@ + + + + Debug + 2.0 + 6f25512f-caba-45b1-9b6a-d2d28b32494a + . + Stroopwafel.py + + + . + . + Stroopwafel + Stroopwafel + False + {257fd04c-048c-4bcb-bc47-024b035ececc} + 3.5 + + + true + false + + + true + false + + + + Code + + + Code + + + Code + + + + Code + + + + + + + 10.0 + $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\Python Tools\Microsoft.PythonTools.targets + + + + + + + + + + \ No newline at end of file diff --git a/Stroopwafel.sln b/Stroopwafel.sln new file mode 100644 index 0000000..fe20007 --- /dev/null +++ b/Stroopwafel.sln @@ -0,0 +1,20 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 14 +VisualStudioVersion = 14.0.25420.1 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{888888A0-9F3D-457C-B088-3A5042F75D52}") = "Stroopwafel", "Stroopwafel.pyproj", "{6F25512F-CABA-45B1-9B6A-D2D28B32494A}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {6F25512F-CABA-45B1-9B6A-D2D28B32494A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {6F25512F-CABA-45B1-9B6A-D2D28B32494A}.Release|Any CPU.ActiveCfg = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/__pycache__/General.cpython-36.pyc b/__pycache__/General.cpython-36.pyc new file mode 100644 index 0000000..13171c9 Binary files /dev/null and b/__pycache__/General.cpython-36.pyc differ diff --git a/__pycache__/Music.cpython-36.pyc b/__pycache__/Music.cpython-36.pyc new file mode 100644 index 0000000..91ae84b Binary files /dev/null and b/__pycache__/Music.cpython-36.pyc differ diff --git a/__pycache__/Porno.cpython-36.pyc b/__pycache__/Porno.cpython-36.pyc new file mode 100644 index 0000000..9648dc9 Binary files /dev/null and b/__pycache__/Porno.cpython-36.pyc differ diff --git a/__pycache__/Shitpost.cpython-36.pyc b/__pycache__/Shitpost.cpython-36.pyc new file mode 100644 index 0000000..474c7e6 Binary files /dev/null and b/__pycache__/Shitpost.cpython-36.pyc differ diff --git a/__pycache__/Voice.cpython-36.pyc b/__pycache__/Voice.cpython-36.pyc new file mode 100644 index 0000000..911535e Binary files /dev/null and b/__pycache__/Voice.cpython-36.pyc differ diff --git a/test.png b/test.png new file mode 100644 index 0000000..a5c5814 Binary files /dev/null and b/test.png differ diff --git a/tijd/1337.jpg b/tijd/1337.jpg new file mode 100644 index 0000000..7ffcec9 Binary files /dev/null and b/tijd/1337.jpg differ diff --git a/tijd/1533.jpg b/tijd/1533.jpg new file mode 100644 index 0000000..7ffcec9 Binary files /dev/null and b/tijd/1533.jpg differ diff --git a/tijd/1620.jpg b/tijd/1620.jpg new file mode 100644 index 0000000..f8216ff Binary files /dev/null and b/tijd/1620.jpg differ diff --git a/tijd/420.jpg b/tijd/420.jpg new file mode 100644 index 0000000..f8216ff Binary files /dev/null and b/tijd/420.jpg differ