Compare commits

..

No commits in common. "deacd42e6eeba085f05a4840f9a998e78f771926" and "0d1620d0bd0f4a5887c51ca846b6839d9768f0c7" have entirely different histories.

3 changed files with 20 additions and 29 deletions

1
.gitignore vendored
View file

@ -1,2 +1 @@
.env .env
__pycache__/

Binary file not shown.

View file

@ -28,11 +28,7 @@ bot = commands.Bot(command_prefix="!",intents=discord.Intents.all(), shard_count
@bot.event @bot.event
async def on_ready(): async def on_ready():
print("Bot is ready!") print("Bot is ready!")
await bot.change_presence( await bot.change_presence(activity=discord.Activity(type=discord.ActivityType.listening, name="ななひら"))
activity=discord.Activity(
type=discord.ActivityType.listening, name="ななひら"
)
)
@bot.command() @bot.command()
@ -85,6 +81,9 @@ async def play(ctx, *, query: str = None):
await voice_channel.disconnect() await voice_channel.disconnect()
return return
if voice_channel.is_playing():
await ctx.send("The bot is already playing, adding song to queue", delete_after=3)
if ctx.message.attachments: if ctx.message.attachments:
downloading = 1 downloading = 1
notice = await ctx.send(":arrow_double_up: Uploading...", suppress_embeds=True) notice = await ctx.send(":arrow_double_up: Uploading...", suppress_embeds=True)
@ -231,7 +230,7 @@ async def play(ctx, *, query: str = None):
await ctx.send("Something went wrong, please try a different query.", delete_after=3) await ctx.send("Something went wrong, please try a different query.", delete_after=3)
return return
print(str(server_id) + " | " + str(item["name"])) print(str(server_id) + " | " + str(item))
if voice_channel.is_playing() or downloading == 1: if voice_channel.is_playing() or downloading == 1:
return return
@ -277,9 +276,9 @@ async def play(ctx, *, query: str = None):
stdout=subprocess.PIPE, stdout=subprocess.PIPE,
).stdout ).stdout
pipe = True pipe = True
print(str(server_id) + " | " + "Playing song through yt-dlp") print("Playing song through yt-dlp")
else: else:
print(str(server_id) + " | " + "Playing song from file") print("Playing song from file")
song_source = song_id song_source = song_id
# Play the converted audio in the voice channel from the temporary file # Play the converted audio in the voice channel from the temporary file
@ -398,7 +397,7 @@ async def skip(ctx, direction = None, number = None):
# Stop the audio playback of the current track # Stop the audio playback of the current track
voice_channel.stop() voice_channel.stop()
elif direction == "to" and number is not None: elif direction == "to" and number is not None:
server_info[server_id]["queue_position"] = number - 1 server_info[server_id]["queue_position"] = number
voice_channel.stop() voice_channel.stop()
elif server_info[server_id]["queue_position"] == 0: elif server_info[server_id]["queue_position"] == 0:
@ -474,7 +473,6 @@ async def q(ctx, action = None, selection = None):
qu = "" qu = ""
d = "" d = ""
p = "" p = ""
total_duration = 0
now_playing = "" now_playing = ""
for entry in server_info[server_id]["queue"]: for entry in server_info[server_id]["queue"]:
if index == server_info[server_id]["queue_position"]: if index == server_info[server_id]["queue_position"]:
@ -490,22 +488,18 @@ async def q(ctx, action = None, selection = None):
p += now_playing + "\n" p += now_playing + "\n"
qu += "**" + str(index + 1) + ":** " + entry_cut + "\n" qu += "**" + str(index + 1) + ":** " + entry_cut + "\n"
if int(entry['duration']) < 3600: if str(strftime("%H", gmtime(int(float(entry['duration'])))))[0:1] == "00":
d += str(strftime("%M:%S", gmtime(int(float(entry['duration']))))) + "\n" d += str(strftime("%M:%S", gmtime(int(float(entry['duration']))))) + "\n"
else: else:
d += str(strftime("%H:%M:%S", gmtime(int(float(entry['duration']))))) + "\n" d += str(strftime("%H:%M:%S", gmtime(int(float(entry['duration']))))) + "\n"
if index >= server_info[server_id]["queue_position"]:
total_duration += entry['duration']
index += 1 index += 1
total_duration = str(strftime("%H:%M:%S", gmtime(int(float(total_duration))))) embed = discord.Embed(title="Queue:", description="", color=0xa032a8)
embed = discord.Embed(title=f"Queue ({total_duration} left):", description="", color=0xa032a8)
try: try:
embed.add_field(name="", value=p, inline=True) embed.add_field(name="", value=p, inline=True)
embed.add_field(name="List", value=qu, inline=True) embed.add_field(name="List", value=qu, inline=True)
embed.add_field(name=f"Length", value=d, inline=True) embed.add_field(name="Length", value=d, inline=True)
except: except:
embed.add_field(name="List", value="Queue is **empty**", inline=False) embed.add_field(name="List", value="Queue is **empty**", inline=False)
@ -520,13 +514,13 @@ async def q(ctx, action = None, selection = None):
await queue_embed.edit(embed=embed) await queue_embed.edit(embed=embed)
return return
if action == "remove" and selection is not None: if action == "remove":
print(str(server_id) + " | " + "Removing item #" + str(selection) + " from queue") print(str(server_id) + " | " + "Removing item #" + str(selection) + " from queue")
selection = int(selection) - 1 selection = selection - 1
current_position = server_info[server_id]["queue_position"] selection = int(selection)
position = server_info[server_id]["queue_position"]
path = server_info[server_id]["queue"][selection]["id"] id = server_info[server_id]["queue"][selection]['id']
if server_info[server_id]["queue"][selection]["thumbnail"] != "/assets/unknown.png": if server_info[server_id]["queue"][selection]['thumbnail'] != "/assets/unknown.png":
thumbnail = None thumbnail = None
else: else:
thumbnail = server_info[server_id]["queue"][selection]['thumbnail'] thumbnail = server_info[server_id]["queue"][selection]['thumbnail']
@ -535,10 +529,10 @@ async def q(ctx, action = None, selection = None):
await ctx.send(":no_entry_sign: Error, cannot remove currently playing item", delete_after=3) await ctx.send(":no_entry_sign: Error, cannot remove currently playing item", delete_after=3)
return return
if selection < 0 and not int(selection) > len(server_info[server_id]["queue"]): if selection != 0 and not int(selection) > len(server_info[server_id]["queue"]):
try: try:
os.remove(path) os.remove(id)
if thumbnail is not None: if not thumbnail is None:
os.remove(thumbnail) os.remove(thumbnail)
else: else:
pass pass
@ -556,8 +550,6 @@ async def q(ctx, action = None, selection = None):
await ctx.send(":white_check_mark: Removed item #" + str(selection) + " from queue.", delete_after=3) await ctx.send(":white_check_mark: Removed item #" + str(selection) + " from queue.", delete_after=3)
server_info[server_id]["queue"].pop(selection) server_info[server_id]["queue"].pop(selection)
await q(ctx) await q(ctx)
elif action == "remove" and selection is None:
await ctx.send(":no_entry_sign: Error, please select a queue item to remove", delete_after=3)
else: else:
await ctx.send(":no_entry_sign: Error, item #" + str(selection) + "not a valid queue item", delete_after=3) await ctx.send(":no_entry_sign: Error, item #" + str(selection) + "not a valid queue item", delete_after=3)
return return