1
0
Fork 0
mirror of synced 2024-06-27 02:31:04 +12:00

Updates to comply with PEP 8

This commit is contained in:
phxntxm 2016-07-30 19:20:55 -05:00
parent 560d15eb62
commit 8e050c016e
9 changed files with 100 additions and 109 deletions

1
bot.py
View file

@ -27,6 +27,7 @@ log.setLevel(logging.INFO)
handler = logging.FileHandler(filename='bonfire.log', encoding='utf-8', mode='a') handler = logging.FileHandler(filename='bonfire.log', encoding='utf-8', mode='a')
log.addHandler(handler) log.addHandler(handler)
# Bot event overrides # Bot event overrides
@bot.event @bot.event
async def on_ready(): async def on_ready():

View file

@ -102,7 +102,6 @@ class Core:
fortune = subprocess.check_output(fortuneCommand.split()).decode("utf-8") fortune = subprocess.check_output(fortuneCommand.split()).decode("utf-8")
await self.bot.say(fortune) await self.bot.say(fortune)
@commands.command(pass_context=True) @commands.command(pass_context=True)
@checks.customPermsOrRole(send_messages=True) @checks.customPermsOrRole(send_messages=True)
async def roll(self, ctx, notation: str="d6"): async def roll(self, ctx, notation: str="d6"):

View file

@ -77,7 +77,7 @@ class Mod:
await self.bot.say("That command has no custom permissions setup on it!") await self.bot.say("That command has no custom permissions setup on it!")
else: else:
permissions = discord.Permissions(perms_value) permissions = discord.Permissions(perms_value)
needed_perm = [perm[0] for perm in permissions._perm_iterator() if perm[1]][0] needed_perm = [perm[0] for perm in permissions if perm[1]][0]
await self.bot.say("You need to have the permission `{}` " await self.bot.say("You need to have the permission `{}` "
"to use the command `{}` in this server".format(needed_perm, command)) "to use the command `{}` in this server".format(needed_perm, command))
@ -110,7 +110,8 @@ class Mod:
break break
if cmd is None: if cmd is None:
await self.bot.say("That command does not exist! You can't have custom permissions on a non-existant command....") await self.bot.say(
"That command does not exist! You can't have custom permissions on a non-existant command....")
return return
for check in cmd.checks: for check in cmd.checks:
@ -182,14 +183,17 @@ class Mod:
rules = config.getContent('rules') or {} rules = config.getContent('rules') or {}
server_rules = rules.get(ctx.message.server.id) server_rules = rules.get(ctx.message.server.id)
if server_rules is None or len(server_rules) == 0: if server_rules is None or len(server_rules) == 0:
await self.bot.say("This server currently has no rules on it! Can't remove something that doesn't exist bro") await self.bot.say(
"This server currently has no rules on it! Can't remove something that doesn't exist bro")
return return
list_rules = "\n".join("{}) {}".format(num + 1, rule) for num, rule in enumerate(server_rules)) list_rules = "\n".join("{}) {}".format(num + 1, rule) for num, rule in enumerate(server_rules))
if rule is None: if rule is None:
await self.bot.say("Your rules are:\n```{}```Please provide the rule number you would like to remove (just the number)".format(list_rules)) await self.bot.say("Your rules are:\n```{}```Please provide the rule number"
"you would like to remove (just the number)".format(list_rules))
msg = await self.bot.wait_for_message(timeout=60.0, author=ctx.message.author, channel = ctx.message.channel, check = lambda m: m.content.isdigit()) msg = await self.bot.wait_for_message(timeout=60.0, author=ctx.message.author, channel=ctx.message.channel,
check=lambda m: m.content.isdigit())
if msg is None: if msg is None:
await self.bot.say("You took too long...it's just a number, seriously? Try typing a bit quicker") await self.bot.say("You took too long...it's just a number, seriously? Try typing a bit quicker")
return return
@ -203,7 +207,8 @@ class Mod:
config.saveContent('rules', rules) config.saveContent('rules', rules)
await self.bot.say("I have just removed that rule from your list of rules!") await self.bot.say("I have just removed that rule from your list of rules!")
except IndexError: except IndexError:
await self.bot.say("That is not a valid rule number, try running the command again. Your current rules are:\n```{}```".format(list_rules)) await self.bot.say("That is not a valid rule number, try running the command again. "
"Your current rules are:\n```{}```".format(list_rules))
def setup(bot): def setup(bot):

View file

@ -5,7 +5,6 @@ import discord
import aiohttp import aiohttp
import json import json
import re
base_url = "https://owapi.net/api/v2/u/" base_url = "https://owapi.net/api/v2/u/"
check_g_stats = ["eliminations", "deaths", 'kpd', 'wins', 'losses', 'time_played', check_g_stats = ["eliminations", "deaths", 'kpd', 'wins', 'losses', 'time_played',

View file

@ -60,7 +60,8 @@ class VoiceState:
self.current = await self.songs.get() self.current = await self.songs.get()
await self.bot.send_message(self.current.channel, 'Now playing ' + str(self.current)) await self.bot.send_message(self.current.channel, 'Now playing ' + str(self.current))
self.current.player = await self.voice.create_ytdl_player(self.current.player.url, ytdl_options=self.opts, after=self.toggle_next) self.current.player = await self.voice.create_ytdl_player(self.current.player.url, ytdl_options=self.opts,
after=self.toggle_next)
self.current.player.start() self.current.player.start()
await self.play_next_song.wait() await self.play_next_song.wait()
@ -69,6 +70,7 @@ class Music:
"""Voice related commands. """Voice related commands.
Works in multiple servers at once. Works in multiple servers at once.
""" """
def __init__(self, bot): def __init__(self, bot):
self.bot = bot self.bot = bot
self.voice_states = {} self.voice_states = {}

View file

@ -2,8 +2,6 @@ from discord.ext import commands
from .utils import config from .utils import config
from .utils import checks from .utils import checks
import discord import discord
import re
import operator
class Stats: class Stats:
@ -17,7 +15,6 @@ class Stats:
async def mostboops(self, ctx): async def mostboops(self, ctx):
"""Shows the person you have 'booped' the most, as well as how many times""" """Shows the person you have 'booped' the most, as well as how many times"""
boops = config.getContent('boops') boops = config.getContent('boops')
members = ctx.message.server.members
if not boops.get(ctx.message.author.id): if not boops.get(ctx.message.author.id):
await self.bot.say("You have not booped anyone {} Why the heck not...?".format(ctx.message.author.mention)) await self.bot.say("You have not booped anyone {} Why the heck not...?".format(ctx.message.author.mention))
return return
@ -36,7 +33,6 @@ class Stats:
@checks.customPermsOrRole(send_messages=True) @checks.customPermsOrRole(send_messages=True)
async def listboops(self, ctx): async def listboops(self, ctx):
"""Lists all the users you have booped and the amount of times""" """Lists all the users you have booped and the amount of times"""
members = ctx.message.server.members
boops = config.getContent('boops') or {} boops = config.getContent('boops') or {}
booped_members = boops.get(ctx.message.author.id) booped_members = boops.get(ctx.message.author.id)
if booped_members is None: if booped_members is None:
@ -46,7 +42,9 @@ class Stats:
server_member_ids = [member.id for member in ctx.message.server.members] server_member_ids = [member.id for member in ctx.message.server.members]
booped_members = {m_id: amt for m_id, amt in booped_members.items() if m_id in server_member_ids} booped_members = {m_id: amt for m_id, amt in booped_members.items() if m_id in server_member_ids}
output = "\n".join("{0.display_name}: {1} times".format(discord.utils.get(self.bot.get_all_members(),id=m_id),amt) for m_id,amt in booped_members) output = "\n".join(
"{0.display_name}: {1} times".format(discord.utils.get(self.bot.get_all_members(), id=m_id), amt) for
m_id, amt in booped_members)
await self.bot.say("You have booped:```{}```".format(output)) await self.bot.say("You have booped:```{}```".format(output))
@commands.command(pass_context=True, no_pm=True) @commands.command(pass_context=True, no_pm=True)
@ -57,7 +55,7 @@ class Stats:
server_member_ids = [member.id for member in ctx.message.server.members] server_member_ids = [member.id for member in ctx.message.server.members]
server_members = {member_id: stats for member_id, stats in battles.items() if member_id in server_member_ids} server_members = {member_id: stats for member_id, stats in battles.items() if member_id in server_member_ids}
sorted_members = sorted(server_members.items(), key = lambda x: x[1]['rating'],reverse=True) sorted_members = sorted(server_members.items(), key=lambda k: k[1]['rating'], reverse=True)
fmt = "" fmt = ""
count = 1 count = 1
@ -67,8 +65,7 @@ class Stats:
member = discord.utils.get(ctx.message.server.members, id=member_id) member = discord.utils.get(ctx.message.server.members, id=member_id)
fmt += "#{}) {} (Rating: {})\n".format(count, member.display_name, stats.get('rating')) fmt += "#{}) {} (Rating: {})\n".format(count, member.display_name, stats.get('rating'))
count += 1 count += 1
await self.bot.say("You have booped:```{}```".format(fmt)) await self.bot.say("Battling leaderboard for this server:```{}```".format(fmt))
@commands.command(pass_context=True) @commands.command(pass_context=True)
@checks.customPermsOrRole(send_messages=True) @checks.customPermsOrRole(send_messages=True)
@ -77,12 +74,13 @@ class Stats:
member = member or ctx.message.author member = member or ctx.message.author
all_members = config.getContent('battle_records') all_members = config.getContent('battle_records')
if not member.id in all_members: if member.id not in all_members:
await self.bot.say("That user has not battled yet!") await self.bot.say("That user has not battled yet!")
return return
server_member_ids = [member.id for member in ctx.message.server.members] server_member_ids = [member.id for member in ctx.message.server.members]
server_members = {member_id:stats for member_id,stats in all_members.items() if member_id in server_member_ids} server_members = {member_id: stats for member_id, stats in all_members.items() if
member_id in server_member_ids}
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)
@ -91,8 +89,10 @@ class Stats:
rating = server_members[member.id]['rating'] rating = server_members[member.id]['rating']
record = "{}-{}".format(server_members[member.id]['wins'], server_members[member.id]['losses']) record = "{}-{}".format(server_members[member.id]['wins'], server_members[member.id]['losses'])
fmt = 'Stats for {}:\n\tRecord: {}\n\tServer Rank: {}/{}\n\tOverall Rank: {}/{}\n\tRating: {}' fmt = 'Stats for {}:\n\tRecord: {}\n\tServer Rank: {}/{}\n\tOverall Rank: {}/{}\n\tRating: {}'
fmt = fmt.format(member.display_name,record,server_rank,len(server_members),total_rank,len(all_members),rating) fmt = fmt.format(member.display_name, record, server_rank, len(server_members), total_rank, len(all_members),
rating)
await self.bot.say('```{}```'.format(fmt)) await self.bot.say('```{}```'.format(fmt))
def setup(bot): def setup(bot):
bot.add_cog(Stats(bot)) bot.add_cog(Stats(bot))

View file

@ -2,6 +2,7 @@ from discord.ext import commands
from .utils import config from .utils import config
from .utils import checks from .utils import checks
class Tags: class Tags:
"""This class contains all the commands for custom tags""" """This class contains all the commands for custom tags"""
@ -43,13 +44,15 @@ class Tags:
if t['tag'] == tag and t['server_id'] == ctx.message.server.id: if t['tag'] == tag and t['server_id'] == ctx.message.server.id:
t['result'] = tag_result t['result'] = tag_result
if config.saveContent('tags', tags): if config.saveContent('tags', tags):
await self.bot.say("I have just updated the tag `{0}`! You can call this tag by entering !tag {0}".format(tag)) await self.bot.say(
"I have just updated the tag `{0}`! You can call this tag by entering !tag {0}".format(tag))
else: else:
await self.bot.say("I was unable to save this data") await self.bot.say("I was unable to save this data")
return return
tags.append({'server_id': ctx.message.server.id, 'tag': tag, 'result': tag_result}) tags.append({'server_id': ctx.message.server.id, 'tag': tag, 'result': tag_result})
if config.saveContent('tags', tags): if config.saveContent('tags', tags):
await self.bot.say("I have just added the tag `{0}`! You can call this tag by entering !tag {0}".format(tag)) await self.bot.say(
"I have just added the tag `{0}`! You can call this tag by entering !tag {0}".format(tag))
else: else:
await self.bot.say("I was unable to save this data") await self.bot.say("I was unable to save this data")
@ -72,5 +75,6 @@ class Tags:
else: else:
await self.bot.say("I was unable to save this data") await self.bot.say("I was unable to save this data")
def setup(bot): def setup(bot):
bot.add_cog(Tags(bot)) bot.add_cog(Tags(bot))

View file

@ -7,24 +7,6 @@ def isOwner(ctx):
return ctx.message.author.id == config.ownerID return ctx.message.author.id == config.ownerID
def customPermsOrRole(perm):
def predicate(ctx):
if ctx.message.channel.is_private:
return False
custom_permissions = config.getContent('custom_permissions')
_perm = None
try:
_perm = custom_permissions[ctx.message.server.id][str(ctx.command)]
except KeyError:
pass
if _perm is None:
return getattr(ctx.message.author.permissions_in(ctx.message.channel), perm)
else:
return getattr(ctx.message.author.permissions_in(ctx.message.channel), _perm)
return commands.check(predicate)
def customPermsOrRole(**perms): def customPermsOrRole(**perms):
def predicate(ctx): def predicate(ctx):
if ctx.message.channel.is_private: if ctx.message.channel.is_private:
@ -41,7 +23,6 @@ def customPermsOrRole(**perms):
required_perm = default_perms required_perm = default_perms
return member_perms >= required_perm return member_perms >= required_perm
return commands.check(predicate) return commands.check(predicate)