added --remove and default messages

merge-requests/4/head
loicbersier 5 years ago
parent 5ca6515616
commit 8441ad09df

@ -4,24 +4,28 @@ const fs = require('fs');
class byeCommand extends Command { class byeCommand extends Command {
constructor() { constructor() {
super('bye', { super('bye', {
aliases: ['bye'], aliases: ['bye', 'leave'],
category: 'admin', category: 'admin',
channelRestriction: 'guild', channelRestriction: 'guild',
userPermissions: ['MANAGE_CHANNELS'], userPermissions: ['MANAGE_CHANNELS'],
clientPermissions: ['SEND_MESSAGES'],
args: [ args: [
{
id: 'remove',
match: 'flag',
flag: '--remove'
},
{ {
id: 'message', id: 'message',
type: 'string', type: 'string',
prompt: { match: 'rest',
start: 'What message should the bot say when a user leave?', default: '[member] just left the server :('
},
match: 'rest'
} }
], ],
description: { description: {
content: 'Send a message to the current channel when a person leave, you can use [member] to show the member username and [server] to show the name of the server', content: 'Send a message to the current channel when a person leave, you can use [member] to show the member username and [server] to show the name of the server',
usage: '[bye message]', usage: '[bye message]',
examples: ['[member] leaved the server, he deserve a ban'] examples: ['[member] left the server, he deserve a ban']
} }
}); });
} }
@ -29,9 +33,21 @@ class byeCommand extends Command {
async exec(message, args) { async exec(message, args) {
let byeChannel = message.channel.id; let byeChannel = message.channel.id;
if (args.remove) {
fs.unlink(`./welcome/${message.guild.id}.json`, (err) => {
if (err) {
console.error(err);
return message.channel.send('An error has occured, there is most likely no welcome message set!');
} else {
return message.channel.send('Disabled unwelcome message');
}
});
}
fs.writeFile(`./bye/${message.guild.id}.json`, `{"channel": "${byeChannel}", "message": "${args.message}"}`, function (err) { fs.writeFile(`./bye/${message.guild.id}.json`, `{"channel": "${byeChannel}", "message": "${args.message}"}`, function (err) {
if (err) { if (err) {
console.log(err); console.log(err);
return message.channel.send('An error has occured! im gonna be honest with you, i do not know what happened yet! but fear not! i will look into it!');
} }
}); });

@ -1,31 +0,0 @@
const { Command } = require('discord-akairo');
const fs = require('fs');
class unbyeCommand extends Command {
constructor() {
super('unbye', {
aliases: ['unbye'],
category: 'admin',
channelRestriction: 'guild',
userPermissions: ['MANAGE_CHANNELS'],
description: {
content: 'Delete leaving message',
usage: '[]',
examples: ['']
}
});
}
async exec(message) {
fs.unlink(`./bye/${message.guild.id}.json`, (err) => {
if (err) {
console.error(err);
return message.channel.send('An error has occured, there is most likely no bye/leave message set!');
} else {
return message.channel.send('Disabled bye/leave message');
}
});
}
}
module.exports = unbyeCommand;

@ -1,31 +0,0 @@
const { Command } = require('discord-akairo');
const fs = require('fs');
class unwelcomeCommand extends Command {
constructor() {
super('unwelcome', {
aliases: ['unwelcome'],
category: 'admin',
channelRestriction: 'guild',
userPermissions: ['MANAGE_CHANNELS'],
description: {
content: 'Delete welcome message',
usage: '[]',
examples: ['']
}
});
}
async exec(message) {
fs.unlink(`./welcome/${message.guild.id}.json`, (err) => {
if (err) {
console.error(err);
return message.channel.send('An error has occured, there is most likely no welcome message set!');
} else {
return message.channel.send('Disabled unwelcome message');
}
});
}
}
module.exports = unwelcomeCommand;

@ -4,18 +4,21 @@ const fs = require('fs');
class welcomeCommand extends Command { class welcomeCommand extends Command {
constructor() { constructor() {
super('welcome', { super('welcome', {
aliases: ['welcome'], aliases: ['welcome', 'join'],
category: 'admin', category: 'admin',
channelRestriction: 'guild', channelRestriction: 'guild',
userPermissions: ['MANAGE_CHANNELS'], userPermissions: ['MANAGE_CHANNELS'],
args: [ args: [
{
id: 'remove',
match: 'flag',
flag: '--remove'
},
{ {
id: 'message', id: 'message',
type: 'string', type: 'string',
match: 'rest', match: 'rest',
prompt: { default: 'Welcome [member] to [server]!'
start: 'What message do you want to welcome peoples?',
}
} }
], ],
description: { description: {
@ -29,9 +32,21 @@ class welcomeCommand extends Command {
async exec(message, args) { async exec(message, args) {
let welcomeChannel = message.channel.id; let welcomeChannel = message.channel.id;
if (args.remove) {
fs.unlink(`./welcome/${message.guild.id}.json`, (err) => {
if (err) {
console.error(err);
return message.channel.send('An error has occured, there is most likely no welcome message set!');
} else {
return message.channel.send('Disabled unwelcome message');
}
});
}
fs.writeFile(`./welcome/${message.guild.id}.json`, `{"channel": "${welcomeChannel}", "message": "${args.message}"}`, function (err) { fs.writeFile(`./welcome/${message.guild.id}.json`, `{"channel": "${welcomeChannel}", "message": "${args.message}"}`, function (err) {
if (err) { if (err) {
console.log(err); console.log(err);
return message.channel.send('An error has occured! im gonna be honest with you, i do not know what happened yet! but fear not! i will look into it!');
} }
}); });

Loading…
Cancel
Save