This commit is contained in:
Lamp 2018-10-06 11:59:22 -07:00
parent f08ec6869b
commit 1ea0adc962
No known key found for this signature in database
GPG Key ID: 0F1F8704BEDE369E
5 changed files with 35 additions and 13 deletions

View File

@ -5,7 +5,6 @@ colorRoles.findColorRole = function (member) { // get color role of member
};
colorRoles.update = async function (member) { // create or remove member's color role based on presence
if (member.guild.id != config.guildID) return;
let existingColorRole = colorRoles.findColorRole(member);
if (member.presence.status == "offline") { // they must not have the role
if (!existingColorRole) return; // ok, they already don't have the role
@ -85,12 +84,12 @@ colorRoles.pruneOrphanRoles = async function() { // delete all color roles that
// event listeners
dClient.on('presenceUpdate', async (oldPresence, newPresence) => { // update color role on presence update // emitted also on member join (iirc)
dClient.on('local_presenceUpdate', async (oldPresence, newPresence) => { // update color role on presence update // emitted also on member join (iirc)
if (oldPresence && (oldPresence.status == newPresence.status)) return;
await colorRoles.update(newPresence.member);
});
dClient.on('guildMemberRemove', async member => { // update (delete) color role on member leave
dClient.on('local_guildMemberRemove', async member => { // update (delete) color role on member leave
await colorRoles.update(member);
});

View File

@ -148,11 +148,9 @@ global.commands = {
dClient.on('message', message => {
if (message.guild.id != config.guildID) return;
dClient.on('local_message', async message => {
if (!message.content.startsWith('!')) return;
if (message.author.id === dClient.user.id) return;
if (message.guild && message.guild.id !== config.guildID) return;
var args = message.content.split(' ');
var cmd = args[0].slice(1).toLowerCase();

24
src/local_events.js Normal file
View File

@ -0,0 +1,24 @@
dClient.on("guildMemberAdd", function(member){
if (member.guild.id == config.guildID)
this.emit("local_guildMemberAdd", member);
});
dClient.on("guildMemberRemove", function(member){
if (member.guild.id == config.guildID)
this.emit("local_guildMemberRemove", member);
});
dClient.on("guildMemberUpdate", function(oldMember, newMember){
if (newMember.guild.id == config.guildID)
this.emit("local_guildMemberUpdate", oldMember, newMember);
});
dClient.on("message", function(message){
if (message.guild.id == config.guildID)
this.emit("local_message", message);
});
dClient.on("presenceUpdate", function(oldPresence, newPresence){
if (newPresence.member && newPresence.member.guild.id == config.guildID)
this.emit("local_presenceUpdate", oldPresence, newPresence);
});
dClient.on("voiceStateUpdate", function(oldState, newState){
if (newState.guild.id == config.guildID)
this.emit("local_voiceStateUpdate", oldState, newState);
});

View File

@ -42,6 +42,7 @@ dClient.once('ready', () => {
console.log('Discord Client Ready');
dClient.defaultGuild = dClient.guilds.get(config.guildID);
require('./local_events');
require('./commands');
require('./colorroles');
require('./mppbridger');

View File

@ -3,10 +3,10 @@
// join/leave
(async function(){
var webhook = new Discord.WebhookClient(config.webhooks.welcome[0], config.webhooks.welcome[1]);
dClient.on('guildMemberAdd', async member => {
dClient.on('local_guildMemberAdd', async member => {
webhook.send(`${member} joined.`, {username: member.user.username, avatarURL: member.user.displayAvatarURL(), disableEveryone:true});
});
dClient.on('guildMemberRemove', async member => {
dClient.on('local_guildMemberRemove', async member => {
webhook.send(`${member.user.tag} left.`, {username: member.user.username, avatarURL: member.user.displayAvatarURL(), disableEveryone:true});
});
})();
@ -16,7 +16,7 @@
(async function(){
var vcid = config.channels.view_deleted_channels;
var rid = config.roles.viewing_deleted_channels;
dClient.on('voiceStateUpdate', async (oldState, newState) => {
dClient.on('local_voiceStateUpdate', async (oldState, newState) => {
if (oldState.channelID != vcid && newState.channelID == vcid) {
// member joined the channel
newState.member.roles.add(newState.member.guild.roles.get(rid));
@ -44,7 +44,7 @@
await member.setNickname(`${nam} ${num}`);
}
}
dClient.on("guildMemberUpdate", async (oldMember, newMember) => {
dClient.on("local_guildMemberUpdate", async (oldMember, newMember) => {
if (oldMember.displayName != newMember.displayName) onName(newMember);
});
}*/// didn't work D:
@ -57,8 +57,8 @@
if (member.user.bot && !member.displayName.startsWith(prefix))
await member.setNickname(`${prefix}${member.displayName}`.substr(0,32));
};
dClient.on('guildMemberAdd', onNick);
dClient.on('guildMemberUpdate', async (oldMember, newMember) => {
dClient.on('local_guildMemberAdd', onNick);
dClient.on('local_guildMemberUpdate', async (oldMember, newMember) => {
if (newMember.displayName != oldMember.displayName) await onNick(newMember);
});
})();
@ -66,7 +66,7 @@
// prevent identical display names
/*(async function(){
dClient.on("guildMemberUpdate", async (oldMember, newMember) => {
dClient.on("local_guildMemberUpdate", async (oldMember, newMember) => {
//var displayNames = newMember.guild.members.map(m => m.displayName);
//if (newMember.nickname && displayNames.includes(newMember.nickname)) newMember.setNickname('');
//else if (displayNames.includes(newMember.displayName)) newMember.setNickname(`${newMember.displayName}_`.substr(0,32));