Fixed issue where required skips was not being set when first starting a queue
This commit is contained in:
parent
09c9e34dbb
commit
2486f62640
|
@ -186,8 +186,6 @@ class Music:
|
||||||
if state.voice is None:
|
if state.voice is None:
|
||||||
return
|
return
|
||||||
voice_channel = state.voice.channel
|
voice_channel = state.voice.channel
|
||||||
if voice_channel != before.voice.voice_channel and voice_channel != after.voice.voice_channel:
|
|
||||||
return
|
|
||||||
num_members = len(voice_channel.voice_members)
|
num_members = len(voice_channel.voice_members)
|
||||||
state.required_skips = math.ceil((num_members + 1) / 3)
|
state.required_skips = math.ceil((num_members + 1) / 3)
|
||||||
|
|
||||||
|
@ -296,6 +294,10 @@ class Music:
|
||||||
await self.bot.say("You are not currently in the channel; please join before trying to request a song.")
|
await self.bot.say("You are not currently in the channel; please join before trying to request a song.")
|
||||||
return
|
return
|
||||||
|
|
||||||
|
# Set the number of required skips to start
|
||||||
|
num_members = len(my_channel.voice_members)
|
||||||
|
state.required_skips = math.ceil((num_members + 1) / 3)
|
||||||
|
|
||||||
# Create the player, and check if this was successful
|
# Create the player, and check if this was successful
|
||||||
# Here all we want is to get the information of the player
|
# Here all we want is to get the information of the player
|
||||||
song = re.sub('[<>\[\]]', '', song)
|
song = re.sub('[<>\[\]]', '', song)
|
||||||
|
|
|
@ -7,8 +7,8 @@ import traceback
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from discord.ext import commands
|
from discord.ext import commands
|
||||||
from .utils import config
|
|
||||||
from .utils import checks
|
from . import utils
|
||||||
|
|
||||||
log = logging.getLogger()
|
log = logging.getLogger()
|
||||||
base_url = 'https://ptvappapi.picarto.tv'
|
base_url = 'https://ptvappapi.picarto.tv'
|
||||||
|
@ -24,7 +24,7 @@ async def online_users():
|
||||||
# In place of requesting for /channel and checking if that is online currently, for each channel
|
# In place of requesting for /channel and checking if that is online currently, for each channel
|
||||||
# This method is in place to just return all online_users
|
# This method is in place to just return all online_users
|
||||||
url = '{}/online/all?key={}'.format(base_url, key)
|
url = '{}/online/all?key={}'.format(base_url, key)
|
||||||
with aiohttp.ClientSession(headers={"User-Agent": config.user_agent}) as s:
|
with aiohttp.ClientSession(headers={"User-Agent": utils.user_agent}) as s:
|
||||||
async with s.get(url) as response:
|
async with s.get(url) as response:
|
||||||
return await response.json()
|
return await response.json()
|
||||||
except:
|
except:
|
||||||
|
@ -43,7 +43,7 @@ def check_online(online_channels, channel):
|
||||||
class Picarto:
|
class Picarto:
|
||||||
def __init__(self, bot):
|
def __init__(self, bot):
|
||||||
self.bot = bot
|
self.bot = bot
|
||||||
self.headers = {"User-Agent": config.user_agent}
|
self.headers = {"User-Agent": utils.user_agent}
|
||||||
self.session = aiohttp.ClientSession()
|
self.session = aiohttp.ClientSession()
|
||||||
|
|
||||||
async def check_channels(self):
|
async def check_channels(self):
|
||||||
|
@ -52,7 +52,7 @@ class Picarto:
|
||||||
try:
|
try:
|
||||||
while not self.bot.is_closed:
|
while not self.bot.is_closed:
|
||||||
r_filter = {'notifications_on': 1}
|
r_filter = {'notifications_on': 1}
|
||||||
picarto = await config.get_content('picarto', r_filter)
|
picarto = await utils.get_content('picarto', r_filter)
|
||||||
# Get all online users before looping, so that only one request is needed
|
# Get all online users before looping, so that only one request is needed
|
||||||
online_users_list = await online_users()
|
online_users_list = await online_users()
|
||||||
old_online_users = {data['member_id']: data for data in picarto if data['live']}
|
old_online_users = {data['member_id']: data for data in picarto if data['live']}
|
||||||
|
@ -69,7 +69,7 @@ class Picarto:
|
||||||
server = self.bot.get_server(server_id)
|
server = self.bot.get_server(server_id)
|
||||||
if server is None:
|
if server is None:
|
||||||
continue
|
continue
|
||||||
server_alerts = await config.get_content('server_alerts', {'server_id': server_id})
|
server_alerts = await utils.get_content('server_alerts', {'server_id': server_id})
|
||||||
try:
|
try:
|
||||||
channel_id = server_alerts[0]['channel_id']
|
channel_id = server_alerts[0]['channel_id']
|
||||||
except (IndexError, TypeError):
|
except (IndexError, TypeError):
|
||||||
|
@ -82,7 +82,7 @@ class Picarto:
|
||||||
|
|
||||||
fmt = "{} has just gone live! View their stream at {}".format(member.display_name, url)
|
fmt = "{} has just gone live! View their stream at {}".format(member.display_name, url)
|
||||||
await self.bot.send_message(channel, fmt)
|
await self.bot.send_message(channel, fmt)
|
||||||
await config.update_content('picarto', {'live': 1}, {'member_id': m_id})
|
await utils.update_content('picarto', {'live': 1}, {'member_id': m_id})
|
||||||
for m_id, result in old_online_users.items():
|
for m_id, result in old_online_users.items():
|
||||||
# Get their url and their user based on that url
|
# Get their url and their user based on that url
|
||||||
url = result['picarto_url']
|
url = result['picarto_url']
|
||||||
|
@ -94,7 +94,7 @@ class Picarto:
|
||||||
server = self.bot.get_server(server_id)
|
server = self.bot.get_server(server_id)
|
||||||
if server is None:
|
if server is None:
|
||||||
continue
|
continue
|
||||||
server_alerts = await config.get_content('server_alerts', {'server_id': server_id})
|
server_alerts = await utils.get_content('server_alerts', {'server_id': server_id})
|
||||||
try:
|
try:
|
||||||
channel_id = server_alerts[0]['channel_id']
|
channel_id = server_alerts[0]['channel_id']
|
||||||
except IndexError:
|
except IndexError:
|
||||||
|
@ -105,7 +105,7 @@ class Picarto:
|
||||||
fmt = "{} has just gone offline! Catch them next time they stream at {}".format(
|
fmt = "{} has just gone offline! Catch them next time they stream at {}".format(
|
||||||
member.display_name, url)
|
member.display_name, url)
|
||||||
await self.bot.send_message(channel, fmt)
|
await self.bot.send_message(channel, fmt)
|
||||||
await config.update_content('picarto', {'live': 0}, {'member_id': m_id})
|
await utils.update_content('picarto', {'live': 0}, {'member_id': m_id})
|
||||||
await asyncio.sleep(30)
|
await asyncio.sleep(30)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
tb = traceback.format_exc()
|
tb = traceback.format_exc()
|
||||||
|
@ -113,7 +113,7 @@ class Picarto:
|
||||||
log.error(fmt)
|
log.error(fmt)
|
||||||
|
|
||||||
@commands.group(pass_context=True, invoke_without_command=True, no_pm=True)
|
@commands.group(pass_context=True, invoke_without_command=True, no_pm=True)
|
||||||
@checks.custom_perms(send_messages=True)
|
@utils.custom_perms(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
|
||||||
|
|
||||||
|
@ -122,7 +122,7 @@ class Picarto:
|
||||||
# If member is not given, base information on the author
|
# If member is not given, base information on the author
|
||||||
member = member or ctx.message.author
|
member = member or ctx.message.author
|
||||||
r_filter = {'member_id': member.id}
|
r_filter = {'member_id': member.id}
|
||||||
picarto_entry = await config.get_content('picarto', r_filter)
|
picarto_entry = await utils.get_content('picarto', r_filter)
|
||||||
if picarto_entry is None:
|
if picarto_entry is None:
|
||||||
await self.bot.say("That user does not have a picarto url setup!")
|
await self.bot.say("That user does not have a picarto url setup!")
|
||||||
return
|
return
|
||||||
|
@ -151,7 +151,7 @@ class Picarto:
|
||||||
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))
|
||||||
|
|
||||||
@picarto.command(name='add', pass_context=True, no_pm=True)
|
@picarto.command(name='add', pass_context=True, no_pm=True)
|
||||||
@checks.custom_perms(send_messages=True)
|
@utils.custom_perms(send_messages=True)
|
||||||
async def add_picarto_url(self, ctx, url: str):
|
async def add_picarto_url(self, ctx, url: str):
|
||||||
"""Saves your user's picarto URL
|
"""Saves your user's picarto URL
|
||||||
|
|
||||||
|
@ -187,20 +187,20 @@ class Picarto:
|
||||||
'notifications_on': 1,
|
'notifications_on': 1,
|
||||||
'live': 0,
|
'live': 0,
|
||||||
'member_id': ctx.message.author.id}
|
'member_id': ctx.message.author.id}
|
||||||
if await config.add_content('picarto', entry, r_filter):
|
if await utils.add_content('picarto', entry, r_filter):
|
||||||
await self.bot.say(
|
await self.bot.say(
|
||||||
"I have just saved your Picarto URL {}, this server will now be notified when you go live".format(
|
"I have just saved your Picarto URL {}, this server will now be notified when you go live".format(
|
||||||
ctx.message.author.mention))
|
ctx.message.author.mention))
|
||||||
else:
|
else:
|
||||||
await config.update_content('picarto', {'picarto_url': url}, r_filter)
|
await utils.update_content('picarto', {'picarto_url': url}, r_filter)
|
||||||
await self.bot.say("I have just updated your Picarto URL")
|
await self.bot.say("I have just updated your Picarto URL")
|
||||||
|
|
||||||
@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.custom_perms(send_messages=True)
|
@utils.custom_perms(send_messages=True)
|
||||||
async def remove_picarto_url(self, ctx):
|
async def remove_picarto_url(self, ctx):
|
||||||
"""Removes your picarto URL"""
|
"""Removes your picarto URL"""
|
||||||
r_filter = {'member_id': ctx.message.author.id}
|
r_filter = {'member_id': ctx.message.author.id}
|
||||||
if await config.remove_content('picarto', r_filter):
|
if await utils.remove_content('picarto', r_filter):
|
||||||
await self.bot.say("I am no longer saving your picarto URL {}".format(ctx.message.author.mention))
|
await self.bot.say("I am no longer saving your picarto URL {}".format(ctx.message.author.mention))
|
||||||
else:
|
else:
|
||||||
await self.bot.say(
|
await self.bot.say(
|
||||||
|
@ -208,7 +208,7 @@ class Picarto:
|
||||||
ctx.message.author.mention, ctx.prefix))
|
ctx.message.author.mention, ctx.prefix))
|
||||||
|
|
||||||
@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.custom_perms(send_messages=True)
|
@utils.custom_perms(send_messages=True)
|
||||||
async def notify(self, ctx):
|
async def notify(self, ctx):
|
||||||
"""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, to add this server to the list of servers to be notified
|
Call this command by itself, to add this server to the list of servers to be notified
|
||||||
|
@ -216,7 +216,7 @@ class Picarto:
|
||||||
EXAMPLE: !picarto notify
|
EXAMPLE: !picarto notify
|
||||||
RESULT: This server will now be notified of you going live"""
|
RESULT: This server will now be notified of you going live"""
|
||||||
r_filter = {'member_id': ctx.message.author.id}
|
r_filter = {'member_id': ctx.message.author.id}
|
||||||
result = await config.get_content('picarto', r_filter)
|
result = await utils.get_content('picarto', r_filter)
|
||||||
# Check if this user is saved at all
|
# Check if this user is saved at all
|
||||||
if result is None:
|
if result is None:
|
||||||
await self.bot.say(
|
await self.bot.say(
|
||||||
|
@ -226,30 +226,30 @@ class Picarto:
|
||||||
elif ctx.message.server.id in result[0]['servers']:
|
elif ctx.message.server.id in result[0]['servers']:
|
||||||
await self.bot.say("I am already set to notify in this server...")
|
await self.bot.say("I am already set to notify in this server...")
|
||||||
else:
|
else:
|
||||||
await config.update_content('picarto', {'servers': r.row['servers'].append(ctx.message.server.id)},
|
await utils.update_content('picarto', {'servers': r.row['servers'].append(ctx.message.server.id)},
|
||||||
r_filter)
|
r_filter)
|
||||||
|
|
||||||
@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.custom_perms(send_messages=True)
|
@utils.custom_perms(send_messages=True)
|
||||||
async def notify_on(self, ctx):
|
async def notify_on(self, ctx):
|
||||||
"""Turns picarto notifications on
|
"""Turns picarto notifications on
|
||||||
|
|
||||||
EXAMPLE: !picarto notify on
|
EXAMPLE: !picarto notify on
|
||||||
RESULT: Notifications are sent when you go live"""
|
RESULT: Notifications are sent when you go live"""
|
||||||
r_filter = {'member_id': ctx.message.author.id}
|
r_filter = {'member_id': ctx.message.author.id}
|
||||||
await config.update_content('picarto', {'notifications_on': 1}, r_filter)
|
await utils.update_content('picarto', {'notifications_on': 1}, r_filter)
|
||||||
await self.bot.say("I will notify if you go live {}, you'll get a bajillion followers I promise c:".format(
|
await self.bot.say("I will notify if you go live {}, you'll get a bajillion followers I promise c:".format(
|
||||||
ctx.message.author.mention))
|
ctx.message.author.mention))
|
||||||
|
|
||||||
@notify.command(name='off', aliases=['stop,no'], pass_context=True, no_pm=True)
|
@notify.command(name='off', aliases=['stop,no'], pass_context=True, no_pm=True)
|
||||||
@checks.custom_perms(send_messages=True)
|
@utils.custom_perms(send_messages=True)
|
||||||
async def notify_off(self, ctx):
|
async def notify_off(self, ctx):
|
||||||
"""Turns picarto notifications off
|
"""Turns picarto notifications off
|
||||||
|
|
||||||
EXAMPLE: !picarto notify off
|
EXAMPLE: !picarto notify off
|
||||||
RESULT: No more notifications sent when you go live"""
|
RESULT: No more notifications sent when you go live"""
|
||||||
r_filter = {'member_id': ctx.message.author.id}
|
r_filter = {'member_id': ctx.message.author.id}
|
||||||
await config.update_content('picarto', {'notifications_on': 0}, r_filter)
|
await utils.update_content('picarto', {'notifications_on': 0}, r_filter)
|
||||||
await self.bot.say(
|
await self.bot.say(
|
||||||
"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(
|
||||||
|
|
|
@ -46,8 +46,8 @@ class Twitch:
|
||||||
# Loop through as long as the bot is connected
|
# Loop through as long as the bot is connected
|
||||||
try:
|
try:
|
||||||
while not self.bot.is_closed:
|
while not self.bot.is_closed:
|
||||||
twitch = await config.get_content('twitch', {'notifications_on': 1})
|
twitch = await utils.get_content('twitch', {'notifications_on': 1})
|
||||||
# Online/offline is based on whether they are set to such, in the config file
|
# Online/offline is based on whether they are set to such, in the utils file
|
||||||
# This means they were detected as online/offline before and we check for a change
|
# This means they were detected as online/offline before and we check for a change
|
||||||
online_users = {data['member_id']: data for data in twitch if data['live']}
|
online_users = {data['member_id']: data for data in twitch if data['live']}
|
||||||
offline_users = {data['member_id']: data for data in twitch if not data['live']}
|
offline_users = {data['member_id']: data for data in twitch if not data['live']}
|
||||||
|
@ -62,7 +62,7 @@ class Twitch:
|
||||||
server = self.bot.get_server(server_id)
|
server = self.bot.get_server(server_id)
|
||||||
if server is None:
|
if server is None:
|
||||||
continue
|
continue
|
||||||
server_alerts = await config.get_content('server_alerts', {'server_id': server_id})
|
server_alerts = await utils.get_content('server_alerts', {'server_id': server_id})
|
||||||
try:
|
try:
|
||||||
channel_id = server_alerts[0]['channel_id']
|
channel_id = server_alerts[0]['channel_id']
|
||||||
except (IndexError, TypeError):
|
except (IndexError, TypeError):
|
||||||
|
@ -75,7 +75,7 @@ class Twitch:
|
||||||
|
|
||||||
fmt = "{} has just gone live! View their stream at {}".format(member.display_name, url)
|
fmt = "{} has just gone live! View their stream at {}".format(member.display_name, url)
|
||||||
await self.bot.send_message(channel, fmt)
|
await self.bot.send_message(channel, fmt)
|
||||||
await config.update_content('twitch', {'live': 1}, {'member_id': m_id})
|
await utils.update_content('twitch', {'live': 1}, {'member_id': m_id})
|
||||||
for m_id, result in online_users.items():
|
for m_id, result in online_users.items():
|
||||||
# Get their url and their user based on that url
|
# Get their url and their user based on that url
|
||||||
url = result['twitch_url']
|
url = result['twitch_url']
|
||||||
|
@ -87,7 +87,7 @@ class Twitch:
|
||||||
server = self.bot.get_server(server_id)
|
server = self.bot.get_server(server_id)
|
||||||
if server is None:
|
if server is None:
|
||||||
continue
|
continue
|
||||||
server_alerts = await config.get_content('server_alerts', {'server_id': server_id})
|
server_alerts = await utils.get_content('server_alerts', {'server_id': server_id})
|
||||||
channel_id = server_id
|
channel_id = server_id
|
||||||
if len(server_alerts) > 0:
|
if len(server_alerts) > 0:
|
||||||
channel_id = server_alerts[0].get('channel_id')
|
channel_id = server_alerts[0].get('channel_id')
|
||||||
|
@ -97,7 +97,7 @@ class Twitch:
|
||||||
fmt = "{} has just gone offline! Catch them next time they stream at {}".format(
|
fmt = "{} has just gone offline! Catch them next time they stream at {}".format(
|
||||||
member.display_name, url)
|
member.display_name, url)
|
||||||
await self.bot.send_message(channel, fmt)
|
await self.bot.send_message(channel, fmt)
|
||||||
await config.update_content('twitch', {'live': 0}, {'member_id': m_id})
|
await utils.update_content('twitch', {'live': 0}, {'member_id': m_id})
|
||||||
await asyncio.sleep(30)
|
await asyncio.sleep(30)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
tb = traceback.format_exc()
|
tb = traceback.format_exc()
|
||||||
|
|
Loading…
Reference in a new issue