Skip to content

Commit 0fa1981

Browse files
authored
Merge pull request #43 from ChocoMeow/request-song-channel
Feature: Enable Song Requests in Specific Text Channels
2 parents 021d596 + 7246974 commit 0fa1981

18 files changed

Lines changed: 323 additions & 109 deletions

File tree

cogs/basic.py

Lines changed: 44 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ async def nowplay(ctx: commands.Context, player: voicelink.Player):
6767
icon = ":red_circle:" if track.is_stream else (":pause_button:" if player.is_paused else ":arrow_forward:")
6868
embed.add_field(name="\u2800", value=f"{icon} {pbar} **[{ctime(player.position)}/{track.formatted_length}]**", inline=False)
6969

70-
return await ctx.send(embed=embed, view=LinkView(texts[2].format(track.source), track.emoji, track.uri))
70+
return await send(ctx, embed, view=LinkView(texts[2].format(track.source), track.emoji, track.uri))
7171

7272
class Basic(commands.Cog):
7373
def __init__(self, bot: commands.Bot) -> None:
@@ -148,9 +148,16 @@ async def play(self, ctx: commands.Context, *, query: str, start: str = "0", end
148148
else:
149149
position = await player.add_track(tracks[0], start_time=format_time(start), end_time=format_time(end))
150150
texts = await get_lang(ctx.guild.id, "live", "trackLoad_pos", "trackLoad")
151-
await ctx.send((f"`{texts[0]}`" if tracks[0].is_stream else "") + (texts[1].format(tracks[0].title, tracks[0].uri, tracks[0].author, tracks[0].formatted_length, position) if position >= 1 and player.is_playing else texts[2].format(tracks[0].title, tracks[0].uri, tracks[0].author, tracks[0].formatted_length)), allowed_mentions=False)
152-
except voicelink.QueueFull as e:
153-
await ctx.send(e)
151+
152+
stream_content = f"`{texts[0]}`" if tracks[0].is_stream else ""
153+
additional_content = texts[1] if position >= 1 and player.is_playing else texts[2]
154+
155+
await send(
156+
ctx,
157+
stream_content + additional_content,
158+
tracks[0].title, tracks[0].uri, tracks[0].author, tracks[0].formatted_length,
159+
position if position >= 1 and player.is_playing else None
160+
)
154161
finally:
155162
if not player.is_playing:
156163
await player.do_next()
@@ -189,10 +196,16 @@ async def _play(self, interaction: discord.Interaction, message: discord.Message
189196
else:
190197
position = await player.add_track(tracks[0])
191198
texts = await get_lang(interaction.guild.id, "live", "trackLoad_pos", "trackLoad")
192-
await interaction.followup.send((f"`{texts[0]}`" if tracks[0].is_stream else "") + (texts[1].format(tracks[0].title, tracks[0].uri, tracks[0].author, tracks[0].formatted_length, position) if position >= 1 and player.is_playing else texts[2].format(tracks[0].title, tracks[0].uri, tracks[0].author, tracks[0].formatted_length)), allowed_mentions=False)
193-
except voicelink.QueueFull as e:
194-
await interaction.followup.send(e)
195199

200+
stream_content = f"`{texts[0]}`" if tracks[0].is_stream else ""
201+
additional_content = texts[1] if position >= 1 and player.is_playing else texts[2]
202+
203+
await send(
204+
interaction,
205+
stream_content + additional_content,
206+
tracks[0].title, tracks[0].uri, tracks[0].author, tracks[0].formatted_length,
207+
position if position >= 1 and player.is_playing else None
208+
)
196209
finally:
197210
if not player.is_playing:
198211
await player.do_next()
@@ -227,7 +240,7 @@ async def search(self, ctx: commands.Context, *, query: str, platform: str = Sea
227240
query_track = "\n".join(f"`{index}.` `[{track.formatted_length}]` **{track.title[:35]}**" for index, track in enumerate(tracks[0:10], start=1))
228241
embed = discord.Embed(title=texts[0].format(query), description=texts[1].format(get_source(platform, "emoji"), platform, len(tracks[0:10]), query_track), color=settings.embed_color)
229242
view = SearchView(tracks=tracks[0:10], texts=[texts[5], texts[6]])
230-
view.response = await ctx.send(embed=embed, view=view, ephemeral=True)
243+
view.response = await send(ctx, embed, view=view, ephemeral=True)
231244

232245
await view.wait()
233246
if view.values is not None:
@@ -236,7 +249,7 @@ async def search(self, ctx: commands.Context, *, query: str, platform: str = Sea
236249
track = tracks[int(value.split(". ")[0]) - 1]
237250
position = await player.add_track(track)
238251
msg += (f"`{texts[2]}`" if track.is_stream else "") + (texts[3].format(track.title, track.uri, track.author, track.formatted_length, position) if position >= 1 else texts[4].format(track.title, track.uri, track.author, track.formatted_length))
239-
await ctx.send(msg, allowed_mentions=False)
252+
await send(ctx, msg)
240253

241254
if not player.is_playing:
242255
await player.do_next()
@@ -272,11 +285,16 @@ async def playtop(self, ctx: commands.Context, *, query: str, start: str = "0",
272285
else:
273286
position = await player.add_track(tracks[0], start_time=format_time(start), end_time=format_time(end), at_front=True)
274287
texts = await get_lang(ctx.guild.id, "live", "trackLoad_pos", "trackLoad")
275-
await ctx.send((f"`{texts[0]}`" if tracks[0].is_stream else "") + (texts[1].format(tracks[0].title, tracks[0].uri, tracks[0].author, tracks[0].formatted_length, position) if position >= 1 and player.is_playing else texts[2].format(tracks[0].title, tracks[0].uri, tracks[0].author, tracks[0].formatted_length)), allowed_mentions=False)
276-
277-
except voicelink.QueueFull as e:
278-
await ctx.send(e)
279288

289+
stream_content = f"`{texts[0]}`" if tracks[0].is_stream else ""
290+
additional_content = texts[1] if position >= 1 and player.is_playing else texts[2]
291+
292+
await send(
293+
ctx,
294+
stream_content + additional_content,
295+
tracks[0].title, tracks[0].uri, tracks[0].author, tracks[0].formatted_length,
296+
position if position >= 1 and player.is_playing else None
297+
)
280298
finally:
281299
if not player.is_playing:
282300
await player.do_next()
@@ -311,11 +329,14 @@ async def forceplay(self, ctx: commands.Context, *, query: str, start: str = "0"
311329
else:
312330
texts = await get_lang(ctx.guild.id, "live", "trackLoad")
313331
await player.add_track(tracks[0], start_time=format_time(start), end_time=format_time(end), at_front=True)
314-
await ctx.send((f"`{texts[0]}`" if tracks[0].is_stream else "") + texts[1].format(tracks[0].title, tracks[0].uri, tracks[0].author, tracks[0].formatted_length), allowed_mentions=False)
315332

316-
except voicelink.QueueFull as e:
317-
await ctx.send(e)
333+
stream_content = f"`{texts[0]}`" if tracks[0].is_stream else ""
318334

335+
await send(
336+
ctx,
337+
stream_content + texts[1],
338+
tracks[0].title, tracks[0].uri, tracks[0].author, tracks[0].formatted_length,
339+
)
319340
finally:
320341
if player.queue._repeat.mode == voicelink.LoopType.TRACK:
321342
await player.set_repeat(voicelink.LoopType.OFF)
@@ -471,7 +492,7 @@ async def queue(self, ctx: commands.Context):
471492
if player.queue.is_empty:
472493
return await nowplay(ctx, player)
473494
view = ListView(player=player, author=ctx.author)
474-
view.response = await ctx.send(embed=await view.build_embed(), view=view)
495+
view.response = await send(ctx, await view.build_embed(), view=view)
475496

476497
@queue.command(name="export", aliases=get_aliases("export"))
477498
@commands.dynamic_cooldown(cooldown_check, commands.BucketType.guild)
@@ -532,10 +553,6 @@ async def _import(self, ctx: commands.Context, attachment: discord.Attachment):
532553

533554
index = await player.add_track(tracks)
534555
await send(ctx, "playlistLoad", attachment.filename, index)
535-
536-
except voicelink.QueueFull as e:
537-
return await ctx.send(e, ephemeral=True)
538-
539556
except Exception as e:
540557
logger.error("error", exc_info=e)
541558
raise e
@@ -559,7 +576,7 @@ async def history(self, ctx: commands.Context):
559576
return await nowplay(ctx, player)
560577

561578
view = ListView(player=player, author=ctx.author, is_queue=False)
562-
view.response = await ctx.send(embed=await view.build_embed(), view=view)
579+
view.response = await send(ctx, await view.build_embed(), view=view)
563580

564581
@commands.hybrid_command(name="leave", aliases=get_aliases("leave"))
565582
@commands.dynamic_cooldown(cooldown_check, commands.BucketType.guild)
@@ -653,7 +670,7 @@ async def remove(self, ctx: commands.Context, position1: int, position2: int = N
653670
await send(ctx, "removed", len(removed_tracks.keys()))
654671

655672
@commands.hybrid_command(name="forward", aliases=get_aliases("forward"))
656-
@app_commands.describe(position="Input a amount that you to forward to. Exmaple: 1:20")
673+
@app_commands.describe(position="Input an amount that you to forward to. Exmaple: 1:20")
657674
@commands.dynamic_cooldown(cooldown_check, commands.BucketType.guild)
658675
async def forward(self, ctx: commands.Context, position: str = "10"):
659676
"Forwards by a certain amount of time in the current track. The default is 10 seconds."
@@ -674,7 +691,7 @@ async def forward(self, ctx: commands.Context, position: str = "10"):
674691
await send(ctx, "forward", ctime(player.position + num))
675692

676693
@commands.hybrid_command(name="rewind", aliases=get_aliases("rewind"))
677-
@app_commands.describe(position="Input a amount that you to rewind to. Exmaple: 1:20")
694+
@app_commands.describe(position="Input an amount that you to rewind to. Exmaple: 1:20")
678695
@commands.dynamic_cooldown(cooldown_check, commands.BucketType.guild)
679696
async def rewind(self, ctx: commands.Context, position: str = "10"):
680697
"Rewind by a certain amount of time in the current track. The default is 10 seconds."
@@ -785,7 +802,7 @@ async def lyrics(self, ctx: commands.Context, title: str = "", artist: str = "")
785802
return await send(ctx, "lyricsNotFound", ephemeral=True)
786803

787804
view = LyricsView(name=title, source={_: re.findall(r'.*\n(?:.*\n){,22}', v) for _, v in song.items()}, author=ctx.author)
788-
view.response = await ctx.send(embed=view.build_embed(), view=view)
805+
view.response = await send(ctx, view.build_embed(), view=view)
789806

790807
@commands.hybrid_command(name="swapdj", aliases=get_aliases("swapdj"))
791808
@app_commands.describe(member="Choose a member to transfer the dj role.")
@@ -841,7 +858,7 @@ async def help(self, ctx: commands.Context, category: str = "News") -> None:
841858
category = "News"
842859
view = HelpView(self.bot, ctx.author)
843860
embed = view.build_embed(category)
844-
view.response = await ctx.send(embed=embed, view=view)
861+
view.response = await send(ctx, embed, view=view)
845862

846863
@commands.hybrid_command(name="ping", aliases=get_aliases("ping"))
847864
@commands.dynamic_cooldown(cooldown_check, commands.BucketType.guild)
@@ -866,7 +883,7 @@ async def ping(self, ctx: commands.Context):
866883
inline=False
867884
)
868885

869-
await ctx.send(embed=embed)
886+
await send(ctx, embed)
870887

871888
async def setup(bot: commands.Bot) -> None:
872889
await bot.add_cog(Basic(bot))

cogs/playlist.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ async def playlist_autocomplete(self, interaction: discord.Interaction, current:
107107
async def playlist(self, ctx: commands.Context):
108108
view = HelpView(self.bot, ctx.author)
109109
embed = view.build_embed(self.qualified_name)
110-
view.response = await ctx.send(embed=embed, view=view)
110+
view.response = send(ctx, embed, view=view)
111111

112112
@playlist.command(name="play", aliases=get_aliases("play"))
113113
@app_commands.describe(
@@ -212,7 +212,7 @@ async def view(self, ctx: commands.Context) -> None:
212212
embed.set_footer(text=text[2])
213213

214214
view = PlaylistView(embed, results, ctx.author)
215-
view.response = await ctx.send(embed=embed, view=view, ephemeral=True)
215+
view.response = await send(ctx, embed, view=view, ephemeral=True)
216216

217217
@playlist.command(name="create", aliases=get_aliases("create"))
218218
@app_commands.describe(
@@ -344,7 +344,7 @@ async def inbox(self, ctx: commands.Context) -> None:
344344

345345
inbox = user['inbox'].copy()
346346
view = InboxView(ctx.author, user['inbox'])
347-
view.response = await ctx.send(embed=view.build_embed(), view=view, ephemeral=True)
347+
view.response = await send(ctx, view.build_embed(), view=view, ephemeral=True)
348348
await view.wait()
349349

350350
if inbox == user['inbox']:

cogs/settings.py

Lines changed: 46 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,16 @@ def __init__(self, bot) -> None:
5858
async def settings(self, ctx: commands.Context):
5959
view = HelpView(self.bot, ctx.author)
6060
embed = view.build_embed(self.qualified_name)
61-
view.response = await ctx.send(embed=embed, view=view)
61+
view.response = await send(ctx, embed, view=view)
6262

6363
@settings.command(name="prefix", aliases=get_aliases("prefix"))
6464
@commands.has_permissions(manage_guild=True)
6565
@commands.dynamic_cooldown(cooldown_check, commands.BucketType.guild)
6666
async def prefix(self, ctx: commands.Context, prefix: str):
6767
"Change the default prefix for message commands."
68+
if not self.bot.intents.message_content:
69+
return await send(ctx, "missingIntents", "MESSAGE_CONTENT", ephemeral=True)
70+
6871
await update_settings(ctx.guild.id, {"$set": {"prefix": prefix}})
6972
await send(ctx, "setPrefix", prefix, prefix)
7073

@@ -170,7 +173,7 @@ async def view(self, ctx: commands.Context):
170173
),
171174
inline=False
172175
)
173-
await ctx.send(embed=embed)
176+
await send(ctx, embed)
174177

175178
@settings.command(name="volume", aliases=get_aliases("volume"))
176179
@app_commands.describe(value="Input a integer.")
@@ -226,7 +229,7 @@ async def customcontroller(self, ctx: commands.Context):
226229
controller_settings = settings.get("default_controller", func.settings.controller)
227230

228231
view = EmbedBuilderView(ctx, controller_settings.get("embeds").copy())
229-
view.response = await ctx.send(embed=view.build_embed(), view=view)
232+
view.response = await send(ctx, view.build_embed(), view=view)
230233

231234
@settings.command(name="controllermsg", aliases=get_aliases("controllermsg"))
232235
@commands.has_permissions(manage_guild=True)
@@ -243,9 +246,46 @@ async def controllermsg(self, ctx: commands.Context):
243246
@commands.has_permissions(manage_guild=True)
244247
@commands.dynamic_cooldown(cooldown_check, commands.BucketType.guild)
245248
async def stageannounce(self, ctx: commands.Context, template: str = None):
246-
"""Customize the channel topic template"""
249+
"Customize the channel topic template"
247250
await update_settings(ctx.guild.id, {"$set": {'stage_announce_template': template}})
248-
await send(ctx, "SetStageAnnounceTemplate")
251+
await send(ctx, "setStageAnnounceTemplate")
252+
253+
@settings.command(name="setupchannel", aliases=get_aliases("setupchannel"))
254+
@app_commands.describe(
255+
channel="Provide a request channel. If not, a text channel will be generated."
256+
)
257+
@commands.has_permissions(manage_guild=True)
258+
@commands.dynamic_cooldown(cooldown_check, commands.BucketType.guild)
259+
async def setupchannel(self, ctx: commands.Context, channel: discord.TextChannel = None) -> None:
260+
"Sets up a dedicated channel for song requests in your server."
261+
if not self.bot.intents.message_content:
262+
return await send(ctx, "missingIntents", "MESSAGE_CONTENT", ephemeral=True)
263+
264+
if not channel:
265+
try:
266+
overwrites = {
267+
ctx.guild.me: discord.PermissionOverwrite(
268+
read_messages=True,
269+
manage_messages=True
270+
)
271+
}
272+
channel = await ctx.guild.create_text_channel("vocard-song-requests", overwrites=overwrites)
273+
except:
274+
return await send(ctx, "noCreatePermission")
275+
276+
channel_perms = channel.permissions_for(ctx.me)
277+
if not channel_perms.text() and not channel_perms.manage_messages:
278+
return await send(ctx, "noCreatePermission")
279+
280+
settings = await func.get_settings(ctx.guild.id)
281+
controller = settings.get("default_controller", func.settings.controller).get("embeds", {}).get("inactive", {})
282+
message = await channel.send(embed=voicelink.build_embed(controller, voicelink.Placeholders(self.bot)))
283+
284+
await update_settings(ctx.guild.id, {"$set": {'music_request_channel': {
285+
"text_channel_id": channel.id,
286+
"controller_msg_id": message.id,
287+
}}})
288+
await send(ctx, "createSongRequestChannel", channel.mention)
249289

250290
@app_commands.command(name="debug")
251291
async def debug(self, interaction: discord.Interaction):
@@ -268,7 +308,7 @@ async def debug(self, interaction: discord.Interaction):
268308
value=f"```• VERSION: {func.settings.version}\n" \
269309
f"• LATENCY: {self.bot.latency:.2f}ms\n" \
270310
f"• GUILDS: {len(self.bot.guilds)}\n" \
271-
f"• USERS: {sum([guild.member_count for guild in self.bot.guilds])}\n" \
311+
f"• USERS: {sum([guild.member_count or 0 for guild in self.bot.guilds])}\n" \
272312
f"• PLAYERS: {len(self.bot.voice_clients)}```",
273313
inline=False
274314
)

0 commit comments

Comments
 (0)