link.js 1.4 KB

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