Changed the notification method name
This commit is contained in:
parent
8b6aea195f
commit
3a857b641f
|
@ -10,12 +10,13 @@ from .utils import checks
|
||||||
|
|
||||||
base_url = 'https://ptvappapi.picarto.tv'
|
base_url = 'https://ptvappapi.picarto.tv'
|
||||||
|
|
||||||
#This is a public key for use, I don't care if this is seen
|
# This is a public key for use, I don't care if this is seen
|
||||||
key = '03e26294-b793-11e5-9a41-005056984bd4'
|
key = '03e26294-b793-11e5-9a41-005056984bd4'
|
||||||
|
|
||||||
|
|
||||||
async def check_online(stream):
|
async def check_online(stream):
|
||||||
try:
|
try:
|
||||||
url = '{}/channel/{}?key={}'.format(base_url,stream,key)
|
url = '{}/channel/{}?key={}'.format(base_url, stream, key)
|
||||||
with aiohttp.ClientSession(headers={"User-Agent": "Bonfire/1.0.0"}) as s:
|
with aiohttp.ClientSession(headers={"User-Agent": "Bonfire/1.0.0"}) as s:
|
||||||
async with s.get(url) as r:
|
async with s.get(url) as r:
|
||||||
response = await r.text()
|
response = await r.text()
|
||||||
|
@ -23,6 +24,7 @@ async def check_online(stream):
|
||||||
except:
|
except:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
class Picarto:
|
class Picarto:
|
||||||
def __init__(self, bot):
|
def __init__(self, bot):
|
||||||
self.bot = bot
|
self.bot = bot
|
||||||
|
@ -37,7 +39,7 @@ class Picarto:
|
||||||
notify = r['notifications_on']
|
notify = r['notifications_on']
|
||||||
channel_id = r.get('channel_id') or None
|
channel_id = r.get('channel_id') or None
|
||||||
user = re.search("(?<=picarto.tv/)(.*)", url).group(1)
|
user = re.search("(?<=picarto.tv/)(.*)", url).group(1)
|
||||||
online = await channel_online(user)
|
online = await check_online(user)
|
||||||
|
|
||||||
if not live and notify and online:
|
if not live and notify and online:
|
||||||
server = self.bot.get_server(r['server_id'])
|
server = self.bot.get_server(r['server_id'])
|
||||||
|
@ -64,7 +66,7 @@ class Picarto:
|
||||||
|
|
||||||
@commands.group(pass_context=True, invoke_without_command=True)
|
@commands.group(pass_context=True, invoke_without_command=True)
|
||||||
@checks.customPermsOrRole(send_messages=True)
|
@checks.customPermsOrRole(send_messages=True)
|
||||||
async def picarto(self, ctx, member: discord.Member=None):
|
async def picarto(self, ctx, member: discord.Member = None):
|
||||||
"""This command can be used to view Picarto stats about a certain member"""
|
"""This command can be used to view Picarto stats about a certain member"""
|
||||||
member = member or ctx.message.author
|
member = member or ctx.message.author
|
||||||
picarto_urls = config.getContent('picarto') or {}
|
picarto_urls = config.getContent('picarto') or {}
|
||||||
|
@ -75,17 +77,19 @@ class Picarto:
|
||||||
member_url = member_url['picarto_url']
|
member_url = member_url['picarto_url']
|
||||||
|
|
||||||
stream = re.search("(?<=picarto.tv/)(.*)", member_url).group(1)
|
stream = re.search("(?<=picarto.tv/)(.*)", member_url).group(1)
|
||||||
url = '{}/channel/{}?key={}'.format(base_url,stream,key)
|
url = '{}/channel/{}?key={}'.format(base_url, stream, key)
|
||||||
with aiohttp.ClientSession(headers={"User-Agent": "Bonfire/1.0.0"}) as s:
|
with aiohttp.ClientSession(headers={"User-Agent": "Bonfire/1.0.0"}) as s:
|
||||||
async with s.get(url) as r:
|
async with s.get(url) as r:
|
||||||
response = await r.text()
|
response = await r.text()
|
||||||
|
|
||||||
data = json.loads(response)
|
data = json.loads(response)
|
||||||
things_to_print = ['channel','commissions_enabled','is_nsfw','program','tablet','followers','content_type']
|
things_to_print = ['channel', 'commissions_enabled', 'is_nsfw', 'program', 'tablet', 'followers',
|
||||||
fmt = "\n".join("{}: {}".format(i.title().replace("_", " "), r) for i,r in data.items() if i in things_to_print)
|
'content_type']
|
||||||
|
fmt = "\n".join(
|
||||||
|
"{}: {}".format(i.title().replace("_", " "), r) for i, r in data.items() if i in things_to_print)
|
||||||
social_links = data.get('social_urls')
|
social_links = data.get('social_urls')
|
||||||
if social_links:
|
if social_links:
|
||||||
fmt2 = "\n".join("\t{}: {}".format(i.title().replace("_", " "), r) for i,r in social_links.items())
|
fmt2 = "\n".join("\t{}: {}".format(i.title().replace("_", " "), r) for i, r in social_links.items())
|
||||||
fmt = "{}\nSocial Links:\n{}".format(fmt, fmt2)
|
fmt = "{}\nSocial Links:\n{}".format(fmt, fmt2)
|
||||||
await self.bot.say("Picarto stats for {}: ```\n{}```".format(member.display_name, fmt))
|
await self.bot.say("Picarto stats for {}: ```\n{}```".format(member.display_name, fmt))
|
||||||
|
|
||||||
|
@ -100,7 +104,7 @@ class Picarto:
|
||||||
else:
|
else:
|
||||||
url = "https://www.{}".format(url)
|
url = "https://www.{}".format(url)
|
||||||
|
|
||||||
api_url = '{}/channel/{}?key={}'.format(base_url,re.search("https://www.picarto.tv/(.*)",url).group(1),key)
|
api_url = '{}/channel/{}?key={}'.format(base_url, re.search("https://www.picarto.tv/(.*)", url).group(1), key)
|
||||||
|
|
||||||
with aiohttp.ClientSession() as s:
|
with aiohttp.ClientSession() as s:
|
||||||
async with s.get(api_url) as r:
|
async with s.get(api_url) as r:
|
||||||
|
@ -116,9 +120,12 @@ class Picarto:
|
||||||
picarto_urls[ctx.message.author.id]['picarto_url'] = url
|
picarto_urls[ctx.message.author.id]['picarto_url'] = url
|
||||||
else:
|
else:
|
||||||
picarto_urls[ctx.message.author.id] = {'picarto_url': url, 'server_id': ctx.message.server.id,
|
picarto_urls[ctx.message.author.id] = {'picarto_url': url, 'server_id': ctx.message.server.id,
|
||||||
'channel_id': ctx.message.channel.id, 'notifications_on': 1, 'live': 0}
|
'channel_id': ctx.message.channel.id, 'notifications_on': 1,
|
||||||
|
'live': 0}
|
||||||
config.saveContent('picarto', picarto_urls)
|
config.saveContent('picarto', picarto_urls)
|
||||||
await self.bot.say("I have just saved your Picarto url {}, this channel will now send a notification when you go live".format(ctx.message.author.mention))
|
await self.bot.say(
|
||||||
|
"I have just saved your Picarto url {}, this channel will now send a notification when you go live".format(
|
||||||
|
ctx.message.author.mention))
|
||||||
|
|
||||||
@picarto.command(name='remove', aliases=['delete'], pass_context=True, no_pm=True)
|
@picarto.command(name='remove', aliases=['delete'], pass_context=True, no_pm=True)
|
||||||
@checks.customPermsOrRole(send_messages=True)
|
@checks.customPermsOrRole(send_messages=True)
|
||||||
|
@ -136,11 +143,10 @@ class Picarto:
|
||||||
|
|
||||||
@picarto.group(pass_context=True, no_pm=True, invoke_without_command=True)
|
@picarto.group(pass_context=True, no_pm=True, invoke_without_command=True)
|
||||||
@checks.customPermsOrRole(send_messages=True)
|
@checks.customPermsOrRole(send_messages=True)
|
||||||
async def notify(self, ctx, channel: discord.Channel=None):
|
async def notify(self, ctx, channel: discord.Channel = None):
|
||||||
"""This can be used to turn picarto notifications on or off
|
"""This can be used to turn picarto notifications on or off
|
||||||
Call this command by itself, with a channel name, to change which one has the notification sent to it"""
|
Call this command by itself, with a channel name, to change which one has the notification sent to it"""
|
||||||
channel = channel or ctx.message.channel
|
channel = channel or ctx.message.channel
|
||||||
server = ctx.message.server
|
|
||||||
member = ctx.message.author
|
member = ctx.message.author
|
||||||
|
|
||||||
picarto = config.getContent('picarto') or {}
|
picarto = config.getContent('picarto') or {}
|
||||||
|
@ -152,7 +158,8 @@ class Picarto:
|
||||||
|
|
||||||
picarto[member.id]['channel_id'] = channel.id
|
picarto[member.id]['channel_id'] = channel.id
|
||||||
config.saveContent('picarto', picarto)
|
config.saveContent('picarto', picarto)
|
||||||
await self.bot.say("I have just changed which channel will be notified when you go live, to {}".format(channel.name))
|
await self.bot.say(
|
||||||
|
"I have just changed which channel will be notified when you go live, to {}".format(channel.name))
|
||||||
|
|
||||||
@notify.command(name='on', aliases=['start,yes'], pass_context=True, no_pm=True)
|
@notify.command(name='on', aliases=['start,yes'], pass_context=True, no_pm=True)
|
||||||
@checks.customPermsOrRole(send_messages=True)
|
@checks.customPermsOrRole(send_messages=True)
|
||||||
|
@ -192,6 +199,8 @@ class Picarto:
|
||||||
"I will not notify if you go live anymore {}, "
|
"I will not notify if you go live anymore {}, "
|
||||||
"are you going to stream some lewd stuff you don't want people to see?~".format(
|
"are you going to stream some lewd stuff you don't want people to see?~".format(
|
||||||
ctx.message.author.mention))
|
ctx.message.author.mention))
|
||||||
|
|
||||||
|
|
||||||
def setup(bot):
|
def setup(bot):
|
||||||
p = Picarto(bot)
|
p = Picarto(bot)
|
||||||
config.loop.create_task(p.check_channels())
|
config.loop.create_task(p.check_channels())
|
||||||
|
|
Loading…
Reference in a new issue