-
Notifications
You must be signed in to change notification settings - Fork 0
/
music.py
95 lines (83 loc) · 2.84 KB
/
music.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import disnake
from disnake.ext import commands
from config import Config
import datetime
import logging
class Music(commands.Cog):
def __init__(
self,
bot
):
self.bot = bot
self._last_member = None
self.wait_time = datetime.datetime.utcnow() - datetime.timedelta(seconds=Config.wait_time)
async def autocomp_songs(
inter: disnake.ApplicationCommandInteraction,
user_input: str
):
sounds_names = []
for sound in Config.sounds:
sounds_names.append(sound.name)
return [sound for sound in sounds_names if user_input.lower() in sound]
@commands.slash_command(description="Přehaj krátký zvuk v Kachně.")
async def play(
self,
inter: disnake.ApplicationCommandInteraction,
sound: str = commands.Param(name="sound", autocomplete=autocomp_songs)
):
"""Play short sound in student club"""
await inter.response.defer()
# Find sound
sounds_names = ""
for sound_from_config in Config.sounds:
sounds_names += f"- {sound_from_config.name}\n"
if sound.lower() == sound_from_config.name.lower():
# play found sound
sound_from_config.play_fade_out()
# send message with emote from found sound
await inter.followup.send(
content=str(sound_from_config.emote)
)
return
# send message when sound is not found
await inter.followup.send(
content=f"Tento zvuk ještě neumím zahrát, zkus něco z těchto:\n{sounds_names[:-1]}"
)
@commands.slash_command()
async def spotify(
self,
inter: disnake.ApplicationCommandInteraction,
):
pass
@spotify.sub_command_group()
async def queue(
self,
inter: disnake.ApplicationCommandInteraction,
):
pass
@queue.sub_command(description="Přidat písničku do Spotify fronty.")
async def add(
self,
inter: disnake.ApplicationCommandInteraction,
track_id: str = commands.Param(name="song_url")
):
"""
Parameters
----------
track_id: ID skladby na Spotify
"""
await inter.response.defer()
logging.info("Adding track to Spotify queue.")
Config.spotify.add_to_queue(track_id)
track = Config.spotify.track(track_id)
embed = disnake.Embed(
title="Skladba přidána do fronty. :white_check_mark:",
description=f"Písnička \"{track['name']}\" byla úspěšně zařazena na konec fronty.",
color=0x1DB954
)
embed.set_thumbnail(url=track["album"]["images"][0]["url"])
# Update message
await inter.followup.send(
content="",
embed=embed
)