link.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. const check_wiki = {
  2. general: require('./wiki/general.js'),
  3. test: require('./test.js').run
  4. };
  5. const help_setup = require('../functions/helpsetup.js');
  6. const phabricator = require('../functions/phabricator.js');
  7. /**
  8. * Processes the wiki linking command.
  9. * @param {import('../util/i18n.js')} lang - The user language.
  10. * @param {import('discord.js').Message} msg - The Discord message.
  11. * @param {String} title - The page title.
  12. * @param {import('../util/wiki.js')} wiki - The wiki for the page.
  13. * @param {String} [cmd] - The command at this point.
  14. */
  15. function cmd_link(lang, msg, title, wiki, cmd = '') {
  16. if ( msg.isAdmin() && msg.defaultSettings ) help_setup(lang, msg);
  17. if ( /^\|\|(?:(?!\|\|).)+\|\|$/.test(title) ) {
  18. title = title.substring( 2, title.length - 2);
  19. var spoiler = '||';
  20. }
  21. if ( /^<[^<>]+>$/.test(title) ) {
  22. title = title.substring( 1, title.length - 1);
  23. var noEmbed = true;
  24. }
  25. msg.reactEmoji('⏳').then( reaction => {
  26. if ( /^phabricator\.(wikimedia|miraheze)\.org$/.test(wiki.hostname) ) {
  27. return phabricator(lang, msg, wiki, new URL('/' + title, wiki), reaction, spoiler, noEmbed);
  28. }
  29. else check_wiki.general(lang, msg, title, wiki, cmd, reaction, spoiler, noEmbed);
  30. } );
  31. }
  32. module.exports = {
  33. name: 'LINK',
  34. everyone: true,
  35. pause: false,
  36. owner: true,
  37. run: cmd_link
  38. };