help.js 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. const {Util} = require('discord.js');
  2. const help_server = require('../functions/helpserver.js');
  3. const {wikis: mcw} = require('./minecraft/commands.json');
  4. const helpmap = {
  5. linkHelp: ['default', 'inline.link', 'inline.template', 'gamepedia', 'fandom', 'wikia'],
  6. link: ['default', 'inline.link', 'inline.template', 'gamepedia', 'fandom', 'wikia', 'mwprojects'],
  7. inline: ['inline.link', 'inline.template'],
  8. user: ['user'],
  9. overview: ['overview'],
  10. random: ['random'],
  11. diff: ['diff.name', 'diff.id'],
  12. page: ['page'],
  13. search: ['search'],
  14. minecraftHelp: ['minecraft.default', 'minecraft.bug'],
  15. command: ['minecraft.default', 'minecraft.command'],
  16. bug: ['minecraft.bug'],
  17. discussion: ['discussion.thread', 'discussion.post'],
  18. //info: ['info'],
  19. help: ['help.default', 'help.command', 'help.admin'],
  20. settings: ['settings.default', 'settings.wiki', 'settings.lang', 'settings.role', 'settings.inline', 'settings.prefix', 'settings.channel'],
  21. verify: ['verify'],
  22. verification: ['verification.default', 'verification.add', 'verification.channel', 'verification.role', 'verification.editcount', 'verification.postcount', 'verification.usergroup', 'verification.accountage', 'verification.rename', 'verification.delete'],
  23. rcscript: ['rcscript.default', 'rcscript.add', 'rcscript.wiki', 'rcscript.lang', 'rcscript.display', 'rcscript.feeds', 'rcscript.delete'],
  24. voice: ['voice'],
  25. pause: ['pause.inactive'],
  26. test: ['test'],
  27. }
  28. const helplist = {
  29. default: [
  30. 'linkHelp',
  31. 'user',
  32. 'overview',
  33. 'random',
  34. 'diff',
  35. 'minecraftHelp',
  36. 'discussion',
  37. //'info',
  38. 'help',
  39. 'test'
  40. ],
  41. admin: [
  42. 'help.admin',
  43. 'settings.default',
  44. 'verification.default',
  45. 'rcscript.default',
  46. 'voice',
  47. 'pause.inactive'
  48. ],
  49. pause: [
  50. 'pause.active',
  51. 'settings.default',
  52. 'verification.default',
  53. 'rcscript.default',
  54. 'voice',
  55. 'test'
  56. ],
  57. minecraft: [
  58. 'minecraft.default',
  59. 'minecraft.bug'
  60. ]
  61. }
  62. const restrictions = {
  63. fandom: ['discussion'],
  64. minecraft: ['minecraftHelp', 'command', 'bug'],
  65. admin: ['settings', 'verification', 'rcscript', 'voice', 'pause'],
  66. inline: ['inline.link', 'inline.template'],
  67. patreon: ['settings.prefix'],
  68. experimental: []
  69. }
  70. /**
  71. * Processes the "help" command.
  72. * @param {import('../util/i18n.js')} lang - The user language.
  73. * @param {import('discord.js').Message} msg - The Discord message.
  74. * @param {String[]} args - The command arguments.
  75. * @param {String} line - The command as plain text.
  76. * @param {import('../util/wiki.js')} wiki - The wiki for the message.
  77. */
  78. function cmd_help(lang, msg, args, line, wiki) {
  79. if ( msg.channel.isGuild() && pause[msg.guildId] && ( args.join('') || !msg.isAdmin() ) ) return;
  80. if ( msg.isAdmin() && msg.defaultSettings ) help_server(lang, msg);
  81. var isMinecraft = mcw.hasOwnProperty(wiki.href);
  82. var maxLength = ( ['hi', 'bn'].includes( lang.lang ) ? 480 : 2000 );
  83. if ( args.join('') ) {
  84. if ( args.join(' ').isMention(msg.guild) ) {
  85. if ( !( msg.isAdmin() && msg.defaultSettings ) ) help_server(lang, msg);
  86. return;
  87. }
  88. var invoke = args[0].toLowerCase();
  89. var cmd = ( lang.aliases[invoke] || invoke );
  90. if ( cmd === 'admin' ) {
  91. if ( !msg.channel.isGuild() || msg.isAdmin() ) {
  92. var cmdlist = lang.get('help.admin') + '\n';
  93. if ( process.env.READONLY ) cmdlist = msg.author.toString() + ', ' + lang.get('general.readonly') + '\n' + process.env.invite + '\n\n' + cmdlist;
  94. cmdlist += formathelp(helplist.admin, msg, lang);
  95. cmdlist += '\n\n🔸 ' + lang.get('help.adminfooter');
  96. if ( process.env.dashboard ) cmdlist += '\n\t\t' + new URL(( msg.channel.isGuild() ? `/guild/${msg.guildId}/settings` : '/' ), process.env.dashboard).href;
  97. Util.splitMessage( cmdlist, {char: '\n🔹', maxLength, prepend: '🔹'} ).forEach( textpart => msg.sendChannel( textpart ) );
  98. }
  99. else {
  100. msg.replyMsg( {content: lang.get('help.noadmin'), allowedMentions: {repliedUser: false}} );
  101. }
  102. }
  103. else if ( cmd === 'minecraft' ) {
  104. var cmdlist = '<' + ( isMinecraft ? wiki : 'https://minecraft.fandom.com/' ) + '>\n';
  105. cmdlist += formathelp(helplist.minecraft, msg, lang);
  106. Util.splitMessage( cmdlist, {char: '\n🔹', maxLength, prepend: '🔹'} ).forEach( textpart => msg.sendChannel( textpart ) );
  107. }
  108. else if ( helpmap.hasOwnProperty(cmd) &&
  109. ( !restrictions.fandom.includes( cmd ) || wiki.isFandom(false) ) &&
  110. ( !restrictions.minecraft.includes( cmd ) || isMinecraft ) &&
  111. ( !restrictions.admin.includes( cmd ) || msg.isAdmin() ) ) {
  112. var cmdlist = formathelp(helpmap[cmd], msg, lang);
  113. if ( !cmdlist.length ) msg.reactEmoji('❓');
  114. else Util.splitMessage( cmdlist, {char: '\n🔹', maxLength, prepend: '🔹'} ).forEach( textpart => msg.sendChannel( textpart ) );
  115. }
  116. else msg.reactEmoji('❓');
  117. }
  118. else if ( msg.isAdmin() && pause[msg.guildId] ) {
  119. var cmdlist = lang.get('help.pause') + '\n';
  120. cmdlist += formathelp(helplist.pause, msg, lang);
  121. Util.splitMessage( cmdlist, {char: '\n🔹', maxLength, prepend: '🔹'} ).forEach( textpart => msg.sendChannel( textpart ) );
  122. }
  123. else {
  124. var cmdlist = lang.get('help.all') + '\n';
  125. helplist.default.forEach( cmd => {
  126. if ( ( !restrictions.fandom.includes( cmd ) || wiki.isFandom(false) ) &&
  127. ( !restrictions.minecraft.includes( cmd ) || isMinecraft ) ) {
  128. cmdlist += formathelp(helpmap[cmd], msg, lang) + '\n';
  129. }
  130. } );
  131. cmdlist += '\n🔸 ' + lang.get('help.footer');
  132. Util.splitMessage( cmdlist, {char: '\n🔹', maxLength, prepend: '🔹'} ).forEach( textpart => msg.sendChannel( textpart ) );
  133. }
  134. }
  135. /**
  136. * Format the help messages.
  137. * @param {String[]} messages - The help messages.
  138. * @param {import('discord.js').Message} msg - The Discord message.
  139. * @param {import('../util/i18n.js')} lang - The user language.
  140. */
  141. function formathelp(messages, msg, lang) {
  142. var prefix = ( msg.channel.isGuild() && patreons[msg.guildId] || process.env.prefix );
  143. var mention = '@' + ( msg.channel.isGuild() ? msg.guild.me.displayName : msg.client.user.username );
  144. return messages.filter( message => {
  145. if ( restrictions.inline.includes( message ) && msg.noInline ) return false;
  146. if ( !restrictions.patreon.includes( message ) ) return true;
  147. return ( msg.channel.isGuild() && patreons[msg.guildId] );
  148. } ).map( message => {
  149. var cmd = message.split('.')[0];
  150. var intro = ( restrictions.inline.includes( message ) ? '' : prefix );
  151. return '🔹 `' + intro + lang.get('help.list.' + message + '.cmd', mention).replace( new RegExp( '^' + cmd ), ( lang.localNames[cmd] || cmd ) ) + '`\n\t' + ( restrictions.experimental.includes( message ) ? lang.get('general.experimental') + '\n\t' : '' ) + lang.get('help.list.' + message + '.desc', prefix)
  152. } ).join('\n');
  153. }
  154. module.exports = {
  155. name: 'help',
  156. everyone: true,
  157. pause: true,
  158. owner: false,
  159. run: cmd_help
  160. };