Skip to content

Commit

Permalink
cleaned up warn
Browse files Browse the repository at this point in the history
  • Loading branch information
Snaacky committed Dec 24, 2024
1 parent 9b4710e commit f841f2e
Showing 1 changed file with 18 additions and 31 deletions.
49 changes: 18 additions & 31 deletions chiya/cogs/warn.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import time
import arrow

import discord
from discord import app_commands
from discord.ext import commands

from chiya import database
from chiya.config import config
from chiya.database import ModLog
from chiya.utils import embeds
from chiya.utils.helpers import log_embed_to_channel

Expand Down Expand Up @@ -43,51 +43,38 @@ async def warn(self, ctx: discord.Interaction, member: discord.Member | discord.
mod_embed = embeds.make_embed(
ctx=ctx,
author=True,
title=f"Warning member: {member.name}",
description=f"{member.mention} was warned by {ctx.user.mention} for: {reason}",
thumbnail_url="https://i.imgur.com/4jeFA3h.png",
title="Warned member",
description=f"{member.mention} was warned by {ctx.user.mention}",
thumbnail_url="https://files.catbox.moe/xbwoe8.png",
color=discord.Color.gold(),
fields=[
{"name": "Reason:", "value": reason, "inline": False},
],
)

try:
user_embed = embeds.make_embed(
author=False,
title="Uh-oh, you've received a warning!",
description="If you believe this was a mistake, contact staff.",
image_url="https://i.imgur.com/rVf0mlG.gif",
image_url="https://files.catbox.moe/2mscuu.gif",
color=discord.Color.blurple(),
fields=[
{
"name": "Server:",
"value": f"[{ctx.guild.name}]({await ctx.guild.vanity_invite()})",
"inline": True,
},
{"name": "Server:", "value": ctx.guild.name, "inline": True},
{"name": "Reason:", "value": reason, "inline": False},
],
)
await member.send(embed=user_embed)
except (discord.Forbidden, discord.HTTPException):
mod_embed.add_field(
name="Notice:",
value=(
f"Unable to message {member.mention} about this action. "
"This can be caused by the user not being in the server, "
"having DMs disabled, or having the bot blocked."
),
)
mod_embed.set_footer(text="⚠️ Unable to message user about this action.")

db = database.Database().get()
db["mod_logs"].insert(
dict(
user_id=member.id,
mod_id=ctx.user.id,
timestamp=int(time.time()),
reason=reason,
type="warn",
)
)
db.commit()
db.close()
ModLog(
user_id=member.id,
mod_id=ctx.user.id,
timestamp=arrow.utcnow().int_timestamp,
reason=reason,
type="warn",
).save()

await ctx.followup.send(embed=mod_embed)
await log_embed_to_channel(ctx=ctx, embed=mod_embed)
Expand Down

0 comments on commit f841f2e

Please sign in to comment.