one day these will stop with black

This commit is contained in:
brandons209 2021-02-13 04:12:09 -05:00
parent 7c00e3c273
commit a7cce76223
2 changed files with 42 additions and 69 deletions

View file

@ -10,9 +10,7 @@ from redbot.core.utils.predicates import MessagePredicate
_ = Translator("Warnings", __file__) _ = Translator("Warnings", __file__)
async def warning_points_add_check( async def warning_points_add_check(config: Config, ctx: commands.Context, user: discord.Member, points: int):
config: Config, ctx: commands.Context, user: discord.Member, points: int
):
"""Handles any action that needs to be taken or not based on the points""" """Handles any action that needs to be taken or not based on the points"""
guild = ctx.guild guild = ctx.guild
guild_settings = config.guild(guild) guild_settings = config.guild(guild)
@ -29,9 +27,7 @@ async def warning_points_add_check(
await create_and_invoke_context(ctx, act["exceed_command"], user) await create_and_invoke_context(ctx, act["exceed_command"], user)
async def warning_points_remove_check( async def warning_points_remove_check(config: Config, ctx: commands.Context, user: discord.Member, points: int):
config: Config, ctx: commands.Context, user: discord.Member, points: int
):
guild = ctx.guild guild = ctx.guild
guild_settings = config.guild(guild) guild_settings = config.guild(guild)
act = {} act = {}
@ -45,9 +41,7 @@ async def warning_points_remove_check(
await create_and_invoke_context(ctx, act["drop_command"], user) await create_and_invoke_context(ctx, act["drop_command"], user)
async def create_and_invoke_context( async def create_and_invoke_context(realctx: commands.Context, command_str: str, user: discord.Member):
realctx: commands.Context, command_str: str, user: discord.Member
):
m = copy(realctx.message) m = copy(realctx.message)
m.content = command_str.format(user=user.mention, prefix=realctx.prefix) m.content = command_str.format(user=user.mention, prefix=realctx.prefix)
fctx = await realctx.bot.get_context(m, cls=commands.Context) fctx = await realctx.bot.get_context(m, cls=commands.Context)
@ -99,9 +93,7 @@ async def get_command_for_exceeded_points(ctx: commands.Context):
await ctx.send(_("You may enter your response now.")) await ctx.send(_("You may enter your response now."))
try: try:
msg = await ctx.bot.wait_for( msg = await ctx.bot.wait_for("message", check=MessagePredicate.same_context(ctx), timeout=30)
"message", check=MessagePredicate.same_context(ctx), timeout=30
)
except asyncio.TimeoutError: except asyncio.TimeoutError:
return None return None
else: else:
@ -143,9 +135,7 @@ async def get_command_for_dropping_points(ctx: commands.Context):
await ctx.send(_("You may enter your response now.")) await ctx.send(_("You may enter your response now."))
try: try:
msg = await ctx.bot.wait_for( msg = await ctx.bot.wait_for("message", check=MessagePredicate.same_context(ctx), timeout=30)
"message", check=MessagePredicate.same_context(ctx), timeout=30
)
except asyncio.TimeoutError: except asyncio.TimeoutError:
return None return None
else: else:

View file

@ -153,15 +153,11 @@ class Warnings_Custom(commands.Cog):
await self.config.guild(ctx.guild).show_mod.set(true_or_false) await self.config.guild(ctx.guild).show_mod.set(true_or_false)
if true_or_false: if true_or_false:
await ctx.send( await ctx.send(
_( _("I will include the name of the moderator who issued the warning when sending a DM to a user.")
"I will include the name of the moderator who issued the warning when sending a DM to a user."
)
) )
else: else:
await ctx.send( await ctx.send(
_( _("I will not include the name of the moderator who issued the warning when sending a DM to a user.")
"I will not include the name of the moderator who issued the warning when sending a DM to a user."
)
) )
@warningset.command() @warningset.command()
@ -174,9 +170,7 @@ class Warnings_Custom(commands.Cog):
guild = ctx.guild guild = ctx.guild
if channel: if channel:
await self.config.guild(guild).warn_channel.set(channel.id) await self.config.guild(guild).warn_channel.set(channel.id)
await ctx.send( await ctx.send(_("The warn channel has been set to {channel}.").format(channel=channel.mention))
_("The warn channel has been set to {channel}.").format(channel=channel.mention)
)
else: else:
await self.config.guild(guild).warn_channel.set(channel) await self.config.guild(guild).warn_channel.set(channel)
await ctx.send(_("Warnings will now be sent in the channel command was used in.")) await ctx.send(_("Warnings will now be sent in the channel command was used in."))
@ -191,9 +185,7 @@ class Warnings_Custom(commands.Cog):
channel = self.bot.get_channel(await self.config.guild(ctx.guild).warn_channel()) channel = self.bot.get_channel(await self.config.guild(ctx.guild).warn_channel())
if true_or_false: if true_or_false:
if channel: if channel:
await ctx.send( await ctx.send(_("Warnings will now be sent to {channel}.").format(channel=channel.mention))
_("Warnings will now be sent to {channel}.").format(channel=channel.mention)
)
else: else:
await ctx.send(_("Warnings will now be sent in the channel command was used in.")) await ctx.send(_("Warnings will now be sent in the channel command was used in."))
else: else:
@ -279,9 +271,7 @@ class Warnings_Custom(commands.Cog):
@warnreason.command(name="create", aliases=["add"]) @warnreason.command(name="create", aliases=["add"])
@commands.guild_only() @commands.guild_only()
async def reason_create( async def reason_create(self, ctx: commands.Context, name: str, points: int, *, description: str):
self, ctx: commands.Context, name: str, points: int, *, description: str
):
"""Create a warning reason.""" """Create a warning reason."""
guild = ctx.guild guild = ctx.guild
@ -329,9 +319,9 @@ class Warnings_Custom(commands.Cog):
msg_list.append(em) msg_list.append(em)
else: else:
msg_list.append( msg_list.append(
_( _("Name: {reason_name}\nPoints: {points}\nDescription: {description}").format(
"Name: {reason_name}\nPoints: {points}\nDescription: {description}" reason_name=r, **v
).format(reason_name=r, **v) )
) )
if msg_list: if msg_list:
await menu(ctx, msg_list, DEFAULT_CONTROLS) await menu(ctx, msg_list, DEFAULT_CONTROLS)
@ -423,8 +413,7 @@ class Warnings_Custom(commands.Cog):
can = False can = False
if can: if can:
msg += " " + _( msg += " " + _(
"Do `{prefix}warningset allowcustomreasons true` to enable custom " "Do `{prefix}warningset allowcustomreasons true` to enable custom " "reasons."
"reasons."
).format(prefix=ctx.clean_prefix) ).format(prefix=ctx.clean_prefix)
return await ctx.send(msg) return await ctx.send(msg)
if reason_type is None: if reason_type is None:
@ -471,7 +460,6 @@ class Warnings_Custom(commands.Cog):
else: else:
context = msg.content context = msg.content
member_settings = self.config.member(user) member_settings = self.config.member(user)
current_point_count = await member_settings.total_points() current_point_count = await member_settings.total_points()
current_point_count += reason_type["points"] current_point_count += reason_type["points"]
@ -493,9 +481,7 @@ class Warnings_Custom(commands.Cog):
em.add_field(name=_("Points"), value=str(reason_type["points"])) em.add_field(name=_("Points"), value=str(reason_type["points"]))
try: try:
await user.send( await user.send(
_("You have received a warning in {guild_name}.").format( _("You have received a warning in {guild_name}.").format(guild_name=ctx.guild.name),
guild_name=ctx.guild.name
),
embed=em, embed=em,
) )
except discord.HTTPException: except discord.HTTPException:
@ -503,10 +489,9 @@ class Warnings_Custom(commands.Cog):
if dm_failed: if dm_failed:
await ctx.send( await ctx.send(
_( _("A warning for {user} has been issued," " but I wasn't able to send them a warn message.").format(
"A warning for {user} has been issued," user=user.mention
" but I wasn't able to send them a warn message." )
).format(user=user.mention)
) )
toggle_channel = guild_settings["toggle_channel"] toggle_channel = guild_settings["toggle_channel"]
@ -533,15 +518,11 @@ class Warnings_Custom(commands.Cog):
if warn_channel: if warn_channel:
await ctx.tick() await ctx.tick()
else: else:
await ctx.send( await ctx.send(_("{user} has been warned.").format(user=user.mention), embed=em)
_("{user} has been warned.").format(user=user.mention), embed=em
)
else: else:
if not dm_failed: if not dm_failed:
await ctx.tick() await ctx.tick()
reason_msg = _( reason_msg = _("{reason}\n\nUse `{prefix}unwarn {user} {message}` to remove this warning.{context}").format(
"{reason}\n\nUse `{prefix}unwarn {user} {message}` to remove this warning.{context}"
).format(
reason=_("{description}\nPoints: {points}").format( reason=_("{description}\nPoints: {points}").format(
description=reason_type["description"], points=reason_type["points"] description=reason_type["description"], points=reason_type["points"]
), ),
@ -551,16 +532,16 @@ class Warnings_Custom(commands.Cog):
context=f"\n\n**Context**:\n{context}" if context else "", context=f"\n\n**Context**:\n{context}" if context else "",
) )
case = await modlog.create_case( case = await modlog.create_case(
self.bot, self.bot,
ctx.guild, ctx.guild,
ctx.message.created_at.replace(tzinfo=timezone.utc), ctx.message.created_at.replace(tzinfo=timezone.utc),
"warning", "warning",
user, user,
ctx.message.author, ctx.message.author,
reason_msg, reason_msg,
until=None, until=None,
channel=None, channel=None,
) )
warning_to_add = { warning_to_add = {
str(ctx.message.id): { str(ctx.message.id): {
@ -568,7 +549,7 @@ class Warnings_Custom(commands.Cog):
"description": reason_type["description"], "description": reason_type["description"],
"mod": ctx.author.id, "mod": ctx.author.id,
"date": ctx.message.created_at.replace(tzinfo=timezone.utc).strftime("%Y-%m-%d %H:%M:%S UTC"), "date": ctx.message.created_at.replace(tzinfo=timezone.utc).strftime("%Y-%m-%d %H:%M:%S UTC"),
"caseno": case.case_number "caseno": case.case_number,
} }
} }
async with member_settings.warnings() as user_warnings: async with member_settings.warnings() as user_warnings:
@ -600,18 +581,19 @@ class Warnings_Custom(commands.Cog):
else: else:
bot = ctx.bot bot = ctx.bot
mod = bot.get_user(mod_id) or _("Unknown Moderator ({})").format(mod_id) mod = bot.get_user(mod_id) or _("Unknown Moderator ({})").format(mod_id)
date = user_warnings[key].get("date", None) # not all warnings may have date if switched from using warnings cog by red date = user_warnings[key].get(
num = user_warnings[key].get("caseno", None) # same as above "date", None
) # not all warnings may have date if switched from using warnings cog by red
num = user_warnings[key].get("caseno", None) # same as above
msg += _( msg += _(
"{num}{num_points} point warning {reason_name} issued by {user} for " "{num}{num_points} point warning {reason_name} issued by {user} for " "{description}{date}\n"
"{description}{date}\n"
).format( ).format(
num_points=user_warnings[key]["points"], num_points=user_warnings[key]["points"],
reason_name=key, reason_name=key,
user=mod, user=mod,
description=user_warnings[key]["description"], description=user_warnings[key]["description"],
date=" at {}".format(date) if date else "", date=" at {}".format(date) if date else "",
num=f"Case #{num}: " if num else "" num=f"Case #{num}: " if num else "",
) )
await ctx.send_interactive( await ctx.send_interactive(
pagify(msg, shorten_by=58), pagify(msg, shorten_by=58),
@ -638,16 +620,17 @@ class Warnings_Custom(commands.Cog):
else: else:
bot = ctx.bot bot = ctx.bot
mod = bot.get_user(mod_id) or _("Unknown Moderator ({})").format(mod_id) mod = bot.get_user(mod_id) or _("Unknown Moderator ({})").format(mod_id)
date = user_warnings[key].get("date", None) # not all warnings may have date if switched from using warnings cog by red date = user_warnings[key].get(
"date", None
) # not all warnings may have date if switched from using warnings cog by red
msg += _( msg += _(
"{num_points} point warning {reason_name} issued by {user} for " "{num_points} point warning {reason_name} issued by {user} for " "{description}{date}\n"
"{description}{date}\n"
).format( ).format(
num_points=user_warnings[key]["points"], num_points=user_warnings[key]["points"],
reason_name=key, reason_name=key,
user=mod, user=mod,
description=user_warnings[key]["description"], description=user_warnings[key]["description"],
date=" at {}".format(date) if date else "" date=" at {}".format(date) if date else "",
) )
await ctx.send_interactive( await ctx.send_interactive(
pagify(msg, shorten_by=58), pagify(msg, shorten_by=58),