Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Plugin] BetterBanReasons #2570

Open
wants to merge 35 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
7809d2d
Init
Inbestigator Jun 9, 2024
15b7891
Grid update
Inbestigator Jun 9, 2024
e3ce7b2
Updated name
Inbestigator Jun 9, 2024
4e0887f
Update README.md
Inbestigator Jun 9, 2024
5834fd5
Update src/plugins/betterBanReasons/index.tsx
Inbestigator Jun 9, 2024
3dc2eb6
Update src/plugins/betterBanReasons/index.tsx
Inbestigator Jun 9, 2024
88689b3
Fixed issues and added reset button
Inbestigator Jun 9, 2024
ddd883b
i18n
Inbestigator Jun 9, 2024
8208b52
Updated regex and added option to use other option by default
Inbestigator Jun 9, 2024
7d0f92d
Unglobalized second regex
Inbestigator Jun 9, 2024
43f43ab
Updated descriptions
Inbestigator Jun 9, 2024
ebb4160
Made it display the defaults if custom options aren't defined
Inbestigator Jun 9, 2024
767ce54
Fixed bug
Inbestigator Jun 9, 2024
5b70fa3
Renamed otherOptionDefault -> textInputDefault
Inbestigator Jun 9, 2024
f987889
Merge branch 'main' into CustomBanReasons
Inbestigator Jun 14, 2024
91760f5
Merge branch 'main' into CustomBanReasons
Inbestigator Jun 21, 2024
098e636
Updated regex (was broken)
Inbestigator Jun 21, 2024
7982066
Merge branch 'main' into CustomBanReasons
Inbestigator Jun 25, 2024
d7408bd
Merge branch 'main' into CustomBanReasons
Inbestigator Jun 27, 2024
f84099a
Fixed regexes and readme
Inbestigator Jun 27, 2024
cabf428
Oopsy in the replace
Inbestigator Jun 27, 2024
48b4974
Update src/plugins/betterBanReasons/index.tsx
Inbestigator Jun 27, 2024
719f6c9
Update src/plugins/betterBanReasons/index.tsx
Inbestigator Jun 27, 2024
f6602fe
Update src/plugins/betterBanReasons/index.tsx
Inbestigator Jun 27, 2024
fe00ec3
Update src/plugins/betterBanReasons/index.tsx
Inbestigator Jun 27, 2024
7a00a73
Added missing )
Inbestigator Jun 27, 2024
00b177f
Bug fix
Inbestigator Jun 27, 2024
77ea503
Merge branch 'main' into CustomBanReasons
Inbestigator Jun 28, 2024
93d9b07
Merge branch 'main' into CustomBanReasons
Inbestigator Jul 3, 2024
73190c8
Merge branch 'main' into CustomBanReasons
Inbestigator Jul 19, 2024
0ff79bd
Merge branch 'main' into CustomBanReasons
Inbestigator Aug 2, 2024
436df28
Merge branch 'main' into CustomBanReasons
Inbestigator Aug 13, 2024
e893081
Merge branch 'main' into CustomBanReasons
Inbestigator Aug 16, 2024
8605e2c
Merge branch 'main' into CustomBanReasons
Inbestigator Aug 26, 2024
d0cac7b
Merge branch 'main' into CustomBanReasons
Inbestigator Oct 9, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/plugins/betterBanReasons/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# BetterBanReasons

* Create custom reasons to use in the Discord ban modal.
* Show a text input by default instead of the options
Inbestigator marked this conversation as resolved.
Show resolved Hide resolved

![image](https://github.com/Vendicated/Vencord/assets/119569726/6227586b-43a2-4b05-9945-85995c3cb513)

![image](https://github.com/Vendicated/Vencord/assets/119569726/4aaaf5f1-6dc4-4844-b4a9-9b23cfb739e2)
100 changes: 100 additions & 0 deletions src/plugins/betterBanReasons/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
/*
* Vencord, a Discord client mod
* Copyright (c) 2024 Vendicated and contributors
* SPDX-License-Identifier: GPL-3.0-or-later
*/

import "./styles.css";

import { definePluginSettings } from "@api/Settings";
import { Devs } from "@utils/constants";
import definePlugin, { OptionType } from "@utils/types";
import { Button, Forms, i18n, TextInput } from "@webpack/common";

function ReasonsComponent() {
const { reasons } = settings.use(["reasons"]);

return (
<Forms.FormSection title="Reasons">
{reasons.map((reason: string, index: number) => (
<div
className="vc-bbr-reason-wrapper"
>
<TextInput
type="text"
key={index}
value={reason}
onChange={v => {
reasons[index] = v;
settings.store.reasons = [...reasons];
}}
placeholder="Reason"
/>
<Button
color={Button.Colors.RED}
className="vc-bbr-remove-button"
onClick={() => {
reasons.splice(index, 1);
settings.store.reasons = [...reasons];
}}
>
Remove
</Button>
</div>
))}
<Button
onClick={() => {
settings.store.reasons = [...reasons, ""];
}}
>
Add new
</Button>
</Forms.FormSection>
);
}

const settings = definePluginSettings({
reasons: {
description: "Your custom reasons",
type: OptionType.COMPONENT,
default: [],
component: ReasonsComponent,
},
textInputDefault: {
type: OptionType.BOOLEAN,
description: 'Shows a text input instead of a select menu by default. (Equivalent to clicking the "Other" option)'
}
});

export default definePlugin({
name: "BetterBanReasons",
description: "Create custom reasons to use in the Discord ban modal, and/or show a text input by default instead of the options.",
authors: [Devs.Inbestigator],
patches: [
{
find: "Messages.BAN_MULTIPLE_CONFIRM_TITLE",
replacement: [{
match: /\[\{name:\i\.\i\.Messages\.BAN_REASON_OPTION_SPAM_ACCOUNT.+?\}\]/,
replace: "$self.getReasons()"
},
{
match: /useState\(0\)(?=.{0,100}targetUserId:)/,
replace: "useState($self.getDefaultState())"
}]
}
],
getReasons() {
const reasons = settings.store.reasons.length
? settings.store.reasons
: [
i18n.Messages.BAN_REASON_OPTION_SPAM_ACCOUNT,
i18n.Messages.BAN_REASON_OPTION_HACKED_ACCOUNT,
i18n.Messages.BAN_REASON_OPTION_BREAKING_RULES
];
return reasons.map(s => ({ name: s, value: s }));
},
getDefaultState() {
return settings.store.textInputDefault ? 1 : 0;
},
settings,
});
11 changes: 11 additions & 0 deletions src/plugins/betterBanReasons/styles.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
.vc-bbr-reason-wrapper {
display: grid;
padding: 0;
padding-bottom: 0.5rem;
gap: 0.5rem;
grid-template-columns: 6fr 1fr;
}

.vc-bbr-remove-button {
height: 100%;
}