[V3] Update code standards (black code format pass) (#1650)

* ran black: code formatter against `redbot/` with `-l 99`

* badge
This commit is contained in:
Michael H
2018-05-14 15:33:24 -04:00
committed by Will
parent e7476edd68
commit b88b5a2601
90 changed files with 3629 additions and 3223 deletions

View File

@@ -9,7 +9,9 @@ from redbot.core.i18n import Translator
_ = Translator("Warnings", __file__)
async def warning_points_add_check(config: Config, ctx: commands.Context, user: discord.Member, points: int):
async def warning_points_add_check(
config: Config, ctx: commands.Context, user: discord.Member, points: int
):
"""Handles any action that needs to be taken or not based on the points"""
guild = ctx.guild
guild_settings = config.guild(guild)
@@ -24,7 +26,9 @@ async def warning_points_add_check(config: Config, ctx: commands.Context, user:
await create_and_invoke_context(ctx, act["exceed_command"], user)
async def warning_points_remove_check(config: Config, ctx: commands.Context, user: discord.Member, points: int):
async def warning_points_remove_check(
config: Config, ctx: commands.Context, user: discord.Member, points: int
):
guild = ctx.guild
guild_settings = config.guild(guild)
act = {}
@@ -38,7 +42,9 @@ async def warning_points_remove_check(config: Config, ctx: commands.Context, use
await create_and_invoke_context(ctx, act["drop_command"], user)
async def create_and_invoke_context(realctx: commands.Context, command_str: str, user: discord.Member):
async def create_and_invoke_context(
realctx: commands.Context, command_str: str, user: discord.Member
):
m = copy(realctx.message)
m.content = command_str.format(user=user.mention, prefix=realctx.prefix)
fctx = await realctx.bot.get_context(m, cls=commands.Context)
@@ -54,7 +60,7 @@ def get_command_from_input(bot, userinput: str):
while com is None:
com = bot.get_command(userinput)
if com is None:
userinput = ' '.join(userinput.split(' ')[:-1])
userinput = " ".join(userinput.split(" ")[:-1])
if len(userinput) == 0:
break
if com is None:
@@ -63,8 +69,9 @@ def get_command_from_input(bot, userinput: str):
check_str = inspect.getsource(checks.is_owner)
if any(inspect.getsource(x) in check_str for x in com.checks):
# command the user specified has the is_owner check
return None, _("That command requires bot owner. I can't "
"allow you to use that for an action")
return None, _(
"That command requires bot owner. I can't " "allow you to use that for an action"
)
return "{prefix}" + orig, None
@@ -72,13 +79,15 @@ async def get_command_for_exceeded_points(ctx: commands.Context):
"""Gets the command to be executed when the user is at or exceeding
the points threshold for the action"""
await ctx.send(
_("Enter the command to be run when the user exceeds the points for "
"this action to occur.\nEnter it exactly as you would if you were "
"actually trying to run the command, except don't put a prefix and "
"use {user} in place of any user/member arguments\n\n"
"WARNING: The command entered will be run without regard to checks or cooldowns. "
"Commands requiring bot owner are not allowed for security reasons.\n\n"
"Please wait 15 seconds before entering your response.")
_(
"Enter the command to be run when the user exceeds the points for "
"this action to occur.\nEnter it exactly as you would if you were "
"actually trying to run the command, except don't put a prefix and "
"use {user} in place of any user/member arguments\n\n"
"WARNING: The command entered will be run without regard to checks or cooldowns. "
"Commands requiring bot owner are not allowed for security reasons.\n\n"
"Please wait 15 seconds before entering your response."
)
)
await asyncio.sleep(15)
@@ -110,15 +119,17 @@ async def get_command_for_dropping_points(ctx: commands.Context):
when the user exceeded the threshold
"""
await ctx.send(
_("Enter the command to be run when the user returns to a value below "
"the points for this action to occur. Please note that this is "
"intended to be used for reversal of the action taken when the user "
"exceeded the action's point value\nEnter it exactly as you would "
"if you were actually trying to run the command, except don't put a prefix "
"and use {user} in place of any user/member arguments\n\n"
"WARNING: The command entered will be run without regard to checks or cooldowns. "
"Commands requiring bot owner are not allowed for security reasons.\n\n"
"Please wait 15 seconds before entering your response.")
_(
"Enter the command to be run when the user returns to a value below "
"the points for this action to occur. Please note that this is "
"intended to be used for reversal of the action taken when the user "
"exceeded the action's point value\nEnter it exactly as you would "
"if you were actually trying to run the command, except don't put a prefix "
"and use {user} in place of any user/member arguments\n\n"
"WARNING: The command entered will be run without regard to checks or cooldowns. "
"Commands requiring bot owner are not allowed for security reasons.\n\n"
"Please wait 15 seconds before entering your response."
)
)
await asyncio.sleep(15)

View File

@@ -1,15 +1,10 @@
import subprocess
TO_TRANSLATE = [
'../warnings.py',
'../helpers.py'
]
TO_TRANSLATE = ["../warnings.py", "../helpers.py"]
def regen_messages():
subprocess.run(
['pygettext', '-n'] + TO_TRANSLATE
)
subprocess.run(["pygettext", "-n"] + TO_TRANSLATE)
if __name__ == "__main__":

View File

@@ -3,8 +3,12 @@ from collections import namedtuple
import discord
import asyncio
from redbot.cogs.warnings.helpers import warning_points_add_check, get_command_for_exceeded_points, \
get_command_for_dropping_points, warning_points_remove_check
from redbot.cogs.warnings.helpers import (
warning_points_add_check,
get_command_for_exceeded_points,
get_command_for_dropping_points,
warning_points_remove_check,
)
from redbot.core import Config, modlog, checks, commands
from redbot.core.bot import Red
from redbot.core.i18n import Translator, cog_i18n
@@ -18,17 +22,9 @@ _ = Translator("Warnings", __file__)
class Warnings:
"""A warning system for Red"""
default_guild = {
"actions": [],
"reasons": {},
"allow_custom_reasons": False
}
default_guild = {"actions": [], "reasons": {}, "allow_custom_reasons": False}
default_member = {
"total_points": 0,
"status": "",
"warnings": {}
}
default_member = {"total_points": 0, "status": "", "warnings": {}}
def __init__(self, bot: Red):
self.config = Config.get_conf(self, identifier=5757575755)
@@ -41,9 +37,7 @@ class Warnings:
@staticmethod
async def register_warningtype():
try:
await modlog.register_casetype(
"warning", True, "\N{WARNING SIGN}", "Warning", None
)
await modlog.register_casetype("warning", True, "\N{WARNING SIGN}", "Warning", None)
except RuntimeError:
pass
@@ -105,7 +99,7 @@ class Warnings:
"action_name": name,
"points": points,
"exceed_command": exceed_command,
"drop_command": drop_command
"drop_command": drop_command,
}
# Have all details for the action, now save the action
@@ -138,9 +132,7 @@ class Warnings:
registered_actions.remove(to_remove)
await ctx.tick()
else:
await ctx.send(
_("No action named {} exists!").format(action_name)
)
await ctx.send(_("No action named {} exists!").format(action_name))
@commands.group()
@commands.guild_only()
@@ -159,13 +151,8 @@ class Warnings:
if name.lower() == "custom":
await ctx.send("That cannot be used as a reason name!")
return
to_add = {
"points": points,
"description": description
}
completed = {
name.lower(): to_add
}
to_add = {"points": points, "description": description}
completed = {name.lower(): to_add}
guild_settings = self.config.guild(guild)
@@ -219,8 +206,7 @@ class Warnings:
msg_list.append(
"Name: {}\nPoints: {}\nExceed command: {}\n"
"Drop command: {}".format(
r["action_name"], r["points"], r["exceed_command"],
r["drop_command"]
r["action_name"], r["points"], r["exceed_command"], r["drop_command"]
)
)
if msg_list:
@@ -262,7 +248,7 @@ class Warnings:
str(ctx.message.id): {
"points": reason_type["points"],
"description": reason_type["description"],
"mod": ctx.author.id
"mod": ctx.author.id,
}
}
async with member_settings.warnings() as user_warnings:
@@ -275,7 +261,7 @@ class Warnings:
@commands.command()
@commands.guild_only()
async def warnings(self, ctx: commands.Context, userid: int=None):
async def warnings(self, ctx: commands.Context, userid: int = None):
"""Show warnings for the specified user.
If userid is None, show warnings for the person running the command
Note that showing warnings for users other than yourself requires
@@ -285,10 +271,7 @@ class Warnings:
else:
if not await is_admin_or_superior(self.bot, ctx.author):
await ctx.send(
warning(
_("You are not allowed to check "
"warnings for other users!")
)
warning(_("You are not allowed to check " "warnings for other users!"))
)
return
else:
@@ -305,22 +288,14 @@ class Warnings:
mod = ctx.guild.get_member(user_warnings[key]["mod"])
if mod is None:
mod = discord.utils.get(
self.bot.get_all_members(),
id=user_warnings[key]["mod"]
self.bot.get_all_members(), id=user_warnings[key]["mod"]
)
if mod is None:
mod = await self.bot.get_user_info(
user_warnings[key]["mod"]
)
mod = await self.bot.get_user_info(user_warnings[key]["mod"])
msg += "{} point warning {} issued by {} for {}\n".format(
user_warnings[key]["points"],
key,
mod,
user_warnings[key]["description"]
user_warnings[key]["points"], key, mod, user_warnings[key]["description"]
)
await ctx.send_interactive(
pagify(msg), box_lang="Warnings for {}".format(user)
)
await ctx.send_interactive(pagify(msg), box_lang="Warnings for {}".format(user))
@commands.command()
@commands.guild_only()
@@ -348,10 +323,7 @@ class Warnings:
@staticmethod
async def custom_warning_reason(ctx: commands.Context):
"""Handles getting description and points for custom reasons"""
to_add = {
"points": 0,
"description": ""
}
to_add = {"points": 0, "description": ""}
def same_author_check(m):
return m.author == ctx.author