From 3e5afe17aa98d591f4abd61d7c01fdd3912d8a81 Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Fri, 19 Jan 2018 09:52:01 +0100 Subject: [PATCH] sdifjsif --- db.py | 14 ++++--- discordbot.py | 2 +- telegrambot.py | 83 +++++++++++++++++++++++-------------- templates/leaderboards.html | 6 +-- 4 files changed, 63 insertions(+), 42 deletions(-) diff --git a/db.py b/db.py index f2c0b70d..621a2aa7 100644 --- a/db.py +++ b/db.py @@ -251,12 +251,16 @@ class Dota(Base): steam_id = Column(String, ForeignKey("steam.steam_id"), primary_key=True) steam = relationship("Steam") - solo_mmr = Column(Integer) - party_mmr = Column(Integer) + rank_tier = Column(Integer) wins = Column(Integer, nullable=False) losses = Column(Integer, nullable=False) + def get_rank_icon_url(self): + if self.rank_tier is None or self.rank_tier < 10: + f"https://www.opendota.com/assets/images/dota2/rank_icons/rank_icon_0.png" + return f"https://www.opendota.com/assets/images/dota2/rank_icons/rank_icon_{self.rank_tier - 10 // 6}.png" + @staticmethod def create(session: Session, steam_id: int): d = session.query(Dota).get(steam_id) @@ -273,8 +277,7 @@ class Dota(Base): raise RequestError("OpenDota returned {r.status_code}") wl = r.json() new_record = Dota(steam_id=steam_id, - solo_mmr=data["solo_competitive_rank"], - party_mmr=data["competitive_rank"], + rank_tier=data["rank_tier"], wins=wl["win"], losses=wl["lose"]) return new_record @@ -288,8 +291,7 @@ class Dota(Base): if r.status_code != 200: raise RequestError("OpenDota returned {r.status_code}") wl = r.json() - self.solo_mmr = data["solo_competitive_rank"] - self.party_mmr = data["competitive_rank"] + self.rank_tier = data["rank_tier"] self.wins = wl["win"] self.losses = wl["lose"] diff --git a/discordbot.py b/discordbot.py index f9f70201..2616d0b9 100644 --- a/discordbot.py +++ b/discordbot.py @@ -289,7 +289,7 @@ async def on_message(message: discord.Message): if voice_player is None: await client.send_message(message.channel, f"ℹ Non c'è nulla in riproduzione al momento.") return - await client.send_message(message.channel, f"ℹ Ora in riproduzione in <#{voice_client.channel.id}>:", embed=voice_playing.create_embed()) + await client.send_message(message.channel, f"▶️ Ora in riproduzione in <#{voice_client.channel.id}>:", embed=voice_playing.create_embed()) elif message.content.startswith("!queue"): if voice_player is None: await client.send_message(message.channel, f"ℹ Non c'è nulla in riproduzione al momento.") diff --git a/telegrambot.py b/telegrambot.py index 96eb8ac3..109cae32 100644 --- a/telegrambot.py +++ b/telegrambot.py @@ -51,41 +51,62 @@ def cmd_register(bot: Bot, update: Update): def cmd_discord(bot: Bot, update: Update): discord_connection.send("/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.status == DiscordStatus.offline and member.voice.voice_channel is None: - continue - if member.bot: - continue - # Online status emoji - if member.status == DiscordStatus.online: - message += "🔵 " - elif member.status == DiscordStatus.idle: - message += "⚫️ " - elif member.status == DiscordStatus.dnd: - message += "🔴 " - elif member.status == DiscordStatus.offline: - message += "⚪️ " - # Nickname - if member.nick is not None: - message += member.nick - else: - message += member.name - # Voice if member.voice.voice_channel is not None: - # Voice status - if member.voice.self_deaf: - message += f" | 🔇 {member.voice.voice_channel.name}" - elif member.voice.self_mute: - message += f" | 🔈 {member.voice.voice_channel.name}" + 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 + if member.bot: + continue + # Online status emoji + if 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 += f" | 🔊 {member.voice.voice_channel.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})" + 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})" + message += "\n" message += "\n" bot.send_message(update.message.chat.id, message, disable_web_page_preview=True, parse_mode="Markdown") diff --git a/templates/leaderboards.html b/templates/leaderboards.html index 215a0ef0..57401067 100644 --- a/templates/leaderboards.html +++ b/templates/leaderboards.html @@ -23,8 +23,7 @@ Royal Steam Wins - Solo MMR - Party MMR + Rank @@ -33,8 +32,7 @@ {{ record.steam.royal.username }} {{ record.steam.persona_name }} {{ record.wins }} - {{ record.solo_mmr if record.solo_mmr is not none}} - {{ record.party_mmr if record.party_mmr is not none}} + {% endfor %}