diff --git a/discordbot.py b/discordbot.py index 38619cac..68d5c109 100644 --- a/discordbot.py +++ b/discordbot.py @@ -172,6 +172,7 @@ class Video: if self.info is not None and self.duration.total_seconds() > int(config["YouTube"]["max_duration"]): raise DurationError() # Download the file + logger.info(f"Now downloading {repr(self)}") with youtube_dl.YoutubeDL({"noplaylist": True, "format": "best", "postprocessors": [{ @@ -357,9 +358,71 @@ class RoyalDiscordBot(discord.Client): await self.wait_until_ready() while True: msg = await loop.run_in_executor(executor, connection.recv) + logger.info(f"Received \"{msg}\" from the Telegram-Discord pipe.") if msg == "get cv": discord_members = list(self.main_guild.members) - connection.send(discord_members) + channels = {0: None} + members_in_channels = {0: []} + message = "" + # Find all the channels + for member in discord_members: + if member.voice.channel is not None: + channel = members_in_channels.get(member.voice.channel.id) + if channel is None: + members_in_channels[member.voice.channel.id] = list() + channel = members_in_channels[member.voice.channel.id] + channels[member.voice.channel.id] = member.voice.channel + channel.append(member) + else: + members_in_channels[0].append(member) + # Edit the message, sorted by channel + for channel in channels: + members_in_channels[channel].sort(key=lambda x: x.nick if x.nick is not None else x.name) + if channel == 0: + message += "Non in chat vocale:\n" + else: + message += f"In #{channels[channel].name}:\n" + for member in members_in_channels[channel]: + if member.status == discord.Status.offline and member.voice.channel is None: + continue + # Online status emoji + if member.bot: + message += "๐Ÿค– " + elif member.status == discord.Status.online: + message += "๐Ÿ”ต " + elif member.status == discord.Status.idle: + message += "โšซ๏ธ " + elif member.status == discord.Status.dnd: + message += "๐Ÿ”ด " + elif member.status == discord.Status.offline: + message += "โšช๏ธ " + # Voice + if channel != 0: + # Voice status + if member.voice.self_deaf: + message += f"๐Ÿ”‡ " + elif member.voice.self_mute: + message += f"๐Ÿ”ˆ " + else: + message += f"๐Ÿ”Š " + # Nickname + if member.nick is not None: + message += member.nick + else: + message += member.name + # Game or stream + if member.activity is not None: + if member.activity == discord.ActivityType.playing: + message += f" | ๐ŸŽฎ {member.activity.name}" + elif member.activity == discord.ActivityType.streaming: + message += f" | ๐Ÿ“ก [{member.activity.name}]({member.activity.url})" + elif member.activity == discord.ActivityType.listening: + message += f" | ๐ŸŽง {member.activity.name}" + elif member.activity.type == discord.ActivityType.watching: + message += f" | ๐Ÿ“บ {member.activity.name}" + message += "\n" + message += "\n" + connection.send(message) elif msg.startswith("!"): data = msg.split(" ") if data[0] not in self.commands: @@ -420,6 +483,7 @@ class RoyalDiscordBot(discord.Client): audio_source = now_playing.create_audio_source() except FileNotDownloadedError: continue + logger.info(f"Started playing {repr(now_playing)}") voice_client.play(audio_source) del self.video_queue[0] activity = discord.Activity(name=now_playing.plain_text(), diff --git a/telegrambot.py b/telegrambot.py index 95f39430..152ad3b1 100644 --- a/telegrambot.py +++ b/telegrambot.py @@ -80,68 +80,7 @@ def cmd_discord(bot: Bot, update: Update): bot.send_message(update.message.chat.id, "โš  Il bot non รจ collegato a Discord al momento.") return discord_connection.send("get cv") - server_members = discord_connection.recv() - channels = {0: None} - members_in_channels = {0: []} - message = "" - # Find all the channels - for member in server_members: - if member.voice.voice_channel is not None: - channel = members_in_channels.get(member.voice.voice_channel.id) - if channel is None: - members_in_channels[member.voice.voice_channel.id] = list() - channel = members_in_channels[member.voice.voice_channel.id] - channels[member.voice.voice_channel.id] = member.voice.voice_channel - channel.append(member) - else: - members_in_channels[0].append(member) - # Edit the message, sorted by channel - for channel in channels: - members_in_channels[channel].sort(key=lambda x: x.nick if x.nick is not None else x.name) - if channel == 0: - message += "Non in chat vocale:\n" - else: - message += f"In #{channels[channel].name}:\n" - for member in members_in_channels[channel]: - if member.status == DiscordStatus.offline and member.voice.voice_channel is None: - continue - # Online status emoji - if member.bot: - message += "๐Ÿค– " - elif member.status == DiscordStatus.online: - message += "๐Ÿ”ต " - elif member.status == DiscordStatus.idle: - message += "โšซ๏ธ " - elif member.status == DiscordStatus.dnd: - message += "๐Ÿ”ด " - elif member.status == DiscordStatus.offline: - message += "โšช๏ธ " - # Voice - if channel != 0: - # Voice status - if member.voice.self_deaf: - message += f"๐Ÿ”‡ " - elif member.voice.self_mute: - message += f"๐Ÿ”ˆ " - else: - message += f"๐Ÿ”Š " - # Nickname - if member.nick is not None: - message += member.nick - else: - message += member.name - # Game or stream - if member.game is not None: - if member.game.type == 0: - message += f" | ๐ŸŽฎ {member.game.name}" - elif member.game.type == 1: - message += f" | ๐Ÿ“ก [{member.game.name}]({member.game.url})" - elif member.game.type == 2: - message += f" | ๐ŸŽง {member.game.name}" - elif member.game.type == 3: - message += f" | ๐Ÿ“บ {member.game.name}" - message += "\n" - message += "\n" + message = discord_connection.recv() bot.send_message(update.message.chat.id, message, disable_web_page_preview=True) @@ -428,43 +367,11 @@ def cmd_bridge(bot: Bot, update: Update): discord_connection.send(f"!{data}") result = discord_connection.recv() if result == "error": - bot.send_message(update.message.chat.id, "โš  Esecuzione del comando fallita.") + bot.send_message(update.message.chat.id, "โš  Il comando specificato non esiste.") if result == "success": bot.send_message(update.message.chat.id, "โฉ Comando eseguito su Discord.") -def cmd_wheel(bot: Bot, update: Update): - """Perchรจ il gioco d'azzardo รจ bello e salutare.""" - session = db.Session() - user = session.query(db.Telegram).filter_by(telegram_id=update.message.from_user.id).join(db.Royal).one_or_none() - if user is None: - bot.send_message(update.message.chat.id, "โš  Non sei connesso a Royalnet!\n" - "Per registrarti, utilizza il comando /register.") - session.close() - return - if user.royal.fiorygi < 1: - bot.send_message(update.message.chat.id, "โš  Non hai abbastanza fiorygi per girare la ruota!\n" - "Costa 1 fioryg.") - session.close() - return - user.royal.fiorygi -= 1 - r = random.randrange(20) - if r == 9: - bot.send_message(update.message.chat.id, "โ˜ธ๏ธ La ruota della fortuna gira, e si ferma su x8!\n" - "Hai ottenuto 8 fiorygi!") - user.royal.fiorygi += 8 - elif r == 8 or r == 7: - bot.send_message(update.message.chat.id, "โ˜ธ๏ธ La ruota della fortuna gira, e si ferma su x4!\n" - "Hai ottenuto 4 fiorygi!") - user.royal.fiorygi += 4 - else: - bot.send_message(update.message.chat.id, "โ˜ธ๏ธ La ruota della fortuna gira, e si ferma su un segno strano.\n" - "| ||\n" - "|| |_") - session.commit() - session.close() - - def parse_timestring(timestring: str) -> typing.Union[datetime.timedelta, datetime.datetime]: # Unix time try: @@ -617,7 +524,6 @@ def process(arg_discord_connection): u.dispatcher.add_handler(CommandHandler("ship", cmd_ship)) u.dispatcher.add_handler(CommandHandler("profile", cmd_profile)) u.dispatcher.add_handler(CommandHandler("bridge", cmd_bridge)) - u.dispatcher.add_handler(CommandHandler("wheel", cmd_wheel)) u.dispatcher.add_handler(CommandHandler("newevent", cmd_newevent)) u.dispatcher.add_handler(CommandHandler("calendar", cmd_calendar)) u.dispatcher.add_handler(CommandHandler("markov", cmd_markov))