commit
e52197ce17
@ -0,0 +1,45 @@
|
|||||||
|
/* template index.js. Doesn't implement actual commands */
|
||||||
|
const cmdLib = require('../../CommandLib'); // required for command objects
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A description what the command module includes and why. Doesn't need to list commands but explains
|
||||||
|
* category of the defined commands aswell as the scope.
|
||||||
|
*/
|
||||||
|
|
||||||
|
class TemplateCommandModule extends cmdLib.CommandModule {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param opts {Object} properties: --- define the properties the opts object needs aswell as the type
|
||||||
|
* bot - the instance of the bot
|
||||||
|
*/
|
||||||
|
constructor(opts) {
|
||||||
|
super(cmdLib.CommandScopes.Global); // call constructor of superclass with the scope of the module
|
||||||
|
this._templateDir = __dirname; // define the current directory as directory for the template.yaml file
|
||||||
|
|
||||||
|
this._bot = opts.bot; // define opts attributes as private properties of the module class
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Defines and registers commands to the commandHandler.
|
||||||
|
* @param commandHandler {CommandHandler}
|
||||||
|
*/
|
||||||
|
async register(commandHandler) {
|
||||||
|
await this._loadTemplate(); // loads the template file to the property this.template.
|
||||||
|
|
||||||
|
let templateCommand = new cmdLib.Command( // create a new instance of Command
|
||||||
|
this.template.template_command, // pass the template to the constructor
|
||||||
|
new cmdLib.Answer(() => { // pass a new instance of Answer to the constructor
|
||||||
|
/* Command Logic */
|
||||||
|
return this.template.response.not_implemented; // this command just returns the answer not_implemented
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
|
// register the commands on the commandHandler
|
||||||
|
commandHandler.registerCommand(templateCommand); // register the command to the handler
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// set the export properties
|
||||||
|
Object.assign(exports, {
|
||||||
|
module: TemplateCommandModule // Export the commandModule as module property. This is the default.
|
||||||
|
});
|
@ -0,0 +1,16 @@
|
|||||||
|
# see yaml references (learnxinyminutes.com/docs/yaml/)
|
||||||
|
|
||||||
|
METADATA: &METADATA
|
||||||
|
category: template # [optional if defined in commands]
|
||||||
|
permission: all # [optional if defined in commands]
|
||||||
|
|
||||||
|
template_command:
|
||||||
|
<<: *METADATA # include the predefined metadata for the command
|
||||||
|
name: templateCommand # [required] the name of the command for execution
|
||||||
|
usage: _templateCommand [templateArg] # [optional] overides the default help that generates from name and args
|
||||||
|
permission: owner # [optional if in METADATA] overiedes the metadata value for permission
|
||||||
|
description: > # [required] the description entry for the command help.
|
||||||
|
A template for a command
|
||||||
|
response: # [optional] predefine responses that can be used in the command logic
|
||||||
|
not_implemented: >
|
||||||
|
This command is not implemented.
|
@ -1,58 +1,57 @@
|
|||||||
|
METADATA: &METADATA
|
||||||
|
category: AniList
|
||||||
|
permission: all
|
||||||
|
|
||||||
anime_search:
|
anime_search:
|
||||||
|
<<: *METADATA
|
||||||
name: alAnime
|
name: alAnime
|
||||||
permission: all
|
|
||||||
usage: alAnime [search query]
|
usage: alAnime [search query]
|
||||||
description: >
|
description: >
|
||||||
Searches [AniList.co](https://anilist.co) for the anime *title* or *id* and returns information about
|
Searches [AniList.co](https://anilist.co) for the anime *title* or *id* and returns information about
|
||||||
it if there is a result. The staff members are not included because the message would grow too big.
|
it if there is a result. The staff members are not included because the message would grow too big.
|
||||||
category: AniList
|
|
||||||
response:
|
response:
|
||||||
not_found: >
|
not_found: >
|
||||||
I couldn't find the anime you were searching for :(
|
I couldn't find the anime you were searching for :(
|
||||||
|
|
||||||
anime_staff_search:
|
anime_staff_search:
|
||||||
|
<<: *METADATA
|
||||||
name: alAnimeStaff
|
name: alAnimeStaff
|
||||||
permission: all
|
|
||||||
usage: alAnimeStaff [search query]
|
usage: alAnimeStaff [search query]
|
||||||
description: >
|
description: >
|
||||||
Searches [AniList.co](https://anilist.co) for the anime *title* or *id* and returns all staff members.
|
Searches [AniList.co](https://anilist.co) for the anime *title* or *id* and returns all staff members.
|
||||||
category: AniList
|
|
||||||
response:
|
response:
|
||||||
not_found: >
|
not_found: >
|
||||||
I couldn't find the anime you were searching for :(
|
I couldn't find the anime you were searching for :(
|
||||||
|
|
||||||
manga_search:
|
manga_search:
|
||||||
|
<<: *METADATA
|
||||||
name: alManga
|
name: alManga
|
||||||
permission: all
|
|
||||||
usage: alManga [search query]
|
usage: alManga [search query]
|
||||||
description: >
|
description: >
|
||||||
Searches [AniList.co](https://anilist.co) for the manga *title* or *id* and returns information about
|
Searches [AniList.co](https://anilist.co) for the manga *title* or *id* and returns information about
|
||||||
it if there is a result.
|
it if there is a result.
|
||||||
category: AniList
|
|
||||||
response:
|
response:
|
||||||
not_found: >
|
not_found: >
|
||||||
I couldn't find the manga you were searching for :(
|
I couldn't find the manga you were searching for :(
|
||||||
|
|
||||||
staff_search:
|
staff_search:
|
||||||
|
<<: *METADATA
|
||||||
name: alStaff
|
name: alStaff
|
||||||
permission: all
|
|
||||||
usage: alStaff [search query]
|
usage: alStaff [search query]
|
||||||
description: >
|
description: >
|
||||||
Searches [AniList.co](https://anilist.co) for the staff member *name* or *id* and returns information about
|
Searches [AniList.co](https://anilist.co) for the staff member *name* or *id* and returns information about
|
||||||
the member aswell as roles in media.
|
the member aswell as roles in media.
|
||||||
category: AniList
|
|
||||||
response:
|
response:
|
||||||
not_found: >
|
not_found: >
|
||||||
I couldn't find the staff member you were searching for :(
|
I couldn't find the staff member you were searching for :(
|
||||||
|
|
||||||
character_search:
|
character_search:
|
||||||
|
<<: *METADATA
|
||||||
name: alCharacter
|
name: alCharacter
|
||||||
permission: all
|
|
||||||
usage: alCharacter [search query]
|
usage: alCharacter [search query]
|
||||||
description: >
|
description: >
|
||||||
Searches [AniList.co](https://anilist.co) for the character *name* or *id* and returns information about
|
Searches [AniList.co](https://anilist.co) for the character *name* or *id* and returns information about
|
||||||
the character aswell as media roles.
|
the character aswell as media roles.
|
||||||
category: AniList
|
|
||||||
response:
|
response:
|
||||||
not_found: >
|
not_found: >
|
||||||
I couldn't find the character member you were searching for :(
|
I couldn't find the character member you were searching for :(
|
@ -0,0 +1,82 @@
|
|||||||
|
/* template index.js. Doesn't implement actual commands */
|
||||||
|
const cmdLib = require('../../CommandLib');
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Several commands that are that special that they can't be included in any other module.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Async delay
|
||||||
|
* @param seconds {Number}
|
||||||
|
*/
|
||||||
|
function delay(seconds) {
|
||||||
|
return new Promise((resolve) => {
|
||||||
|
setTimeout(resolve, seconds * 1000);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
class TemplateCommandModule extends cmdLib.CommandModule {
|
||||||
|
|
||||||
|
constructor() {
|
||||||
|
super(cmdLib.CommandScopes.Global);
|
||||||
|
this._templateDir = __dirname;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Defines and registers commands to the commandHandler.
|
||||||
|
* @param commandHandler {CommandHandler}
|
||||||
|
*/
|
||||||
|
async register(commandHandler) {
|
||||||
|
await this._loadTemplate();
|
||||||
|
|
||||||
|
let sayCommand = new cmdLib.Command(
|
||||||
|
this.template.say,
|
||||||
|
new cmdLib.Answer((m, k, s) => {
|
||||||
|
return s.replace(/^"|"$/g, '');
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
|
let delayCommand = new cmdLib.Command(
|
||||||
|
this.template.delay,
|
||||||
|
new cmdLib.Answer(async (m, k) => {
|
||||||
|
this._logger.silly(`Delaying for ${k.seconds} seconds`);
|
||||||
|
await delay(k.seconds);
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
|
let chooseCommand = new cmdLib.Command(
|
||||||
|
this.template.choose,
|
||||||
|
new cmdLib.Answer(async (m, k, s) => {
|
||||||
|
let options = s.split(',').map(x => {
|
||||||
|
if (x) {
|
||||||
|
let strippedValue = x.replace(/^\s+|\s+$/, '');
|
||||||
|
if (strippedValue.length === 0)
|
||||||
|
return null;
|
||||||
|
else
|
||||||
|
return strippedValue;
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}).filter(x => x);
|
||||||
|
if (options.length === 0) {
|
||||||
|
return this.template.choose.response.no_options;
|
||||||
|
} else {
|
||||||
|
this._logger.silly(`Choosing from ${options.join(', ')}`);
|
||||||
|
let item = options[Math.floor(Math.random() * options.length)];
|
||||||
|
return `I've chosen ${item.replace(/^"|"$|^\s+|\s+$/g, '')}`;
|
||||||
|
}
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
|
/* Register commands to handler */
|
||||||
|
commandHandler
|
||||||
|
.registerCommand(sayCommand)
|
||||||
|
.registerCommand(delayCommand)
|
||||||
|
.registerCommand(chooseCommand);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Object.assign(exports, {
|
||||||
|
module: TemplateCommandModule
|
||||||
|
});
|
@ -0,0 +1,29 @@
|
|||||||
|
METADATA: &METADATA
|
||||||
|
category: Misc
|
||||||
|
permission: all
|
||||||
|
|
||||||
|
say:
|
||||||
|
<<: *METADATA
|
||||||
|
name: say
|
||||||
|
usage: say [...message]
|
||||||
|
description: >
|
||||||
|
The bot says what you defined in the message argument
|
||||||
|
|
||||||
|
delay:
|
||||||
|
<<: *METADATA
|
||||||
|
name: delay
|
||||||
|
usage: delay
|
||||||
|
args:
|
||||||
|
- seconds
|
||||||
|
description: >
|
||||||
|
Set a delay in seconds. Useful for command sequences.
|
||||||
|
|
||||||
|
choose:
|
||||||
|
<<: *METADATA
|
||||||
|
name: choose
|
||||||
|
usage: choose [opt-1], [opt-2], ..., [opt-n]
|
||||||
|
description: >
|
||||||
|
Chooses randomly from one of the options
|
||||||
|
response:
|
||||||
|
no_options: >
|
||||||
|
You need to define options for me to choose from.
|
@ -1,42 +1,42 @@
|
|||||||
|
METADATA: &METADATA
|
||||||
|
category: Utility
|
||||||
|
permission: owner
|
||||||
|
|
||||||
shutdown:
|
shutdown:
|
||||||
|
<<: *METADATA
|
||||||
name: shutdown
|
name: shutdown
|
||||||
description: >
|
description: >
|
||||||
Shuts down the bot.
|
Shuts down the bot.
|
||||||
permission: owner
|
|
||||||
category: Utility
|
|
||||||
|
|
||||||
add_presence:
|
add_presence:
|
||||||
|
<<: *METADATA
|
||||||
name: addpresence
|
name: addpresence
|
||||||
description: >
|
description: >
|
||||||
Adds a Rich Presence to the bot.
|
Adds a Rich Presence to the bot.
|
||||||
permission: owner
|
|
||||||
category: Utility
|
|
||||||
usage: addpresence [presence]
|
usage: addpresence [presence]
|
||||||
|
|
||||||
rotate_presence:
|
rotate_presence:
|
||||||
|
<<: *METADATA
|
||||||
name: rotatepresence
|
name: rotatepresence
|
||||||
description: >
|
description: >
|
||||||
Forces a presence rotation
|
Forces a presence rotation
|
||||||
permission: owner
|
|
||||||
category: Utility
|
|
||||||
|
|
||||||
create_user:
|
create_user:
|
||||||
|
<<: *METADATA
|
||||||
name: createuser
|
name: createuser
|
||||||
description: >
|
description: >
|
||||||
Creates a user for the webinterface.
|
Creates a user for the webinterface.
|
||||||
permission: owner
|
|
||||||
category: Utility
|
|
||||||
args:
|
args:
|
||||||
- username
|
- username
|
||||||
- password
|
- password
|
||||||
- scope
|
- scope
|
||||||
|
|
||||||
bugreport:
|
bugreport:
|
||||||
|
<<: *METADATA
|
||||||
name: bug
|
name: bug
|
||||||
|
permission: all
|
||||||
description: >
|
description: >
|
||||||
Get information about where to report bugs.
|
Get information about where to report bugs.
|
||||||
permission: all
|
|
||||||
category: Utility
|
|
||||||
response:
|
response:
|
||||||
title: >
|
title: >
|
||||||
You want to report a bug?
|
You want to report a bug?
|
Loading…
Reference in New Issue