· 6 years ago · Sep 14, 2019, 12:12 PM
1import discord
2from discord.ext import commands
3from config import config
4from api import footer
5import nacl
6import asyncio
7from api import log
8
9prefix = config["prefix"]
10nopm = config["nopm"]
11
12players = {}
13now_playing = {}
14rmenus = {}
15
16
17class Music(commands.Cog):
18 def __init__(self, client):
19 self.client = client
20
21 @commands.command(pass_context = True, aliases = ["summon"])
22 async def join(self, ctx):
23 if ctx.message.guild == None:
24 embed = discord.Embed(title = "Hiba!", description = nopm, colour = discord.Colour.red())
25 embed.set_footer(text = footer())
26 return await ctx.message.channel.send(embed = embed)
27 try:
28 channel = ctx.message.author.voice.voice_channel
29 await self.client.join_voice_channel(channel)
30 await self.client.say(":white_check_mark: Sikeresen csatlakoztam a hangcsatornához!")
31 log("A(z) {} szerveren csatlakoztam a(z) {} hangcs")
32 except:
33 await self.client.say(":x: Már csatlakoztam egy hangcsatornához!")
34
35 @commands.command(pass_context = True, aliases = ["disconnect", "fuckoff", "bye", "cs"])
36 async def leave(self, ctx):
37 if ctx.message.guild == None:
38 embed = discord.Embed(title = "Hiba!", description = nopm, colour = discord.Colour.red())
39 embed.set_footer(text = footer())
40 return await self.client.say(embed = embed)
41 voice_client = self.client.voice_client_in(ctx.message.guild)
42 if not voice_client == None:
43 await voice_client.disconnect()
44 await self.client.say(":white_check_mark: Sikeresen lecsatlakoztam a hangcsatornából!")
45 del players[ctx.message.guild.id]
46 del now_playing[ctx.message.guild.id]
47 else:
48 await self.client.say(":x: Nem vagyok egy hangcsatornában sem!")
49
50 '''
51 @commands.command(pass_context = True)
52 async def play(self, ctx, url):
53 await self.client.say(":mag_right: Keresés a következő zenére: `{}`".format(url))
54 try:
55 voice_client = self.client.voice_client_in(ctx.message.guild)
56 player = await voice_client.create_ytdl_player(url)
57 players[ctx.message.guild.id] = player
58 player.start()
59 embed = discord.Embed(description = ":white_check_mark: A zene elindult!", colour = discord.Colour.green())
60 await self.client.say(embed = embed)
61 except:
62 embed = discord.Embed(description = ":x: Nem találtam semmilyen zenét ezen a linken!", colour = discord.Colour.red())
63 await self.client.say(embed = embed)
64 '''
65
66 @commands.command(aliases=['p'], pass_context=True)
67 async def play(self, ctx, * ,url: str = None, ytdl_options=None, **kwarg):
68 if ctx.message.author.bot:
69 return
70
71 guild = ctx.message.guild
72 voice_client = self.client.voice_client_in(guild)
73 channel = ctx.message.author.voice.voice_channel
74 if channel == None:
75 return ctx.message.channel.send(":x: Csatlakozz egy hangcsatornához, hogy használhasd ezt a parancsot!")
76
77 if url == None:
78 return ctx.message.channel.send(":x: Használat: {}play [url / zene címe]".format(prefix))
79
80 if voice_client == None:
81 await self.client.join_voice_channel(channel)
82
83 if ctx.message.guild.id in players:
84 if not players[ctx.message.guild.id].is_done():
85 return ctx.message.channel.send(":x: Már fut egy zene!")
86
87
88 await ctx.message.channel.send(":mag_right: Keresés a következőre: `{}`".format(url))
89 try:
90 guild = ctx.message.guild
91 voice_client = self.client.voice_client_in(guild)
92 #ydl_opts = { 'format': 'bestaudio/best', 'postprocessors': [{ 'key': 'FFmpegExtractAudio', 'preferredcodec': 'mp4', 'preferredquality': '192', }], }
93 player = await voice_client.create_ytdl_player("ytsearch: {}".format(url), before_options="-reconnect 1 -reconnect_streamed 1 -reconnect_delay_max 5", after=lambda: check_queue(guild.id))
94 player.start()
95 players[guild.id] = player
96 player.volume = 1
97 now_playing[guild.id] = {}
98 now_playing[guild.id]["title"] = player.title
99 now_playing[guild.id]["author"] = player.uploader
100 now_playing[guild.id]["duration"] = player.duration
101 now_playing[guild.id]["views"] = player.views
102 #embed = discord.Embed(title = "Teszt", colour = discord.Colour.blue())
103 #embed.set_image(url = video_url)
104 #msg = await self.client.say(embed = embed)
105 embed = discord.Embed(title = "Zene elindítva", description = ":notes: `{}` lejátszása".format(now_playing[guild.id]["title"]))
106 embed.set_footer(text = footer())
107 msg = ctx.message.channel.send(embed = embed)
108 """
109 reactions = ["⏮", "⏸", "⏹", "⏭", "?", "⭐"]
110 for reaction in reactions:
111 await self.client.add_reaction(msg, reaction)
112 """
113 rmenus[ctx.message.id] = {}
114 rmenus[ctx.message.id]["page"] = 1
115 except Exception as error:
116 print("Hiba: {}".format(error))
117 await ctx.message.channel.send("Valami nem jó! Csatlakoztasd újra a botot!")
118 while player.is_done():
119 guild = ctx.message.guild
120 voice_client = self.client.voice_client_in(guild)
121 await voice_client.disconnect()
122 return await ctx.message.channel.send("A zene végetért!")
123
124 async def on_reaction_add(self, reaction, user):
125 if reaction.message.id in rmenus:
126 if reaction.emoji == "⏮":
127 await self.client.send_message(reaction.message.channel, ":x: Ez a funkció jelenleg nem elérhető!")
128 elif reaction.emoji == "⏸":
129 players[reaction.message.guild].pause()
130 await self.client.send_message(reaction.message.guild, ":white_check_mark: Zene megállítva!")
131 await self.client.clear_reactions(reaction.message)
132 reactions = ["⏮", "⏸", "⏹", "⏭", "?", "⭐"]
133 for r in reactions:
134 await self.client.add_reaction(reaction.message, r)
135 elif reaction.emoji == "➡":
136 pass
137 elif reaction.emoji == "⏹":
138 await self.client.delete_message(reaction.message)
139 del players[reaction.message.guild.id]
140 del now_playing[reaction.message.guild.id]
141 del rmenus[reaction.message.id]
142 elif reaction.emoji == "⏭":
143 pass
144 elif reaction.emoji == "?":
145 pass
146 elif reaction.emoji == "⭐":
147 pass
148 else:
149 await self.client.remove_reaction(reaction.message, reaction.emoji, user)
150
151 @commands.command(pass_context=True)
152 async def radio1(self, ctx):
153 await self.client.say(":mag_right: Keresés a következőre: `Rádió1 - Élő adás`")
154 try:
155 guild = ctx.message.guild
156 url = "http://213.181.210.106:80/high.mp3"
157 try:
158 channel = ctx.message.author.voice.voice_channel
159 await self.client.join_voice_channel(channel)
160 except:
161 return False
162 voice_client = self.client.voice_client_in(guild)
163 player = await voice_client.create_ytdl_player(url)
164 players[guild.id] = player
165 player.start()
166 player.volume = 1
167 global playing
168 playing = "Jelenlegi zene: **{}**".format(player.title)
169 global last_played
170 last_played = player.url
171 embed = discord.Embed(title = "Stream elindítva", description = ":notes: `Rádió1 (96.4MHz) - Élő adás` lejátszása")
172 embed.set_footer(text = footer())
173 await self.client.say(embed=embed)
174 except:
175 await self.client.say("Hiba történt! Kérlek próbáld meg a *modkilépés* parancsot, majd a *modbelépés* parancsot! ❌")
176 #radio1.cancel()
177 while player.is_done():
178 guild = ctx.message.guild
179 voice_client = self.client.voice_client_in(guild)
180 await voice_client.disconnect()
181 await self.client.say("Az élő adást megállította valaki! Én most kilépek!")
182
183 @radio1.error
184 async def radio1_error(self, ctx, error):
185 await self.client.say("❌ Hiba lépett fel a lejátszás közben! Kérlek indítsad újra az élő adást: ``modrádió``!")
186
187
188 @commands.command(pass_context = True, aliases = ["np"])
189 async def nowplaying(self, ctx):
190 if ctx.message.guild == None:
191 return await self.client.say(":x: {}".format(nopm))
192 guild = ctx.message.guild
193 if guild.id in now_playing:
194 embed = discord.Embed(title = "Jelenleg futó zene", colour = discord.Colour.blue(), description = "Cím: **{}**\nFeltöltő: **{}**\nHossz: **{}** másodperc\nMegtekintések: **{}**".format(now_playing[guild.id]["title"], now_playing[guild.id]["author"], now_playing[guild.id]["duration"], now_playing[guild.id]["views"]))
195 embed.set_footer(text = footer())
196 await self.client.say(embed = embed)
197 else:
198 await self.client.say(":x: Jelenleg nincs futó zene!")
199
200 @commands.command(pass_context = True)
201 async def pause(self, ctx):
202 if ctx.message.guild == None:
203 return await self.client.say(":x: {}".format(nopm))
204 id = ctx.message.guild.id
205 try:
206 players[id].pause()
207 except:
208 embed = discord.Embed(description = ":x: Jelenleg nem fut semmilyen zene!", colour = discord.Colour.red())
209 return await self.client.say(embed = embed)
210 embed = discord.Embed(description = ":white_check_mark: Leállítottam a zenét!")
211 await self.client.say(embed = embed)
212
213 @commands.command(pass_context = True)
214 async def resume(self, ctx):
215 if ctx.message.guild == None:
216 return await self.client.say(":x: {}".format(nopm))
217 id = ctx.message.guild.id
218 try:
219 players[id].resume()
220 except:
221 embed = discord.Embed(description = ":x: Jelenleg nem fut semmilyen zene!", colour = discord.Colour.red())
222 return await self.client.say(embed = embed)
223 embed = discord.Embed(description = ":white_check_mark: A zene folytatódik!")
224 await self.client.say(embed = embed)
225
226 @commands.command(pass_context = True)
227 async def stop(self, ctx):
228 if ctx.message.guild == None:
229 return await self.client.say(":x: {}".format(nopm))
230 id = ctx.message.guild.id
231 try:
232 players[id].stop()
233 except:
234 embed = discord.Embed(description = ":x: Jelenleg nem fut semmilyen zene!", colour = discord.Colour.red())
235 return await self.client.say(embed = embed)
236 embed = discord.Embed(description = ":white_check_mark: Zene kikapcsolva!")
237 await self.client.say(embed = embed)
238 del players[id]
239
240 @commands.command(pass_context=True, aliases = ["vol", "v"])
241 async def volume(self, ctx, value: float = None):
242 if ctx.message.guild == None:
243 return await self.client.say(":x: {}".format(nopm))
244 if not ctx.message.guild.id in players:
245 return await self.client.say(":x: Jelenleg nincs futó zene!")
246 if value >= 0 and value <= 100:
247 vol = value / 20
248 players[ctx.message.guild.id].volume = vol
249 await self.client.say(":white_check_mark: Hangerő beállítva {}%-ra".format(value))
250 else:
251 await self.client.say(":x: Használat: {}volume [0-100]".format(prefix))
252
253
254
255def setup(client):
256 client.add_cog(Music((client)))