say.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. /**
  2. * Processes the "say" command.
  3. * @param {import('../util/i18n.js')} lang - The user language.
  4. * @param {import('discord.js').Message} msg - The Discord message.
  5. * @param {String[]} args - The command arguments.
  6. * @param {String} line - The command as plain text.
  7. * @param {import('../util/wiki.js')} wiki - The wiki for the message.
  8. */
  9. function cmd_say(lang, msg, args, line, wiki) {
  10. var text = args.join(' ');
  11. var imgs = [];
  12. if ( msg.uploadFiles() ) imgs = msg.attachments.map( function(img) {
  13. return {attachment:img.url,name:img.filename};
  14. } );
  15. if ( text.includes( '${' ) ) {
  16. try {
  17. text = eval( '`' + text + '`' );
  18. } catch ( error ) {
  19. log_error(error);
  20. }
  21. }
  22. if ( text.trim() || imgs.length ) {
  23. var allowedMentions = {parse:['users']};
  24. if ( msg.member.hasPermission(['MENTION_EVERYONE']) ) allowedMentions.parse = ['users','roles','everyone'];
  25. else allowedMentions.roles = msg.guild.roles.cache.filter( role => role.mentionable ).map( role => role.id ).slice(0,100)
  26. msg.channel.send( text, {allowedMentions,files:imgs} ).then( () => msg.delete().catch(log_error), error => {
  27. log_error(error);
  28. msg.reactEmoji('error', true);
  29. } );
  30. } else if ( !pause[msg.guild.id] ) this.LINK(lang, msg, line, wiki);
  31. }
  32. module.exports = {
  33. name: 'say',
  34. everyone: false,
  35. pause: false,
  36. owner: true,
  37. run: cmd_say
  38. };