1
Fork 0
mirror of https://github.com/RYGhub/royalnet.git synced 2024-11-23 19:44:20 +00:00
This commit is contained in:
Steffo 2018-01-19 09:52:01 +01:00
parent c5e45621f2
commit 3e5afe17aa
WARNING! Although there is a key with this ID in the database it does not verify this commit! This commit is SUSPICIOUS.
GPG key ID: C27544372FBB445D
4 changed files with 63 additions and 42 deletions

14
db.py
View file

@ -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"]

View file

@ -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.")

View file

@ -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")

View file

@ -23,8 +23,7 @@
<th>Royal</th>
<th>Steam</th>
<th>Wins</th>
<th>Solo MMR</th>
<th>Party MMR</th>
<th>Rank</th>
</tr>
</thead>
<tbody>
@ -33,8 +32,7 @@
<td>{{ record.steam.royal.username }}</td>
<td><a href="http://steamcommunity.com/profiles/{{ record.steam.steam_id }}"><img src="{{ record.steam.avatar_url() }}"> {{ record.steam.persona_name }}</a></td>
<td>{{ record.wins }}</td>
<td>{{ record.solo_mmr if record.solo_mmr is not none}}</td>
<td>{{ record.party_mmr if record.party_mmr is not none}}</td>
<td><img src="{{ record.get_rank_icon_url() }}"</td>
</tr>
{% endfor %}
</tbody>