1
0
Fork 0
mirror of synced 2024-05-18 11:32:26 +12:00

Changed which endpoint was checked, so there's no need to make an http request for every user to check if they are online

This commit is contained in:
Phxntxm 2016-08-11 14:33:19 -05:00
parent 0f1e566b04
commit dee1b616f2
2 changed files with 11 additions and 7 deletions

View file

@ -21,7 +21,7 @@ class Mod:
server_alerts = config.getContent('server_alerts') or {}
server_alerts[ctx.message.server.id] = channel.id
await self.bot.say("I have just changed this server's 'notifications' channel"
"All notifications will now go to {}".format(channel))
"\nAll notifications will now go to `{}`".format(channel))
@commands.command(pass_context=True, no_pm=True)
@checks.customPermsOrRole(kick_members=True)
@ -33,7 +33,7 @@ class Mod:
notifications = config.getContent('user_notifications') or {}
notifications[ctx.message.server.id] = on_off
config.saveContent('user_notifications',notifications)
fmt = "notify, in this channel" if on_off else "not notify"
fmt = "notify" if on_off else "not notify"
await self.bot.say("This server will now {} if someone has joined or left".format(fmt))
@commands.group(pass_context=True, no_pm=True)

View file

@ -14,16 +14,19 @@ base_url = 'https://ptvappapi.picarto.tv'
key = '03e26294-b793-11e5-9a41-005056984bd4'
async def check_online(stream):
async def online_users():
try:
url = '{}/channel/{}?key={}'.format(base_url, stream, key)
url = '{}/online/all?key={}'.format(base_url, key)
with aiohttp.ClientSession(headers={"User-Agent": "Bonfire/1.0.0"}) as s:
async with s.get(url) as r:
response = await r.text()
return json.loads(response).get('is_online')
return json.loads(response)
except:
return False
return {}
def check_online(online_channels, channel):
matches = [stream for stream in online_channels if stream['channel_name'].lower() == channel.lower()]
return len(matches) > 0
class Picarto:
def __init__(self, bot):
@ -33,12 +36,13 @@ class Picarto:
await self.bot.wait_until_ready()
while not self.bot.is_closed:
picarto = config.getContent('picarto') or {}
online_users = await online_users()
for m_id, r in picarto.items():
url = r['picarto_url']
live = r['live']
notify = r['notifications_on']
user = re.search("(?<=picarto.tv/)(.*)", url).group(1)
online = await check_online(user)
online = check_online(online_users, user)
if not live and notify and online:
for server_id in r['servers'].items():