pockybot
Version:
Spark bot that handles team recognition
285 lines (283 loc) • 16 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const trigger_1 = require("../../models/trigger");
const constants_1 = require("../../constants");
const database_1 = require("../../models/database");
const config_action_1 = require("../../models/config-action");
const command_1 = require("../../models/command");
const xmlMessageParser_1 = require("../parsers/xmlMessageParser");
const location_action_1 = require("../../models/location-action");
class Help extends trigger_1.default {
constructor(config) {
super();
this.helpCommand = `(?: )*${command_1.Command.Help}(?: )*`;
this.config = config;
}
isToTriggerOn(message) {
let parsedMessage = xmlMessageParser_1.default.parseNonPegMessage(message);
return parsedMessage.botId === constants_1.default.botId && parsedMessage.command.toLowerCase().startsWith(command_1.Command.Help);
}
isToTriggerOnPM(message) {
return message.text.toLowerCase().trim().startsWith(command_1.Command.Help);
}
async createMessage(message) {
const pattern = new RegExp('^@?' + constants_1.default.botName, 'ui');
const helpPattern = new RegExp('^' + this.helpCommand, 'ui');
const command = message.text.trim().replace(pattern, '').trim().replace(helpPattern, '').trim();
const newMessage = this.createHelpResponseMessage(message, command);
return {
markdown: newMessage
};
}
createHelpResponseMessage(message, command) {
if (!command) {
return this.createCommandListMessage(message);
}
switch (command.toLowerCase()) {
case command_1.Command.Peg:
return this.createPegHelpMessage();
case command_1.Command.Status:
return this.createStatusHelpMessage();
case command_1.Command.Keywords:
return this.createKeywordsHelpMessage();
case command_1.Command.Ping:
return this.createPingHelpMessage();
case command_1.Command.Welcome:
return this.createWelcomeHelpMessage();
case command_1.Command.Rotation:
return this.createRotationHelpMessage();
case command_1.Command.Winners:
return this.createWinnersHelpMessage(message);
case command_1.Command.Results:
return this.createResultsHelpMessage(message);
case command_1.Command.Reset:
return this.createResetHelpMessage(message);
case command_1.Command.Update:
return this.createUpdateHelpMessage(message);
case command_1.Command.Finish:
return this.createFinishHelpMessage(message);
case command_1.Command.NumberConfig:
return this.createNumberConfigHelpMessage(message);
case command_1.Command.StringConfig:
return this.createStringConfigHelpMessage(message);
case command_1.Command.RoleConfig:
return this.createRoleConfigHelpMessage(message);
case command_1.Command.LocationConfig:
return this.createLocationConfigHelpMessage(message);
case command_1.Command.UserLocation:
return this.createUserLocationHelpMessage(message);
case command_1.Command.RemoveUser:
return this.createRemoveUserHelpMessage(message);
case command_1.Command.LocationWeight:
return this.createLocationWeightHelpMessage(message);
default:
return this.createDefaultHelpMessage();
}
}
createCommandListMessage(message) {
let newMessage = `## What I can do (List of Commands)
* ${command_1.Command.Peg}
* ${command_1.Command.Status}
* ${command_1.Command.Keywords}
* ${command_1.Command.Ping}
* ${command_1.Command.Welcome}
* ${command_1.Command.Rotation}
* ${command_1.Command.LocationConfig}
* ${command_1.Command.UserLocation}\n`;
if (this.config.checkRole(message.personId, database_1.Role.Admin) || this.config.checkRole(message.personId, database_1.Role.Winners)) {
newMessage += `* ${command_1.Command.Winners}\n`;
}
if (this.config.checkRole(message.personId, database_1.Role.Admin) || this.config.checkRole(message.personId, database_1.Role.Results)) {
newMessage += `* ${command_1.Command.Results}\n`;
}
if (this.config.checkRole(message.personId, database_1.Role.Admin) || this.config.checkRole(message.personId, database_1.Role.Reset)) {
newMessage += `* ${command_1.Command.Reset}\n`;
}
if (this.config.checkRole(message.personId, database_1.Role.Admin) || this.config.checkRole(message.personId, database_1.Role.Update)) {
newMessage += `* ${command_1.Command.Update}\n`;
}
if (this.config.checkRole(message.personId, database_1.Role.Admin) || this.config.checkRole(message.personId, database_1.Role.Finish)) {
newMessage += `* ${command_1.Command.Finish}\n`;
}
if (this.config.checkRole(message.personId, database_1.Role.Admin) || this.config.checkRole(message.personId, database_1.Role.Config)) {
newMessage += `* ${command_1.Command.NumberConfig}
* ${command_1.Command.StringConfig}
* ${command_1.Command.RoleConfig}
* ${command_1.Command.LocationWeight}\n`;
}
if (this.config.checkRole(message.personId, database_1.Role.Admin) || this.config.checkRole(message.personId, database_1.Role.RemoveUser)) {
newMessage += `* ${command_1.Command.RemoveUser}\n`;
}
newMessage += `\nFor more information on a command type \`@${constants_1.default.botName} help command-name\` or direct message me with \`help command-name\`\n`;
newMessage += `\nI am still being worked on, so [more features to come : )] (${constants_1.default.todoUrl})`;
return newMessage;
}
createDefaultHelpMessage() {
return `Command not found. To see a full list of commands type \`@${constants_1.default.botName} help\` or direct message me with \`help\`.`;
}
createPegHelpMessage() {
let keywordsRequired = this.config.getConfig('requireValues');
let newMessage = `### How to give a peg 🎁!
1. To give someone a peg type: \`@${constants_1.default.botName} ${command_1.Command.Peg} @bob {comment}\`.\n`;
if (keywordsRequired) {
newMessage += '1. Note that your comment MUST include a keyword.';
}
return newMessage;
}
createStatusHelpMessage() {
return `### How to check your status 📈!
1. To get a PM type: \`@${constants_1.default.botName} ${command_1.Command.Status}\` OR direct message me with \`${command_1.Command.Status}\`.
1. I will PM you number of pegs you have left and who you gave it to.`;
}
createKeywordsHelpMessage() {
return `### How to check the available keywords 🔑!
1. To get a list of the available keywords, type: \`@${constants_1.default.botName} ${command_1.Command.Keywords}\` OR direct message me with \`${command_1.Command.Keywords}\`.
1. I will respond in the room you messaged me in with a list of keywords.`;
}
createPingHelpMessage() {
return `### How to ping me 🏓!
1. To check whether I'm alive, type: \`@${constants_1.default.botName} ${command_1.Command.Ping}\` OR direct message me with \`${command_1.Command.Ping}\`.
1. I will respond in the room you messaged me in if I am alive.`;
}
createWelcomeHelpMessage() {
return `### How to welcome someone 👐!
1. To get a welcome message from me, type \`@${constants_1.default.botName} ${command_1.Command.Welcome}\` OR direct message me with \`${command_1.Command.Welcome}\`.
1. I will respond in the room you messaged me in.`;
}
createRotationHelpMessage() {
return `### How to check the rotation!
1. To check the rotation of teams responsible for buying snacks, type \`@${constants_1.default.botName} ${command_1.Command.Rotation}\` OR direct message me with \`${command_1.Command.Rotation}\`.
1. I will respond in the room you messaged me in.\n`;
}
createWinnersHelpMessage(message) {
if (this.config.checkRole(message.personId, database_1.Role.Admin) || this.config.checkRole(message.personId, database_1.Role.Winners)) {
return `### How to display the winners 🏆!
1. To display winners, type \`@${constants_1.default.botName} ${command_1.Command.Winners}\`.
1. I will respond in the room you messaged me in.`;
}
else {
return this.createDefaultHelpMessage();
}
}
createResultsHelpMessage(message) {
if (this.config.checkRole(message.personId, database_1.Role.Admin) || this.config.checkRole(message.personId, database_1.Role.Results)) {
return `### How to display the results 📃!
1. To display results, type \`@${constants_1.default.botName} ${command_1.Command.Results}\`.
1. I will respond in the room you messaged me in.`;
}
else {
return this.createDefaultHelpMessage();
}
}
createResetHelpMessage(message) {
if (this.config.checkRole(message.personId, database_1.Role.Admin) || this.config.checkRole(message.personId, database_1.Role.Reset)) {
return `### How to reset all pegs 🙅!
1. To clear all pegs, type \`@${constants_1.default.botName} ${command_1.Command.Reset}\`.
1. I will respond in the room you messaged me in.`;
}
else {
return this.createDefaultHelpMessage();
}
}
createUpdateHelpMessage(message) {
if (this.config.checkRole(message.personId, database_1.Role.Admin) || this.config.checkRole(message.personId, database_1.Role.Update)) {
return `### How to update names 📛!
1. To update user names with users' current display names, type \`@${constants_1.default.botName} ${command_1.Command.Update}\`.
1. I will respond in the room you messaged me in.`;
}
else {
return this.createDefaultHelpMessage();
}
}
createFinishHelpMessage(message) {
if (this.config.checkRole(message.personId, database_1.Role.Admin) || this.config.checkRole(message.personId, database_1.Role.Finish)) {
return `### How to complete the cycle 🚲!
1. To display winners and results and clear the database, type \`@${constants_1.default.botName} ${command_1.Command.Finish}\`.
1. I will respond in the room you messaged me in.`;
}
else {
return this.createDefaultHelpMessage();
}
}
createNumberConfigHelpMessage(message) {
if (this.config.checkRole(message.personId, database_1.Role.Admin) || this.config.checkRole(message.personId, database_1.Role.Config)) {
return `### How to configure number config values 🔢!
1. To get/edit/refresh/delete number config values, type \`@${constants_1.default.botName} ${command_1.Command.NumberConfig} ${Object.values(config_action_1.ConfigAction).join('|')} {name} {number}\`
1. I will respond in the room you messaged me in.`;
}
else {
return this.createDefaultHelpMessage();
}
}
createStringConfigHelpMessage(message) {
if (this.config.checkRole(message.personId, database_1.Role.Admin) || this.config.checkRole(message.personId, database_1.Role.Config)) {
return `### How to configure string config values 🎻!
1. To get/edit/refresh/delete string config values, type \`@${constants_1.default.botName} ${command_1.Command.StringConfig} ${Object.values(config_action_1.ConfigAction).join('|')} {name} {value}\`
1. I will respond in the room you messaged me in.`;
}
else {
return this.createDefaultHelpMessage();
}
}
createRoleConfigHelpMessage(message) {
if (this.config.checkRole(message.personId, database_1.Role.Admin) || this.config.checkRole(message.personId, database_1.Role.Config)) {
return `### How to configure role config values 🗞️!
1. To get/edit/refresh/delete user roles, type \`@${constants_1.default.botName} ${command_1.Command.RoleConfig} ${Object.values(config_action_1.ConfigAction).join('|')} {@User} {role}\`
1. I will respond in the room you messaged me in.`;
}
else {
return this.createDefaultHelpMessage();
}
}
createLocationConfigHelpMessage(message) {
if (this.config.checkRole(message.personId, database_1.Role.Admin) || this.config.checkRole(message.personId, database_1.Role.Config)) {
return `### How to configure location config values!
1. To get/edit/delete locations, type \`@${constants_1.default.botName} ${command_1.Command.LocationConfig} ${Object.values(location_action_1.LocationAction).join('|')} {location}\`
1. I will respond in the room you messaged me in.`;
}
else {
return `### How to get location values!
1. To get a list of locations, type \`@${constants_1.default.botName} ${command_1.Command.LocationConfig} ${location_action_1.LocationAction.Get}\`
* To configure locations, please ask an admin.
1. I will respond in the room you messaged me in.`;
}
}
createUserLocationHelpMessage(message) {
if (this.config.checkRole(message.personId, database_1.Role.Admin) || this.config.checkRole(message.personId, database_1.Role.UserLocation)) {
return `### How to configure user location values!
1. To get user locations for yourself or others, type \`@${constants_1.default.botName} ${command_1.Command.UserLocation} ${location_action_1.LocationAction.Get} me|all|unset|@User\`
1. To set user locations, type \`@${constants_1.default.botName} ${command_1.Command.UserLocation} ${location_action_1.LocationAction.Set} {location} me|@User1 @User2\`
1. To delete user locations, type \`@${constants_1.default.botName} ${command_1.Command.UserLocation} ${location_action_1.LocationAction.Delete} me|@User1 @User2\`
1. I will respond in the room you messaged me in.`;
}
else {
return `### How to config your user location value!
1. To get user locations for yourself or others, type \`@${constants_1.default.botName} ${command_1.Command.UserLocation} ${location_action_1.LocationAction.Get} me|all|unset|@User\`
1. To set your user location, type \`@${constants_1.default.botName} ${command_1.Command.UserLocation} ${location_action_1.LocationAction.Set} {location} me\`
* To bulk configure user locations, please ask an admin.
1. To delete your user location, type \`@${constants_1.default.botName} ${command_1.Command.UserLocation} ${location_action_1.LocationAction.Delete} me\`
1. I will respond in the room you messaged me in.`;
}
}
createRemoveUserHelpMessage(message) {
if (this.config.checkRole(message.personId, database_1.Role.Admin) || this.config.checkRole(message.personId, database_1.Role.RemoveUser)) {
return `### How to remove users!
1. To remove a user, type \`@${constants_1.default.botName} ${command_1.Command.RemoveUser} {@User}|'{username}'\`
1. I will respond in the room you messaged me in.`;
}
else {
return this.createDefaultHelpMessage();
}
}
createLocationWeightHelpMessage(message) {
if (this.config.checkRole(message.personId, database_1.Role.Admin) || this.config.checkRole(message.personId, database_1.Role.Config)) {
return `### How to configure location weight values!
1. To get/edit/delete location weight values, type \`@${constants_1.default.botName} ${command_1.Command.LocationWeight} ${Object.values(location_action_1.LocationAction).join('|')} {location1} {location2} {weight}\`
1. I will respond in the room you messaged me in.`;
}
else {
return this.createDefaultHelpMessage();
}
}
}
exports.default = Help;