Skip to content

Commit e29dd35

Browse files
committed
feat: added support for context menues (close source sync)
1 parent 223c9fe commit e29dd35

117 files changed

Lines changed: 6173 additions & 564 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎locales/en.json‎

Lines changed: 123 additions & 19 deletions
Large diffs are not rendered by default.

‎modules/auto-delete/events/botReady.js‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
const {localize} = require('../../../src/functions/localize');
2+
const {
3+
isMessageProtected,
4+
loadProtectedMessages
5+
} = require('../../../src/functions/protectedMessages');
26
module.exports.run = async function (client) {
7+
// Rebuild the protected-message registry from persisted ids before sweeping.
8+
await loadProtectedMessages(client);
9+
310
const channels = client.configurations['auto-delete']['channels'];
411
const voiceChannels = client.configurations['auto-delete']['voice-channels'];
512

@@ -29,7 +36,7 @@ module.exports.run = async function (client) {
2936
if (idsToKeep.length !== parseInt(channel.keepMessageCount)) idsToKeep.push(message.id);
3037
}
3138
}
32-
dcChannel.bulkDelete(channelMessages.filter(m => !idsToKeep.includes(m.id) && !m.pinned && m.deletable), true);
39+
dcChannel.bulkDelete(channelMessages.filter(m => !idsToKeep.includes(m.id) && !m.pinned && m.deletable && !isMessageProtected(client, channel.channelID, m.id)), true);
3340
}
3441

3542
for (const voiceChannel of uniqueConfigVoiceChannels) {

‎modules/auto-delete/events/messageCreate.js‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
const {isMessageProtected} = require('../../../src/functions/protectedMessages');
2+
13
module.exports.run = async function (client, msg) {
24
if (!client.botReadyAt) return;
35
if (!msg.guild) return;
@@ -9,7 +11,7 @@ module.exports.run = async function (client, msg) {
911
if (!channel) return;
1012
setTimeout(async () => {
1113
if (parseInt(channel.keepMessageCount) === 0) {
12-
if (msg.deletable && !msg.pinned) msg.delete().catch(() => {
14+
if (msg.deletable && !msg.pinned && !isMessageProtected(client, msg.channel.id, msg.id)) msg.delete().catch(() => {
1315
});
1416
return;
1517
}
@@ -18,6 +20,7 @@ module.exports.run = async function (client, msg) {
1820
limit: parseInt(channel.keepMessageCount)
1921
})).sort((a, b) => a.createdAt < b.createdAt ? 1 : -1);
2022
if (oldMessages.length < parseInt(channel.keepMessageCount)) return;
21-
if (oldMessages.last().deletable && !oldMessages.last().pinned) await oldMessages.last().delete();
23+
const oldest = oldMessages.last();
24+
if (oldest.deletable && !oldest.pinned && !isMessageProtected(client, msg.channel.id, oldest.id)) await oldest.delete();
2225
}, parseInt(channel.timeout) * 60000);
2326
};
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
const {localize} = require('../../../src/functions/localize');
2+
const {memberCanSendInChannel} = require('../../../src/functions/helpers');
3+
const connectFourCommand = require('./connect-four');
4+
5+
module.exports.config = {
6+
name: 'Challenge to Connect Four',
7+
type: 'USER',
8+
contextMenu: true,
9+
description: localize('connect-four', 'challenge-to-connect-four-context-description')
10+
};
11+
12+
/*
13+
* Thin adapter: /connect-four run() resolves its opponent via interaction.options.getMember('user')
14+
* and an optional field_size via getInteger('field_size') (defaulting to 7). We reuse run()
15+
* unchanged by handing it the real interaction with those option reads overridden so the
16+
* challenge and game flow is identical, against the right-clicked user with the default field size.
17+
*/
18+
module.exports.run = async function (interaction) {
19+
if (!memberCanSendInChannel(interaction.member, interaction.channel)) return interaction.reply({
20+
ephemeral: true,
21+
content: '⚠️ ' + localize('command', 'no-send-permission')
22+
});
23+
const proxy = Object.create(interaction, {
24+
options: {
25+
value: {
26+
...interaction.options,
27+
getMember: (name) => (name === 'user' ? interaction.targetMember : interaction.options.getMember(name)),
28+
getInteger: (name) => (name === 'field_size' ? null : interaction.options.getInteger(name))
29+
}
30+
}
31+
});
32+
return connectFourCommand.run(proxy);
33+
};
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
const {localize} = require('../../../src/functions/localize');
2+
const {memberCanSendInChannel} = require('../../../src/functions/helpers');
3+
const duelCommand = require('./duel');
4+
5+
module.exports.config = {
6+
name: 'Duel',
7+
type: 'USER',
8+
contextMenu: true,
9+
description: localize('duel', 'duel-context-description')
10+
};
11+
12+
/*
13+
* Thin adapter: /duel run() resolves its opponent via interaction.options.getMember('user', true).
14+
* We reuse run() unchanged by handing it the real interaction with getMember overridden to return
15+
* the right-clicked member, so the challenge -> accept -> duel flow is identical against that user.
16+
* The self-challenge guard inside run() applies unchanged.
17+
*/
18+
module.exports.run = async function (interaction) {
19+
if (!memberCanSendInChannel(interaction.member, interaction.channel)) return interaction.reply({
20+
ephemeral: true,
21+
content: '⚠️ ' + localize('command', 'no-send-permission')
22+
});
23+
const proxy = Object.create(interaction, {
24+
options: {
25+
value: {
26+
...interaction.options,
27+
getMember: (name) => (name === 'user' ? interaction.targetMember : interaction.options.getMember(name))
28+
}
29+
}
30+
});
31+
return duelCommand.run(proxy);
32+
};
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
const {localize} = require('../../../src/functions/localize');
2+
const {adminGuard} = require('./economy-system');
3+
const {
4+
ModalBuilder,
5+
ActionRowBuilder,
6+
TextInputBuilder,
7+
TextInputStyle
8+
} = require('discord.js');
9+
10+
module.exports.config = {
11+
name: 'Add Money',
12+
type: 'USER',
13+
contextMenu: true,
14+
defaultMemberPermissions: ['ADMINISTRATOR'],
15+
description: localize('economy-system', 'add-money-context-description')
16+
};
17+
18+
/*
19+
* /economy add adapter: runs the slash admin guard, then opens the amount modal (customId encodes
20+
* action + target) handled in events/interactionCreate.js. showModal must be first, so no defer.
21+
*/
22+
module.exports.run = async function (interaction) {
23+
interaction.str = interaction.client.configurations['economy-system']['strings'];
24+
interaction.config = interaction.client.configurations['economy-system']['config'];
25+
if (!await adminGuard(interaction, interaction.targetUser)) return;
26+
27+
const modal = new ModalBuilder()
28+
.setCustomId(`eco-ctx:add:${interaction.targetUser.id}`)
29+
.setTitle(localize('economy-system', 'add-money-context-modal-title'))
30+
.addComponents(
31+
new ActionRowBuilder().addComponents(
32+
new TextInputBuilder()
33+
.setCustomId('amount')
34+
.setLabel(localize('economy-system', 'amount-context-label'))
35+
.setStyle(TextInputStyle.Short)
36+
.setRequired(true)
37+
)
38+
);
39+
return interaction.showModal(modal);
40+
};

0 commit comments

Comments
 (0)