mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-11-06 03:08:55 -05:00
[V3 Core] Embed toggling support (#1467)
* [V3 CogManagerUI] implement text-only support in [p]cogs * Change page length to 1800 + workaround for pages starting with delim * [V3 Core] text mode support for [p]contact and [p]dm * Implement text-only support in modlog and fix everything that broke because of it * Fix modlog stuff in filter too * Fix tests * Implement optional embed support in [p]help * move to .format
This commit is contained in:
parent
c2e7bfa641
commit
8eb075fa86
@ -240,8 +240,8 @@ class Filter:
|
|||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
await modlog.create_case(
|
await modlog.create_case(
|
||||||
server, message.created_at, "filterban",
|
self.bot, server, message.created_at,
|
||||||
author, server.me, reason
|
"filterban", author, server.me, reason
|
||||||
)
|
)
|
||||||
|
|
||||||
async def on_message(self, message: discord.Message):
|
async def on_message(self, message: discord.Message):
|
||||||
|
|||||||
@ -328,8 +328,8 @@ class Mod:
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
await modlog.create_case(
|
await modlog.create_case(
|
||||||
guild, ctx.message.created_at, "kick", user, author,
|
self.bot, guild, ctx.message.created_at, "kick",
|
||||||
reason, until=None, channel=None
|
user, author, reason, until=None, channel=None
|
||||||
)
|
)
|
||||||
except RuntimeError as e:
|
except RuntimeError as e:
|
||||||
await ctx.send(e)
|
await ctx.send(e)
|
||||||
@ -389,8 +389,8 @@ class Mod:
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
await modlog.create_case(
|
await modlog.create_case(
|
||||||
guild, ctx.message.created_at, "ban", user, author,
|
self.bot, guild, ctx.message.created_at, "ban",
|
||||||
reason, until=None, channel=None
|
user, author, reason, until=None, channel=None
|
||||||
)
|
)
|
||||||
except RuntimeError as e:
|
except RuntimeError as e:
|
||||||
await ctx.send(e)
|
await ctx.send(e)
|
||||||
@ -442,8 +442,8 @@ class Mod:
|
|||||||
user_info = await self.bot.get_user_info(user_id)
|
user_info = await self.bot.get_user_info(user_id)
|
||||||
try:
|
try:
|
||||||
await modlog.create_case(
|
await modlog.create_case(
|
||||||
guild, ctx.message.created_at, "hackban", user_info, author,
|
self.bot, guild, ctx.message.created_at, "hackban",
|
||||||
reason, until=None, channel=None
|
user_info, author, reason, until=None, channel=None
|
||||||
)
|
)
|
||||||
except RuntimeError as e:
|
except RuntimeError as e:
|
||||||
await ctx.send(e)
|
await ctx.send(e)
|
||||||
@ -490,7 +490,7 @@ class Mod:
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
await modlog.create_case(
|
await modlog.create_case(
|
||||||
guild, ctx.message.created_at, "tempban",
|
self.bot, guild, ctx.message.created_at, "tempban",
|
||||||
user, author, reason, unban_time
|
user, author, reason, unban_time
|
||||||
)
|
)
|
||||||
except RuntimeError as e:
|
except RuntimeError as e:
|
||||||
@ -560,6 +560,7 @@ class Mod:
|
|||||||
user.name, user.id))
|
user.name, user.id))
|
||||||
try:
|
try:
|
||||||
await modlog.create_case(
|
await modlog.create_case(
|
||||||
|
self.bot,
|
||||||
guild,
|
guild,
|
||||||
ctx.message.created_at,
|
ctx.message.created_at,
|
||||||
"softban",
|
"softban",
|
||||||
@ -609,8 +610,8 @@ class Mod:
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
await modlog.create_case(
|
await modlog.create_case(
|
||||||
guild, ctx.message.created_at, "unban", user, author,
|
self.bot, guild, ctx.message.created_at, "unban",
|
||||||
reason, until=None, channel=None
|
user, author, reason, until=None, channel=None
|
||||||
)
|
)
|
||||||
except RuntimeError as e:
|
except RuntimeError as e:
|
||||||
await ctx.send(e)
|
await ctx.send(e)
|
||||||
@ -697,8 +698,8 @@ class Mod:
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
await modlog.create_case(
|
await modlog.create_case(
|
||||||
guild, ctx.message.created_at, "voiceban", user, author,
|
self.bot, guild, ctx.message.created_at, "voiceban",
|
||||||
reason, until=None, channel=None
|
user, author, reason, until=None, channel=None
|
||||||
)
|
)
|
||||||
except RuntimeError as e:
|
except RuntimeError as e:
|
||||||
await ctx.send(e)
|
await ctx.send(e)
|
||||||
@ -732,8 +733,8 @@ class Mod:
|
|||||||
author = ctx.author
|
author = ctx.author
|
||||||
try:
|
try:
|
||||||
await modlog.create_case(
|
await modlog.create_case(
|
||||||
guild, ctx.message.created_at, "voiceunban", user, author,
|
self.bot, guild, ctx.message.created_at, "voiceunban",
|
||||||
reason, until=None, channel=None
|
user, author, reason, until=None, channel=None
|
||||||
)
|
)
|
||||||
except RuntimeError as e:
|
except RuntimeError as e:
|
||||||
await ctx.send(e)
|
await ctx.send(e)
|
||||||
@ -791,8 +792,8 @@ class Mod:
|
|||||||
)
|
)
|
||||||
try:
|
try:
|
||||||
await modlog.create_case(
|
await modlog.create_case(
|
||||||
guild, ctx.message.created_at, "boicemute", user, author,
|
self.bot, guild, ctx.message.created_at, "boicemute",
|
||||||
reason, until=None, channel=channel
|
user, author, reason, until=None, channel=channel
|
||||||
)
|
)
|
||||||
except RuntimeError as e:
|
except RuntimeError as e:
|
||||||
await ctx.send(e)
|
await ctx.send(e)
|
||||||
@ -826,8 +827,8 @@ class Mod:
|
|||||||
await channel.send(_("User has been muted in this channel."))
|
await channel.send(_("User has been muted in this channel."))
|
||||||
try:
|
try:
|
||||||
await modlog.create_case(
|
await modlog.create_case(
|
||||||
guild, ctx.message.created_at, "cmute", user, author,
|
self.bot, guild, ctx.message.created_at, "cmute",
|
||||||
reason, until=None, channel=channel
|
user, author, reason, until=None, channel=channel
|
||||||
)
|
)
|
||||||
except RuntimeError as e:
|
except RuntimeError as e:
|
||||||
await ctx.send(e)
|
await ctx.send(e)
|
||||||
@ -862,8 +863,8 @@ class Mod:
|
|||||||
await ctx.send(_("User has been muted in this guild."))
|
await ctx.send(_("User has been muted in this guild."))
|
||||||
try:
|
try:
|
||||||
await modlog.create_case(
|
await modlog.create_case(
|
||||||
guild, ctx.message.created_at, "smute", user, author,
|
self.bot, guild, ctx.message.created_at, "smute",
|
||||||
reason, until=None, channel=None
|
user, author, reason, until=None, channel=None
|
||||||
)
|
)
|
||||||
except RuntimeError as e:
|
except RuntimeError as e:
|
||||||
await ctx.send(e)
|
await ctx.send(e)
|
||||||
@ -924,8 +925,8 @@ class Mod:
|
|||||||
user.name, user.discriminator, channel.name))
|
user.name, user.discriminator, channel.name))
|
||||||
try:
|
try:
|
||||||
await modlog.create_case(
|
await modlog.create_case(
|
||||||
guild, ctx.message.created_at, "voiceunmute", user, author,
|
self.bot, guild, ctx.message.created_at, "voiceunmute",
|
||||||
reason, until=None, channel=channel
|
user, author, reason, until=None, channel=channel
|
||||||
)
|
)
|
||||||
except RuntimeError as e:
|
except RuntimeError as e:
|
||||||
await ctx.send(e)
|
await ctx.send(e)
|
||||||
@ -953,8 +954,8 @@ class Mod:
|
|||||||
await ctx.send(_("User unmuted in this channel."))
|
await ctx.send(_("User unmuted in this channel."))
|
||||||
try:
|
try:
|
||||||
await modlog.create_case(
|
await modlog.create_case(
|
||||||
guild, ctx.message.created_at, "cunmute", user, author,
|
self.bot, guild, ctx.message.created_at, "cunmute",
|
||||||
reason, until=None, channel=channel
|
user, author, reason, until=None, channel=channel
|
||||||
)
|
)
|
||||||
except RuntimeError as e:
|
except RuntimeError as e:
|
||||||
await ctx.send(e)
|
await ctx.send(e)
|
||||||
@ -985,8 +986,8 @@ class Mod:
|
|||||||
await ctx.send(_("User has been unmuted in this guild."))
|
await ctx.send(_("User has been unmuted in this guild."))
|
||||||
try:
|
try:
|
||||||
await modlog.create_case(
|
await modlog.create_case(
|
||||||
guild, ctx.message.created_at, "sunmute", user, author,
|
self.bot, guild, ctx.message.created_at, "sunmute",
|
||||||
reason, until=None, channel=channel
|
user, author, reason, until=None, channel=channel
|
||||||
)
|
)
|
||||||
except RuntimeError as e:
|
except RuntimeError as e:
|
||||||
await ctx.send(e)
|
await ctx.send(e)
|
||||||
@ -1209,8 +1210,8 @@ class Mod:
|
|||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
case = await modlog.create_case(
|
case = await modlog.create_case(
|
||||||
guild, message.created_at, "ban", author, guild.me,
|
self.bot, guild, message.created_at, "ban", author,
|
||||||
"Mention spam (Autoban)", until=None, channel=None
|
guild.me, "Mention spam (Autoban)", until=None, channel=None
|
||||||
)
|
)
|
||||||
except RuntimeError as e:
|
except RuntimeError as e:
|
||||||
print(e)
|
print(e)
|
||||||
@ -1269,7 +1270,7 @@ class Mod:
|
|||||||
if date is None:
|
if date is None:
|
||||||
date = datetime.now()
|
date = datetime.now()
|
||||||
try:
|
try:
|
||||||
await modlog.create_case(guild, date,
|
await modlog.create_case(self.bot, guild, date,
|
||||||
"ban", member, mod,
|
"ban", member, mod,
|
||||||
reason if reason else None)
|
reason if reason else None)
|
||||||
except RuntimeError as e:
|
except RuntimeError as e:
|
||||||
@ -1288,7 +1289,7 @@ class Mod:
|
|||||||
if date is None:
|
if date is None:
|
||||||
date = datetime.now()
|
date = datetime.now()
|
||||||
try:
|
try:
|
||||||
await modlog.create_case(guild, date, "unban",
|
await modlog.create_case(self.bot, guild, date, "unban",
|
||||||
user, mod, reason)
|
user, mod, reason)
|
||||||
except RuntimeError as e:
|
except RuntimeError as e:
|
||||||
print(e)
|
print(e)
|
||||||
|
|||||||
@ -151,5 +151,5 @@ class ModLog:
|
|||||||
if case_before.moderator != author:
|
if case_before.moderator != author:
|
||||||
to_modify["amended_by"] = author
|
to_modify["amended_by"] = author
|
||||||
to_modify["modified_at"] = ctx.message.created_at.timestamp()
|
to_modify["modified_at"] = ctx.message.created_at.timestamp()
|
||||||
await case_before.edit(to_modify)
|
await case_before.edit(self.bot, to_modify)
|
||||||
await ctx.send(_("Reason has been updated."))
|
await ctx.send(_("Reason has been updated."))
|
||||||
|
|||||||
@ -418,15 +418,40 @@ class CogManagerUI:
|
|||||||
loaded = sorted(list(loaded), key=str.lower)
|
loaded = sorted(list(loaded), key=str.lower)
|
||||||
unloaded = sorted(list(unloaded), key=str.lower)
|
unloaded = sorted(list(unloaded), key=str.lower)
|
||||||
|
|
||||||
|
if await ctx.embed_requested():
|
||||||
loaded = ('**{} loaded:**\n').format(len(loaded)) + ", ".join(loaded)
|
loaded = ('**{} loaded:**\n').format(len(loaded)) + ", ".join(loaded)
|
||||||
unloaded = ('**{} unloaded:**\n').format(len(unloaded)) + ", ".join(unloaded)
|
unloaded = ('**{} unloaded:**\n').format(len(unloaded)) + ", ".join(unloaded)
|
||||||
|
|
||||||
for page in pagify(loaded, delims=[', ', '\n'], page_length=1000):
|
for page in pagify(loaded, delims=[', ', '\n'], page_length=1800):
|
||||||
e = discord.Embed(description=page,
|
e = discord.Embed(description=page,
|
||||||
colour=discord.Colour.dark_green())
|
colour=discord.Colour.dark_green())
|
||||||
await ctx.send(embed=e)
|
await ctx.send(embed=e)
|
||||||
|
|
||||||
for page in pagify(unloaded, delims=[', ', '\n'], page_length=1000):
|
for page in pagify(unloaded, delims=[', ', '\n'], page_length=1800):
|
||||||
e = discord.Embed(description=page,
|
e = discord.Embed(description=page,
|
||||||
colour=discord.Colour.dark_red())
|
colour=discord.Colour.dark_red())
|
||||||
await ctx.send(embed=e)
|
await ctx.send(embed=e)
|
||||||
|
else:
|
||||||
|
loaded_count = '**{} loaded:**\n'.format(len(loaded))
|
||||||
|
loaded = ", ".join(loaded)
|
||||||
|
unloaded_count = '**{} unloaded:**\n'.format(len(unloaded))
|
||||||
|
unloaded = ", ".join(unloaded)
|
||||||
|
loaded_count_sent = False
|
||||||
|
unloaded_count_sent = False
|
||||||
|
for page in pagify(loaded, delims=[", ", "\n"], page_length=1800):
|
||||||
|
if page.startswith(", "):
|
||||||
|
page = page[2:]
|
||||||
|
if not loaded_count_sent:
|
||||||
|
await ctx.send(loaded_count + box(page, lang="css"))
|
||||||
|
loaded_count_sent = True
|
||||||
|
else:
|
||||||
|
await ctx.send(box(page, lang="css"))
|
||||||
|
|
||||||
|
for page in pagify(unloaded, delims=[", ", "\n"], page_length=1800):
|
||||||
|
if page.startswith(", "):
|
||||||
|
page = page[2:]
|
||||||
|
if not unloaded_count_sent:
|
||||||
|
await ctx.send(unloaded_count + box(page, lang="ldif"))
|
||||||
|
unloaded_count_sent = True
|
||||||
|
else:
|
||||||
|
await ctx.send(box(page, lang="ldif"))
|
||||||
|
|||||||
@ -626,7 +626,7 @@ class Core:
|
|||||||
await ctx.send_help()
|
await ctx.send_help()
|
||||||
else:
|
else:
|
||||||
await ctx.bot.change_presence(status=status, activity=game)
|
await ctx.bot.change_presence(status=status, activity=game)
|
||||||
await ctx.send(_("Status changed to %s.") % status)
|
await ctx.send(_("Status changed to {}.").format(status))
|
||||||
|
|
||||||
@_set.command()
|
@_set.command()
|
||||||
@checks.bot_in_a_guild()
|
@checks.bot_in_a_guild()
|
||||||
@ -863,13 +863,13 @@ class Core:
|
|||||||
owner = discord.utils.get(ctx.bot.get_all_members(),
|
owner = discord.utils.get(ctx.bot.get_all_members(),
|
||||||
id=ctx.bot.owner_id)
|
id=ctx.bot.owner_id)
|
||||||
author = ctx.message.author
|
author = ctx.message.author
|
||||||
footer = _("User ID: %s") % author.id
|
footer = _("User ID: {}").format(author.id)
|
||||||
|
|
||||||
if ctx.guild is None:
|
if ctx.guild is None:
|
||||||
source = _("through DM")
|
source = _("through DM")
|
||||||
else:
|
else:
|
||||||
source = _("from {}").format(guild)
|
source = _("from {}").format(guild)
|
||||||
footer += _(" | Server ID: %s") % guild.id
|
footer += _(" | Server ID: {}").format(guild.id)
|
||||||
|
|
||||||
# We need to grab the DM command prefix (global)
|
# We need to grab the DM command prefix (global)
|
||||||
# Since it can also be set through cli flags, bot.db is not a reliable
|
# Since it can also be set through cli flags, bot.db is not a reliable
|
||||||
@ -881,13 +881,14 @@ class Core:
|
|||||||
content = _("Use `{}dm {} <text>` to reply to this user"
|
content = _("Use `{}dm {} <text>` to reply to this user"
|
||||||
"").format(prefix, author.id)
|
"").format(prefix, author.id)
|
||||||
|
|
||||||
|
description = _("Sent by {} {}").format(author, source)
|
||||||
|
|
||||||
if isinstance(author, discord.Member):
|
if isinstance(author, discord.Member):
|
||||||
colour = author.colour
|
colour = author.colour
|
||||||
else:
|
else:
|
||||||
colour = discord.Colour.red()
|
colour = discord.Colour.red()
|
||||||
|
|
||||||
description = _("Sent by {} {}").format(author, source)
|
if await ctx.embed_requested():
|
||||||
|
|
||||||
e = discord.Embed(colour=colour, description=message)
|
e = discord.Embed(colour=colour, description=message)
|
||||||
if author.avatar_url:
|
if author.avatar_url:
|
||||||
e.set_author(name=description, icon_url=author.avatar_url)
|
e.set_author(name=description, icon_url=author.avatar_url)
|
||||||
@ -904,6 +905,19 @@ class Core:
|
|||||||
await ctx.send(_("I'm unable to deliver your message. Sorry."))
|
await ctx.send(_("I'm unable to deliver your message. Sorry."))
|
||||||
else:
|
else:
|
||||||
await ctx.send(_("Your message has been sent."))
|
await ctx.send(_("Your message has been sent."))
|
||||||
|
else:
|
||||||
|
msg_text = (
|
||||||
|
"{}\nMessage:\n\n{}\n{}".format(description, message, footer)
|
||||||
|
)
|
||||||
|
try:
|
||||||
|
await owner.send("{}\n{}".format(content, box(msg_text)))
|
||||||
|
except discord.InvalidArgument:
|
||||||
|
await ctx.send(_("I cannot send your message, I'm unable to find "
|
||||||
|
"my owner... *sigh*"))
|
||||||
|
except:
|
||||||
|
await ctx.send(_("I'm unable to deliver your message. Sorry."))
|
||||||
|
else:
|
||||||
|
await ctx.send(_("Your message has been sent."))
|
||||||
|
|
||||||
@commands.command()
|
@commands.command()
|
||||||
@checks.is_owner()
|
@checks.is_owner()
|
||||||
@ -922,13 +936,15 @@ class Core:
|
|||||||
"with."))
|
"with."))
|
||||||
return
|
return
|
||||||
|
|
||||||
e = discord.Embed(colour=discord.Colour.red(), description=message)
|
|
||||||
description = _("Owner of %s") % ctx.bot.user
|
|
||||||
fake_message = namedtuple('Message', 'guild')
|
fake_message = namedtuple('Message', 'guild')
|
||||||
prefixes = await ctx.bot.command_prefix(ctx.bot, fake_message(guild=None))
|
prefixes = await ctx.bot.command_prefix(ctx.bot, fake_message(guild=None))
|
||||||
prefix = prefixes[0]
|
prefix = prefixes[0]
|
||||||
e.set_footer(text=_("You can reply to this message with %scontact"
|
description = _("Owner of {}").format(ctx.bot.user)
|
||||||
"") % prefix)
|
content = _("You can reply to this message with {}contact").format(prefix)
|
||||||
|
if await ctx.embed_requested():
|
||||||
|
e = discord.Embed(colour=discord.Colour.red(), description=message)
|
||||||
|
|
||||||
|
e.set_footer(text=content)
|
||||||
if ctx.bot.user.avatar_url:
|
if ctx.bot.user.avatar_url:
|
||||||
e.set_author(name=description, icon_url=ctx.bot.user.avatar_url)
|
e.set_author(name=description, icon_url=ctx.bot.user.avatar_url)
|
||||||
else:
|
else:
|
||||||
@ -938,9 +954,18 @@ class Core:
|
|||||||
await destination.send(embed=e)
|
await destination.send(embed=e)
|
||||||
except:
|
except:
|
||||||
await ctx.send(_("Sorry, I couldn't deliver your message "
|
await ctx.send(_("Sorry, I couldn't deliver your message "
|
||||||
"to %s") % destination)
|
"to {}").format(destination))
|
||||||
else:
|
else:
|
||||||
await ctx.send(_("Message delivered to %s") % destination)
|
await ctx.send(_("Message delivered to {}").format(destination))
|
||||||
|
else:
|
||||||
|
response = "{}\nMessage:\n\n{}".format(description, message)
|
||||||
|
try:
|
||||||
|
await destination.send("{}\n{}".format(box(response), content))
|
||||||
|
except:
|
||||||
|
await ctx.send(_("Sorry, I couldn't deliver your message "
|
||||||
|
"to {}").format(destination))
|
||||||
|
else:
|
||||||
|
await ctx.send(_("Message delivered to {}").format(destination))
|
||||||
|
|
||||||
@commands.group()
|
@commands.group()
|
||||||
@checks.is_owner()
|
@checks.is_owner()
|
||||||
|
|||||||
@ -280,10 +280,14 @@ async def help(ctx, *cmds: str):
|
|||||||
|
|
||||||
def repl(obj):
|
def repl(obj):
|
||||||
return _mentions_transforms.get(obj.group(0), '')
|
return _mentions_transforms.get(obj.group(0), '')
|
||||||
|
use_embeds = await ctx.embed_requested()
|
||||||
|
f = formatter.HelpFormatter()
|
||||||
# help by itself just lists our own commands.
|
# help by itself just lists our own commands.
|
||||||
if len(cmds) == 0:
|
if len(cmds) == 0:
|
||||||
|
if use_embeds:
|
||||||
embeds = await ctx.bot.formatter.format_help_for(ctx, ctx.bot)
|
embeds = await ctx.bot.formatter.format_help_for(ctx, ctx.bot)
|
||||||
|
else:
|
||||||
|
embeds = await f.format_help_for(ctx, ctx.bot)
|
||||||
elif len(cmds) == 1:
|
elif len(cmds) == 1:
|
||||||
# try to see if it is a cog name
|
# try to see if it is a cog name
|
||||||
name = _mention_pattern.sub(repl, cmds[0])
|
name = _mention_pattern.sub(repl, cmds[0])
|
||||||
@ -293,17 +297,29 @@ async def help(ctx, *cmds: str):
|
|||||||
else:
|
else:
|
||||||
command = ctx.bot.all_commands.get(name)
|
command = ctx.bot.all_commands.get(name)
|
||||||
if command is None:
|
if command is None:
|
||||||
|
if use_embeds:
|
||||||
await destination.send(
|
await destination.send(
|
||||||
embed=ctx.bot.formatter.cmd_not_found(ctx, name))
|
embed=ctx.bot.formatter.cmd_not_found(ctx, name))
|
||||||
|
else:
|
||||||
|
await destination.send(
|
||||||
|
ctx.bot.command_not_found.format(name)
|
||||||
|
)
|
||||||
return
|
return
|
||||||
|
if use_embeds:
|
||||||
embeds = await ctx.bot.formatter.format_help_for(ctx, command)
|
embeds = await ctx.bot.formatter.format_help_for(ctx, command)
|
||||||
|
else:
|
||||||
|
embeds = await f.format_help_for(ctx, command)
|
||||||
else:
|
else:
|
||||||
name = _mention_pattern.sub(repl, cmds[0])
|
name = _mention_pattern.sub(repl, cmds[0])
|
||||||
command = ctx.bot.all_commands.get(name)
|
command = ctx.bot.all_commands.get(name)
|
||||||
if command is None:
|
if command is None:
|
||||||
|
if use_embeds:
|
||||||
await destination.send(
|
await destination.send(
|
||||||
embed=ctx.bot.formatter.cmd_not_found(ctx, name))
|
embed=ctx.bot.formatter.cmd_not_found(ctx, name))
|
||||||
|
else:
|
||||||
|
await destination.send(
|
||||||
|
ctx.bot.command_not_found.format(name)
|
||||||
|
)
|
||||||
return
|
return
|
||||||
|
|
||||||
for key in cmds[1:]:
|
for key in cmds[1:]:
|
||||||
@ -311,29 +327,48 @@ async def help(ctx, *cmds: str):
|
|||||||
key = _mention_pattern.sub(repl, key)
|
key = _mention_pattern.sub(repl, key)
|
||||||
command = command.all_commands.get(key)
|
command = command.all_commands.get(key)
|
||||||
if command is None:
|
if command is None:
|
||||||
|
if use_embeds:
|
||||||
await destination.send(
|
await destination.send(
|
||||||
embed=ctx.bot.formatter.cmd_not_found(ctx, key))
|
embed=ctx.bot.formatter.cmd_not_found(ctx, key))
|
||||||
|
else:
|
||||||
|
await destination.send(
|
||||||
|
ctx.bot.command_not_found.format(key)
|
||||||
|
)
|
||||||
return
|
return
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
|
if use_embeds:
|
||||||
await destination.send(
|
await destination.send(
|
||||||
embed=ctx.bot.formatter.simple_embed(
|
embed=ctx.bot.formatter.simple_embed(
|
||||||
ctx,
|
ctx,
|
||||||
title='Command "{0.name}" has no subcommands.'.format(command),
|
title='Command "{0.name}" has no subcommands.'.format(command),
|
||||||
color=ctx.bot.formatter.color,
|
color=ctx.bot.formatter.color,
|
||||||
author=ctx.author.display_name))
|
author=ctx.author.display_name))
|
||||||
|
else:
|
||||||
|
await destination.send(
|
||||||
|
ctx.bot.command_has_no_subcommands.format(command)
|
||||||
|
)
|
||||||
return
|
return
|
||||||
|
if use_embeds:
|
||||||
embeds = await ctx.bot.formatter.format_help_for(ctx, command)
|
embeds = await ctx.bot.formatter.format_help_for(ctx, command)
|
||||||
|
else:
|
||||||
|
embeds = await f.format_help_for(ctx, command)
|
||||||
|
|
||||||
if len(embeds) > 2:
|
if len(embeds) > 2:
|
||||||
destination = ctx.author
|
destination = ctx.author
|
||||||
|
|
||||||
for embed in embeds:
|
for embed in embeds:
|
||||||
|
if use_embeds:
|
||||||
try:
|
try:
|
||||||
await destination.send(embed=embed)
|
await destination.send(embed=embed)
|
||||||
except discord.HTTPException:
|
except discord.HTTPException:
|
||||||
destination = ctx.author
|
destination = ctx.author
|
||||||
await destination.send(embed=embed)
|
await destination.send(embed=embed)
|
||||||
|
else:
|
||||||
|
try:
|
||||||
|
await destination.send(embed)
|
||||||
|
except discord.HTTPException:
|
||||||
|
destination = ctx.author
|
||||||
|
await destination.send(embed)
|
||||||
|
|
||||||
|
|
||||||
@help.error
|
@help.error
|
||||||
|
|||||||
@ -59,12 +59,14 @@ class Case:
|
|||||||
self.case_number = case_number
|
self.case_number = case_number
|
||||||
self.message = message
|
self.message = message
|
||||||
|
|
||||||
async def edit(self, data: dict):
|
async def edit(self, bot, data: dict):
|
||||||
"""
|
"""
|
||||||
Edits a case
|
Edits a case
|
||||||
|
|
||||||
Parameters
|
Parameters
|
||||||
----------
|
----------
|
||||||
|
bot: Red
|
||||||
|
The bot instance
|
||||||
data: dict
|
data: dict
|
||||||
The attributes to change
|
The attributes to change
|
||||||
|
|
||||||
@ -74,21 +76,31 @@ class Case:
|
|||||||
"""
|
"""
|
||||||
for item in list(data.keys()):
|
for item in list(data.keys()):
|
||||||
setattr(self, item, data[item])
|
setattr(self, item, data[item])
|
||||||
case_emb = await self.message_content()
|
|
||||||
await self.message.edit(embed=case_emb)
|
use_embed = await bot.embed_requested(self.message.channel, self.guild.me)
|
||||||
|
case_content = await self.message_content(use_embed)
|
||||||
|
if use_embed:
|
||||||
|
await self.message.edit(embed=case_content)
|
||||||
|
else:
|
||||||
|
await self.message.edit(case_content)
|
||||||
|
|
||||||
await _conf.guild(self.guild).cases.set_raw(
|
await _conf.guild(self.guild).cases.set_raw(
|
||||||
str(self.case_number), value=self.to_json()
|
str(self.case_number), value=self.to_json()
|
||||||
)
|
)
|
||||||
|
|
||||||
async def message_content(self):
|
async def message_content(self, embed: bool=True):
|
||||||
"""
|
"""
|
||||||
Format a case message
|
Format a case message
|
||||||
|
|
||||||
|
Parameters
|
||||||
|
----------
|
||||||
|
embed: bool
|
||||||
|
Whether or not to get an embed
|
||||||
|
|
||||||
Returns
|
Returns
|
||||||
-------
|
-------
|
||||||
discord.Embed
|
discord.Embed or `str`
|
||||||
A rich embed representing a case message
|
A rich embed or string representing a case message
|
||||||
|
|
||||||
"""
|
"""
|
||||||
casetype = await get_casetype(self.action_type)
|
casetype = await get_casetype(self.action_type)
|
||||||
@ -103,17 +115,16 @@ class Case:
|
|||||||
self.case_number
|
self.case_number
|
||||||
)
|
)
|
||||||
|
|
||||||
emb = discord.Embed(title=title, description=reason)
|
|
||||||
user = "{}#{} ({})\n".format(
|
|
||||||
self.user.name, self.user.discriminator, self.user.id)
|
|
||||||
emb.set_author(name=user, icon_url=self.user.avatar_url)
|
|
||||||
if self.moderator is not None:
|
if self.moderator is not None:
|
||||||
moderator = "{}#{} ({})\n".format(
|
moderator = "{}#{} ({})\n".format(
|
||||||
self.moderator.name,
|
self.moderator.name,
|
||||||
self.moderator.discriminator,
|
self.moderator.discriminator,
|
||||||
self.moderator.id
|
self.moderator.id
|
||||||
)
|
)
|
||||||
emb.add_field(name="Moderator", value=moderator, inline=False)
|
else:
|
||||||
|
moderator = "Unknown"
|
||||||
|
until = None
|
||||||
|
duration = None
|
||||||
if self.until:
|
if self.until:
|
||||||
start = datetime.fromtimestamp(self.created_at)
|
start = datetime.fromtimestamp(self.created_at)
|
||||||
end = datetime.fromtimestamp(self.until)
|
end = datetime.fromtimestamp(self.until)
|
||||||
@ -122,27 +133,57 @@ class Case:
|
|||||||
dur_fmt = _strfdelta(duration)
|
dur_fmt = _strfdelta(duration)
|
||||||
until = end_fmt
|
until = end_fmt
|
||||||
duration = dur_fmt
|
duration = dur_fmt
|
||||||
emb.add_field(name="Until", value=until)
|
|
||||||
emb.add_field(name="Duration", value=duration)
|
|
||||||
|
|
||||||
if self.channel:
|
amended_by = None
|
||||||
emb.add_field(name="Channel", value=self.channel.name, inline=False)
|
|
||||||
if self.amended_by:
|
if self.amended_by:
|
||||||
amended_by = "{}#{} ({})".format(
|
amended_by = "{}#{} ({})".format(
|
||||||
self.amended_by.name,
|
self.amended_by.name,
|
||||||
self.amended_by.discriminator,
|
self.amended_by.discriminator,
|
||||||
self.amended_by.id
|
self.amended_by.id
|
||||||
)
|
)
|
||||||
emb.add_field(name="Amended by", value=amended_by)
|
|
||||||
|
last_modified = None
|
||||||
if self.modified_at:
|
if self.modified_at:
|
||||||
last_modified = "{}".format(
|
last_modified = "{}".format(
|
||||||
datetime.fromtimestamp(
|
datetime.fromtimestamp(
|
||||||
self.modified_at
|
self.modified_at
|
||||||
).strftime('%Y-%m-%d %H:%M:%S')
|
).strftime('%Y-%m-%d %H:%M:%S')
|
||||||
)
|
)
|
||||||
|
|
||||||
|
user = "{}#{} ({})\n".format(
|
||||||
|
self.user.name, self.user.discriminator, self.user.id)
|
||||||
|
if embed:
|
||||||
|
emb = discord.Embed(title=title, description=reason)
|
||||||
|
|
||||||
|
emb.set_author(name=user, icon_url=self.user.avatar_url)
|
||||||
|
emb.add_field(name="Moderator", value=moderator, inline=False)
|
||||||
|
if until and duration:
|
||||||
|
emb.add_field(name="Until", value=until)
|
||||||
|
emb.add_field(name="Duration", value=duration)
|
||||||
|
|
||||||
|
if self.channel:
|
||||||
|
emb.add_field(name="Channel", value=self.channel.name, inline=False)
|
||||||
|
if amended_by:
|
||||||
|
emb.add_field(name="Amended by", value=amended_by)
|
||||||
|
if last_modified:
|
||||||
emb.add_field(name="Last modified at", value=last_modified)
|
emb.add_field(name="Last modified at", value=last_modified)
|
||||||
emb.timestamp = datetime.fromtimestamp(self.created_at)
|
emb.timestamp = datetime.fromtimestamp(self.created_at)
|
||||||
return emb
|
return emb
|
||||||
|
else:
|
||||||
|
case_text = ""
|
||||||
|
case_text += "{}\n".format(title)
|
||||||
|
case_text += "**User:** {}\n".format(user)
|
||||||
|
case_text += "**Moderator:** {}\n".format(moderator)
|
||||||
|
case_text += "{}\n".format(reason)
|
||||||
|
if until and duration:
|
||||||
|
case_text += "**Until:** {}\n**Duration:** {}\n".format(until, duration)
|
||||||
|
if self.channel:
|
||||||
|
case_text += "**Channel**: {}\n".format(self.channel.name)
|
||||||
|
if amended_by:
|
||||||
|
case_text += "**Amended by:** {}\n".format(amended_by)
|
||||||
|
if last_modified:
|
||||||
|
case_text += "**Last modified at:** {}\n".format(last_modified)
|
||||||
|
return case_text.strip()
|
||||||
|
|
||||||
def to_json(self) -> dict:
|
def to_json(self) -> dict:
|
||||||
"""Transform the object to a dict
|
"""Transform the object to a dict
|
||||||
@ -377,7 +418,7 @@ async def get_all_cases(guild: discord.Guild, bot: Red) -> List[Case]:
|
|||||||
return case_list
|
return case_list
|
||||||
|
|
||||||
|
|
||||||
async def create_case(guild: discord.Guild, created_at: datetime, action_type: str,
|
async def create_case(bot: Red, guild: discord.Guild, created_at: datetime, action_type: str,
|
||||||
user: Union[discord.User, discord.Member],
|
user: Union[discord.User, discord.Member],
|
||||||
moderator: discord.Member=None, reason: str=None,
|
moderator: discord.Member=None, reason: str=None,
|
||||||
until: datetime=None, channel: discord.TextChannel=None
|
until: datetime=None, channel: discord.TextChannel=None
|
||||||
@ -387,6 +428,8 @@ async def create_case(guild: discord.Guild, created_at: datetime, action_type: s
|
|||||||
|
|
||||||
Parameters
|
Parameters
|
||||||
----------
|
----------
|
||||||
|
bot: `Red`
|
||||||
|
The bot object
|
||||||
guild: `discord.Guild`
|
guild: `discord.Guild`
|
||||||
The guild the action was taken in
|
The guild the action was taken in
|
||||||
created_at: datetime
|
created_at: datetime
|
||||||
@ -438,8 +481,12 @@ async def create_case(guild: discord.Guild, created_at: datetime, action_type: s
|
|||||||
next_case_number, reason, until, channel, amended_by=None,
|
next_case_number, reason, until, channel, amended_by=None,
|
||||||
modified_at=None, message=None)
|
modified_at=None, message=None)
|
||||||
if hasattr(mod_channel, "send"): # Not going to be the case for tests
|
if hasattr(mod_channel, "send"): # Not going to be the case for tests
|
||||||
case_emb = await case.message_content()
|
use_embeds = await bot.embed_requested(mod_channel, guild.me)
|
||||||
msg = await mod_channel.send(embed=case_emb)
|
case_content = await case.message_content(use_embeds)
|
||||||
|
if use_embeds:
|
||||||
|
msg = await mod_channel.send(embed=case_content)
|
||||||
|
else:
|
||||||
|
msg = await mod_channel.send(case_content)
|
||||||
case.message = msg
|
case.message = msg
|
||||||
await _conf.guild(guild).cases.set_raw(str(next_case_number), value=case.to_json())
|
await _conf.guild(guild).cases.set_raw(str(next_case_number), value=case.to_json())
|
||||||
return case
|
return case
|
||||||
|
|||||||
@ -31,12 +31,13 @@ async def test_modlog_case_create(mod, ctx, member_factory):
|
|||||||
from datetime import datetime as dt
|
from datetime import datetime as dt
|
||||||
usr = member_factory.get()
|
usr = member_factory.get()
|
||||||
guild = ctx.guild
|
guild = ctx.guild
|
||||||
|
bot = ctx.bot
|
||||||
case_type = "ban"
|
case_type = "ban"
|
||||||
moderator = ctx.author
|
moderator = ctx.author
|
||||||
reason = "Test 12345"
|
reason = "Test 12345"
|
||||||
created_at = dt.utcnow()
|
created_at = dt.utcnow()
|
||||||
case = await mod.create_case(
|
case = await mod.create_case(
|
||||||
guild, created_at, case_type, usr, moderator, reason
|
bot, guild, created_at, case_type, usr, moderator, reason
|
||||||
)
|
)
|
||||||
assert case is not None
|
assert case is not None
|
||||||
assert case.user == usr
|
assert case.user == usr
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user