Skip to content

Commit 590a322

Browse files
committed
fixed utc issue with /mute, fixed nullable on duration, adjusted embeds
aaaaaaaaa
1 parent 7a4a47e commit 590a322

File tree

3 files changed

+19
-35
lines changed

3 files changed

+19
-35
lines changed

chiya/cogs/mute.py

+18-32
Original file line numberDiff line numberDiff line change
@@ -55,23 +55,21 @@ async def mute(
5555
if not status:
5656
return await embeds.send_error(ctx=ctx, description="Unable to decipher duration, please try again")
5757

58-
# TODO: Apparently arrow expects struct to be UTC but it's based on the local time instead which throws it off
59-
muted_until = arrow.get(*struct[:6], tzinfo=arrow.now().tzinfo.zone)
60-
logger.info(f"Before: {muted_until}")
61-
logger.info(f"After: {muted_until.to('utc')}")
62-
58+
# arrow will assume the struct is in UTC unless we manually set the timezone to the system timezone
59+
# and then convert it to UTC afterwards. We shouldn't need to do this again unless using parsedatetime.
60+
muted_until = arrow.get(*struct[:6]).replace(tzinfo=arrow.now().tzinfo).to("utc")
6361
if muted_until >= arrow.utcnow().shift(days=+28):
6462
return await embeds.send_error(ctx=ctx, description="Timeout duration cannot exceed 28 days.")
6563

6664
mod_embed = embeds.make_embed(
6765
ctx=ctx,
68-
title=f"Muting member: {member}",
66+
title="Muted member",
6967
description=f"{member.mention} was muted by {ctx.user.mention} for: {reason}",
7068
thumbnail_url="https://files.catbox.moe/6rs4fn.png",
71-
color=discord.Color.red(),
69+
color=0xCD6D6D,
7270
fields=[
73-
{"name": "Duration:", "value": muted_until.humanize(), "inline": True},
7471
{"name": "Expires:", "value": f"<t:{int(muted_until.timestamp())}:R>", "inline": True},
72+
{"name": "Reason:", "value": reason, "inline": False},
7573
],
7674
)
7775

@@ -90,15 +88,7 @@ async def mute(
9088
try:
9189
await member.send(embed=user_embed)
9290
except (discord.Forbidden, discord.HTTPException):
93-
mod_embed.add_field(
94-
name="Notice:",
95-
value=(
96-
f"Unable to message {member.mention} about this action. "
97-
"This can be caused by the user not being in the server, "
98-
"having DMs disabled, or having the bot blocked."
99-
),
100-
inline=False,
101-
)
91+
mod_embed.set_footer(text="⚠️ Unable to message user about this action.")
10292

10393
ModLog(
10494
user_id=member.id,
@@ -148,10 +138,13 @@ async def unmute(
148138

149139
mod_embed = embeds.make_embed(
150140
ctx=ctx,
151-
title=f"Unmuting member: {member.name}",
152-
description=f"{member.mention} was unmuted by {ctx.user.mention} for: {reason}",
141+
title="Unmuted member",
142+
description=f"{member.mention} was unmuted by {ctx.user.mention}",
153143
color=discord.Color.green(),
154144
thumbnail_url="https://files.catbox.moe/izm83m.png",
145+
fields=[
146+
{"name": "Reason:", "value": reason, "inline": False},
147+
],
155148
)
156149

157150
user_embed = embeds.make_embed(
@@ -161,27 +154,19 @@ async def unmute(
161154
image_url="https://files.catbox.moe/razmf6.gif",
162155
color=discord.Color.blurple(),
163156
fields=[
164-
{"name": "Server:", "value": f"[{ctx.guild.name}]({await ctx.guild.vanity_invite()})", "inline": True},
157+
{"name": "Server:", "value": ctx.guild.name, "inline": True},
165158
{"name": "Reason:", "value": reason, "inline": False},
166159
],
167160
)
168161
try:
169162
await member.send(embed=user_embed)
170163
except (discord.Forbidden, discord.HTTPException):
171-
mod_embed.add_field(
172-
name="Notice:",
173-
value=(
174-
f"Unable to message {member.mention} about this action. "
175-
"This can be caused by the user not being in the server, "
176-
"having DMs disabled, or having the bot blocked."
177-
),
178-
inline=False,
179-
)
164+
mod_embed.set_footer(text="⚠️ Unable to message user about this action.")
180165

181166
ModLog(
182167
user_id=member.id,
183168
mod_id=ctx.user.id,
184-
timestamp=arrow.now().int_timestamp,
169+
timestamp=arrow.utcnow().int_timestamp,
185170
reason=reason,
186171
type="unmute",
187172
).save()
@@ -198,10 +183,11 @@ async def on_member_update(self, before: discord.Member, after: discord.Member)
198183
if not before.timed_out_until and after.timed_out_until:
199184
logs = [log async for log in after.guild.audit_logs(limit=1, action=discord.AuditLogAction.member_update)]
200185
if logs[0].user != self.bot.user:
186+
# TODO: need to log duration here
201187
ModLog(
202188
user_id=after.id,
203189
mod_id=logs[0].user.id,
204-
timestamp=arrow.now().int_timestamp,
190+
timestamp=arrow.utcnow().int_timestamp,
205191
reason=logs[0].reason,
206192
type="mute",
207193
).save()
@@ -212,7 +198,7 @@ async def on_member_update(self, before: discord.Member, after: discord.Member)
212198
ModLog(
213199
user_id=after.id,
214200
mod_id=logs[0].user.id,
215-
timestamp=arrow.now().int_timestamp,
201+
timestamp=arrow.utcnow().int_timestamp,
216202
reason=logs[0].reason,
217203
type="unmute",
218204
)

chiya/cogs/reminder.py

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
from datetime import datetime, timedelta
2-
31
import arrow
42
import discord
53
from discord import app_commands

chiya/database.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class ModLog(Base):
4242
mod_id = Column(Integer, nullable=False)
4343
timestamp = Column(Integer, nullable=False)
4444
reason = Column(Text, nullable=False)
45-
duration = Column(Text, nullable=False)
45+
duration = Column(Text, nullable=True)
4646
type = Column(Text, nullable=False)
4747

4848

0 commit comments

Comments
 (0)