1
Fork 0
mirror of https://github.com/RYGhub/royalnet.git synced 2024-11-30 15:04:18 +00:00

Miglioramenti al musicbot e altre piccole cose

This commit is contained in:
Steffo 2018-05-28 00:08:28 +02:00
parent 673e3892c1
commit 87e492127d
2 changed files with 70 additions and 0 deletions

View file

@ -308,6 +308,14 @@ async def on_message(message: discord.Message):
await cmd_play(channel=message.channel, await cmd_play(channel=message.channel,
author=message.author, author=message.author,
params=message.content.split(" ")) params=message.content.split(" "))
elif message.content.startswith("!remove"):
await cmd_remove(channel=message.channel,
author=message.author,
params=message.content.split(" "))
elif message.content.startswith("!queue"):
await cmd_queue(channel=message.channel,
author=message.author,
params=message.content.split(" "))
elif message.content.startswith("!cast"): elif message.content.startswith("!cast"):
try: try:
spell = message.content.split(" ", 1)[1] spell = message.content.split(" ", 1)[1]
@ -332,6 +340,8 @@ async def update_users_pipe(users_connection):
if msg == "/cv": if msg == "/cv":
discord_members = list(client.get_server(config["Discord"]["server_id"]).members) discord_members = list(client.get_server(config["Discord"]["server_id"]).members)
users_connection.send(discord_members) users_connection.send(discord_members)
if msg == "/uranium":
add_video_from_url("https://www.youtube.com/watch?v=iutuQbMAx04")
def command(func): def command(func):
@ -465,6 +475,51 @@ async def cmd_play(channel: discord.Channel, author: discord.Member, params: typ
await client.send_message(channel, f"✅ Video aggiunto alla coda.") await client.send_message(channel, f"✅ Video aggiunto alla coda.")
@command
@requires_cv
async def cmd_skip(channel: discord.Channel, author: discord.Member, params: typing.List[str]):
global voice_player
voice_player.stop()
await client.send_message(channel, f"⏩ Video saltato.")
@command
@requires_cv
async def cmd_remove(channel: discord.Channel, author: discord.Member, params: typing.List[str]):
if len(voice_queue) == 0:
await client.send_message(channel, "⚠ Non c'è nessun video in coda.")
return
if len(params) < 2:
index = len(voice_queue) - 1
else:
try:
index = int(params[1]) - 1
except ValueError:
await client.send_message(channel, "⚠ Il numero inserito non è valido.\n"
"Sintassi: `!remove [numerovideo]`")
return
if abs(index) >= len(voice_queue):
await client.send_message(channel, "⚠ Il numero inserito non corrisponde a nessun video nella playlist.\n"
"Sintassi: `!remove [numerovideo]`")
return
video = voice_queue.pop(index)
await client.send_message(channel, f":regional_indicator_x: {str(video)} è stato rimosso dalla coda.")
@command
async def cmd_queue(channel: discord.Channel, author: discord.Member, params: typing.List[str]):
if len(voice_queue) == 0:
await client.send_message(channel, "**Video in coda:**\n"
"nessuno")
return
msg = "**Video in coda:**\n"
for index, video in enumerate(voice_queue[:10]):
msg += f"{queue_emojis[index]} {str(video)}\n"
if len(voice_queue) > 10:
msg += f"più altri {len(voice_queue) - 10} video!"
await client.send_message(channel, msg)
async def queue_predownload_videos(): async def queue_predownload_videos():
while True: while True:
for index, video in enumerate(voice_queue[:int(config["YouTube"]["predownload_videos"])].copy()): for index, video in enumerate(voice_queue[:int(config["YouTube"]["predownload_videos"])].copy()):

View file

@ -351,6 +351,20 @@ def cmd_ban(bot: Bot, update: Update):
session.close() session.close()
def cmd_eat(bot: Bot, update: Update):
try:
food: str = update.message.text.split(" ", 1)[1].capitalize()
except IndexError:
bot.send_message(update.message.chat.id, "⚠️ Non hai specificato cosa mangiare!\n"
"Sintassi corretta: `/food <cibo>`")
return
if food == "Uranio" and discord_connection is not None:
bot.send_message(update.message.chat.id, f"☢️ Ti senti improvvisamente radioattivo.")
discord_connection.send("/uranium")
return
bot.send_message(update.message.chat.id, f"🍗 Hai mangiato {food}!")
def process(arg_discord_connection): def process(arg_discord_connection):
print("Telegrambot starting...") print("Telegrambot starting...")
if arg_discord_connection is not None: if arg_discord_connection is not None:
@ -369,6 +383,7 @@ def process(arg_discord_connection):
u.dispatcher.add_handler(CommandHandler("diario", cmd_diario)) u.dispatcher.add_handler(CommandHandler("diario", cmd_diario))
u.dispatcher.add_handler(CommandHandler("vote", cmd_vote)) u.dispatcher.add_handler(CommandHandler("vote", cmd_vote))
u.dispatcher.add_handler(CommandHandler("ban", cmd_ban)) u.dispatcher.add_handler(CommandHandler("ban", cmd_ban))
u.dispatcher.add_handler(CommandHandler("eat", cmd_eat))
u.dispatcher.add_handler(CallbackQueryHandler(on_callback_query)) u.dispatcher.add_handler(CallbackQueryHandler(on_callback_query))
u.bot.send_message(config["Telegram"]["main_group"], u.bot.send_message(config["Telegram"]["main_group"],
f" Royal Bot avviato e pronto a ricevere comandi!\n" f" Royal Bot avviato e pronto a ricevere comandi!\n"