Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

help.js #22

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
98 changes: 98 additions & 0 deletions help.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
module.exports.config = {
name: 'help',
version: '1.0.0',
role: 0,
hasPrefix: true,
aliases: ['info'],
description: "Beginner's guide",
usage: "Help [page] or [command]",
credits: 'Develeoper',
};
module.exports.run = async function({
api,
event,
enableCommands,
args,
Utils,
prefix
}) {
const input = args.join(' ');
try {
const eventCommands = enableCommands[1].handleEvent;
const commands = enableCommands[0].commands;
if (!input) {
const pages = 20;
let page = 1;
let start = (page - 1) * pages;
let end = start + pages;
let helpMessage = `Command List:\n\n`;
for (let i = start; i < Math.min(end, commands.length); i++) {
helpMessage += `\t${i + 1}. 「 ${prefix}${commands[i]} 」\n`;
}
helpMessage += '\nEvent List:\n\n';
eventCommands.forEach((eventCommand, index) => {
helpMessage += `\t${index + 1}. 「 ${prefix}${eventCommand} 」\n`;
});
helpMessage += `\nPage ${page}/${Math.ceil(commands.length / pages)}. To view the next page, type '${prefix}help page number'. To view information about a specific command, type '${prefix}help command name'.`;
api.sendMessage(helpMessage, event.threadID, event.messageID);
} else if (!isNaN(input)) {
const page = parseInt(input);
const pages = 20;
let start = (page - 1) * pages;
let end = start + pages;
let helpMessage = `Command List:\n\n`;
for (let i = start; i < Math.min(end, commands.length); i++) {
helpMessage += `\t${i + 1}. 「 ${prefix}${commands[i]} 」\n`;
}
helpMessage += '\nEvent List:\n\n';
eventCommands.forEach((eventCommand, index) => {
helpMessage += `\t${index + 1}. 「 ${prefix}${eventCommand} 」\n`;
});
helpMessage += `\nPage ${page} of ${Math.ceil(commands.length / pages)}`;
api.sendMessage(helpMessage, event.threadID, event.messageID);
} else {
const command = [...Utils.handleEvent, ...Utils.commands].find(([key]) => key.includes(input?.toLowerCase()))?.[1];
if (command) {
const {
name,
version,
role,
aliases = [],
description,
usage,
credits,
cooldown,
hasPrefix
} = command;
const roleMessage = role !== undefined ? (role === 0 ? '➛ Permission: user' : (role === 1 ? '➛ Permission: admin' : (role === 2 ? '➛ Permission: thread Admin' : (role === 3 ? '➛ Permission: super Admin' : '')))) : '';
const aliasesMessage = aliases.length ? `➛ Aliases: ${aliases.join(', ')}\n` : '';
const descriptionMessage = description ? `Description: ${description}\n` : '';
const usageMessage = usage ? `➛ Usage: ${usage}\n` : '';
const creditsMessage = credits ? `➛ Credits: ${credits}\n` : '';
const versionMessage = version ? `➛ Version: ${version}\n` : '';
const cooldownMessage = cooldown ? `➛ Cooldown: ${cooldown} second(s)\n` : '';
const message = ` 「 Command 」\n\n➛ Name: ${name}\n${versionMessage}${roleMessage}\n${aliasesMessage}${descriptionMessage}${usageMessage}${creditsMessage}${cooldownMessage}`;
api.sendMessage(message, event.threadID, event.messageID);
} else {
api.sendMessage('Command not found.', event.threadID, event.messageID);
}
}
} catch (error) {
console.log(error);
}
};
module.exports.handleEvent = async function({
api,
event,
prefix
}) {
const {
threadID,
messageID,
body
} = event;
const message = prefix ? 'This is my prefix: ' + prefix : "Sorry i don't have prefix";
if (body?.toLowerCase().startsWith('prefix')) {
api.sendMessage(message, threadID, messageID);
}
}