diff --git a/Procfile b/Procfile new file mode 100644 index 0000000..dc544cf --- /dev/null +++ b/Procfile @@ -0,0 +1 @@ +worker: python catmusicbot.py \ No newline at end of file diff --git a/catmusicbot.py b/catmusicbot.py new file mode 100644 index 0000000..57ceedb --- /dev/null +++ b/catmusicbot.py @@ -0,0 +1,60 @@ +import os +import asyncio +import discord +from discord.ext import commands +import yandex_music + +# Add bot to a server: +# https://discord.com/api/oauth2/authorize?client_id=861599847441104926&permissions=2184277249&scope=bot + +# Options +token = 'ODYxNTk5ODQ3NDQxMTA0OTI2.YOMJYw.8Q6ZIfp_hr4_TCJYOwoAebhPAI0' +bot = commands.Bot(command_prefix='/') +# Setting up YandexMusic +ymcl = yandex_music.Client.from_credentials('achtest22@yandex.ru', 'tEs#t22') + +# Command /catplay +@bot.command(name='catplay', description='Plays the music in a voice channel') +async def catplay(ctx, *args): + + # Get the server (guild) and the music channel + curserver = ctx.guild + music_channel = None + for vch in curserver.voice_channels: + if (vch.name == 'Музыка'): + music_channel = vch + + if (music_channel != None): + + song_query = ' '.join(args) + await ctx.send(':mag: **Searching...**') + + song = ymcl.search(song_query, True, 'track').tracks.results[0] + song.download(str(song.id) + '.mp3', 'mp3') + artist = '' + + # Joining artists into a string + for artist_obj in song.artists: + artist += artist_obj.name + ', ' + # Removing a comma in the end of the string + artist = artist[:len(artist)-2] + + # Beautiful notification + notif = discord.Embed(color=0xe3813e, title='Playing:', description=f'{artist} - {song.title}') + notif.set_image(url=song.cover_uri) + + # Connecting to the voice channel + sp = await music_channel.connect() + # Stopping previously playing music + if (sp.is_playing()): + sp.stop() + # Playing music to the voice channel + sp.play(discord.FFmpegPCMAudio(source=(str(song.id) + '.mp3')), after=None) + await ctx.send(embed=notif) + while (sp.is_playing()): + await asyncio.sleep(1) + sp.stop() + os.remove(str(song.id) + '.mp3') + +# Starting bot after setup +bot.run(token) diff --git a/logo/cat-006.png b/logo/cat-006.png new file mode 100644 index 0000000..24486a9 Binary files /dev/null and b/logo/cat-006.png differ diff --git a/logo/catmusic.png b/logo/catmusic.png new file mode 100644 index 0000000..5cc8bc1 Binary files /dev/null and b/logo/catmusic.png differ diff --git a/logo/catmusic.xcf b/logo/catmusic.xcf new file mode 100644 index 0000000..f240131 Binary files /dev/null and b/logo/catmusic.xcf differ diff --git a/logo/license.pdf b/logo/license.pdf new file mode 100644 index 0000000..702c2a5 Binary files /dev/null and b/logo/license.pdf differ diff --git a/logo/playlist.svg b/logo/playlist.svg new file mode 100644 index 0000000..69ce3c0 --- /dev/null +++ b/logo/playlist.svg @@ -0,0 +1,46 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..9298573 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,26 @@ +aiohttp==3.7.4.post0 +async-timeout==3.0.1 +attrs==21.2.0 +beautifulsoup4==4.9.3 +certifi==2020.12.5 +cffi==1.14.5 +chardet==4.0.0 +click==7.1.2 +discord.py==1.7.3 +idna==2.10 +multidict==5.1.0 +numpy==1.20.2 +Pillow==8.2.0 +pycparser==2.20 +pygal==2.4.0 +pygame==2.0.1 +PyNaCl==1.4.0 +PySocks==1.7.1 +requests==2.25.1 +six==1.15.0 +soupsieve==2.2.1 +typing-extensions==3.10.0.0 +urllib3==1.26.3 +wikipedia==1.4.0 +yandex-music==1.0.0 +yarl==1.6.3 diff --git a/runtime.txt b/runtime.txt new file mode 100644 index 0000000..88f4ef2 --- /dev/null +++ b/runtime.txt @@ -0,0 +1 @@ +python-3.9.5 \ No newline at end of file