From c46d607bb1c0437483501760aa3afafac6ad6027 Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Tue, 19 Jul 2016 12:26:55 +0200 Subject: [PATCH] non so cosa ho scritto ti prego funziona --- bot.py | 35 +++++++++++++++++++++++++++++++++-- discord.py | 11 +++++++++++ 2 files changed, 44 insertions(+), 2 deletions(-) create mode 100644 discord.py diff --git a/bot.py b/bot.py index cef09387..2b9d68f0 100644 --- a/bot.py +++ b/bot.py @@ -8,6 +8,7 @@ import random import osu import hearthstone import lol +import discord # Elenco di username dei membri della RYG royalgames = json.loads(filemanager.readfile("db.json")) @@ -320,7 +321,37 @@ while True: telegram.sendmessage("Automaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa! Devi funzionare, cavolo!", sentin, source) - elif text.startswith('/online') or text.startswith('/cv'): + elif text.startswith('/cv'): + # Elenco di tutte le persone online su Discord + tosend = "*Su Discord ora:*\n" + r = discord.getwidgetdata("176353500710699008") + for member in r['members']: + # Credo di aver scritto il peggior algoritmo di sempre. gg me + if 'channel_id' in member: + if deaf or self_deaf: + emoji = chr(128263) + elif mute or self_mute: + emoji = chr(128264) + else: + emoji = chr(128266) + for channel in r['channels']: + if member['channel_id'] == channel['id']: + channelname = channel['name'] + break + else: + if member['status'] == "online": + if 'game' in member: + gamename = member['game']['name'] + emoji = chr(128308) + else: + emoji = chr(128309) + else: + emoji = chr(9899) + name = member['username'] + if gamename in locals() and channelname in locals(): + tosend += "{emoji} *{channelname}* {name} | _{gamename}_" + telegram.sendmessage(tosend, sentin, source) + elif text.startswith('/online'): # Elenco di tutte le persone online su Steam print("@" + username + ": /online ") # Informa Telegram che il messaggio è stato ricevuto. @@ -339,7 +370,7 @@ while True: for membro in royalgames: if "steam" in royalgames[membro]: userids += str(royalgames[membro]["steam"]) + ',' - tosend = "*Online ora:*\n" + tosend = "*Su Steam ora:*\n" r = steam.getplayersummaries(userids) for player in r: # In gioco diff --git a/discord.py b/discord.py new file mode 100644 index 00000000..f273418d --- /dev/null +++ b/discord.py @@ -0,0 +1,11 @@ +import filemanager +import requests + +# No, non ci sto nemmeno più provando a scrivere decentemente il bot. E' una schifezza e andrebbe rifatto da capo. +def getwidgetdata(token): + r = requests.get("https://discordapp.com/api/servers/{0}/widget.json".format(token)) + if r.status_code == 200: + return r.json + else: + # Sì, dovrei fare una DiscordException + raise Exception("Qualcosa di discord non va")