k44Eqha/misc.js

84 lines
3.1 KiB
JavaScript
Raw Normal View History

2018-05-12 07:19:31 +02:00
// join/leave
2018-07-14 01:29:48 +02:00
(async function(){
2022-01-04 05:40:43 +01:00
var webhook = new Discord.WebhookClient({url: config.webhooks.welcome});
dClient.on('guildMemberAdd', async member => {
if (member.guild.id != config.guildID) return;
2020-03-09 06:49:31 +01:00
let username = member.user.username.toLowerCase().includes('clyde') ? member.user.username.replace(/C/g,'Q').replace(/c/g,'q') : member.user.username;
2022-01-04 05:40:43 +01:00
webhook.send(`${member} joined.`, {username, avatarURL: member.user.displayAvatarURL({format:'png',size:2048})});
2018-05-12 07:19:31 +02:00
});
2022-01-04 05:40:43 +01:00
dClient.on('guildMemberRemove', async member => {
if (member.guild.id != config.guildID) return;
2020-03-09 06:49:31 +01:00
let username = member.user.username.toLowerCase().includes('clyde') ? member.user.username.replace(/C/g,'Q').replace(/c/g,'q') : member.user.username;
2022-01-04 05:40:43 +01:00
webhook.send(`${member.user.tag} left.`, {username, avatarURL: member.user.displayAvatarURL({format:'png',size:2048})});
2018-05-12 07:19:31 +02:00
});
})();
// view deleted channels
2018-07-14 01:29:48 +02:00
(async function(){
2022-01-04 05:40:43 +01:00
dClient.on('voiceStateUpdate', async (oldState, newState) => {
if (oldState.channelId != config.channels.view_deleted_channels && newState.channelId == config.channels.view_deleted_channels) {
2018-05-12 07:19:31 +02:00
// member joined the channel
2022-01-04 05:40:43 +01:00
newState.member.roles.add(config.roles.viewing_deleted_channels);
} else if (oldState.channelId == config.channels.view_deleted_channels && newState.channelId != config.channels.view_deleted_channels) {
2018-05-12 07:19:31 +02:00
// member left the channel
2022-01-04 05:40:43 +01:00
newState.member.roles.remove(config.roles.viewing_deleted_channels);
2018-05-12 07:19:31 +02:00
}
});
2018-08-22 21:25:14 +02:00
})();
2018-09-01 22:27:56 +02:00
2020-11-17 20:58:28 +01:00
// arrange bots at bottom of list
2018-10-01 20:14:39 +02:00
(async function(){
2020-11-17 20:58:28 +01:00
let prefix = "\u17b5";
2018-10-01 20:14:39 +02:00
let onNick = async member => {
2022-01-04 05:40:43 +01:00
if (member.guild.id != config.guildID) return;
if (member.user.bot && !member.displayName.startsWith(prefix))
await member.setNickname(`${prefix}${member.displayName}`.substring(0,32));
2018-10-01 20:14:39 +02:00
};
2022-01-04 05:40:43 +01:00
dClient.on('guildMemberAdd', onNick);
dClient.on('guildMemberUpdate', async (oldMember, newMember) => {
2018-10-01 20:16:18 +02:00
if (newMember.displayName != oldMember.displayName) await onNick(newMember);
2018-10-01 20:14:39 +02:00
});
2020-11-17 20:58:28 +01:00
})();
2018-10-03 21:01:20 +02:00
2018-12-12 07:46:21 +01:00
// persistent emojis
2022-01-04 05:40:43 +01:00
dClient.on("emojiDelete", async emoji => {
2019-08-05 02:39:27 +02:00
console.log("emoji deleted:", emoji.name, emoji.url);
2019-04-04 00:42:34 +02:00
if (global.disableEmojiProtection) return;
2019-08-05 02:39:27 +02:00
if (emoji.name.toLowerCase().includes('delete')) return;
async function readdEmoji() {
await emoji.guild.emojis.create(emoji.url, emoji.name);
delete readdEmoji;
}
// re-add emoji in 5 to 10 minutes
setTimeout(() => {
if (readdEmoji) readdEmoji();
}, 300000 + Math.random() * 300000);
// wouldn't want emoji to be lost if process is stopped before timeout ends
exitHook(callback => {
if (readdEmoji) readdEmoji().then(() => callback());
else callback();
});
2018-12-13 07:12:24 +01:00
});
// allow anyone to pin a message via reaction
2022-01-04 05:40:43 +01:00
// todo need enable partials for it to work on old messages
dClient.on("messageReactionAdd", async (messageReaction) => {
if (messageReaction.guild.id != config.guildID) return;
if (messageReaction.emoji.name == "📌" || messageReaction.emoji.name == "📍")
await messageReaction.message.pin();
});
2018-12-13 07:12:24 +01:00