samiroexpikachu

My help js

Feb 6th, 2024 (edited)
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.24 KB | None | 0 0
  1. const fs = require("fs-extra");
  2. const axios = require("axios");
  3. const path = require("path");
  4. const { getPrefix } = global.utils;
  5. const { commands, aliases } = global.GoatBot;
  6. const doNotDelete ="「 𝚖𝚒𝚝𝚍𝚎𝚟𝚜 𝚜𝚞𝚙𝚙𝚘𝚛𝚝𝚎𝚍 𝚋𝚢 𝚜𝚊𝚖𝚒𝚛 」";
  7. /**
  8. * @author NTKhang
  9. * @author: do not delete it
  10. * @message if you delete or edit it you will get a global ban
  11. */
  12.  
  13. module.exports = {
  14. config: {
  15. name: "help",
  16. version: "1.0",
  17. author: "NTKhang",
  18. countDown: 20,
  19. role: 0,
  20. shortDescription: {
  21. vi: "Xem cách dùng lệnh",
  22. en: "View command usage"
  23. },
  24. longDescription: {
  25. vi: "Xem cách sử dụng của các lệnh",
  26. en: "View command usage"
  27. },
  28. category: "info",
  29. guide: {
  30. en: "{pn} [empty | <page number> | <command name>]"
  31. + "\n {pn} <command name> [-u | usage | -g | guide]: only show command usage"
  32. + "\n {pn} <command name> [-i | info]: only show command info"
  33. + "\n {pn} <command name> [-r | role]: only show command role"
  34. + "\n {pn} <command name> [-a | alias]: only show command alias"
  35. },
  36. priority: 1
  37. },
  38.  
  39. langs: {
  40. en: { help:
  41. `
  42. ╭───✰《 𝗔𝗜 》
  43. │❍ai ❍gpt
  44. │❍forever ❍pikachu
  45. │❍isha ❍ai2
  46. |❍imagine ❍x
  47. |❍bard
  48. ╰───────────○
  49. ╭───✰《 𝗔𝗡𝗜𝗠𝗘 》
  50. │✿anime ✿waifu ✿animevideo
  51. │✿aniboy ✿anigirl ✿aniblur
  52. │✿animeinfo ✿animerelease
  53. │✿malnews ✿animequote
  54. │✿animescrape
  55. ╰───────────○
  56. ╭───✰《 𝗚𝗥𝗢𝗨𝗣 》
  57. │◎filteruser ◎all
  58. │◎kick ◎badwords
  59. │◎warn ◎tid
  60. │◎busy ◎count
  61. │◎unsend ◎uid
  62. │◎setrole ◎setname
  63. │◎adduser ◎antiout
  64. │◎onlyadminbox ◎rules
  65. │◎group ◎box
  66. ╰───────────○
  67. ╭───✰《 𝗢𝗪𝗡𝗘𝗥 》
  68. │⚘setrole ⚘admin
  69. │⚘user ⚘approve
  70. │⚘cmd ⚘event
  71. ╰───────────○
  72. ╭───✰《 𝗜𝗠𝗔𝗚𝗘 》
  73. │✧avatar ✧avatar2
  74. │✧avatar3 ✧avatar4
  75. │✧gfx✧gfx2✧gfx3
  76. │✧gfx4✧gfx5✧gfx6
  77. │✧cover✧cover2✧cover3
  78. │✧cover4 ✧blink ✧blink2
  79. │✧clown ✧bed ✧sadcat
  80. │✧fbcover ✧fbcover2
  81. │✧fbcover3 ✧moonwall
  82. │✧mpanel ✧meme
  83. ╰───────────○
  84. ╭───✰《 𝗙𝗨𝗡 》
  85. │✾emojimix ✾gay
  86. │✾say ✾jail ✾slap
  87. │✾buttslap ✾fak
  88. │✾delate ✾install
  89. │✾phub ✾spiderman
  90. │✾pet ✾avoid
  91. │✾hug ✾kiss
  92. │✾pair ✾cdp2
  93. │✾age ✾trash
  94. |✾meme
  95. ╰───────────○
  96. ╭───✰《 𝗕𝗔𝗡𝗞 》
  97. │❖Bank ❖rob
  98. ╰───────────○
  99. ╭───✰《 𝗠𝗘𝗗𝗜𝗔 》
  100. │▷fbvideo ▷insta
  101. │▷sing ▷ytb
  102. │▷video▷music
  103. │▷play▷lyrics
  104. │▷video2 ▷song
  105. │▷spdl ▷vps
  106. ╰───────────○
  107. ╭───✰《 𝗥𝗔𝗡𝗞 》
  108. │✘rank ✘rankup
  109. │✘customrankcard
  110. ╰───────────○
  111. ╭───✰《 𝗦𝗬𝗦𝗧𝗘𝗠 》
  112. │⏣say ⏣translate
  113. │⏣info ⏣weather
  114. │⏣help ⏣ocr
  115. │⏣supportgc ⏣uptime
  116. │⏣ping ⏣pastebin
  117. │⏣rbg ⏣out
  118. │⏣outall ⏣set
  119. │⏣git ⏣tikinfo
  120. │⏣chrome ⏣tiksr
  121. ╰───────────○
  122. ╭───✰《 𝗪𝗜𝗞𝗜 》
  123. │☻emojimean ☻wiki
  124. │☻emojimix ☻exersiseinfo
  125. │☻imbb ☻Pinterest
  126. │☻gg ☻gg3☻img
  127. ╰───────────○
  128. ╭───✰《 𝕥𝕖𝕩𝕥 𝕡𝕣𝕠 》
  129. │:⁠logo :bigtxt
  130. ╰───────────○
  131. ╭───✰《 𝗪𝗥𝗜𝗧𝗘 》
  132. │✎zuck ✎post ✎biden
  133. │✎kabby ✎elon ✎r
  134. │✎post ✎ntkhang
  135. │✎trump ✎smith
  136. │✎blackpanther
  137. ╰───────────○
  138. ╭───✰《 𝗚𝗔𝗠𝗘 》
  139. │๛bal ๛guessnumber
  140. │๛quiz ๛slot
  141. │๛dice ๛flag ๛pokemon
  142. │๛ttt ๛ttt2
  143. │๛pubgguess
  144. ╰───────────○
  145. ╭───✰《 𝗦𝗨𝗣𝗣𝗢𝗥𝗧 》
  146. │ Type %5ishasupport
  147. ╰───────────○
  148. \n ☞ Total cmds: [ %4 ].\n ☞ Type: [%5help <cmd> ]\n ☞ To see how to use it.
  149. `,
  150. help2: "%1\n❆────────────❆\n ⌲ Currently, the bot has %2 commands that can be used\n %4\n❆────────────❆",
  151. commandNotFound: "Command \"%1\" does not exist",
  152. getInfoCommand: "✭ ─── NAME ──── ✭\n » %1\n❆ ─── INFO ─── ❆\n ☞ Author: %8\n ☞ Description: %2\n\✎ ─── Usage ─── ✎\n%9",
  153. onlyInfo: "✰── INFO ────✰\n Command name: %1\n Description: %2\n Other names: %3\n Other names in your group: %4\n Version: %5\n Role: %6\n Time per command: %7s\n Author: %8\n✰─────────────⌲",
  154. onlyUsage: "✰── USAGE ────✰\n %1\n✰─────────────⌲",
  155. onlyAlias: "✰── ALIAS ────✰\n Other names: %1\n Other names in your group: %2\n✰─────────────⌲",
  156. onlyRole: "✰── ROLE ────⌲\n %1\n✰─────────────⌲",
  157. doNotHave: "Do not have",
  158. roleText0: "0 (All users)",
  159. roleText1: "1 (Group administrators)",
  160. roleText2: "2 (Admin bot)",
  161. roleText0setRole: "0 (set role, all users)",
  162. roleText1setRole: "1 (set role, group administrators)",
  163. pageNotFound: "Page %1 does not exist"
  164. }
  165. },
  166.  
  167. onStart: async function ({ message, args, event, threadsData, getLang, role }) {
  168. const langCode = await threadsData.get(event.threadID, "data.lang") || global.GoatBot.config.language;
  169. let customLang = {};
  170. const pathCustomLang = path.join(__dirname, "..", "..", "languages", "cmds", `${langCode}.js`);
  171. if (fs.existsSync(pathCustomLang))
  172. customLang = require(pathCustomLang);
  173. const { threadID } = event;
  174. const threadData = await threadsData.get(threadID);
  175. const prefix = getPrefix(threadID);
  176. let sortHelp = threadData.settings.sortHelp || "name";
  177. if (!["category", "name"].includes(sortHelp))
  178. sortHelp = "name";
  179. const commandName = (args[0] || "").toLowerCase();
  180. const command = commands.get(commandName) || commands.get(aliases.get(commandName));
  181. // ———————————————— LIST ALL COMMAND ——————————————— //
  182. if (!command && !args[0] || !isNaN(args[0])) {
  183. const arrayInfo = [];
  184. let msg = "";
  185. if (sortHelp == "name") {
  186. const page = parseInt(args[0]) || 1;
  187. const numberOfOnePage = 30;
  188. for (const [name, value] of commands) {
  189. if (value.config.role > 1 && role < value.config.role)
  190. continue;
  191. let describe = name;
  192. let shortDescription;
  193. const shortDescriptionCustomLang = customLang[name]?.shortDescription;
  194. if (shortDescriptionCustomLang != undefined)
  195. shortDescription = checkLangObject(shortDescriptionCustomLang, langCode);
  196. else if (value.config.shortDescription)
  197. shortDescription = checkLangObject(value.config.shortDescription, langCode);
  198. if (shortDescription)
  199. describe += `: ${cropContent(shortDescription.charAt(0).toUpperCase() + shortDescription.slice(1))}`;
  200. arrayInfo.push({
  201. data: describe,
  202. priority: value.priority || 0
  203. });
  204. }
  205. arrayInfo.sort((a, b) => a.data - b.data);
  206. arrayInfo.sort((a, b) => a.priority > b.priority ? -1 : 1);
  207. const { allPage, totalPage } = global.utils.splitPage(arrayInfo, numberOfOnePage);
  208. if (page < 1 || page > totalPage)
  209. return message.reply(getLang("pageNotFound", page));
  210. const returnArray = allPage[page - 1] || [];
  211. const startNumber = (page - 1) * numberOfOnePage + 1;
  212. msg += (returnArray || []).reduce((text, item, index) => text += `│ ${index + startNumber}${index + startNumber < 10 ? " " : ""}. ${item.data}\n`, '').slice(0, -1);
  213. await message.reply(getLang("help", msg, page, totalPage, commands.size, prefix, doNotDelete));
  214. }
  215. else if (sortHelp == "category") {
  216. for (const [, value] of commands) {
  217. if (value.config.role > 1 && role < value.config.role)
  218. continue;
  219. if (arrayInfo.some(item => item.category == value.config.category.toLowerCase())) {
  220. const index = arrayInfo.findIndex(item => item.category == value.config.category.toLowerCase());
  221. arrayInfo[index].names.push(value.config.name);
  222. }
  223. else
  224. arrayInfo.push({
  225. category: value.config.category.toLowerCase(),
  226. names: [value.config.name]
  227. });
  228. }
  229. arrayInfo.sort((a, b) => (a.category < b.category ? -1 : 1));
  230. arrayInfo.forEach((data, index) => {
  231. const categoryUpcase = `${index == 0 ? `╭` : `├`}─── ${data.category.toUpperCase()} ${index == 0 ? "⭓" : "⭔"}`;
  232. data.names = data.names.sort().map(item => item = `│ ${item}`);
  233. msg += `${categoryUpcase}\n${data.names.join("\n")}\n`;
  234. });
  235. message.reply(getLang("help2", msg, commands.size, prefix, doNotDelete));
  236. }
  237. }
  238. // ———————————— COMMAND DOES NOT EXIST ———————————— //
  239. else if (!command && args[0]) {
  240. return message.reply(getLang("commandNotFound", args[0]));
  241. }
  242. // ————————————————— INFO COMMAND ————————————————— //
  243. else {
  244. const formSendMessage = {};
  245. const configCommand = command.config;
  246.  
  247. let guide = configCommand.guide?.[langCode] || configCommand.guide?.["en"];
  248. if (guide == undefined)
  249. guide = customLang[configCommand.name]?.guide?.[langCode] || customLang[configCommand.name]?.guide?.["en"];
  250.  
  251. guide = guide || {
  252. body: ""
  253. };
  254. if (typeof guide == "string")
  255. guide = { body: guide };
  256. const guideBody = guide.body
  257. .replace(/\{prefix\}|\{p\}/g, prefix)
  258. .replace(/\{name\}|\{n\}/g, configCommand.name)
  259. .replace(/\{pn\}/g, prefix + configCommand.name);
  260.  
  261. const aliasesString = configCommand.aliases ? configCommand.aliases.join(", ") : getLang("doNotHave");
  262. const aliasesThisGroup = threadData.data.aliases ? (threadData.data.aliases[configCommand.name] || []).join(", ") : getLang("doNotHave");
  263.  
  264. let roleOfCommand = configCommand.role;
  265. let roleIsSet = false;
  266. if (threadData.data.setRole?.[configCommand.name]) {
  267. roleOfCommand = threadData.data.setRole[configCommand.name];
  268. roleIsSet = true;
  269. }
  270.  
  271. const roleText = roleOfCommand == 0 ?
  272. (roleIsSet ? getLang("roleText0setRole") : getLang("roleText0")) :
  273. roleOfCommand == 1 ?
  274. (roleIsSet ? getLang("roleText1setRole") : getLang("roleText1")) :
  275. getLang("roleText2");
  276.  
  277. const author = configCommand.author;
  278. const descriptionCustomLang = customLang[configCommand.name]?.longDescription;
  279. let description = checkLangObject(configCommand.longDescription, langCode);
  280. if (description == undefined)
  281. if (descriptionCustomLang != undefined)
  282. description = checkLangObject(descriptionCustomLang, langCode);
  283. else
  284. description = getLang("doNotHave");
  285.  
  286. let sendWithAttachment = false;
  287.  
  288. if (args[1]?.match(/^-g|guide|-u|usage$/)) {
  289. formSendMessage.body = getLang("onlyUsage", guideBody.split("\n").join("\n│"));
  290. sendWithAttachment = true;
  291. }
  292. else if (args[1]?.match(/^-a|alias|aliase|aliases$/))
  293. formSendMessage.body = getLang("onlyAlias", aliasesString, aliasesThisGroup);
  294. else if (args[1]?.match(/^-r|role$/))
  295. formSendMessage.body = getLang("onlyRole", roleText);
  296. else if (args[1]?.match(/^-i|info$/))
  297. formSendMessage.body = getLang("onlyInfo", configCommand.name, description, aliasesString, aliasesThisGroup, configCommand.version, roleText, configCommand.countDown || 1, author || "");
  298. else {
  299. formSendMessage.body = getLang("getInfoCommand", configCommand.name, description, aliasesString, aliasesThisGroup, configCommand.version, roleText, configCommand.countDown || 1, author || "", `${guideBody.split("\n").join("\n│")}`);
  300. sendWithAttachment = true;
  301. }
  302.  
  303. if (sendWithAttachment && guide.attachment) {
  304. if (typeof guide.attachment == "object") {
  305. formSendMessage.attachment = [];
  306. for (const pathFile in guide.attachment) {
  307. if (!fs.existsSync(pathFile)) {
  308. const cutFullPath = pathFile.split("/").filter(item => item != "");
  309. cutFullPath.pop();
  310. for (let i = 0; i < cutFullPath.length; i++) {
  311. const path = cutFullPath.slice(0, i + 1).join('/');
  312. if (!fs.existsSync(path))
  313. fs.mkdirSync(path);
  314. }
  315. const getFile = await axios.get(guide.attachment[pathFile], { responseType: 'arraybuffer' });
  316. fs.writeFileSync(pathFile, Buffer.from(getFile.data));
  317. }
  318. formSendMessage.attachment.push(fs.createReadStream(pathFile));
  319. }
  320. }
  321. }
  322. return message.reply(formSendMessage);
  323. }
  324. }
  325. };
  326.  
  327. function checkLangObject(data, langCode) {
  328. if (typeof data == "string")
  329. return data;
  330. if (typeof data == "object" && !Array.isArray(data))
  331. return data[langCode] || data.en || undefined;
  332. return undefined;
  333. }
  334.  
  335. function cropContent(content, max) {
  336. if (content.length > max) {
  337. content = content.slice(0, max - 3);
  338. content = content + "...";
  339. }
  340. return content;
  341. }
Add Comment
Please, Sign In to add comment