فهرست منبع

delete response when reacted with 🗑

Markus-Rost 6 سال پیش
والد
کامیت
31d27721a5
1فایلهای تغییر یافته به همراه22 افزوده شده و 12 حذف شده
  1. 22 12
      main.js

+ 22 - 12
main.js

@@ -1356,7 +1356,7 @@ function cmd_bug(lang, mclang, msg, args, title, cmd, querystring, fragment, rea
 		} );
 		} );
 	}
 	}
 	else if ( invoke && invoke.toLowerCase() === 'version' && args.length && args.join(' ').length < 100 ) {
 	else if ( invoke && invoke.toLowerCase() === 'version' && args.length && args.join(' ').length < 100 ) {
-		var jql = encodeURIComponent( 'fixVersion="' + args.join(' ') + '"order by key' );
+		var jql = encodeURIComponent( 'fixVersion="' + args.join(' ') + '" order by key' );
 		request( {
 		request( {
 			uri: 'https://bugs.mojang.com/rest/api/2/search?fields=summary,resolution,status&jql=' + jql + '&maxResults=25',
 			uri: 'https://bugs.mojang.com/rest/api/2/search?fields=summary,resolution,status&jql=' + jql + '&maxResults=25',
 			json: true
 			json: true
@@ -1628,11 +1628,10 @@ Discord.MessageReaction.prototype.removeEmoji = function() {
 
 
 Discord.Message.prototype.sendChannel = function(content, options, ignorePause = false) {
 Discord.Message.prototype.sendChannel = function(content, options, ignorePause = false) {
 	if ( this.channel.type !== 'text' || !pause[this.guild.id] || ( ignorePause && ( this.isAdmin() || this.isOwner() ) ) ) {
 	if ( this.channel.type !== 'text' || !pause[this.guild.id] || ( ignorePause && ( this.isAdmin() || this.isOwner() ) ) ) {
-		return this.channel.send(content, options).then(msg => {
-			if ( !( msg instanceof Discord.Message ) ) {
-				log_error({name:'Message is not a message',message:'\n\u200b' + util.inspect( msg ).replace( /\n/g, '\n\u200b' )}, true, 'Sending');
-			} else return msg;
-		}, log_error);
+		return this.channel.send(content, options).then( msg => {
+			msg.allowDelete(this.author.id);
+			return msg;
+		}, log_error );
 	} else {
 	} else {
 		console.log( '- Aborted, paused.' );
 		console.log( '- Aborted, paused.' );
 		return Promise.resolve();
 		return Promise.resolve();
@@ -1640,16 +1639,19 @@ Discord.Message.prototype.sendChannel = function(content, options, ignorePause =
 };
 };
 
 
 Discord.Message.prototype.sendChannelError = function(content, options) {
 Discord.Message.prototype.sendChannelError = function(content, options) {
-	return this.channel.send(content, options).then( message => message.reactEmoji('error'), log_error );
+	return this.channel.send(content, options).then( msg => {
+		msg.reactEmoji('error');
+		msg.allowDelete(this.author.id);
+		return msg;
+	}, log_error );
 };
 };
 
 
 Discord.Message.prototype.replyMsg = function(content, options, ignorePause = false) {
 Discord.Message.prototype.replyMsg = function(content, options, ignorePause = false) {
 	if ( this.channel.type !== 'text' || !pause[this.guild.id] || ( ignorePause && ( this.isAdmin() || this.isOwner() ) ) ) {
 	if ( this.channel.type !== 'text' || !pause[this.guild.id] || ( ignorePause && ( this.isAdmin() || this.isOwner() ) ) ) {
-		return this.reply(content, options).then(msg => {
-			if ( !( msg instanceof Discord.Message ) ) {
-				log_error({name:'Message is not a message',message:'\n\u200b' + util.inspect( msg ).replace( /\n/g, '\n\u200b' )}, true, 'Sending');
-			} else return msg;
-		}, log_error);;
+		return this.reply(content, options).then( msg => {
+			msg.allowDelete(this.author.id);
+			return msg;
+		}, log_error );
 	} else {
 	} else {
 		console.log( '- Aborted, paused.' );
 		console.log( '- Aborted, paused.' );
 		return Promise.resolve();
 		return Promise.resolve();
@@ -1660,6 +1662,14 @@ Discord.Message.prototype.deleteMsg = function(timeout = 0) {
 	return this.delete(timeout).catch(log_error);
 	return this.delete(timeout).catch(log_error);
 };
 };
 
 
+Discord.Message.prototype.allowDelete = function(author) {
+	return this.awaitReactions( (reaction, user) => reaction.emoji.name === '🗑' && user.id === author, {max:1,time:30000} ).then( reaction => {
+		if ( reaction.size ) {
+			this.deleteMsg();
+		}
+	} );
+};
+
 String.prototype.hasPrefix = function(flags = '') {
 String.prototype.hasPrefix = function(flags = '') {
 	if ( RegExp( '^' + process.env.prefix + '(?: |$)', flags ).test(this.toLowerCase()) ) return true;
 	if ( RegExp( '^' + process.env.prefix + '(?: |$)', flags ).test(this.toLowerCase()) ) return true;
 	else return false;
 	else return false;