mentions
This commit is contained in:
		
							parent
							
								
									e3e6fe419c
								
							
						
					
					
						commit
						b988416ae3
					
				
					 2 changed files with 43 additions and 5 deletions
				
			
		
							
								
								
									
										15
									
								
								src/index.js
									
										
									
									
									
								
							
							
						
						
									
										15
									
								
								src/index.js
									
										
									
									
									
								
							| 
						 | 
					@ -157,6 +157,21 @@ rpc.once("ready", function () {
 | 
				
			||||||
rpc.on("error", function () {});
 | 
					rpc.on("error", function () {});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
client.on("messageCreate", async function (msg) {
 | 
					client.on("messageCreate", async function (msg) {
 | 
				
			||||||
 | 
					  if (
 | 
				
			||||||
 | 
					    (msg.mentions.find((user) => user.id == client.user.id) ||
 | 
				
			||||||
 | 
					      msg.mentionEveryone) &&
 | 
				
			||||||
 | 
					    msg.channel.id != comcord.state.currentChannel &&
 | 
				
			||||||
 | 
					    msg.channel.type !== Constants.ChannelTypes.DM &&
 | 
				
			||||||
 | 
					    msg.channel.type !== Constants.ChannelTypes.GROUP_DM
 | 
				
			||||||
 | 
					  ) {
 | 
				
			||||||
 | 
					    const data = {ping: true, channel: msg.channel, author: msg.author};
 | 
				
			||||||
 | 
					    if (comcord.state.inPrompt) {
 | 
				
			||||||
 | 
					      comcord.state.messageQueue.push(data);
 | 
				
			||||||
 | 
					    } else {
 | 
				
			||||||
 | 
					      processMessage(data);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  if (!msg.author) return;
 | 
					  if (!msg.author) return;
 | 
				
			||||||
  if (msg.author.id === client.user.id) return;
 | 
					  if (msg.author.id === client.user.id) return;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -3,7 +3,7 @@ const chalk = require("chalk");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const REGEX_CODEBLOCK = /```(?:([a-z0-9_+\-.]+?)\n)?\n*([^\n][^]*?)\n*```/i;
 | 
					const REGEX_CODEBLOCK = /```(?:([a-z0-9_+\-.]+?)\n)?\n*([^\n][^]*?)\n*```/i;
 | 
				
			||||||
const REGEX_CODEBLOCK_GLOBAL =
 | 
					const REGEX_CODEBLOCK_GLOBAL =
 | 
				
			||||||
  /```(?:([a-z0-9_+\-.]+?)\n)?\n*([^\n][^]*?)\n*```/gi;
 | 
					  /```(?:[a-z0-9_+\-.]+?\n)?\n*([^\n][^]*?)\n*```/gi;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const REGEX_MENTION = /<@!?(\d+)>/g;
 | 
					const REGEX_MENTION = /<@!?(\d+)>/g;
 | 
				
			||||||
const REGEX_ROLE_MENTION = /<@&?(\d+)>/g;
 | 
					const REGEX_ROLE_MENTION = /<@&?(\d+)>/g;
 | 
				
			||||||
| 
						 | 
					@ -163,6 +163,7 @@ function formatMessage({
 | 
				
			||||||
  stickers,
 | 
					  stickers,
 | 
				
			||||||
  reply,
 | 
					  reply,
 | 
				
			||||||
  timestamp,
 | 
					  timestamp,
 | 
				
			||||||
 | 
					  mention = false,
 | 
				
			||||||
  noColor = false,
 | 
					  noColor = false,
 | 
				
			||||||
  dump = false,
 | 
					  dump = false,
 | 
				
			||||||
  history = false,
 | 
					  history = false,
 | 
				
			||||||
| 
						 | 
					@ -301,13 +302,17 @@ function formatMessage({
 | 
				
			||||||
          )} ${content}`
 | 
					          )} ${content}`
 | 
				
			||||||
        );
 | 
					        );
 | 
				
			||||||
      } else {
 | 
					      } else {
 | 
				
			||||||
        const nameColor = bot ? chalk.bold.yellow : chalk.bold.cyan;
 | 
					        const nameColor = mention
 | 
				
			||||||
 | 
					          ? chalk.bold.red
 | 
				
			||||||
 | 
					          : bot
 | 
				
			||||||
 | 
					          ? chalk.bold.yellow
 | 
				
			||||||
 | 
					          : chalk.bold.cyan;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // TODO: markdown
 | 
					 | 
				
			||||||
        console.log(
 | 
					        console.log(
 | 
				
			||||||
          nameColor(`[${name}]`) +
 | 
					          nameColor(`[${name}]`) +
 | 
				
			||||||
            " ".repeat(Math.abs(comcord.state.nameLength - (name.length + 2))) +
 | 
					            " ".repeat(Math.abs(comcord.state.nameLength - (name.length + 2))) +
 | 
				
			||||||
            chalk.reset(" " + content)
 | 
					            chalk.reset(" " + content) +
 | 
				
			||||||
 | 
					            (mention ? "\x07" : "")
 | 
				
			||||||
        );
 | 
					        );
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
| 
						 | 
					@ -356,6 +361,14 @@ function processMessage(msg, options = {}) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  if (msg.time) {
 | 
					  if (msg.time) {
 | 
				
			||||||
    console.log(msg.content);
 | 
					    console.log(msg.content);
 | 
				
			||||||
 | 
					  } else if (msg.ping) {
 | 
				
			||||||
 | 
					    console.log(
 | 
				
			||||||
 | 
					      chalk.bold.red(
 | 
				
			||||||
 | 
					        `**mentioned by ${msg.author?.username ?? "<unknown>"} in #${
 | 
				
			||||||
 | 
					          msg.channel?.name ?? "<unknown>"
 | 
				
			||||||
 | 
					        } in ${msg.channel.guild?.name ?? "<unknown>"}**\x07`
 | 
				
			||||||
 | 
					      )
 | 
				
			||||||
 | 
					    );
 | 
				
			||||||
  } else if (msg.content && msg.content.indexOf("\n") > -1) {
 | 
					  } else if (msg.content && msg.content.indexOf("\n") > -1) {
 | 
				
			||||||
    if (msg.content.match(REGEX_CODEBLOCK)) {
 | 
					    if (msg.content.match(REGEX_CODEBLOCK)) {
 | 
				
			||||||
      formatMessage({
 | 
					      formatMessage({
 | 
				
			||||||
| 
						 | 
					@ -364,12 +377,15 @@ function processMessage(msg, options = {}) {
 | 
				
			||||||
        bot: msg.author.bot,
 | 
					        bot: msg.author.bot,
 | 
				
			||||||
        content: msg.content.replace(
 | 
					        content: msg.content.replace(
 | 
				
			||||||
          REGEX_CODEBLOCK_GLOBAL,
 | 
					          REGEX_CODEBLOCK_GLOBAL,
 | 
				
			||||||
          (_, lang, content) => content
 | 
					          (_, content) => content
 | 
				
			||||||
        ),
 | 
					        ),
 | 
				
			||||||
        attachments: msg.attachments,
 | 
					        attachments: msg.attachments,
 | 
				
			||||||
        stickers: msg.stickerItems,
 | 
					        stickers: msg.stickerItems,
 | 
				
			||||||
        reply: msg.referencedMessage,
 | 
					        reply: msg.referencedMessage,
 | 
				
			||||||
        timestamp: msg.timestamp,
 | 
					        timestamp: msg.timestamp,
 | 
				
			||||||
 | 
					        mention:
 | 
				
			||||||
 | 
					          msg.mentionsEveryone ||
 | 
				
			||||||
 | 
					          msg.mentions.find((user) => user.id == comcord.client.user.id),
 | 
				
			||||||
        dump: true,
 | 
					        dump: true,
 | 
				
			||||||
        ...options,
 | 
					        ...options,
 | 
				
			||||||
      });
 | 
					      });
 | 
				
			||||||
| 
						 | 
					@ -390,6 +406,10 @@ function processMessage(msg, options = {}) {
 | 
				
			||||||
          stickers: index == lines.length - 1 ? msg.stickerItems : [],
 | 
					          stickers: index == lines.length - 1 ? msg.stickerItems : [],
 | 
				
			||||||
          reply: index == 0 ? msg.referencedMessage : null,
 | 
					          reply: index == 0 ? msg.referencedMessage : null,
 | 
				
			||||||
          timestamp: msg.timestamp,
 | 
					          timestamp: msg.timestamp,
 | 
				
			||||||
 | 
					          mention:
 | 
				
			||||||
 | 
					            index == 0 &&
 | 
				
			||||||
 | 
					            (msg.mentionsEveryone ||
 | 
				
			||||||
 | 
					              msg.mentions.find((user) => user.id == comcord.client.user.id)),
 | 
				
			||||||
          ...options,
 | 
					          ...options,
 | 
				
			||||||
        });
 | 
					        });
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
| 
						 | 
					@ -404,6 +424,9 @@ function processMessage(msg, options = {}) {
 | 
				
			||||||
      stickers: msg.stickerItems,
 | 
					      stickers: msg.stickerItems,
 | 
				
			||||||
      reply: msg.referencedMessage,
 | 
					      reply: msg.referencedMessage,
 | 
				
			||||||
      timestamp: msg.timestamp,
 | 
					      timestamp: msg.timestamp,
 | 
				
			||||||
 | 
					      mention:
 | 
				
			||||||
 | 
					        msg.mentionsEveryone ||
 | 
				
			||||||
 | 
					        msg.mentions.find((user) => user.id == comcord.client.user.id),
 | 
				
			||||||
      ...options,
 | 
					      ...options,
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue