1
Fork 0
mirror of https://github.com/RYGhub/royalnet.git synced 2024-11-23 19:44:20 +00:00

Possible bugfixes

This commit is contained in:
Steffo 2018-04-09 19:51:05 +02:00
parent 74e8bc3709
commit 804ca43175
2 changed files with 23 additions and 7 deletions

View file

@ -1,6 +1,5 @@
import random import random
import re import re
import discord import discord
import discord.opus import discord.opus
import discord.voice_client import discord.voice_client
@ -16,6 +15,7 @@ import typing
import os import os
import asyncio import asyncio
import configparser import configparser
import subprocess
# Queue emojis # Queue emojis
queue_emojis = [":one:", ":two:", ":three:", ":four:", ":five:", ":six:", ":seven:", ":eight:", ":nine:", ":ten:"] queue_emojis = [":one:", ":two:", ":three:", ":four:", ":five:", ":six:", ":seven:", ":eight:", ":nine:", ":ten:"]
@ -98,7 +98,6 @@ if __debug__:
version = "Dev" version = "Dev"
else: else:
# Find the latest git tag # Find the latest git tag
import subprocess
old_wd = os.getcwd() old_wd = os.getcwd()
try: try:
os.chdir(os.path.dirname(__file__)) os.chdir(os.path.dirname(__file__))
@ -113,7 +112,7 @@ client = discord.Client()
if platform.system() == "Linux": if platform.system() == "Linux":
discord.opus.load_opus("/usr/lib/x86_64-linux-gnu/libopus.so") discord.opus.load_opus("/usr/lib/x86_64-linux-gnu/libopus.so")
elif platform.system() == "Windows": elif platform.system() == "Windows":
discord.opus.load_opus("libopus-0.dll") discord.opus.load_opus("libopus-0.x64.dll")
voice_client: typing.Optional[discord.VoiceClient] = None voice_client: typing.Optional[discord.VoiceClient] = None
voice_player: typing.Optional[discord.voice_client.StreamPlayer] = None voice_player: typing.Optional[discord.voice_client.StreamPlayer] = None
@ -236,7 +235,7 @@ async def on_message(message: discord.Message):
return return
# Find the sent text # Find the sent text
try: try:
text:str = message.content.split(" ", 1)[1] text: str = message.content.split(" ", 1)[1]
except IndexError: except IndexError:
await client.send_message(message.channel, "⚠️ Non hai specificato il nome del file!\n" await client.send_message(message.channel, "⚠️ Non hai specificato il nome del file!\n"
"Sintassi corretta: `!file <nomefile>`") "Sintassi corretta: `!file <nomefile>`")
@ -277,6 +276,17 @@ async def on_message(message: discord.Message):
voice_player.stop() voice_player.stop()
voice_player = None voice_player = None
await client.send_message(message.channel, f"⏹ Riproduzione interrotta e playlist svuotata.") await client.send_message(message.channel, f"⏹ Riproduzione interrotta e playlist svuotata.")
elif message.content.startswith("!disconnect"):
if voice_client is None:
await client.send_message(message.channel, "⚠ Il bot in questo momento non è in chat vocale.")
return
if voice_player is not None:
await client.send_message(message.channel, "⚠ Prima di disconnettere il bot, interrompi la riproduzione di "
"una canzone scrivendo `!stop`.")
return
await voice_client.disconnect()
voice_client = None
await client.send_message(message.channel, "✅ Mi sono disconnesso dalla chat vocale.")
elif message.content.startswith("!queue"): elif message.content.startswith("!queue"):
msg = "Video in coda:\n" msg = "Video in coda:\n"
for position in range(10) if len(voice_queue) > 10 else range(len(voice_queue)): for position in range(10) if len(voice_queue) > 10 else range(len(voice_queue)):
@ -348,7 +358,7 @@ async def update_music_queue():
await video.download() await video.download()
except DurationError: except DurationError:
await client.send_message(client.get_channel(config["Discord"]["main_channel"]), await client.send_message(client.get_channel(config["Discord"]["main_channel"]),
f" Il file supera il limite di durata impostato in config.ini " f" Il file supera il limite di durata impostato in config.ini "
f"(`{config['YouTube']['max_duration']}` secondi).") f"(`{config['YouTube']['max_duration']}` secondi).")
continue continue
except Exception as e: except Exception as e:
@ -373,7 +383,13 @@ def process(users_connection=None):
asyncio.ensure_future(update_users_pipe(users_connection)) asyncio.ensure_future(update_users_pipe(users_connection))
asyncio.ensure_future(update_music_queue()) asyncio.ensure_future(update_music_queue())
client.on_error = on_error client.on_error = on_error
client.run(config["Discord"]["bot_token"]) while True:
try:
client.run(config["Discord"]["bot_token"])
except Exception as e:
on_error("client_run")
print(e)
print("Discordbot restarting...")
if __name__ == "__main__": if __name__ == "__main__":

View file

@ -1,4 +1,4 @@
discord.py discord.py[voice]
python-telegram-bot python-telegram-bot
flask flask
sqlalchemy sqlalchemy