verify.js 3.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. var db = require('../util/database.js');
  2. var verify = require('../functions/verify.js');
  3. /**
  4. * Processes the "verify" command.
  5. * @param {import('../util/i18n.js')} lang - The user language.
  6. * @param {import('discord.js').Message} msg - The Discord message.
  7. * @param {String[]} args - The command arguments.
  8. * @param {String} line - The command as plain text.
  9. * @param {import('../util/wiki.js')} wiki - The wiki for the message.
  10. */
  11. function cmd_verify(lang, msg, args, line, wiki) {
  12. if ( !msg.channel.isGuild() || msg.defaultSettings ) return this.LINK(lang, msg, line, wiki);
  13. if ( !msg.guild.me.permissions.has('MANAGE_ROLES') ) {
  14. if ( msg.isAdmin() ) {
  15. console.log( msg.guild.id + ': Missing permissions - MANAGE_ROLES' );
  16. msg.replyMsg( lang.get('general.missingperm') + ' `MANAGE_ROLES`' );
  17. }
  18. else if ( !msg.onlyVerifyCommand ) this.LINK(lang, msg, line, wiki);
  19. return;
  20. }
  21. db.query( 'SELECT role, editcount, postcount, usergroup, accountage, rename FROM verification WHERE guild = $1 AND channel LIKE $2 ORDER BY configid ASC', [msg.guild.id, '%|' + msg.channel.id + '|%'] ).then( ({rows}) => {
  22. if ( !rows.length ) {
  23. if ( msg.onlyVerifyCommand ) return;
  24. return msg.replyMsg( lang.get('verify.missing') + ( msg.isAdmin() ? '\n`' + ( patreons[msg.guild.id] || process.env.prefix ) + 'verification`' : '' ) );
  25. }
  26. var username = args.join(' ').replace( /_/g, ' ' ).trim().replace( /^<\s*(.*)\s*>$/, '$1' ).replace( /^@/, '' ).split('#')[0].substring(0, 250).trim();
  27. if ( /^(?:https?:)?\/\/([a-z\d-]{1,50})\.(?:gamepedia\.com\/|(?:fandom\.com|wikia\.org)\/(?:[a-z-]{1,8}\/)?(?:wiki\/)?)/.test(username) ) {
  28. username = decodeURIComponent( username.replace( /^(?:https?:)?\/\/([a-z\d-]{1,50})\.(?:gamepedia\.com\/|(?:fandom\.com|wikia\.org)\/(?:[a-z-]{1,8}\/)?(?:wiki\/)?)/, '' ) );
  29. }
  30. if ( wiki.isGamepedia() ) username = username.replace( /^userprofile\s*:\s*/i, '' );
  31. if ( !username.trim() ) {
  32. args[0] = line.split(' ')[0];
  33. if ( args[0] === 'verification' ) args[0] = ( lang.localNames.verify || 'verify' );
  34. return this.help(lang, msg, args, line, wiki);
  35. }
  36. msg.reactEmoji('⏳').then( reaction => {
  37. verify(lang, msg.channel, msg.member, username, wiki, rows).then( result => {
  38. if ( result.reaction ) msg.reactEmoji(result.reaction);
  39. else {
  40. var options = {embed: result.embed, components: []};
  41. if ( result.add_button ) options.components.push({
  42. type: 1,
  43. components: [
  44. {
  45. type: 2,
  46. style: 1,
  47. label: lang.get('verify.button_again'),
  48. emoji: {id: null, name: '🔂'},
  49. custom_id: 'verify_again',
  50. disabled: false
  51. }
  52. ]
  53. });
  54. msg.replyMsg( result.content, options, false, false ).then( message => {
  55. if ( !result.logging.channel || !msg.guild.channels.cache.has(result.logging.channel) ) return;
  56. if ( message ) {
  57. if ( result.logging.embed ) result.logging.embed.addField(message.url, '<#' + msg.channel.id + '>');
  58. else result.logging.content += '\n<#' + msg.channel.id + '> – <' + message.url + '>';
  59. }
  60. msg.guild.channels.cache.get(result.logging.channel).send(result.logging.content, {
  61. embed: result.logging.embed,
  62. allowedMentions: {parse: []}
  63. }).catch(log_error);
  64. } );
  65. }
  66. if ( reaction ) reaction.removeEmoji();
  67. }, error => {
  68. console.log( '- Error during the verifications: ' + error );
  69. msg.replyMsg( lang.get('verify.error_reply'), {}, false, false ).then( message => {
  70. if ( message ) message.reactEmoji('error');
  71. } );
  72. } );
  73. } );
  74. }, dberror => {
  75. console.log( '- Error while getting the verifications: ' + dberror );
  76. msg.replyMsg( lang.get('verify.error_reply'), {}, false, false ).then( message => {
  77. if ( message ) message.reactEmoji('error');
  78. } );
  79. } );
  80. }
  81. module.exports = {
  82. name: 'verify',
  83. everyone: true,
  84. pause: false,
  85. owner: false,
  86. run: cmd_verify
  87. };