Last active
April 16, 2024 11:33
-
-
Save shinmai/78df3b2237345d8b273eca671e2135bb to your computer and use it in GitHub Desktop.
BetterDiscord addon/plug-in to help trying to keep from being a nuissance
This file contains hidden or 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
/** | |
* @name Don't Be A Bother! | |
* @description Try to be less cringey on Discord | |
* @version 0.0.2 | |
* @author shi | |
* @authorId 142594671078539264 | |
* @website https://shinmai.wtf/ | |
* @source https://gist.github.com/shinmai/78df3b2237345d8b273eca671e2135bb/raw/DontBeABother.plugin.js | |
* @updateUrl https://gist.github.com/shinmai/78df3b2237345d8b273eca671e2135bb/raw/DontBeABother.plugin.js | |
*/ | |
/** | |
* Changelog: | |
* 0.0.1 - initial version | |
* 0.0.2 - a few fixes | |
*/ | |
module.exports = meta => ({ | |
start() { | |
const { createToast } = BdApi.Webpack.getModule(x => x.createToast), | |
{ _, showToast } = BdApi.Webpack.getModule(x => x.showToast), | |
getChannel = BdApi.Webpack.getStore("ChannelStore").getChannel, | |
targetTimestamps = {}, | |
targets = ["1337", "80085"], // add serverIDs or user IDs to the list | |
timeout = 15 * 60 * 1000 // cooldown in milliseconds, defaults to 15 minutes, | |
selfControlHelper = (_,args,oFn)=> { | |
let channelId = args[0].channelId | |
if(!args[0].channelId) | |
[ channelId ] = args | |
const channel = getChannel(channelId), | |
target = channel.recipients?.at(0) || channel.guild_id | |
if(targets.includes(target)) { | |
const lastSent = targetTimestamps[target], | |
now = Date.now() | |
if (lastSent && now - lastSent < timeout) | |
return showToast(createToast(`Don't be a bother! Wait ${ (timeout - (now - lastSent)) / 1000 } seconds more.`, 2)) | |
targetTimestamps[target] = now | |
} | |
return oFn(...args) | |
} | |
targets.forEach(target => targetTimestamps[target]=Date.now()) | |
BdApi.Patcher.instead('dontBeABother', BdApi.Webpack.getModule(BdApi.Webpack.Filters.byProps('sendMessage')), 'sendMessage', selfControlHelper) | |
BdApi.Patcher.instead('dontBeABother', BdApi.Webpack.getModule(BdApi.Webpack.Filters.byProps('uploadFiles')), 'uploadFiles', selfControlHelper) | |
}, | |
stop() { BdApi.Patcher.unpatchAll('dontBeABother') } | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment