1
Fork 0
mirror of https://github.com/RYGhub/royalnet.git synced 2024-11-27 13:34:28 +00:00

Move radio messages inside the class

This commit is contained in:
Steffo 2019-01-02 20:33:15 +01:00
parent de79bd5ed8
commit da8af8baf9

View file

@ -27,26 +27,21 @@ logger = logging.getLogger(__name__)
os.environ["COLOREDLOGS_LOG_FORMAT"] = "%(asctime)s %(levelname)s %(name)s %(message)s" os.environ["COLOREDLOGS_LOG_FORMAT"] = "%(asctime)s %(levelname)s %(name)s %(message)s"
coloredlogs.install(level="DEBUG", logger=logger) coloredlogs.install(level="DEBUG", logger=logger)
# Queue emojis # Number emojis from one to ten
queue_emojis = [":one:", number_emojis = [":one:",
":two:", ":two:",
":three:", ":three:",
":four:", ":four:",
":five:", ":five:",
":six:", ":six:",
":seven:", ":seven:",
":eight:", ":eight:",
":nine:", ":nine:",
":keycap_ten:"] ":keycap_ten:"]
# Init the event loop # Init the event loop
loop = asyncio.get_event_loop() loop = asyncio.get_event_loop()
# Radio messages
radio_messages = ["https://www.youtube.com/watch?v=3-yeK1Ck4yk",
"https://youtu.be/YcR7du_A1Vc",
"https://clyp.it/byg3i52l"]
song_special_messages = { song_special_messages = {
"despacito": ":arrow_forward: this is so sad. alexa play {song}", "despacito": ":arrow_forward: this is so sad. alexa play {song}",
"faded": ":arrow_forward: Basta Garf, lasciami ascoltare {song}", "faded": ":arrow_forward: Basta Garf, lasciami ascoltare {song}",
@ -482,12 +477,26 @@ class RoyalDiscordBot(discord.Client):
self.max_video_ready_time = math.inf self.max_video_ready_time = math.inf
# Radio messages # Radio messages
try: try:
self.radio_messages_enabled = True if config["Discord"]["radio_messages_enabled"] == "True" else False if config["Discord"]["radio_messages_enabled"] == "True":
self.radio_messages_every = int(config["Discord"]["radio_messages_every"]) self.radio_messages = ["https://www.youtube.com/watch?v=3-yeK1Ck4yk",
self.radio_messages_next_in = self.radio_messages_every "https://youtu.be/YcR7du_A1Vc",
"https://clyp.it/byg3i52l"]
try:
self.radio_messages_every = int(config["Discord"]["radio_messages_every"])
self.radio_messages_next_in = self.radio_messages_every
except (KeyError, ValueError):
logger.warning("Radio messages config error, disabling them.")
self.radio_messages = []
self.radio_messages_every = math.inf
self.radio_messages_next_in = math.inf
else:
logger.info("Radio messages are force-disabled.")
self.radio_messages = []
self.radio_messages_every = math.inf
self.radio_messages_next_in = math.inf
except (KeyError, ValueError): except (KeyError, ValueError):
logger.warning("Radio messages config error, disabling them.") logger.warning("Radio messages config error, disabling them.")
self.radio_messages_enabled = False self.radio_messages = []
self.radio_messages_every = math.inf self.radio_messages_every = math.inf
self.radio_messages_next_in = math.inf self.radio_messages_next_in = math.inf
# Activity reporting # Activity reporting
@ -503,6 +512,7 @@ class RoyalDiscordBot(discord.Client):
logger.warning("Sentry client config error, disabling it.") logger.warning("Sentry client config error, disabling it.")
self.sentry_token = None self.sentry_token = None
# noinspection PyAsyncCall # noinspection PyAsyncCall
async def on_ready(self): async def on_ready(self):
# Get the main guild # Get the main guild
@ -1017,12 +1027,12 @@ class RoyalDiscordBot(discord.Client):
msg += f":arrow_forward: {str(self.video_queue.now_playing)}\n" msg += f":arrow_forward: {str(self.video_queue.now_playing)}\n"
if self.video_queue.loop_mode == LoopMode.NORMAL: if self.video_queue.loop_mode == LoopMode.NORMAL:
for index, video in enumerate(self.video_queue.list[:10]): for index, video in enumerate(self.video_queue.list[:10]):
msg += f"{queue_emojis[index]} {str(video)}\n" msg += f"{number_emojis[index]} {str(video)}\n"
if len(self.video_queue) > 10: if len(self.video_queue) > 10:
msg += f"più altri {len(self.video_queue) - 10} video!" msg += f"più altri {len(self.video_queue) - 10} video!"
elif self.video_queue.loop_mode == LoopMode.LOOP_QUEUE: elif self.video_queue.loop_mode == LoopMode.LOOP_QUEUE:
for index, video in enumerate(self.video_queue.list[:10]): for index, video in enumerate(self.video_queue.list[:10]):
msg += f"{queue_emojis[index]} {str(video)}\n" msg += f"{number_emojis[index]} {str(video)}\n"
if len(self.video_queue) > 10: if len(self.video_queue) > 10:
msg += f"più altri {len(self.video_queue) - 10} video che si ripetono!" msg += f"più altri {len(self.video_queue) - 10} video che si ripetono!"
else: else:
@ -1082,7 +1092,7 @@ class RoyalDiscordBot(discord.Client):
@command @command
async def cmd_radiomessages(self, channel: discord.TextChannel, author: discord.Member, params: typing.List[str]): async def cmd_radiomessages(self, channel: discord.TextChannel, author: discord.Member, params: typing.List[str]):
if not self.radio_messages_enabled: if not self.radio_messages:
await channel.send("⚠ I messaggi radio sono stati disabilitati dall'amministratore del bot.") await channel.send("⚠ I messaggi radio sono stati disabilitati dall'amministratore del bot.")
return return
if len(params) < 2: if len(params) < 2: