-
-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
172 additions
and
253 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,30 @@ | ||
{ | ||
"translations": { | ||
"fr": { | ||
"errorTitle": "{pseudo}, hmmm... Cela n'a pas fonctionné !", | ||
"notInAguild": "Vous devez appartenir à une guilde pour effectuer cette commande", | ||
"cannotGetKickedUser": "Veuillez mentionner un joueur existant. Ex : `guildAdd @user#0000`", | ||
"notInTheGuild": "Le joueur n'appartient pas à votre guilde.", | ||
"notChiefError": "Vous devez être chef de la guilde pour effectuer cette commande.", | ||
"kickTitle": "{pseudo}, confirmation :", | ||
"kick": "Exclure {kickedPseudo} de la guilde `{guildName}` ?", | ||
"successTitle": "{kickedPseudo} a quitté la guilde {guildName} !", | ||
"kickSuccess": "You'r poor lonesome cowboy and a long long way from home...", | ||
"kickCancelled" : "l'exclusion de {kickedPseudo} a été annulée !", | ||
"excludeHimself" : "Vous ne pouvez pas vous exclure vous même" | ||
}, | ||
"en": { | ||
"errorTitle": "{pseudo}, hmmm... That didn't work!", | ||
"notInAguild": "You have to be in a guild to use this command.", | ||
"cannotGetKickedUser": "Please mention an existing player. Ex : `guildAdd @user#0000`", | ||
"notInTheGuild": "This player is not in your guild.", | ||
"notChiefError": "You have to be a guil leader to use this commabd.", | ||
"kickTitle": "{pseudo}, confirmation:", | ||
"kick": "Are you sure you want to kick {kickedPseudo} from the guild `{guildName}`?", | ||
"successTitle": "{kickedPseudo} left the guild {guildName}!", | ||
"kickSuccess": "You'r poor lonesome cowboy and a long long way from home...", | ||
"kickCancelled" : "You did not join the guild `{guildName}`!", | ||
"excludeHimself" : "You cannot exclude yourself." | ||
} | ||
} | ||
} |
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,142 @@ | ||
/** | ||
* Allow to kick a member from a guild | ||
* @param {("fr"|"en")} language - Language to use in the response | ||
* @param {module:"discord.js".Message} message - Message from the discord server | ||
* @param {String[]} args=[] - Additional arguments sent with the command | ||
*/ | ||
const GuildKickCommand = async (language, message, args) => { | ||
|
||
let entity, kickedEntity, guild, kickedGuild; | ||
let embed = new discord.MessageEmbed(); | ||
|
||
[entity] = await Entities.getOrRegister(message.author.id); | ||
|
||
try { | ||
kickedEntity = await Entities.getByArgs(args, message); | ||
} catch (error) { | ||
kickedEntity = null; | ||
} | ||
|
||
if (kickedEntity == null) { //no user provided | ||
embed.setColor(JsonReader.bot.embed.error) | ||
.setAuthor(format(JsonReader.commands.guildKick.getTranslation(language).errorTitle, { | ||
pseudo: message.author.username | ||
}), message.author.displayAvatarURL()) | ||
.setDescription(JsonReader.commands.guildKick.getTranslation(language).cannotGetKickedUser); | ||
return message.channel.send(embed); | ||
} | ||
|
||
// search for a user's guild | ||
try { | ||
guild = await Guilds.getById(entity.Player.guild_id); | ||
} catch (error) { | ||
guild = null; | ||
} | ||
|
||
if (guild == null) { // not in a guild | ||
embed.setColor(JsonReader.bot.embed.error) | ||
.setAuthor(format(JsonReader.commands.guildKick.getTranslation(language).errorTitle, { | ||
pseudo: message.author.username | ||
}), message.author.displayAvatarURL()) | ||
.setDescription(JsonReader.commands.guildKick.getTranslation(language).notInAguild); | ||
return message.channel.send(embed); | ||
} | ||
|
||
if (guild.chief_id != entity.id) { | ||
embed.setColor(JsonReader.bot.embed.error) | ||
.setAuthor(format(JsonReader.commands.guildKick.getTranslation(language).errorTitle, { | ||
pseudo: message.author.username | ||
}), message.author.displayAvatarURL()) | ||
.setDescription(JsonReader.commands.guildKick.getTranslation(language).notChiefError); | ||
return message.channel.send(embed); | ||
} | ||
|
||
// search for a user's guild | ||
try { | ||
kickedGuild = await Guilds.getById(kickedEntity.Player.guild_id); | ||
} catch (error) { | ||
kickedGuild = null; | ||
} | ||
|
||
if (kickedGuild == null || kickedGuild.id != guild.id) { // not the same guild | ||
embed.setColor(JsonReader.bot.embed.error) | ||
.setAuthor(format(JsonReader.commands.guildKick.getTranslation(language).errorTitle, { | ||
pseudo: message.author.username | ||
}), message.author.displayAvatarURL()) | ||
.setDescription(JsonReader.commands.guildKick.getTranslation(language).notInTheGuild); | ||
return message.channel.send(embed); | ||
} | ||
|
||
if (kickedEntity.id === entity.id) { | ||
embed.setColor(JsonReader.bot.embed.error) | ||
.setAuthor(format(JsonReader.commands.guildKick.getTranslation(language).errorTitle, { | ||
pseudo: message.author.username | ||
}), message.author.displayAvatarURL()) | ||
.setDescription(JsonReader.commands.guildKick.getTranslation(language).excludeHimself); | ||
return message.channel.send(embed); | ||
} | ||
|
||
|
||
embed.setAuthor(format(JsonReader.commands.guildKick.getTranslation(language).kickTitle, { | ||
pseudo: message.author.username | ||
}), message.author.displayAvatarURL()); | ||
embed.setDescription(format(JsonReader.commands.guildKick.getTranslation(language).kick, { | ||
guildName: guild.name, | ||
kickedPseudo: message.mentions.users.last().username | ||
})); | ||
|
||
let msg = await message.channel.send(embed); | ||
|
||
embed = new discord.MessageEmbed(); | ||
const filterConfirm = (reaction, user) => { | ||
return ((reaction.emoji.name == MENU_REACTION.ACCEPT || reaction.emoji.name == MENU_REACTION.DENY) && user.id === message.author.id); | ||
}; | ||
|
||
const collector = msg.createReactionCollector(filterConfirm, { | ||
time: 120000, | ||
max: 1 | ||
}); | ||
|
||
collector.on('end', async (reaction) => { | ||
if (reaction.first()) { // a reaction exist | ||
if (reaction.first().emoji.name == MENU_REACTION.ACCEPT) { | ||
|
||
kickedEntity.Player.guild_id = null; | ||
|
||
await Promise.all([ | ||
kickedEntity.save(), | ||
kickedEntity.Player.save() | ||
]); | ||
|
||
embed.setAuthor(format(JsonReader.commands.guildKick.getTranslation(language).successTitle, { | ||
kickedPseudo: message.mentions.users.last().username, | ||
guildName: guild.name | ||
}), message.mentions.users.last().displayAvatarURL()); | ||
embed.setDescription(JsonReader.commands.guildKick.getTranslation(language).kickSuccess); | ||
return message.channel.send(embed); | ||
} | ||
} | ||
|
||
//Cancel the creation | ||
embed.setColor(JsonReader.bot.embed.error) | ||
.setAuthor(format(JsonReader.commands.guildKick.getTranslation(language).errorTitle, { | ||
pseudo: message.author.username | ||
}), message.author.displayAvatarURL()) | ||
.setDescription(format(JsonReader.commands.guildKick.getTranslation(language).kickCancelled, { | ||
kickedPseudo: message.mentions.users.last().username | ||
})); | ||
message.channel.send(embed); | ||
|
||
}); | ||
|
||
await msg.react(MENU_REACTION.ACCEPT); | ||
await msg.react(MENU_REACTION.DENY); | ||
|
||
}; | ||
|
||
|
||
module.exports = { | ||
"guildkick": GuildKickCommand, | ||
"gkick": GuildKickCommand, | ||
"gk": GuildKickCommand | ||
}; |
Oops, something went wrong.