diff --git a/bot.py b/bot.py index 4c1f85ef..e0354ee5 100644 --- a/bot.py +++ b/bot.py @@ -308,10 +308,7 @@ def cv(): m['emoji'] = chr(128264) else: m['emoji'] = chr(128266) - for channel in r['channels']: - if member['channel_id'] == channel['id']: - m['channelname'] = channel['name'] - break + m['channelname'] = discord.getchannelname(r, member['channel_id']) else: if member['status'] == "online": if 'game' in member: @@ -332,13 +329,9 @@ def cv(): else: tosend += "{emoji} {name}\n".format(**m) # Controlla se l'utente è royal music - elif 'id' == "176358898851250176": + elif member['id'] == "176358898851250176": if 'game' in member: - for channel in r['channels']: - if member['channel_id'] == channel['id']: - musicchannel = channel['name'] - break - # Todo: migliorami + musicchannel = discord.getchannelname(r, member['channel_id']) musicstatus = "{emoji} *{channelname}* {songname}\n".format(emoji="\U0001F3B5", channelname=musicchannel, songname=member['game']['name']) diff --git a/discord.py b/discord.py index 721342b2..806c3d72 100644 --- a/discord.py +++ b/discord.py @@ -9,3 +9,8 @@ def getwidgetdata(token): else: # Sì, dovrei fare una DiscordException raise Exception("Qualcosa di discord non va") + +def getchannelname(r, id): + for channel in r['channels']: + if id == channel['id']: + return channel['name']