-
-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add untested sticky messages module * Some sticky fixes * My mistakes xD * Remove unused client
- Loading branch information
1 parent
0662a69
commit e7fd5d1
Showing
4 changed files
with
2,096 additions
and
1,220 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
{ | ||
"description": { | ||
"en": "Manage the sticky messages here", | ||
"de": "Passe hier die Sticky-Nachrichten an" | ||
}, | ||
"humanName": { | ||
"en": "Sticky messages", | ||
"de": "Sticky-Nachrichten" | ||
}, | ||
"filename": "sticky-messages.json", | ||
"configElements": true, | ||
"content": [ | ||
{ | ||
"name": "channelId", | ||
"humanName": { | ||
"en": "Channel", | ||
"de": "Kanal" | ||
}, | ||
"default": { | ||
"en": "" | ||
}, | ||
"description": { | ||
"en": "Channel-ID in which the message should get send", | ||
"de": "Kanal-ID, in welchem die Nachricht gesendet werden soll" | ||
}, | ||
"type": "channelID" | ||
}, | ||
{ | ||
"name": "message", | ||
"humanName": { | ||
"en": "Message", | ||
"de": "Nachricht" | ||
}, | ||
"default": { | ||
"en": "" | ||
}, | ||
"description": { | ||
"en": "Message that should get send", | ||
"de": "Nachricht, die gesendet werden soll" | ||
}, | ||
"type": "string", | ||
"allowEmbed": true | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
const { embedTypeV2 } = require('../../../src/functions/helpers'); | ||
const channelData = {}; | ||
|
||
/** | ||
* Deletes the sticky message sent by the bot | ||
* @param {Discord.Client} client | ||
* @param {Discord.Message} msg | ||
*/ | ||
async function deleteMessage(client, msg) { | ||
let message; | ||
message = await msg.channel.messages.fetch(channelData[msg.channel.id].msg).catch(async () => { | ||
const msgs = await msg.channel.messages.fetch({limit: 20}); | ||
message = msgs.find(m => m.author.id === client.user.id); | ||
}); | ||
|
||
if (message) message.delete().catch(() => {}); | ||
} | ||
|
||
/** | ||
* Sends the message to the channel | ||
* @param {Discord.Message} msg | ||
* @param {Object} configMsg The configured message | ||
*/ | ||
async function sendMessage(msg, configMsg) { | ||
channelData[msg.channel.id] = { | ||
msg: null, | ||
timeout: null, | ||
time: Date.now() | ||
}; | ||
const sentMessage = await msg.channel.send(await embedTypeV2(configMsg)); | ||
channelData[msg.channel.id] = { | ||
msg: sentMessage.id, | ||
timeout: null, | ||
time: Date.now() | ||
}; | ||
} | ||
|
||
module.exports.run = async (client, msg) => { | ||
if (!client.botReadyAt) return; | ||
if (!msg.guild) return; | ||
if (msg.guild.id !== client.guildID) return; | ||
if (!msg.member) return; | ||
if (msg.author.bot) 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 (channelData[msg.channel.id]) { | ||
if (channelData[msg.channel.id].time + 5000 > Date.now()) { | ||
if (!channelData[msg.channel.id].timeout) channelData[msg.channel.id].timeout = setTimeout(() => { | ||
deleteMessage(client, msg); | ||
sendMessage(msg, currentConfig.message); | ||
}, 5000); | ||
return; | ||
} | ||
|
||
deleteMessage(client, msg); | ||
sendMessage(msg, currentConfig.message); | ||
} else sendMessage(msg, currentConfig.message); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
{ | ||
"name": "sticky-messages", | ||
"humanReadableName": { | ||
"en": "Sticky messages", | ||
"de": "Sticky-Nachrichten" | ||
}, | ||
"author": { | ||
"scnxOrgID": "60", | ||
"name": "TomatoCake", | ||
"link": "https://github.com/DEVTomatoCake" | ||
}, | ||
"description": { | ||
"en": "Let a set message always appear at the end of a channel.", | ||
"de": "Lasse eine festgelegte Nachricht immer am Ende eines Kanals erscheinen." | ||
}, | ||
"events-dir": "/events", | ||
"config-example-files": [ | ||
"configs/sticky-messages.json" | ||
], | ||
"tags": [ | ||
"community" | ||
], | ||
"openSourceURL": "https://github.com/DEVTomatoCake/ScootKit-CustomBot/tree/main/modules/sticky-messages" | ||
} |
Oops, something went wrong.