Skip to content

Commit

Permalink
feat(PNJ): pnj module
Browse files Browse the repository at this point in the history
  • Loading branch information
Khaaz committed Jul 2, 2020
1 parent 500282e commit 9927b13
Show file tree
Hide file tree
Showing 10 changed files with 320 additions and 0 deletions.
41 changes: 41 additions & 0 deletions src/modules/PNJ/commands/Add.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { Command, CommandOptions } from 'axoncore';

class Add extends Command {
constructor(module) {
super(module);

this.label = 'add';
this.aliases = ['add'];

this.hasSubcmd = false;

this.info = {
owners: ['KhaaZ'],
name: 'add',
description: 'Indique que tu as le PNJ en question sur ton ile.',
usage: 'add [pnj<blaise, celeste, racine, rounard, sarah>]',
examples: [
'add celeste',
'add rounard',
'add sarah',
],
};

this.options = new CommandOptions(this, {
argsMin: 1,
} );
}

async execute( { msg, args } ) {
const pnj = this.module.PNJs.find(e => e.toLowerCase() === args[0].toLowerCase() );
if (!pnj) {
return this.sendError(msg.channel, 'Donnez un PNJ valide !');
}

this.module.pnjDB.add(pnj.toLowerCase(), msg.author.id);

return this.sendMessage(msg.channel, `:white_check_mark: ${pnj} se trouve actuellement sur ton île, c'est noté !`);
}
}

export default Add;
30 changes: 30 additions & 0 deletions src/modules/PNJ/commands/Blaise.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { Command, CommandOptions } from 'axoncore';

class Blaise extends Command {
constructor(module) {
super(module);

this.label = 'blaise';
this.aliases = ['blaise'];

this.hasSubcmd = false;

this.info = {
owners: ['KhaaZ'],
name: 'blaise',
description: 'Affiche une liste de personne ayant le PNJ demandé sur leur ile.',
usage: 'blaise [page]',
examples: ['blaise', 'blaise 1'],
};

this.options = new CommandOptions(this, {
argsMin: 0,
} );
}

async execute( { msg, args } ) {
return this.module.pnj(msg, args[0], 'Blaise');
}
}

export default Blaise;
30 changes: 30 additions & 0 deletions src/modules/PNJ/commands/Celeste.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { Command, CommandOptions } from 'axoncore';

class Celeste extends Command {
constructor(module) {
super(module);

this.label = 'celeste';
this.aliases = ['celeste'];

this.hasSubcmd = false;

this.info = {
owners: ['KhaaZ'],
name: 'celeste',
description: 'Affiche une liste de personne ayant le PNJ demandé sur leur ile.',
usage: 'celeste [page]',
examples: ['celeste', 'celeste 1'],
};

this.options = new CommandOptions(this, {
argsMin: 0,
} );
}

async execute( { msg, args } ) {
return this.module.pnj(msg, args[0], 'Celeste');
}
}

export default Celeste;
41 changes: 41 additions & 0 deletions src/modules/PNJ/commands/Delete.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { Command, CommandOptions } from 'axoncore';

class Delete extends Command {
constructor(module) {
super(module);

this.label = 'delete';
this.aliases = ['delete'];

this.hasSubcmd = false;

this.info = {
owners: ['KhaaZ'],
name: 'delete',
description: 'Indique que le PNJ en question n\'est plus sur ton ile.',
usage: 'delete [pnj<blaise, celeste, racine, rounard, sarah>]',
examples: [
'delete celeste',
'delete rounard',
'delete sarah',
],
};

this.options = new CommandOptions(this, {
argsMin: 1,
} );
}

async execute( { msg, args } ) {
const pnj = this.module.PNJs.find(e => e.toLowerCase() === args[0].toLowerCase() );
if (!pnj) {
return this.sendError(msg.channel, 'Donnez un PNJ valide !');
}

this.module.pnjDB.delete(pnj.toLowerCase(), msg.author.id);

return this.sendMessage(msg.channel, `:x: ${pnj} n'est plus sur ton île, c'est noté !`);
}
}

export default Delete;
30 changes: 30 additions & 0 deletions src/modules/PNJ/commands/Racine.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { Command, CommandOptions } from 'axoncore';

class Racine extends Command {
constructor(module) {
super(module);

this.label = 'racine';
this.aliases = ['racine'];

this.hasSubcmd = false;

this.info = {
owners: ['KhaaZ'],
name: 'racine',
description: 'Affiche une liste de personne ayant le PNJ demandé sur leur ile.',
usage: 'racine [page]',
examples: ['racine', 'racine 1'],
};

this.options = new CommandOptions(this, {
argsMin: 0,
} );
}

async execute( { msg, args } ) {
return this.module.pnj(msg, args[0], 'Racine');
}
}

export default Racine;
30 changes: 30 additions & 0 deletions src/modules/PNJ/commands/Rounard.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { Command, CommandOptions } from 'axoncore';

class Rounard extends Command {
constructor(module) {
super(module);

this.label = 'rounard';
this.aliases = ['rounard'];

this.hasSubcmd = false;

this.info = {
owners: ['KhaaZ'],
name: 'rounard',
description: 'Affiche une liste de personne ayant le PNJ demandé sur leur ile.',
usage: 'rounard [page]',
examples: ['rounard', 'rounard 1'],
};

this.options = new CommandOptions(this, {
argsMin: 0,
} );
}

async execute( { msg, args } ) {
return this.module.pnj(msg, args[0], 'Rounard');
}
}

export default Rounard;
30 changes: 30 additions & 0 deletions src/modules/PNJ/commands/Sarah.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { Command, CommandOptions } from 'axoncore';

class Sarah extends Command {
constructor(module) {
super(module);

this.label = 'sarah';
this.aliases = ['sarah'];

this.hasSubcmd = false;

this.info = {
owners: ['KhaaZ'],
name: 'sarah',
description: 'Affiche une liste de personne ayant le PNJ demandé sur leur ile.',
usage: 'sarah [page]',
examples: ['sarah', 'sarah 1'],
};

this.options = new CommandOptions(this, {
argsMin: 0,
} );
}

async execute( { msg, args } ) {
return this.module.pnj(msg, args[0], 'Sarah');
}
}

export default Sarah;
7 changes: 7 additions & 0 deletions src/modules/PNJ/commands/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export { default as Add } from './Add';
export { default as Delete } from './Delete';
export { default as Blaise } from './Blaise';
export { default as Celeste } from './Celeste';
export { default as Racine } from './Racine';
export { default as Rounard } from './Rounard';
export { default as Sarah } from './Sarah';
80 changes: 80 additions & 0 deletions src/modules/PNJ/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import { Module } from 'axoncore';

import * as commands from './commands/index';
import PNJDB from '../../lib/PNJDB';

class PNJ extends Module {
constructor(...args) {
super(...args);

this.label = 'Pnj';

this.enabled = true;
this.serverBypass = true;

this.info = {
name: 'pnj',
description: 'The PNJ module (check pnj status).',
};

this.pnjDB = new PNJDB(this.axon.custom.DBLocation);

this.PNJs = [
'Blaise',
'Celeste',
'Racine',
'Rounard',
'Sarah',
];
}

init() {
return { commands };
}

pnj(msg, page, pnj) {
const chunk = this.calculateChunk(page || 1);

const users = this.pnjDB.getAll(pnj.toLowerCase() );
if (users.length < chunk) {
return this.sendError(msg.channel, 'Page invalide !', { triggerCooldown: false } );
}

const date = new Date();

const all = users.map(u => {
const user = msg.channel.guild.members.get(u.id);
if (!user) {
this.module.navetDB.delete(u.id);
}
return user.username;
} );

const display = this.chunk(all, chunk)
.map( (u, i) => `${chunk + i + 1}) [${u}]`);

if (display.length < 1) {
return this.sendError(msg.channel, `Personne n'a enregistré avoir ${pnj} sur son ile pour le moment.`);
}

return this.sendMessage(msg.channel, {
embed: {
timestamp: date,
title: 'Céleste',
description: `*Liste des joueurs ayant ${pnj} sur leur île !*\n\n${display.join('\n')}`,
color: 5301186,
},
} );
}

calculateChunk(i) {
return (i - 1) * 10;
}

chunk(arr, start) {
const end = start + 10;
return arr.slice(start, end);
}
}

export default PNJ;
1 change: 1 addition & 0 deletions src/modules/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ export { default as Core } from './Core/index';
export { default as Private } from './Private/index';
export { default as CodeAmis } from './CodeAmis/index';
export { default as Navet } from './Navet/index';
export { default as PNJ } from './PNJ/index';

0 comments on commit 9927b13

Please sign in to comment.