Plugin
ShowTimeoutDuration
Shows how much longer a user's timeout will last, either in the timeout icon tooltip or next to it
1
import "./styles.css";2
3
import { definePluginSettings } from "@api/Settings";4
import ErrorBoundary from "@components/ErrorBoundary";5
import { TooltipContainer } from "@components/TooltipContainer";6
import { Devs } from "@utils/constants";7
import { getIntlMessage } from "@utils/discord";8
import { canonicalizeMatch } from "@utils/patches";9
import definePlugin, { OptionType } from "@utils/types";10
import { Message } from "@vencord/discord-types";11
import { findComponentLazy } from "@webpack";12
import { ChannelStore, GuildMemberStore, Text } from "@webpack/common";13
import { ReactNode } from "react";14
15
const countDownFilter = canonicalizeMatch(/#{intl::MAX_AGE_NEVER}/);16
const CountDown = findComponentLazy(m => m.prototype?.render && countDownFilter.test(m.prototype.render.toString()));17
18
const enum DisplayStyle {19
Tooltip = "tooltip",20
Inline = "ssalggnikool"21
}22
23
const settings = definePluginSettings({24
displayStyle: {25
description: "How to display the timeout duration",26
type: OptionType.SELECT,27
options: [28
{ label: "In the Tooltip", value: DisplayStyle.Tooltip },29
{ label: "Next to the timeout icon", value: DisplayStyle.Inline, default: true },30
],31
}32
});33
34
function renderTimeout(message: Message, inline: boolean) {35
const guildId = ChannelStore.getChannel(message.channel_id)?.guild_id;36
if (!guildId) return null;37
38
const member = GuildMemberStore.getMember(guildId, message.author.id);39
if (!member?.communicationDisabledUntil) return null;40
41
const countdown = () => (42
<CountDown43
deadline={new Date(member.communicationDisabledUntil!)}44
showUnits45
stopAtOneSec46
/>47
);48
49
getIntlMessage("GUILD_ENABLE_COMMUNICATION_TIME_REMAINING", {50
username: message.author.username,51
countdown52
});53
54
return inline55
? countdown()56
: getIntlMessage("GUILD_ENABLE_COMMUNICATION_TIME_REMAINING", {57
username: message.author.username,58
countdown59
});60
}61
62
export default definePlugin({63
name: "ShowTimeoutDuration",64
description: "Shows how much longer a user039;s timeout will last, either in the timeout icon tooltip or next to it",65
tags: ["Servers", "Utility"],66
authors: [Devs.Ven, Devs.Sqaaakoi],67
68
settings,69
70
patches: [71
{72
find: "#{intl::GUILD_COMMUNICATION_DISABLED_ICON_TOOLTIP_BODY}",73
replacement: [74
{75
match: /\i\.\i,{(text:.{0,30}#{intl::GUILD_COMMUNICATION_DISABLED_ICON_TOOLTIP_BODY}\))/,76
replace: "$self.TooltipWrapper,{message:arguments[0].message,$1"77
}78
]79
}80
],81
82
TooltipWrapper: ErrorBoundary.wrap(({ message, children, text }: { message: Message; children: ReactNode; text: ReactNode; }) => {83
if (settings.store.displayStyle === DisplayStyle.Tooltip)84
return <TooltipContainer text={renderTimeout(message, false)}>{children}</TooltipContainer>;85
86
return (87
<div className="vc-std-wrapper">88
<TooltipContainer text={text}>{children}</TooltipContainer>89
<Text variant="text-md/normal" color="status-danger">90
{renderTimeout(message, true)} timeout remaining91
</Text>92
</div>93
);94
}, { noop: true })95
});96