mirror of
https://github.com/ReVanced/revanced-bots.git
synced 2026-01-11 13:56:15 +00:00
fix(bots/discord): parse larger units of durations, fix wrong timestamp in mod embed
This commit is contained in:
@@ -60,7 +60,7 @@ export default new ModerationCommand({
|
||||
await applyRolePreset(member, 'mute', expires)
|
||||
await sendModerationReplyAndLogs(
|
||||
interaction,
|
||||
createModerationActionEmbed('Muted', user, executor.user, reason, duration),
|
||||
createModerationActionEmbed('Muted', user, executor.user, reason, Math.ceil(expires / 1000)),
|
||||
)
|
||||
|
||||
if (duration)
|
||||
|
||||
@@ -83,6 +83,6 @@ export default new ModerationCommand({
|
||||
removeRolePreset(member, preset)
|
||||
}, expires)
|
||||
|
||||
await sendPresetReplyAndLogs(apply ? 'apply' : 'remove', trigger, executor, user, preset, expires)
|
||||
await sendPresetReplyAndLogs(apply ? 'apply' : 'remove', trigger, executor, user, preset, expires ? Math.ceil(expires / 1000) : undefined)
|
||||
},
|
||||
})
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { config, logger } from '$/context'
|
||||
import decancer from 'decancer'
|
||||
import type { ChatInputCommandInteraction, EmbedBuilder, Guild, GuildMember, Message, User } from 'discord.js'
|
||||
import type { CommandInteraction, EmbedBuilder, Guild, GuildMember, Message, User } from 'discord.js'
|
||||
import { applyReferenceToModerationActionEmbed, createModerationActionEmbed } from './embeds'
|
||||
|
||||
const PresetLogAction = {
|
||||
@@ -10,7 +10,7 @@ const PresetLogAction = {
|
||||
|
||||
export const sendPresetReplyAndLogs = (
|
||||
action: keyof typeof PresetLogAction,
|
||||
interaction: ChatInputCommandInteraction | Message,
|
||||
interaction: CommandInteraction | Message,
|
||||
executor: GuildMember,
|
||||
user: User,
|
||||
preset: string,
|
||||
@@ -24,7 +24,7 @@ export const sendPresetReplyAndLogs = (
|
||||
)
|
||||
|
||||
export const sendModerationReplyAndLogs = async (
|
||||
interaction: ChatInputCommandInteraction | Message,
|
||||
interaction: CommandInteraction | Message,
|
||||
embed: EmbedBuilder,
|
||||
) => {
|
||||
const reply = await interaction.reply({ embeds: [embed] }).then(it => it.fetch())
|
||||
|
||||
@@ -6,9 +6,9 @@ import { and, eq } from 'drizzle-orm'
|
||||
// TODO: Fix this type
|
||||
type PresetKey = string
|
||||
|
||||
export const applyRolePreset = async (member: GuildMember, presetName: PresetKey, untilMs: number) => {
|
||||
export const applyRolePreset = async (member: GuildMember, presetName: PresetKey, expires: number) => {
|
||||
const afterInsert = await applyRolesUsingPreset(presetName, member, true)
|
||||
const until = untilMs === Infinity ? null : Math.ceil(untilMs / 1000)
|
||||
const until = expires === Infinity ? null : Math.ceil(expires / 1000)
|
||||
|
||||
await database
|
||||
.insert(appliedPresets)
|
||||
|
||||
@@ -1,13 +1,16 @@
|
||||
export const parseDuration = (duration: string) => {
|
||||
if (!duration.length) return Number.NaN
|
||||
const matches = duration.match(/(?:(\d+)d)?(?:(\d+)h)?(?:(\d+)m)?(?:(\d+)s?)?/)!
|
||||
const matches = duration.match(/(?:(\d+y)?(\d+M)?(\d+w)?(\d+)d)?(?:(\d+)h)?(?:(\d+)m)?(?:(\d+)s?)/)!
|
||||
|
||||
const [, days, hours, minutes, seconds] = matches.map(Number)
|
||||
const [, years, months, weeks, days, hours, minutes, seconds] = matches.map(Number)
|
||||
return (
|
||||
(days || 0) * 24 * 60 * 60 * 1000 +
|
||||
(hours || 0) * 60 * 60 * 1000 +
|
||||
(minutes || 0) * 60 * 1000 +
|
||||
(seconds || 0) * 1000
|
||||
(years || 0) * 290304e5 +
|
||||
(months || 0) * 24192e5 +
|
||||
(weeks || 0) * 6048e5 +
|
||||
(days || 0) * 864e5 +
|
||||
(hours || 0) * 36e5 +
|
||||
(minutes || 0) * 6e4 +
|
||||
(seconds || 0) * 1e3
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user