added help cmd, and helper function to misc
This commit is contained in:
		
							parent
							
								
									a530b4ae8e
								
							
						
					
					
						commit
						102c3f097b
					
				
					 2 changed files with 37 additions and 4 deletions
				
			
		|  | @ -1,15 +1,35 @@ | |||
| // import { Constants } from "oceanic.js";
 | ||||
| // import database from "../../utils/database.js";
 | ||||
| // import * as collections from "../../utils/collections.js";
 | ||||
| // import { random } from "../../utils/misc.js";
 | ||||
| import * as collections from "../../utils/collections.js"; | ||||
| import { htmlescape } from "../../utils/misc.js"; | ||||
| // import paginator from "../../utils/pagination/pagination.js";
 | ||||
| // import * as help from "../../utils/help.js";
 | ||||
| import * as help from "../../utils/help.js"; | ||||
| import Command from "../../classes/command.js"; | ||||
| // const tips = ["You can change the bot's prefix using the prefix command.", "Image commands also work with images previously posted in that channel.", "You can use the tags commands to save things for later use.", "You can visit https://esmbot.net/help.html for a web version of this command list.", "You can view a command's aliases by putting the command name after the help command (e.g. help image).", "Parameters wrapped in [] are required, while parameters wrapped in {} are optional.", "esmBot is hosted and paid for completely out-of-pocket by the main developer. If you want to support development, please consider donating! https://patreon.com/TheEssem"];
 | ||||
| 
 | ||||
| class HelpCommand extends Command { | ||||
|   async run() { | ||||
|     return { html: "<h1>There are no mrmBot Docs Yet</h1>In the meantime, please refer to https://esmbot.net/help.html" }; | ||||
|     let html; | ||||
|     if (this.args.length !== 0) { | ||||
|       if (collections.commands.has(this.args[0].toLowerCase())) { | ||||
|         const command = collections.aliases.get(this.args[0].toLowerCase()) ?? this.args[0].toLowerCase(); | ||||
|         const info = collections.info.get(command); | ||||
|         // TODO: room-specific prefix
 | ||||
|         const prefix = htmlescape(process.env.PREFIX); | ||||
|         html = `<h3><ins>mrmBot Help</ins></h3><h6><code>${prefix}${command}</code></h6>${htmlescape(info.description)}` | ||||
|         return { html: html } | ||||
|       } | ||||
|       if (help.categories[this.args[0].toLowerCase()]) { | ||||
|       } | ||||
|     } | ||||
|     html = `<h2>mrmBot Help</h2><table><tr><th>Command</th><th>Description</th></tr>` | ||||
|     for (const [command] of collections.commands) { | ||||
|       const description = collections.info.get(command).description; | ||||
|       html = html + `<tr><td>${command}</td><td>${description}</td></tr>` | ||||
|     } | ||||
|     html = html + "</table>" | ||||
|     return { html: html } | ||||
|     // return { html: "<h1>There are no mrmBot Docs Yet</h1>In the meantime, please refer to https://esmbot.net/help.html" };
 | ||||
|   } | ||||
|    | ||||
| 
 | ||||
|  |  | |||
|  | @ -20,6 +20,8 @@ const optionalReplace = (token) => { | |||
|   return token === undefined || token === "" ? "" : (token === "true" || token === "false" ? token : "<redacted>"); | ||||
| }; | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| // clean(text) to clean message of any private info or mentions
 | ||||
| export function clean(text) { | ||||
|   if (typeof text !== "string") | ||||
|  | @ -63,6 +65,17 @@ export async function activityChanger(bot) { | |||
|   setTimeout(() => activityChanger(bot), 900000); | ||||
| } | ||||
| 
 | ||||
| export function htmlescape (s) { | ||||
|   let lookup = { | ||||
|       '&': "&", | ||||
|       '"': """, | ||||
|       '\'': "'", | ||||
|       '<': "<", | ||||
|       '>': ">" | ||||
|   }; | ||||
|   return s.replace( /[&"'<>]/g, c => lookup[c] ); | ||||
| } | ||||
| 
 | ||||
| export async function checkBroadcast(bot) { | ||||
|   if (!db) { | ||||
|     return; | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue