feat(bot-discord): stickied messages (#13)

This commit is contained in:
GramingFoxTeam
2023-07-31 17:59:50 +03:00
parent 860589f1bd
commit 9ed5365811
5 changed files with 50 additions and 6 deletions

View File

View File

@@ -1,9 +1,23 @@
{
"discord": {
"trainRoles": ["1019903194941362198", "955220417969262612"],
"trainRoles": [
"1019903194941362198",
"955220417969262612"
],
"botId": "1038762591805247518",
"ignoreRole": "1027874293192863765",
"ignoreChannels": ["953965039105232906", "953964264400515092", "952987428786941952"]
"ignoreChannels": [
"953965039105232906",
"953964264400515092",
"952987428786941952"
]
},
"sticky": {
"channelId": "1135563848586379264",
"stickyMessage": {
"title": "Read me!"
},
"timeout": 30000
},
"server": {
"port": 3000,

View File

@@ -1,9 +1,23 @@
{
"discord": {
"trainRoles": ["1019903194941362198", "955220417969262612"],
"trainRoles": [
"1019903194941362198",
"955220417969262612"
],
"botId": "1038762591805247518",
"ignoreRole": "1027874293192863765",
"ignoreChannels": ["953965039105232906", "953964264400515092", "952987428786941952"]
"ignoreChannels": [
"953965039105232906",
"953964264400515092",
"952987428786941952"
]
},
"sticky": {
"channelId": "1135563848586379264",
"stickyMessage": {
"title": "Read me!"
},
"timeout": 30000
},
"server": {
"port": 3000,
@@ -146,4 +160,4 @@
}
}
]
}
}

View File

@@ -10,11 +10,25 @@ export default {
if (msg.attachments.first() && msg.attachments.first().contentType.startsWith('image')) {
helper.scanImage(msg.attachments.first().url, `${msg.channelId}/${msg.id}`);
}
if (!msg.content || msg.author.bot) return;
helper.scanText(
msg.content.toLowerCase().replace(/<.*?>/g, ''),
`${msg.channelId}/${msg.id}`
);
// Sticky message
if (msg.channel.id !== config.sticky.channelId) return;
if (msg.client.stickiedMessageTimeout) clearInterval(msg.client.stickiedMessageTimeout);
msg.client.stickiedMessageTimeout = setTimeout(() => {
const channel = await msg.client.channels.fetch(config.sticky.channelId);
const message = await channel.send({ embeds: [config.sticky.stickyMessage] });
if (msg.client.stickiedMessage) channel.delete(msg.client.stickiedMessage);
msg.client.stickiedMessage = message.id;
}, config.sticky.timeout);
}
};

View File

@@ -21,6 +21,8 @@ const client = new Client({
client.commands = new Collection();
client.trainingVotes = new Collection();
client.stickiedMessage = null;
client.stickiedMessageTimeout = null;
const commandsPath = join(__dirname, 'commands');
const commandFiles = readdirSync(commandsPath).filter((file) =>