Skip to content
This repository has been archived by the owner on May 30, 2022. It is now read-only.

Commit

Permalink
Update isac-bot.js
Browse files Browse the repository at this point in the history
  • Loading branch information
saacki authored Feb 7, 2021
1 parent 5452968 commit d3a3012
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions isac-bot.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ const commands = [
'isac',
'clan',
'donate',
'update_nicknames',
'obey'
];

Expand Down Expand Up @@ -247,6 +248,46 @@ if ( command === "obey" ) {
return;
}

/*************************************************
// CHANGE NICKNAMES OF USERS TO THEIR AGENT NAMES
*************************************************/
if ( command === "update_nicknames" ) {
let members = [];
if( isAdmin ) {
await message.channel.guild.members.fetch().then(async function(guild){
// exclude server owner as bot can't change owner's nickname
members = message.guild.members.cache.filter(function(member){ return member.user.bot === false && member.user.id != member.guild.ownerID })
.map(function(member){ return {id: member.user.id, nickname: member.nickname, member: member} });

if(members.length > 0) {
let success = [];
let failure = [];

for(var i=0; i<members.length; i++) {
await pool.query("SELECT * FROM users WHERE user_id = ?", [members[i].id]).then(async function(res){
if( res.length > 0 ) {
await members[i].member.setNickname(res[0].agent_name)
.then(function(member){
console.log("Updated nickname of: " + member.displayName + " to " + res[0].agent_name);
success.push(res[0].agent_name);
})
.catch(function(err){
console.log("Unable to update nickname of: " + members[i].member.displayName);
console.log("Reason: " + err.message + "\n");
failure.push(res[0].agent_name);
});
}
});
}

if( success.length > 0 )
message.channel.send("Successfully updated nicknames in" + message.guild.name + ": `" + success.join(', ') + "`").then(function(msg){ if( message.autoDelete ) msg.delete({ timeout: 15000 }); });
}
});
}
return;
}

/*************************************************
// CLAN COMMANDS
*************************************************/
Expand Down

0 comments on commit d3a3012

Please sign in to comment.