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

Sticky messages setting to allow responses to bots #130

Merged
merged 3 commits into from
Oct 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
14 changes: 14 additions & 0 deletions modules/sticky-messages/configs/sticky-messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,20 @@
},
"type": "string",
"allowEmbed": true
},{
"name": "respondBots",
"humanName": {
"en": "Respond to bots",
"de": "Antworten auf Bots"
},
"default": {
"en": false
},
"description": {
"en": "Whether your bot reacts to messages from other bots in the channel",
"de": "Ob dein Bot auf Nachrichten von anderen Bots in dem Kanal reagiert"
},
"type": "boolean"
}
]
}
7 changes: 6 additions & 1 deletion modules/sticky-messages/events/messageCreate.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const { embedTypeV2 } = require('../../../src/functions/helpers');
const channelData = {};
const sendPending = new Set();

/**
* Deletes the sticky message sent by the bot
Expand All @@ -24,17 +25,20 @@ module.exports.deleteMessage = deleteMessage;
* @param {Object|String} configMsg The configured message
*/
async function sendMessage(channel, configMsg) {
sendPending.add(channel.id);
channelData[channel.id] = {
msg: null,
timeout: null,
time: Date.now()
};

const sentMessage = await channel.send(await embedTypeV2(configMsg));
channelData[channel.id] = {
msg: sentMessage.id,
timeout: null,
time: Date.now()
};
sendPending.delete(channel.id);
}
module.exports.sendMessage = sendMessage;

Expand All @@ -43,13 +47,14 @@ module.exports.run = async (client, msg) => {
if (!msg.guild) return;
if (msg.guild.id !== client.guildID) return;
if (!msg.member) return;
if (msg.author.bot) return;
if (msg.author.id === client.user.id && sendPending.has(msg.channel.id)) return;

const stickyChannels = client.configurations['sticky-messages']['sticky-messages'];
if (!stickyChannels) return;

const currentConfig = stickyChannels.find(c => c.channelId === msg.channel.id);
if (!currentConfig || !currentConfig.message) return;
if (!currentConfig.respondBots && msg.author.bot) return;

if (channelData[msg.channel.id]) {
if (channelData[msg.channel.id].time + 5000 > Date.now()) {
Expand Down
Loading