diff --git a/bin/config.ini b/bin/config.ini index 4eb83c1..68e297e 100644 --- a/bin/config.ini +++ b/bin/config.ini @@ -1,5 +1,5 @@ [DISCORD] -token= NDIzMjE1NTM1ODkxODA4MjY2.Wqg0Lg.CPLIjKVfJSARt-p8MOKHcMr6RTY +token= NDIzMjE1NTM1ODkxODA4MjY2.Wqg0Lg.Y4kOUUhso_p98pEMfx6cZbGsNMA owner= 155076323612688384 game= 2021.02.01-1 prefix= unk. diff --git a/run.py b/run.py index b512d7d..2097505 100644 --- a/run.py +++ b/run.py @@ -1,7 +1,15 @@ +# pip install discord.py discord.py[voice] configparser sentry-sdk youtube_dl requests ffmpeg import logging import discord import configparser import sys +import sentry_sdk +from youtube_dl import YoutubeDL +from requests import get +sentry_sdk.init( + "https://d012b451482f428ab43ef4cbb3766931@sentry.syslul.de/5", + traces_sample_rate=1.0 +) config = configparser.ConfigParser() config.read('bin/config.ini') @@ -17,6 +25,32 @@ class discord(discord.Client): if message.content.startswith('{0}help'.format(config['DISCORD']['PREFIX'])): await message.channel.send('MOIN MEISTA') + async def join(ctx, voice): + channel = ctx.author.voice.channel + + if voice and voice.is_connected(): + await voice.move_to(channel) + else: + voice = await channel.connect() + + async def play(ctx, *, query): + #Solves a problem I'll explain later + FFMPEG_OPTS = {'before_options': '-reconnect 1 -reconnect_streamed 1 -reconnect_delay_max 5', 'options': '-vn'} + + video, source = search(query) + voice = get(bot.voice_clients, guild=ctx.guild) + + await join(ctx, voice) + await ctx.send(f'Now playing {info['title']}.') + + voice.play(FFmpegPCMAudio(source, **FFMPEG_OPTS), after=lambda e: print('done', e)) + voice.is_playing() + def search(query): + with YoutubeDL({'format': 'bestaudio', 'noplaylist':'True'}) as ydl: + try: requests.get(arg) + except: info = ydl.extract_info(f"ytsearch:{arg}", download=False)['entries'][0] + else: info = ydl.extract_info(arg, download=False) + return (info, info['formats'][0]['url']) client = discord() client.run(config["DISCORD"]["TOKEN"])