1
0
Fork 0
mirror of synced 2024-06-01 18:29:38 +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')
log.addHandler(handler)
# Bot event overrides
@bot.event
async def on_ready():

View file

@ -102,7 +102,6 @@ class Core:
fortune = subprocess.check_output(fortuneCommand.split()).decode("utf-8")
await self.bot.say(fortune)
@commands.command(pass_context=True)
@checks.customPermsOrRole(send_messages=True)
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!")
else:
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 `{}` "
"to use the command `{}` in this server".format(needed_perm, command))
@ -90,13 +90,13 @@ class Mod:
command = " ".join(msg[0:len(msg) - 1])
permissions = msg[len(msg) - 1]
#If a user can run the command, they have to have send_messages permissions; so use this as the base
# If a user can run the command, they have to have send_messages permissions; so use this as the base
if permissions.lower() == "none":
permissions = "send_messages"
#Convert the string to an int value of the permissions obj, based on the required permission
# Convert the string to an int value of the permissions obj, based on the required permission
perm_obj = discord.Permissions.none()
setattr(perm_obj,permissions,True)
setattr(perm_obj, permissions, True)
perm_value = perm_obj.value
cmd = None
@ -110,7 +110,8 @@ class Mod:
break
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
for check in cmd.checks:
@ -159,7 +160,7 @@ class Mod:
if server_rules is None or len(server_rules) == 0:
await self.bot.say("This server currently has no rules on it! I see you like to live dangerously...")
return
fmt = "\n".join("{}) {}".format(num+1,rule) for num,rule in enumerate(server_rules))
fmt = "\n".join("{}) {}".format(num + 1, rule) for num, rule in enumerate(server_rules))
await self.bot.say('```{}```'.format(fmt))
@rules.command(name='add', aliases=['create'], pass_context=True, no_pm=True)
@ -170,7 +171,7 @@ class Mod:
server_rules = rules.get(ctx.message.server.id) or []
server_rules.append(rule)
rules[ctx.message.server.id] = server_rules
config.saveContent('rules',rules)
config.saveContent('rules', rules)
await self.bot.say("I have just saved your new rule, use the rules command to view this server's current rules")
@rules.command(name='remove', aliases=['delete'], pass_context=True, no_pm=True)
@ -182,28 +183,32 @@ class Mod:
rules = config.getContent('rules') or {}
server_rules = rules.get(ctx.message.server.id)
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
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:
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:
await self.bot.say("You took too long...it's just a number, seriously? Try typing a bit quicker")
return
del server_rules[int(msg.content)-1]
del server_rules[int(msg.content) - 1]
rules[ctx.message.server.id] = server_rules
config.saveContent('rules',rules)
config.saveContent('rules', rules)
try:
del server_rules[rule-1]
del server_rules[rule - 1]
rules[ctx.message.server.id] = server_rules
config.saveContent('rules',rules)
config.saveContent('rules', rules)
await self.bot.say("I have just removed that rule from your list of rules!")
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):

View file

@ -5,7 +5,6 @@ import discord
import aiohttp
import json
import re
base_url = "https://owapi.net/api/v2/u/"
check_g_stats = ["eliminations", "deaths", 'kpd', 'wins', 'losses', 'time_played',
@ -29,7 +28,7 @@ class Overwatch:
@ow.command(name="stats", pass_context=True, no_pm=True)
@checks.customPermsOrRole(send_messages=True)
async def ow_stats(self, ctx, user: discord.Member = None, hero: str = ""):
async def ow_stats(self, ctx, user: discord.Member=None, hero: str=""):
"""Prints out a basic overview of a member's stats
Provide a hero after the member to get stats for that specific hero"""
if user is None:
@ -42,7 +41,7 @@ class Overwatch:
await self.bot.say("Searching profile information....")
if hero == "":
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(base_url + "{}/stats/general".format(bt)) as r:
result = await r.text()
@ -54,7 +53,7 @@ class Overwatch:
"Overwatch stats for {}: ```py\n{}```".format(user.name, fmt.title().replace("_", " ")))
else:
url = base_url + "{}/heroes/{}".format(bt, hero.lower().replace('-', ''))
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:
if r.status == 500:
fmt = "{} has not used the hero {} before!".format(user.name, hero.title())
@ -81,7 +80,7 @@ class Overwatch:
await self.bot.say("Looking up your profile information....")
url = base_url + "{}/stats/general".format(bt)
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:
if not r.status == 200:
await self.bot.say("Profile does not exist! Battletags are picky, "

View file

@ -60,7 +60,8 @@ class VoiceState:
self.current = await self.songs.get()
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()
await self.play_next_song.wait()
@ -69,6 +70,7 @@ class Music:
"""Voice related commands.
Works in multiple servers at once.
"""
def __init__(self, bot):
self.bot = bot
self.voice_states = {}

View file

@ -2,8 +2,6 @@ from discord.ext import commands
from .utils import config
from .utils import checks
import discord
import re
import operator
class Stats:
@ -17,7 +15,6 @@ class Stats:
async def mostboops(self, ctx):
"""Shows the person you have 'booped' the most, as well as how many times"""
boops = config.getContent('boops')
members = ctx.message.server.members
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))
return
@ -36,7 +33,6 @@ class Stats:
@checks.customPermsOrRole(send_messages=True)
async def listboops(self, ctx):
"""Lists all the users you have booped and the amount of times"""
members = ctx.message.server.members
boops = config.getContent('boops') or {}
booped_members = boops.get(ctx.message.author.id)
if booped_members is None:
@ -44,9 +40,11 @@ class Stats:
return
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))
@commands.command(pass_context=True, no_pm=True)
@ -56,19 +54,18 @@ class Stats:
battles = config.getContent('battle_records')
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}
sorted_members = sorted(server_members.items(), key = lambda x: x[1]['rating'],reverse=True)
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 k: k[1]['rating'], reverse=True)
fmt = ""
count = 1
for x in sorted_members:
member_id = x[0]
stats = x[1]
member = discord.utils.get(ctx.message.server.members,id=member_id)
fmt += "#{}) {} (Rating: {})\n".format(count,member.display_name,stats.get('rating'))
member = discord.utils.get(ctx.message.server.members, id=member_id)
fmt += "#{}) {} (Rating: {})\n".format(count, member.display_name, stats.get('rating'))
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)
@checks.customPermsOrRole(send_messages=True)
@ -77,22 +74,25 @@ class Stats:
member = member or ctx.message.author
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!")
return
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}
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)
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_all_members = sorted(all_members.items(), key=lambda x: x[1]['rating'], reverse=True)
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
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
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 = 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))
def setup(bot):
bot.add_cog(Stats(bot))

View file

@ -2,6 +2,7 @@ from discord.ext import commands
from .utils import config
from .utils import checks
class Tags:
"""This class contains all the commands for custom tags"""
@ -13,7 +14,7 @@ class Tags:
async def tags(self, ctx):
"""Prints all the custom tags that this server currently has"""
tags = config.getContent('tags')
fmt = "\n".join("{}".format(tag['tag']) for tag in tags if tag['server_id']==ctx.message.server.id)
fmt = "\n".join("{}".format(tag['tag']) for tag in tags if tag['server_id'] == ctx.message.server.id)
await self.bot.say('```{}```'.format(fmt))
@commands.group(pass_context=True, invoke_without_command=True, no_pm=True)
@ -43,13 +44,15 @@ class Tags:
if t['tag'] == tag and t['server_id'] == ctx.message.server.id:
t['result'] = tag_result
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:
await self.bot.say("I was unable to save this data")
return
tags.append({'server_id': ctx.message.server.id, 'tag': tag, 'result': tag_result})
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:
await self.bot.say("I was unable to save this data")
@ -72,5 +75,6 @@ class Tags:
else:
await self.bot.say("I was unable to save this data")
def setup(bot):
bot.add_cog(Tags(bot))

View file

@ -41,14 +41,14 @@ class Twitch:
twitch[m_id]['live'] = 1
fmt = "{} has just gone live! View their stream at {}".format(member.name, url)
await self.bot.send_message(server, fmt)
config.saveContent('twitch',twitch)
config.saveContent('twitch', twitch)
elif live and not online:
server = discord.utils.find(lambda s: s.id == r['server_id'], self.bot.servers)
member = discord.utils.find(lambda m: m.id == m_id, server.members)
twitch[m_id]['live'] = 0
fmt = "{} has just gone offline! Catch them next time they stream at {}".format(member.name, url)
await self.bot.send_message(server,fmt)
config.saveContent('twitch',twitch)
await self.bot.send_message(server, fmt)
config.saveContent('twitch', twitch)
await asyncio.sleep(30)
@commands.group(no_pm=True, invoke_without_command=True, pass_context=True)

View file

@ -7,24 +7,6 @@ def isOwner(ctx):
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 predicate(ctx):
if ctx.message.channel.is_private:
@ -32,8 +14,8 @@ def customPermsOrRole(**perms):
member_perms = ctx.message.author.permissions_in(ctx.message.channel)
default_perms = discord.Permissions.none()
for perm,setting in perms.items():
setattr(default_perms,perm,setting)
for perm, setting in perms.items():
setattr(default_perms, perm, setting)
try:
required_perm = config.getContent('custom_permissions')[ctx.message.server.id][ctx.command.qualified_name]
@ -41,7 +23,6 @@ def customPermsOrRole(**perms):
required_perm = default_perms
return member_perms >= required_perm
return commands.check(predicate)