Skip to content

Commit e4e6370

Browse files
committed
Improve error and status messages
1 parent 85905d3 commit e4e6370

File tree

4 files changed

+25
-5
lines changed

4 files changed

+25
-5
lines changed

Diff for: README.md

+1
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ Go to your server, and type the config command, and set the API key for your ser
5858
/chat-gpt-config
5959
```
6060

61+
![config-api-key.png](config-api-key.png)
6162

6263

6364
## Environment Variables

Diff for: config-api-key.png

122 KB
Loading

Diff for: src/discord/handlers/commands/ConfigCommand.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ Total messages sent by all users of this server's API key: ${totalSum}.`,
129129
} else {
130130
fields.push({
131131
name: 'Sent Messages',
132-
value: `You sent ${messageCounter[user.id] ?? 0}/${config.maxMessagePerUser === -1 ? 'Unlimited' : config.maxMessagePerUser} messages.
132+
value: `You sent ${(messageCounter[user.id] ?? {count: 0}).count}/${config.maxMessagePerUser === -1 ? 'Unlimited' : config.maxMessagePerUser} messages.
133133
134134
Total messages sent by all users of this server's API key: ${totalSum}.`
135135
});
@@ -259,7 +259,7 @@ If you'd like to use the server's API key, please send me the /${CONFIG_COMMAND_
259259

260260
const fields = [{
261261
name: 'Sent Messages',
262-
value: `You sent ${messageCounter[commandInteraction.user.id] ?? 0}/${config.maxMessagePerUser === -1 ? 'Unlimited' : config.maxMessagePerUser} messages.`
262+
value: `You sent ${(messageCounter[commandInteraction.user.id] ?? {count: 0}).count}/${config.maxMessagePerUser === -1 ? 'Unlimited' : config.maxMessagePerUser} messages.`
263263
}];
264264

265265
await commandInteraction.followUp({

Diff for: src/discord/handlers/modals/MessageLimitsModal.ts

+22-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
import {defineModal} from "../DefineModal";
22
import {EmbedBuilder, ModalSubmitInteraction, TextInputStyle} from "discord.js";
3-
import {getConfig, getConfigForId, setConfig, setConfigForId} from "../../../core/config";
3+
import {
4+
getConfig,
5+
getConfigForId,
6+
getMessageCounter,
7+
saveMessageCounter,
8+
setConfig,
9+
setConfigForId
10+
} from "../../../core/config";
411
import {parseInt} from "lodash";
512
import {retrieveConversation} from "../../../core/RetrieveConversation";
613
import {getConfigIdForInteraction} from "../commands/ConfigCommand";
@@ -55,15 +62,27 @@ export const MessageLimitsModal = defineModal(
5562

5663
if (!isNaN(maxMessagePerUserValue)) {
5764
config.maxMessagePerUser = maxMessagePerUserValue < 0 ? -1 : maxMessagePerUserValue;
58-
config.exceptionRoleIds = (exceptionRoleIds ?? '').split('\n').map(item => item.trim());
65+
config.exceptionRoleIds = (exceptionRoleIds ?? '')
66+
.split('\n')
67+
.map(item => item.trim())
68+
.filter(item => item.length > 0);
69+
70+
const messageCounter = await getMessageCounter(configId);
71+
for (let value of Object.values(messageCounter)) {
72+
if(value) {
73+
value.warned = false;
74+
}
75+
}
76+
77+
await saveMessageCounter(configId, messageCounter);
5978

6079
await setConfigForId(configId, config);
6180

6281
await submitInteraction.followUp({
6382
content: '',
6483
embeds: [
6584
new EmbedBuilder()
66-
.setDescription(`Updated.\n${getMessageLimitsMessage(config)}`)
85+
.setDescription(`Updated.\n\n${getMessageLimitsMessage(config)}`)
6786
.setColor(0x00ff00)
6887
],
6988
components: [],

0 commit comments

Comments
 (0)