Corrected some syntax/pep8 errors
This commit is contained in:
parent
8239d66524
commit
c8730a3b6f
|
@ -9,7 +9,8 @@ import random
|
|||
def battling_off(player_id):
|
||||
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}
|
||||
|
||||
config.save_content('battling', battling)
|
||||
|
@ -166,7 +167,6 @@ class Interaction:
|
|||
await self.bot.say("You are not currently being challenged to a battle!")
|
||||
return
|
||||
|
||||
|
||||
battleP1 = discord.utils.find(lambda m: m.id == p1[0], ctx.message.server.members)
|
||||
battleP2 = ctx.message.author
|
||||
|
||||
|
@ -180,6 +180,7 @@ class Interaction:
|
|||
@checks.custom_perms(send_messages=True)
|
||||
async def boop(self, ctx, boopee: discord.Member):
|
||||
"""Boops the mentioned person"""
|
||||
booper = ctx.message.author
|
||||
if boopee.id == booper.id:
|
||||
await self.bot.say("You can't boop yourself! Silly...")
|
||||
return
|
||||
|
@ -189,7 +190,8 @@ class Interaction:
|
|||
|
||||
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
|
||||
# Get all the booped stats for the author
|
||||
booper_boops = boops.get(ctx.message.author.id)
|
||||
|
@ -197,7 +199,8 @@ class Interaction:
|
|||
# Create a new dictionary with the amount
|
||||
if booper_boops is None:
|
||||
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:
|
||||
booper_boops[boopee.id] = 1
|
||||
boops[ctx.message.author.id] = booper_boops
|
||||
|
|
|
@ -27,8 +27,10 @@ class Owner:
|
|||
# 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
|
||||
# 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()]
|
||||
await self.bot.say("Sorry, it's not safe to restart. I am currently playing a song on {} servers".format(len(servers_playing_music)))
|
||||
servers_playing_music = [server_id for server_id, state in self.bot.get_cog('Music').voice_states.items() if
|
||||
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'))
|
||||
|
||||
@commands.command(pass_context=True)
|
||||
|
@ -85,7 +87,6 @@ class Owner:
|
|||
# ```\nGet all content in this format```
|
||||
match_multi = multi.findall(ctx.message.content)
|
||||
|
||||
|
||||
if match_single:
|
||||
result = eval(match_single[0])
|
||||
|
||||
|
@ -97,6 +98,7 @@ class Owner:
|
|||
# Internal method to send the message to the channel, of whatever is passed
|
||||
def r(v):
|
||||
self.bot.loop.create_task(self.bot.say("```\n{}```".format(v)))
|
||||
|
||||
exec(match_multi[0])
|
||||
except Exception as error:
|
||||
fmt = 'An error occurred while processing this request: ```py\n{}: {}\n```'
|
||||
|
@ -131,7 +133,7 @@ class Owner:
|
|||
async def status(self, *, status: str):
|
||||
"""Changes the bot's 'playing' status"""
|
||||
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.check(checks.is_owner)
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
import aiohttp
|
||||
import json
|
||||
import asyncio
|
||||
import discord
|
||||
import re
|
||||
|
@ -27,12 +26,16 @@ async def online_users():
|
|||
except:
|
||||
return {}
|
||||
|
||||
|
||||
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
|
||||
# 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
|
||||
# online_channels is the dictionary of all users online currently
|
||||
# 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()]
|
||||
return len(matches) > 0
|
||||
|
||||
|
||||
class Picarto:
|
||||
def __init__(self, bot):
|
||||
self.bot = bot
|
||||
|
@ -55,7 +58,8 @@ class Picarto:
|
|||
# This is whether or not they are actually online
|
||||
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:
|
||||
for server_id in r['servers']:
|
||||
# Get the channel to send the message to, based on the saved alert's channel
|
||||
|
@ -71,7 +75,8 @@ class Picarto:
|
|||
fmt = "{} has just gone live! View their stream at {}".format(member.display_name, url)
|
||||
config.save_content('picarto', picarto)
|
||||
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:
|
||||
for server_id in r['servers']:
|
||||
# Get the channel to send the message to, based on the saved alert's channel
|
||||
|
@ -82,7 +87,8 @@ class Picarto:
|
|||
# Get the member that has just gone live
|
||||
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
|
||||
fmt = "{} has just gone offline! Catch them next time they stream at {}".format(
|
||||
member.display_name,
|
||||
|
@ -117,7 +123,8 @@ class Picarto:
|
|||
fmt = "\n".join(
|
||||
"{}: {}".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')
|
||||
if social_links:
|
||||
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)
|
||||
# This means that the url was just given as a user (or something complete invalid)
|
||||
# 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:
|
||||
url = re.search("((?<=://)?picarto.tv/)+(.*)", url).group(0)
|
||||
except AttributeError:
|
||||
|
@ -155,7 +163,8 @@ class Picarto:
|
|||
result = picarto_urls.get(ctx.message.author.id)
|
||||
|
||||
# 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:
|
||||
picarto_urls[ctx.message.author.id]['picarto_url'] = url
|
||||
else:
|
||||
|
@ -200,7 +209,8 @@ class Picarto:
|
|||
picarto[member.id]['servers'].append(ctx.message.server.id)
|
||||
config.save_content('picarto', picarto)
|
||||
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)
|
||||
@checks.custom_perms(send_messages=True)
|
||||
|
|
|
@ -28,9 +28,12 @@ class VoiceState:
|
|||
self.voice = None
|
||||
self.bot = bot
|
||||
self.play_next_song = asyncio.Event()
|
||||
self.songs = asyncio.Queue(maxsize=10) # This is the queue that holds all VoiceEntry's
|
||||
self.skip_votes = set() # a set of user_ids that voted
|
||||
self.audio_player = self.bot.loop.create_task(self.audio_player_task()) # Our actual task that handles the queue system
|
||||
# This is the queue that holds all VoiceEntry's
|
||||
self.songs = asyncio.Queue(maxsize=10)
|
||||
# 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 = {
|
||||
'default_search': 'auto',
|
||||
'quiet': True,
|
||||
|
@ -67,7 +70,8 @@ class VoiceState:
|
|||
# Clear the votes skip that were for the last song
|
||||
self.skip_votes.clear()
|
||||
# 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
|
||||
# Now wait for the next song in the queue
|
||||
self.current = await self.songs.get()
|
||||
|
@ -95,7 +99,8 @@ class Music:
|
|||
state = self.voice_states.get(server.id)
|
||||
|
||||
# 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
|
||||
if state is None:
|
||||
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)
|
||||
except youtube_dl.DownloadError:
|
||||
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
|
||||
|
||||
# Now we can create a VoiceEntry and queue it
|
||||
|
@ -308,7 +313,7 @@ class Music:
|
|||
if len(queue) == 0:
|
||||
fmt = "Nothing currently in the queue"
|
||||
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))
|
||||
|
||||
@commands.command(pass_context=True, no_pm=True)
|
||||
|
|
|
@ -24,7 +24,7 @@ class Stats:
|
|||
# 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
|
||||
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]
|
||||
|
||||
# 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_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
|
||||
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
|
||||
|
|
|
@ -55,7 +55,8 @@ class Strawpoll:
|
|||
data = await response.json()
|
||||
|
||||
# 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
|
||||
fmt_options = "\n\t".join(
|
||||
"{}: {}".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
|
||||
match_single = getter.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:
|
||||
options = match_single
|
||||
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:
|
||||
options = match_multi[0].splitlines()
|
||||
options = [option for option in options if option]
|
||||
|
|
Loading…
Reference in a new issue