1
0
Fork 0
mirror of synced 2024-06-28 03:00:55 +12:00

Corrected some syntax/pep8 errors

This commit is contained in:
phxntxm 2016-08-16 10:22:32 -05:00
parent 8239d66524
commit c8730a3b6f
6 changed files with 96 additions and 72 deletions

View file

@ -8,8 +8,9 @@ import random
def battling_off(player_id): def battling_off(player_id):
battling = config.get_content('battling') or {} battling = config.get_content('battling') or {}
# Create a new dictionary, exactly the way the last one was setup, but don't include any that have the player's ID provided # Create a new dictionary, exactly the way the last one was setup
# But don't include any that have the player's ID provided
battling = {p1: p2 for p1, p2 in battling.items() if not p2 == player_id and not p1 == player_id} battling = {p1: p2 for p1, p2 in battling.items() if not p2 == player_id and not p1 == player_id}
config.save_content('battling', battling) config.save_content('battling', battling)
@ -17,7 +18,7 @@ def battling_off(player_id):
def user_battling(ctx, player2=None): def user_battling(ctx, player2=None):
battling = config.get_content('battling') battling = config.get_content('battling')
# If no one is battling, obviously the user is not battling # If no one is battling, obviously the user is not battling
if battling is None: if battling is None:
return False return False
@ -37,14 +38,14 @@ def update_battle_records(winner, loser):
battles = config.get_content('battle_records') battles = config.get_content('battle_records')
if battles is None: if battles is None:
battles = {winner.id: "1-0", loser.id: "0-1"} battles = {winner.id: "1-0", loser.id: "0-1"}
# Start ratings at 1000 if they have no rating # Start ratings at 1000 if they have no rating
winner_stats = battles.get(winner.id) or {} winner_stats = battles.get(winner.id) or {}
winner_rating = winner_stats.get('rating') or 1000 winner_rating = winner_stats.get('rating') or 1000
loser_stats = battles.get(loser.id) or {} loser_stats = battles.get(loser.id) or {}
loser_rating = loser_stats.get('rating') or 1000 loser_rating = loser_stats.get('rating') or 1000
# The scale is based off of increments of 25, increasing the change by 1 for each increment # The scale is based off of increments of 25, increasing the change by 1 for each increment
# That is all this loop does, increment the "change" for every increment of 25 # That is all this loop does, increment the "change" for every increment of 25
# The change caps off at 300 however, so break once we are over that limit # The change caps off at 300 however, so break once we are over that limit
@ -56,7 +57,7 @@ def update_battle_records(winner, loser):
break break
rating_change += 1 rating_change += 1
count += 25 count += 25
# 16 is the base change, increased or decreased based on whoever has the higher current rating # 16 is the base change, increased or decreased based on whoever has the higher current rating
if winner_rating > loser_rating: if winner_rating > loser_rating:
winner_rating += 16 - rating_change winner_rating += 16 - rating_change
@ -64,7 +65,7 @@ def update_battle_records(winner, loser):
else: else:
winner_rating += 16 + rating_change winner_rating += 16 + rating_change
loser_rating -= 16 + rating_change loser_rating -= 16 + rating_change
# Just increase wins/losses for each person, making sure it's at least 0 # Just increase wins/losses for each person, making sure it's at least 0
winner_wins = winner_stats.get('wins') or 0 winner_wins = winner_stats.get('wins') or 0
winner_losses = winner_stats.get('losses') or 0 winner_losses = winner_stats.get('losses') or 0
@ -72,7 +73,7 @@ def update_battle_records(winner, loser):
loser_losses = loser_stats.get('losses') or 0 loser_losses = loser_stats.get('losses') or 0
winner_wins += 1 winner_wins += 1
loser_losses += 1 loser_losses += 1
# Now save the new wins, losses, and ratings # Now save the new wins, losses, and ratings
winner_stats = {'wins': winner_wins, 'losses': winner_losses, 'rating': winner_rating} winner_stats = {'wins': winner_wins, 'losses': winner_losses, 'rating': winner_rating}
loser_stats = {'wins': loser_wins, 'losses': loser_losses, 'rating': loser_rating} loser_stats = {'wins': loser_wins, 'losses': loser_losses, 'rating': loser_rating}
@ -102,12 +103,12 @@ class Interaction:
if user_battling(ctx, player2): if user_battling(ctx, player2):
await self.bot.say("You or the person you are trying to battle is already in a battle!") await self.bot.say("You or the person you are trying to battle is already in a battle!")
return return
# Add the author and player provided in a new battle # Add the author and player provided in a new battle
battling = config.get_content('battling') or {} battling = config.get_content('battling') or {}
battling[ctx.message.author.id] = ctx.message.mentions[0].id battling[ctx.message.author.id] = ctx.message.mentions[0].id
config.save_content('battling', battling) config.save_content('battling', battling)
fmt = "{0.mention} has challenged you to a battle {1.mention}\n!accept or !decline" fmt = "{0.mention} has challenged you to a battle {1.mention}\n!accept or !decline"
# Add a call to turn off battling, if the battle is not accepted/declined in 3 minutes # Add a call to turn off battling, if the battle is not accepted/declined in 3 minutes
config.loop.call_later(180, battling_off, ctx.message.author.id) config.loop.call_later(180, battling_off, ctx.message.author.id)
@ -122,7 +123,7 @@ class Interaction:
if not user_battling(ctx): if not user_battling(ctx):
await self.bot.say("You are not currently in a battle!") await self.bot.say("You are not currently in a battle!")
return return
# This is an extra check to make sure that the author is the one being BATTLED # This is an extra check to make sure that the author is the one being BATTLED
# And not the one that started the battle # And not the one that started the battle
battling = config.get_content('battling') or {} battling = config.get_content('battling') or {}
@ -133,12 +134,12 @@ class Interaction:
battleP1 = discord.utils.find(lambda m: m.id == p1[0], ctx.message.server.members) battleP1 = discord.utils.find(lambda m: m.id == p1[0], ctx.message.server.members)
battleP2 = ctx.message.author battleP2 = ctx.message.author
# Get a random win message from our list # Get a random win message from our list
fmt = config.battleWins[random.SystemRandom().randint(0, len(config.battleWins) - 1)] fmt = config.battleWins[random.SystemRandom().randint(0, len(config.battleWins) - 1)]
# Due to our previous check, the ID should only be in the dictionary once, in the current battle we're checking # Due to our previous check, the ID should only be in the dictionary once, in the current battle we're checking
battling_off(ctx.message.author.id) battling_off(ctx.message.author.id)
# Randomize the order of who is printed/sent to the update system # Randomize the order of who is printed/sent to the update system
# All we need to do is change what order the challengers are printed/added as a paramater # All we need to do is change what order the challengers are printed/added as a paramater
if random.SystemRandom().randint(0, 1): if random.SystemRandom().randint(0, 1):
@ -147,7 +148,7 @@ class Interaction:
else: else:
await self.bot.say(fmt.format(battleP2.mention, battleP1.mention)) await self.bot.say(fmt.format(battleP2.mention, battleP1.mention))
update_battle_records(battleP2, battleP1) update_battle_records(battleP2, battleP1)
await self.bot.delete_message(ctx.message) await self.bot.delete_message(ctx.message)
@commands.command(pass_context=True, no_pm=True) @commands.command(pass_context=True, no_pm=True)
@ -157,7 +158,7 @@ class Interaction:
if not user_battling(ctx): if not user_battling(ctx):
await self.bot.say("You are not currently in a battle!") await self.bot.say("You are not currently in a battle!")
return return
# This is an extra check to make sure that the author is the one being BATTLED # This is an extra check to make sure that the author is the one being BATTLED
# And not the one that started the battle # And not the one that started the battle
battling = config.get_content('battling') or {} battling = config.get_content('battling') or {}
@ -165,11 +166,10 @@ class Interaction:
if len(p1) == 0: if len(p1) == 0:
await self.bot.say("You are not currently being challenged to a battle!") await self.bot.say("You are not currently being challenged to a battle!")
return return
battleP1 = discord.utils.find(lambda m: m.id == p1[0], ctx.message.server.members) battleP1 = discord.utils.find(lambda m: m.id == p1[0], ctx.message.server.members)
battleP2 = ctx.message.author battleP2 = ctx.message.author
# There's no need to update the stats for the members if they declined the battle # There's no need to update the stats for the members if they declined the battle
battling_off(ctx.message.author.id) battling_off(ctx.message.author.id)
await self.bot.say("{0} has chickened out! What a loser~".format(battleP2.mention, battleP1.mention)) await self.bot.say("{0} has chickened out! What a loser~".format(battleP2.mention, battleP1.mention))
@ -180,6 +180,7 @@ class Interaction:
@checks.custom_perms(send_messages=True) @checks.custom_perms(send_messages=True)
async def boop(self, ctx, boopee: discord.Member): async def boop(self, ctx, boopee: discord.Member):
"""Boops the mentioned person""" """Boops the mentioned person"""
booper = ctx.message.author
if boopee.id == booper.id: if boopee.id == booper.id:
await self.bot.say("You can't boop yourself! Silly...") await self.bot.say("You can't boop yourself! Silly...")
return return
@ -188,8 +189,9 @@ class Interaction:
return return
boops = config.get_content('boops') or {} boops = config.get_content('boops') or {}
# This is only used to print the amount of times they've booped someone, set to 1 for the first time someone was booped # This is only used to print the amount of times they've booped someone
# Set to 1 for the first time someone was booped
amount = 1 amount = 1
# Get all the booped stats for the author # Get all the booped stats for the author
booper_boops = boops.get(ctx.message.author.id) booper_boops = boops.get(ctx.message.author.id)
@ -197,7 +199,8 @@ class Interaction:
# Create a new dictionary with the amount # Create a new dictionary with the amount
if booper_boops is None: if booper_boops is None:
boops[ctx.message.author.id] = {boopee.id: 1} boops[ctx.message.author.id] = {boopee.id: 1}
# If the booper has never booped the member provided, still add that user to the dictionary with the amount of 1 to start it off # If the booper has never booped the member provided, still add that user
# To the dictionary with the amount of 1 to start it off
elif booper_boops.get(boopee.id) is None: elif booper_boops.get(boopee.id) is None:
booper_boops[boopee.id] = 1 booper_boops[boopee.id] = 1
boops[ctx.message.author.id] = booper_boops boops[ctx.message.author.id] = booper_boops

View file

@ -18,7 +18,7 @@ class Owner:
def __init__(self, bot): def __init__(self, bot):
self.bot = bot self.bot = bot
@commands.command(pass_context=True) @commands.command(pass_context=True)
@commands.check(checks.is_owner) @commands.check(checks.is_owner)
async def saferestart(self, ctx): async def saferestart(self, ctx):
@ -27,10 +27,12 @@ class Owner:
# I do not want to restart the bot if someone is playing music # I do not want to restart the bot if someone is playing music
# This gets all the exiting VoiceStates that are playing music right now # This gets all the exiting VoiceStates that are playing music right now
# If we are, say which server it # If we are, say which server it
servers_playing_music = [server_id for server_id, state in self.bot.get_cog('Music').voice_states.items() if state.is_playing()] servers_playing_music = [server_id for server_id, state in self.bot.get_cog('Music').voice_states.items() if
await self.bot.say("Sorry, it's not safe to restart. I am currently playing a song on {} servers".format(len(servers_playing_music))) state.is_playing()]
await self.bot.say("Sorry, it's not safe to restart. I am currently playing a song on {} servers".format(
len(servers_playing_music)))
ctx.invoke(self.bot.commands.get('restart')) ctx.invoke(self.bot.commands.get('restart'))
@commands.command(pass_context=True) @commands.command(pass_context=True)
@commands.check(checks.is_owner) @commands.check(checks.is_owner)
async def restart(self, ctx): async def restart(self, ctx):
@ -47,7 +49,7 @@ class Owner:
"""Saves a URL as an image to add for the doggo command""" """Saves a URL as an image to add for the doggo command"""
# Save the local path based on how many images there currently are # Save the local path based on how many images there currently are
local_path = 'images/doggo{}.jpg'.format(len(glob.glob('images/doggo*'))) local_path = 'images/doggo{}.jpg'.format(len(glob.glob('images/doggo*')))
# "read" the image and save as bytes # "read" the image and save as bytes
with aiohttp.ClientSession() as s: with aiohttp.ClientSession() as s:
async with s.get(url) as r: async with s.get(url) as r:
@ -56,14 +58,14 @@ class Owner:
f.write(val) f.write(val)
await self.bot.say( await self.bot.say(
"Just saved a new doggo image! I now have {} doggo images!".format(len(glob.glob('images/doggo*')))) "Just saved a new doggo image! I now have {} doggo images!".format(len(glob.glob('images/doggo*'))))
@commands.command() @commands.command()
@commands.check(checks.is_owner) @commands.check(checks.is_owner)
async def addsnek(self, url: str): async def addsnek(self, url: str):
"""Saves a URL as an image to add for the snek command""" """Saves a URL as an image to add for the snek command"""
# Save the local path based on how many images there currently are # Save the local path based on how many images there currently are
local_path = 'images/snek{}.jpg'.format(len(glob.glob('images/snek*'))) local_path = 'images/snek{}.jpg'.format(len(glob.glob('images/snek*')))
# "read" the image and save as bytes # "read" the image and save as bytes
with aiohttp.ClientSession() as s: with aiohttp.ClientSession() as s:
async with s.get(url) as r: async with s.get(url) as r:
@ -79,16 +81,15 @@ class Owner:
"""Executes code""" """Executes code"""
# Eval and exec have different useful purposes, so use both # Eval and exec have different useful purposes, so use both
try: try:
# `Get all content in this format` # `Get all content in this format`
match_single = getter.findall(ctx.message.content) match_single = getter.findall(ctx.message.content)
# ```\nGet all content in this format``` # ```\nGet all content in this format```
match_multi = multi.findall(ctx.message.content) match_multi = multi.findall(ctx.message.content)
if match_single: if match_single:
result = eval(match_single[0]) result = eval(match_single[0])
# In case the result needs to be awaited, handle that # In case the result needs to be awaited, handle that
if inspect.isawaitable(result): if inspect.isawaitable(result):
result = await result result = await result
@ -97,6 +98,7 @@ class Owner:
# Internal method to send the message to the channel, of whatever is passed # Internal method to send the message to the channel, of whatever is passed
def r(v): def r(v):
self.bot.loop.create_task(self.bot.say("```\n{}```".format(v))) self.bot.loop.create_task(self.bot.say("```\n{}```".format(v)))
exec(match_multi[0]) exec(match_multi[0])
except Exception as error: except Exception as error:
fmt = 'An error occurred while processing this request: ```py\n{}: {}\n```' fmt = 'An error occurred while processing this request: ```py\n{}: {}\n```'
@ -131,18 +133,18 @@ class Owner:
async def status(self, *, status: str): async def status(self, *, status: str):
"""Changes the bot's 'playing' status""" """Changes the bot's 'playing' status"""
await self.bot.change_status(discord.Game(name=status, type=0)) await self.bot.change_status(discord.Game(name=status, type=0))
await self.bot.say("Just changed my status to '{0}'!".format(newStatus)) await self.bot.say("Just changed my status to '{0}'!".format(status))
@commands.command() @commands.command()
@commands.check(checks.is_owner) @commands.check(checks.is_owner)
async def load(self, *, module: str): async def load(self, *, module: str):
"""Loads a module""" """Loads a module"""
# Do this because I'm too lazy to type cogs.module # Do this because I'm too lazy to type cogs.module
module = module.lower() module = module.lower()
if not module.startswith("cogs"): if not module.startswith("cogs"):
module = "cogs.{}".format(module) module = "cogs.{}".format(module)
# This try catch will catch errors such as syntax errors in the module we are loading # This try catch will catch errors such as syntax errors in the module we are loading
try: try:
self.bot.load_extension(module) self.bot.load_extension(module)
@ -150,17 +152,17 @@ class Owner:
except Exception as error: except Exception as error:
fmt = 'An error occurred while processing this request: ```py\n{}: {}\n```' fmt = 'An error occurred while processing this request: ```py\n{}: {}\n```'
await self.bot.say(fmt.format(type(error).__name__, error)) await self.bot.say(fmt.format(type(error).__name__, error))
@commands.command() @commands.command()
@commands.check(checks.is_owner) @commands.check(checks.is_owner)
async def unload(self, *, module: str): async def unload(self, *, module: str):
"""Unloads a module""" """Unloads a module"""
# Do this because I'm too lazy to type cogs.module # Do this because I'm too lazy to type cogs.module
module = module.lower() module = module.lower()
if not module.startswith("cogs"): if not module.startswith("cogs"):
module = "cogs.{}".format(module) module = "cogs.{}".format(module)
self.bot.unload_extension(module) self.bot.unload_extension(module)
await self.bot.say("I have just unloaded the {} module".format(module)) await self.bot.say("I have just unloaded the {} module".format(module))
@ -168,13 +170,13 @@ class Owner:
@commands.check(checks.is_owner) @commands.check(checks.is_owner)
async def reload(self, *, module: str): async def reload(self, *, module: str):
"""Reloads a module""" """Reloads a module"""
# Do this because I'm too lazy to type cogs.module # Do this because I'm too lazy to type cogs.module
module = module.lower() module = module.lower()
if not module.startswith("cogs"): if not module.startswith("cogs"):
module = "cogs.{}".format(module) module = "cogs.{}".format(module)
self.bot.unload_extension(module) self.bot.unload_extension(module)
# This try block will catch errors such as syntax errors in the module we are loading # This try block will catch errors such as syntax errors in the module we are loading
try: try:
self.bot.load_extension(module) self.bot.load_extension(module)

View file

@ -1,5 +1,4 @@
import aiohttp import aiohttp
import json
import asyncio import asyncio
import discord import discord
import re import re
@ -27,12 +26,16 @@ async def online_users():
except: except:
return {} return {}
def check_online(online_channels, channel): def check_online(online_channels, channel):
# online_channels is the dictionary of all users online currently, and channel is the name we are checking against that # online_channels is the dictionary of all users online currently
# This creates a list of all users that match this channel name (should only ever be 1) and returns True as long as it is more than 0 # And channel is the name we are checking against that
# This creates a list of all users that match this channel name (should only ever be 1)
# And returns True as long as it is more than 0
matches = [stream for stream in online_channels if stream['channel_name'].lower() == channel.lower()] matches = [stream for stream in online_channels if stream['channel_name'].lower() == channel.lower()]
return len(matches) > 0 return len(matches) > 0
class Picarto: class Picarto:
def __init__(self, bot): def __init__(self, bot):
self.bot = bot self.bot = bot
@ -54,8 +57,9 @@ class Picarto:
user = re.search("(?<=picarto.tv/)(.*)", url).group(1) user = re.search("(?<=picarto.tv/)(.*)", url).group(1)
# This is whether or not they are actually online # This is whether or not they are actually online
online = check_online(online_users_list, user) online = check_online(online_users_list, user)
# If they're set to notify, not live in the config file, but online currently, means they went online since the last check # If they're set to notify, not live in the config file
# But online currently, means they went online since the last check
if not live and notify and online: if not live and notify and online:
for server_id in r['servers']: for server_id in r['servers']:
# Get the channel to send the message to, based on the saved alert's channel # Get the channel to send the message to, based on the saved alert's channel
@ -65,13 +69,14 @@ class Picarto:
channel = self.bot.get_channel(channel_id) channel = self.bot.get_channel(channel_id)
# Get the member that has just gone live # Get the member that has just gone live
member = discord.utils.get(server.members, id=m_id) member = discord.utils.get(server.members, id=m_id)
# Set them as live in the configuration file, and send a message saying they have just gone live # Set them as live in the configuration file, and send a message saying they have just gone live
picarto[m_id]['live'] = 1 picarto[m_id]['live'] = 1
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)
config.save_content('picarto', picarto) config.save_content('picarto', picarto)
await self.bot.send_message(channel, fmt) await self.bot.send_message(channel, fmt)
# If they're live in the configuration file, but not online currently, means they went offline since the last check # If they're live in the configuration file, but not online currently
# Means they went offline since the last check
elif live and not online: elif live and not online:
for server_id in r['servers']: for server_id in r['servers']:
# Get the channel to send the message to, based on the saved alert's channel # Get the channel to send the message to, based on the saved alert's channel
@ -81,8 +86,9 @@ class Picarto:
channel = self.bot.get_channel(channel_id) channel = self.bot.get_channel(channel_id)
# Get the member that has just gone live # Get the member that has just gone live
member = discord.utils.get(server.members, id=m_id) member = discord.utils.get(server.members, id=m_id)
# Set them as offline in the confugration, then send a message letting the channel know they've just gone offline # Set them as offline in the confugration
# Then send a message letting the channel know they've just gone offline
picarto[m_id]['live'] = 0 picarto[m_id]['live'] = 0
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, member.display_name,
@ -103,21 +109,22 @@ class Picarto:
except: except:
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
# Use regex to get the actual username so that we can make a request to the API # Use regex to get the actual username so that we can make a request to the API
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)
async with self.session.get(url, headers=self.headers) as r: async with self.session.get(url, headers=self.headers) as r:
data = await r.json() data = await r.json()
# Not everyone has all these settings, so use this as a way to print information if it does, otherwise ignore it # Not everyone has all these settings, so use this as a way to print information if it does, otherwise ignore it
things_to_print = ['channel', 'commissions_enabled', 'is_nsfw', 'program', 'tablet', 'followers', things_to_print = ['channel', 'commissions_enabled', 'is_nsfw', 'program', 'tablet', 'followers',
'content_type'] 'content_type']
# Using title and replace to provide a nice way to print the data # Using title and replace to provide a nice way to print the data
fmt = "\n".join( fmt = "\n".join(
"{}: {}".format(i.title().replace("_", " "), r) for i, r in data.items() if i in things_to_print) "{}: {}".format(i.title().replace("_", " "), r) for i, r in data.items() if i in things_to_print)
# Social URL's can be given if a user wants them to show, print them if they exist, otherwise don't try to include them # Social URL's can be given if a user wants them to show
# Print them if they exist, otherwise don't try to include them
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())
@ -134,7 +141,8 @@ class Picarto:
# Otherwise if it doesn't match, we'll hit an AttributeError due to .group(0) # Otherwise if it doesn't match, we'll hit an AttributeError due to .group(0)
# This means that the url was just given as a user (or something complete invalid) # This means that the url was just given as a user (or something complete invalid)
# So set URL as https://www.picarto.tv/[url] # So set URL as https://www.picarto.tv/[url]
# Even if this was invalid such as https://www.picarto.tv/twitch.tv/user for example, our next check handles that # Even if this was invalid such as https://www.picarto.tv/twitch.tv/user
# For example, our next check handles that
try: try:
url = re.search("((?<=://)?picarto.tv/)+(.*)", url).group(0) url = re.search("((?<=://)?picarto.tv/)+(.*)", url).group(0)
except AttributeError: except AttributeError:
@ -143,7 +151,7 @@ class Picarto:
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)
# Check if we can find a user with the provided information, if we can't just return # Check if we can find a user with the provided information, if we can't just return
async with self.session.get(api_url, headers=self.headers) as r: async with self.session.get(api_url, headers=self.headers) as r:
if not r.status == 200: if not r.status == 200:
@ -153,9 +161,10 @@ class Picarto:
picarto_urls = config.get_content('picarto') or {} picarto_urls = config.get_content('picarto') or {}
result = picarto_urls.get(ctx.message.author.id) result = picarto_urls.get(ctx.message.author.id)
# If information for this user already exists, override just the url, and not the information # If information for this user already exists, override just the url, and not the information
# Otherwise create the information with notications on, and that they're not live. The next time it's checked, they'll go 'online' # Otherwise create the information with notications on, and that they're not live.
# The next time it's checked, they'll go 'online'
if result is not None: if result is not None:
picarto_urls[ctx.message.author.id]['picarto_url'] = url picarto_urls[ctx.message.author.id]['picarto_url'] = url
else: else:
@ -187,7 +196,7 @@ class Picarto:
"""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"""
member = ctx.message.author member = ctx.message.author
# If this user's picarto URL is not saved, no use in adding this server to the list that doesn't exist # If this user's picarto URL is not saved, no use in adding this server to the list that doesn't exist
picarto = config.get_content('picarto') or {} picarto = config.get_content('picarto') or {}
result = picarto.get(member.id) result = picarto.get(member.id)
@ -195,12 +204,13 @@ class Picarto:
await self.bot.say( await self.bot.say(
"I do not have your picarto URL added {}. You can save your picarto url with {}picarto add".format( "I do not have your picarto URL added {}. You can save your picarto url with {}picarto add".format(
member.mention, ctx.prefix)) member.mention, ctx.prefix))
# Append this server's ID and save the new content # Append this server's ID and save the new content
picarto[member.id]['servers'].append(ctx.message.server.id) picarto[member.id]['servers'].append(ctx.message.server.id)
config.save_content('picarto', picarto) config.save_content('picarto', picarto)
await self.bot.say( await self.bot.say(
"I have just changed which channel will be notified when you go live, to `{}`".format(channel.name)) "I have just changed which channel will be notified when you go live, to `{}`".format(
ctx.message.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.custom_perms(send_messages=True) @checks.custom_perms(send_messages=True)

View file

@ -28,9 +28,12 @@ class VoiceState:
self.voice = None self.voice = None
self.bot = bot self.bot = bot
self.play_next_song = asyncio.Event() self.play_next_song = asyncio.Event()
self.songs = asyncio.Queue(maxsize=10) # This is the queue that holds all VoiceEntry's # This is the queue that holds all VoiceEntry's
self.skip_votes = set() # a set of user_ids that voted self.songs = asyncio.Queue(maxsize=10)
self.audio_player = self.bot.loop.create_task(self.audio_player_task()) # Our actual task that handles the queue system # a set of user_ids that voted
self.skip_votes = set()
# Our actual task that handles the queue system
self.audio_player = self.bot.loop.create_task(self.audio_player_task())
self.opts = { self.opts = {
'default_search': 'auto', 'default_search': 'auto',
'quiet': True, 'quiet': True,
@ -67,7 +70,8 @@ class VoiceState:
# Clear the votes skip that were for the last song # Clear the votes skip that were for the last song
self.skip_votes.clear() self.skip_votes.clear()
# Set current to none while we are waiting for the next song in the queue # Set current to none while we are waiting for the next song in the queue
# If we don't do this and we hit the end of the queue, our current song will remain the song that just finished # If we don't do this and we hit the end of the queue
# our current song will remain the song that just finished
self.current = None self.current = None
# Now wait for the next song in the queue # Now wait for the next song in the queue
self.current = await self.songs.get() self.current = await self.songs.get()
@ -95,7 +99,8 @@ class Music:
state = self.voice_states.get(server.id) state = self.voice_states.get(server.id)
# Internally handle creating a voice state if there isn't a current state # Internally handle creating a voice state if there isn't a current state
# This can be used for example, in case something is skipped when not being connected, we create the voice state when checked # This can be used for example, in case something is skipped when not being connected
# We create the voice state when checked
# This only creates the state, we are still not playing anything, which can then be handled separately # This only creates the state, we are still not playing anything, which can then be handled separately
if state is None: if state is None:
state = VoiceState(self.bot) state = VoiceState(self.bot)
@ -196,7 +201,7 @@ class Music:
player = await state.voice.create_ytdl_player(song, ytdl_options=state.opts, after=state.toggle_next) player = await state.voice.create_ytdl_player(song, ytdl_options=state.opts, after=state.toggle_next)
except youtube_dl.DownloadError: except youtube_dl.DownloadError:
fmt = "Sorry, either I had an issue downloading that video, or that's not a supported URL!" fmt = "Sorry, either I had an issue downloading that video, or that's not a supported URL!"
await self.bot.say(fmt) await self.bot.send_message(ctx.message.channel, fmt)
return return
# Now we can create a VoiceEntry and queue it # Now we can create a VoiceEntry and queue it
@ -308,7 +313,7 @@ class Music:
if len(queue) == 0: if len(queue) == 0:
fmt = "Nothing currently in the queue" fmt = "Nothing currently in the queue"
else: else:
fmt = "\n\n".join(str(x) for x in state.songs._queue) fmt = "\n\n".join(str(x) for x in queue)
await self.bot.say("Current songs in the queue:```\n{}```".format(fmt)) await self.bot.say("Current songs in the queue:```\n{}```".format(fmt))
@commands.command(pass_context=True, no_pm=True) @commands.command(pass_context=True, no_pm=True)

View file

@ -24,7 +24,7 @@ class Stats:
# Then get a sorted list, based on the amount of times they've booped the member # Then get a sorted list, based on the amount of times they've booped the member
# Reverse needs to be true, as we want it to go from highest to lowest # Reverse needs to be true, as we want it to go from highest to lowest
sorted_boops = sorted(boops.get(ctx.message.author.id).items(), key=lambda x: x[1], reverse=True) sorted_boops = sorted(boops.get(ctx.message.author.id).items(), key=lambda x: x[1], reverse=True)
# Then override the same list, checking if the member they've booped is in this server, using our previous list comprehension # Then override the same list, checking if the member they've booped is in this server
sorted_boops = [x for x in sorted_boops if x[0] in server_member_ids] sorted_boops = [x for x in sorted_boops if x[0] in server_member_ids]
# Since this is sorted, we just need to get the following information on the first user in the list # Since this is sorted, we just need to get the following information on the first user in the list
@ -94,7 +94,8 @@ class Stats:
sorted_server_members = sorted(server_members.items(), key=lambda x: x[1]['rating'], reverse=True) sorted_server_members = sorted(server_members.items(), key=lambda x: x[1]['rating'], reverse=True)
sorted_all_members = sorted(all_members.items(), key=lambda x: x[1]['rating'], reverse=True) sorted_all_members = sorted(all_members.items(), key=lambda x: x[1]['rating'], reverse=True)
# Enumurate the list so that we can go through, find the user's place in the list, and get just that for the rank # Enumurate the list so that we can go through, find the user's place in the list
# and get just that for the rank
server_rank = [i for i, x in enumerate(sorted_server_members) if x[0] == member.id][0] + 1 server_rank = [i for i, x in enumerate(sorted_server_members) if x[0] == member.id][0] + 1
total_rank = [i for i, x in enumerate(sorted_all_members) if x[0] == member.id][0] + 1 total_rank = [i for i, x in enumerate(sorted_all_members) if x[0] == member.id][0] + 1
# The rest of this is straight forward, just formatting # The rest of this is straight forward, just formatting

View file

@ -55,7 +55,8 @@ class Strawpoll:
data = await response.json() data = await response.json()
# The response for votes and options is provided as two separate lists # The response for votes and options is provided as two separate lists
# We are enumarting the list of options, to print r (the option) and the votes to match it, based on the index of the option # We are enumarting the list of options, to print r (the option)
# And the votes to match it, based on the index of the option
# The rest is simple formatting # The rest is simple formatting
fmt_options = "\n\t".join( fmt_options = "\n\t".join(
"{}: {}".format(r, data['votes'][i]) for i, r in enumerate(data['options'])) "{}: {}".format(r, data['votes'][i]) for i, r in enumerate(data['options']))
@ -78,11 +79,13 @@ class Strawpoll:
# We're using this instead of other things, to allow most used puncation inside the options # We're using this instead of other things, to allow most used puncation inside the options
match_single = getter.findall(options) match_single = getter.findall(options)
match_multi = multi.findall(options) match_multi = multi.findall(options)
# Since match_single is already going to be a list, we just set the options to match_single and remove any blank entries # Since match_single is already going to be a list, we just set
# The options to match_single and remove any blank entries
if match_single: if match_single:
options = match_single options = match_single
options = [option for option in options if option] options = [option for option in options if option]
# Otherwise, options need to be set based on the list, split by lines. Then remove blank entries like the last one # Otherwise, options need to be set based on the list, split by lines.
# Then remove blank entries like the last one
elif match_multi: elif match_multi:
options = match_multi[0].splitlines() options = match_multi[0].splitlines()
options = [option for option in options if option] options = [option for option in options if option]