-
Notifications
You must be signed in to change notification settings - Fork 2
/
Settings.jsx
159 lines (139 loc) · 6.63 KB
/
Settings.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
const { getModule, getModuleByDisplayName, React } = require('powercord/webpack');
/** @type {import("../../../fake_node_modules/powercord/components/settings/TextInput")} */
const Category = require("powercord/components/settings/TextInput");
const List = require("./components/List");
const { TextInput, SwitchItem, SliderInput, Toggle } = require('powercord/components/settings');
const { dialog } = require("electron");
module.exports = function (props) {
const { getSetting, toggleSetting, updateSetting } = props;
const [channels, setChannels] = React.useState(JSON.parse(window.localStorage.getItem("excluded-channel")) ?? []);
const [selectedChannelID, setSelectedChannelID] = React.useState(channels[0] ?? "");
const [channelTextInputText, setChannelInputText] = React.useState("");
const [servers, setServers] = React.useState(JSON.parse(window.localStorage.getItem("excluded-server")) ?? []);
const [selectedserverID, setSelectedserverID] = React.useState(servers[0] ?? "");
const [serverTextInputText, setServerInputText] = React.useState("");
const [maxEmoji, setMaxEmoji] = React.useState(window.localStorage.getItem("max-emoji-per-word") ?? 1);
React.useEffect(() => {
window.localStorage.setItem("max-emoji-per-word", maxEmoji);
}, [maxEmoji]);
const { getChannel } = getModule(["getChannel"], false);
const { getUser } = getModule(["getUser"], false);
const { getGuild } = getModule(["getGuild"], false);
return (
<div>
<div className="emojifier-remove-channel">
</div>
<div className="emojifier-remove-channel">
<h2>Max emoji per word</h2>
<input type="range" min="0" max="100" step="1"
value={maxEmoji} onChange={e => setMaxEmoji(e.target.value)} />
<p>{`There will be a maximum of ${maxEmoji} emoji per word`}</p>
</div>
<div class="divider-3573oO dividerDefault-3rvLe-"></div>
<div className="emojifier-remove-channel">
<h2>Excluded channels</h2>
<TextInput
note="Channel ID of an new excluded channel (you can also put a user id to ignore dm with specific user)"
required={false}
onChange={setChannelInputText}
value={channelTextInputText}
>
Excluded channels &s; excluded users
</TextInput>
<List
item={channels}
name="Channel ID & users"
selectedItem={selectedChannelID}
onSelectItem={setSelectedChannelID}
/>
<div className="manage-channel-control">
<button onClick={async function () {
/** @type {string[]} */
const excludedChannel = JSON.parse(window.localStorage.getItem("excluded-channel")) ?? [];
if (!channelTextInputText || Number(channelTextInputText) === NaN || excludedChannel.includes(channelTextInputText))
return;
try {
excludedChannel.push(`${getChannel(channelTextInputText).id} (${getChannel(channelTextInputText).name} in the discord server ${getGuild(getChannel(channelTextInputText).guild_id).name})`);
window.localStorage.setItem("excluded-channel", JSON.stringify(excludedChannel));
setChannels(excludedChannel);
}
catch (e) {
// try to add a user if it cant add a user
try {
if (/\d+/.test(channelTextInputText))
setChannelInputText("");
const user = await getUser(channelTextInputText);
excludedChannel.push(`${channelTextInputText} (user ${user.username})`);
window.localStorage.setItem("excluded-channel", JSON.stringify(excludedChannel));
setChannels(excludedChannel);
}
catch (e2) {
}
}
finally {
setChannelInputText("");
}
}}>Add channel</button>
<button onClick={function () {
try {
/** @type {string[]} */
let excludedChannel = JSON.parse(window.localStorage.getItem("excluded-channel")) ?? [];
if (selectedChannelID)
excludedChannel = excludedChannel.filter(e => e != selectedChannelID); // will return ['A', 'C']
else if (selectedChannelID == "" || channels.length < 2)
excludedChannel.pop();
window.localStorage.setItem("excluded-channel", JSON.stringify(excludedChannel));
setChannels(excludedChannel);
} catch { }
}}>Remove selected channel</button>
</div>
</div>
<div class="divider-3573oO dividerDefault-3rvLe-"></div>
<div className="emojifier-remove-channel">
<h2>Excluded servers</h2>
<TextInput
note="Server ID of an server to exclude"
required={false}
onChange={setServerInputText}
value={serverTextInputText}
>
Excluded server
</TextInput>
<List
item={servers}
name="Excluded servers"
selectedItem={selectedserverID}
onSelectItem={setSelectedserverID}
/>
<div className="manage-channel-control">
<button onClick={function () {
/** @type {string[]} */
const excludedserver = JSON.parse(window.localStorage.getItem("excluded-server")) ?? [];
if (!serverTextInputText || Number(serverTextInputText) === NaN || excludedserver.includes(serverTextInputText))
return;
try {
excludedserver.push(serverTextInputText + " (" + getGuild(serverTextInputText).name + ")");
window.localStorage.setItem("excluded-server", JSON.stringify(excludedserver));
setServers(excludedserver);
}
catch (e) {
}
finally {
setServerInputText("");
}
}}>Add server</button>
<button onClick={function () {
/** @type {string[]} */
let excludedserver = JSON.parse(window.localStorage.getItem("excluded-server")) ?? [];
if (selectedserverID)
excludedserver = excludedserver.filter(e => e != selectedserverID); // will return ['A', 'C']
else if (selectedserverID == "" || servers.length < 2)
excludedserver.pop();
window.localStorage.setItem("excluded-server", JSON.stringify(excludedserver));
setServers(excludedserver);
}}>Remove selected server</button>
</div>
</div>
</div>
);
};