From 5d3a2335715a05683c2523a56c634a4c9495bee7 Mon Sep 17 00:00:00 2001 From: brandons209 Date: Fri, 31 Jan 2020 19:37:32 -0500 Subject: [PATCH] forgot style --- costmanager/__init__.py | 1 + costmanager/manager.py | 30 +++++++++++++++++++----------- rolemanagement/core.py | 4 +++- welcome/welcome.py | 4 +++- 4 files changed, 26 insertions(+), 13 deletions(-) diff --git a/costmanager/__init__.py b/costmanager/__init__.py index 6723274..9167606 100644 --- a/costmanager/__init__.py +++ b/costmanager/__init__.py @@ -1,4 +1,5 @@ from .manager import CostManager + def setup(bot): bot.add_cog(CostManager(bot)) diff --git a/costmanager/manager.py b/costmanager/manager.py index fab8b49..8c09866 100644 --- a/costmanager/manager.py +++ b/costmanager/manager.py @@ -5,9 +5,11 @@ import discord from collections import defaultdict + class PoorError(commands.CommandError): pass + # 0 -> member, 1 -> guild NEW_RECEIPT_MESSAGE = "Hello {0.mention}! This is will be your receipt for commands you pay for in {1.name}.\nThe message below will auto update as you pay for commands. I will pin the message for you so you can refer back to this to track your spending." @@ -16,12 +18,14 @@ RECEIPT_MESSAGE = "{0}. {1}: {2} {3}\n" MAX_MSG_LEN = 2000 + class CostManager(commands.Cog): """ Allows customizing costs for any commands loaded into read, and also set users who are exempt from costs on a per member or per role level. Hierarchy: user > role > guild_role """ + def __init__(self, bot): self.bot = bot self.config = Config.get_conf(self, identifier=13291493293, force_registration=True) @@ -34,10 +38,7 @@ class CostManager(commands.Cog): # }, # ... # } - default_guild = { - "FREE_ROLES": [], - "COMMANDS": {} - } + default_guild = {"FREE_ROLES": [], "COMMANDS": {}} self.config.register_guild(**default_guild) self.config.register_member(receipt=0) self.bot.before_invoke(self.cost_checker) @@ -88,7 +89,7 @@ class CostManager(commands.Cog): # check role cost, choose lowest cost if mutliple roles found. elif found_roles: cost = min([command_data["role_ids"][r] for r in found_roles]) - else: # get normal cost for command and check guild free roles + else: # get normal cost for command and check guild free roles cost = command_data["cost"] found_roles = set(guild_data["FREE_ROLES"]) & member_roles if found_roles: @@ -123,8 +124,10 @@ class CostManager(commands.Cog): try: await channel.send(NEW_RECEIPT_MESSAGE.format(member, guild)) except: - if receipt != -1: # send mention if first time getting this message - await ctx.send(f"Hey {member.mention}, please turn on DMs from server members in your settings so I can send you receipts for purchase of commands.") + if receipt != -1: # send mention if first time getting this message + await ctx.send( + f"Hey {member.mention}, please turn on DMs from server members in your settings so I can send you receipts for purchase of commands." + ) await self.config.member(member).receipt.set(-1) return @@ -283,7 +286,9 @@ class CostManager(commands.Cog): not_found = len([r for r in curr if r is None]) curr = [r.name for r in curr if curr is not None] if not_found: - await ctx.send(f"{not_found} roles weren't found, please run {ctx.prefix}costset clear to remove these roles.\nFree Roles: {self.format_list(*curr)}") + await ctx.send( + f"{not_found} roles weren't found, please run {ctx.prefix}costset clear to remove these roles.\nFree Roles: {self.format_list(*curr)}" + ) else: await ctx.send(f"Free Roles: {self.format_list(*curr)}") return @@ -307,7 +312,9 @@ class CostManager(commands.Cog): found.add(role) if not_found: - await ctx.send(warning("These roles weren't found, please try again: {}".format(self.format_list(*not_found)))) + await ctx.send( + warning("These roles weren't found, please try again: {}".format(self.format_list(*not_found))) + ) return async with self.config.guild(ctx.guild).FREE_ROLES() as free: @@ -376,7 +383,6 @@ class CostManager(commands.Cog): currency_name = await bank.get_currency_name(ctx.guild) await ctx.send(f"{command} costs `{cost}` {currency_name} for you.") - @commands.Cog.listener() async def on_member_remove(self, member): await self.clean_data(member.guild) @@ -392,4 +398,6 @@ class CostManager(commands.Cog): cost = await self.get_cost(ctx) currency_name = await bank.get_currency_name(ctx.guild) balance = await bank.get_balance(ctx.author) - await ctx.send(f"Sorry {ctx.author.name}, you do not have enough {currency_name} to use that command. (Cost: {cost}, Balance: {balance})") + await ctx.send( + f"Sorry {ctx.author.name}, you do not have enough {currency_name} to use that command. (Cost: {cost}, Balance: {balance})" + ) diff --git a/rolemanagement/core.py b/rolemanagement/core.py index e9afb75..3c33ab9 100644 --- a/rolemanagement/core.py +++ b/rolemanagement/core.py @@ -787,7 +787,9 @@ class RoleManagement( await ctx.send(f"You aren't allowed to add `{role}` to yourself {ctx.author.mention}!") elif cost: - await ctx.send("This role is not free. " "Please use `[p]selfrole buy` if you would like to purchase it.") + await ctx.send( + "This role is not free. " "Please use `[p]selfrole buy` if you would like to purchase it." + ) else: await self.update_roles_atomically(who=ctx.author, give=[role], remove=remove) await ctx.tick() diff --git a/welcome/welcome.py b/welcome/welcome.py index a9a2268..c0437b5 100644 --- a/welcome/welcome.py +++ b/welcome/welcome.py @@ -793,7 +793,9 @@ class Welcome(commands.Cog): try: return await channel.send( - format_str.format(member=user, server=guild, bot=user, count=count or "", plural=plural, roles=roles, stats=stats) + format_str.format( + member=user, server=guild, bot=user, count=count or "", plural=plural, roles=roles, stats=stats + ) ) except discord.Forbidden: log.error(