history now does lines and not messages
This commit is contained in:
		
							parent
							
								
									b67347b18e
								
							
						
					
					
						commit
						5a0c0e9b67
					
				
					 2 changed files with 43 additions and 24 deletions
				
			
		| 
						 | 
				
			
			@ -10,16 +10,18 @@ async function getHistory(limit = 20, channel = null) {
 | 
			
		|||
  }
 | 
			
		||||
 | 
			
		||||
  const messages = await comcord.client.getMessages(
 | 
			
		||||
    channel ?? comcord.state.currentChannel,
 | 
			
		||||
    {limit}
 | 
			
		||||
    channel ?? comcord.state.currentChannel
 | 
			
		||||
  );
 | 
			
		||||
  messages.reverse();
 | 
			
		||||
 | 
			
		||||
  console.log("--Beginning-Review".padEnd(72, "-"));
 | 
			
		||||
 | 
			
		||||
  const lines = [];
 | 
			
		||||
  for (const msg of messages) {
 | 
			
		||||
    processMessage(msg, {noColor: true, history: true});
 | 
			
		||||
    const processedLines = processMessage(msg, {noColor: true, history: true});
 | 
			
		||||
    if (processedLines) lines.push(...processedLines);
 | 
			
		||||
  }
 | 
			
		||||
  console.log(lines.slice(-limit).join("\n"));
 | 
			
		||||
 | 
			
		||||
  console.log("--Review-Complete".padEnd(73, "-"));
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -176,6 +176,16 @@ function formatMessage({
 | 
			
		|||
    minutes = dateObj.getUTCMinutes().toString().padStart(2, "0"),
 | 
			
		||||
    seconds = dateObj.getUTCSeconds().toString().padStart(2, "0");
 | 
			
		||||
 | 
			
		||||
  let console = global.console;
 | 
			
		||||
  const lines = [];
 | 
			
		||||
  if (history) {
 | 
			
		||||
    console = {
 | 
			
		||||
      log: function (...args) {
 | 
			
		||||
        lines.push(...args.join(" ").split("\n"));
 | 
			
		||||
      },
 | 
			
		||||
    };
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  if (name.length + 2 > comcord.state.nameLength)
 | 
			
		||||
    comcord.state.nameLength = name.length + 2;
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -343,6 +353,10 @@ function formatMessage({
 | 
			
		|||
      }
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  if (history) {
 | 
			
		||||
    return lines;
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
function processMessage(msg, options = {}) {
 | 
			
		||||
| 
						 | 
				
			
			@ -371,7 +385,7 @@ function processMessage(msg, options = {}) {
 | 
			
		|||
    );
 | 
			
		||||
  } else if (msg.content && msg.content.indexOf("\n") > -1) {
 | 
			
		||||
    if (msg.content.match(REGEX_CODEBLOCK)) {
 | 
			
		||||
      formatMessage({
 | 
			
		||||
      return formatMessage({
 | 
			
		||||
        channel: msg.channel,
 | 
			
		||||
        name: msg.author.username,
 | 
			
		||||
        bot: msg.author.bot,
 | 
			
		||||
| 
						 | 
				
			
			@ -391,8 +405,10 @@ function processMessage(msg, options = {}) {
 | 
			
		|||
      });
 | 
			
		||||
    } else {
 | 
			
		||||
      const lines = msg.content.split("\n");
 | 
			
		||||
      const outLines = [];
 | 
			
		||||
      for (const index in lines) {
 | 
			
		||||
        const line = lines[index];
 | 
			
		||||
        outLines.push(
 | 
			
		||||
          formatMessage({
 | 
			
		||||
            channel: msg.channel,
 | 
			
		||||
            name: msg.author.username,
 | 
			
		||||
| 
						 | 
				
			
			@ -411,11 +427,12 @@ function processMessage(msg, options = {}) {
 | 
			
		|||
              (msg.mentionsEveryone ||
 | 
			
		||||
                msg.mentions.find((user) => user.id == comcord.client.user.id)),
 | 
			
		||||
            ...options,
 | 
			
		||||
        });
 | 
			
		||||
          })
 | 
			
		||||
        );
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
  } else {
 | 
			
		||||
    formatMessage({
 | 
			
		||||
    return formatMessage({
 | 
			
		||||
      channel: msg.channel,
 | 
			
		||||
      name: msg.author.username,
 | 
			
		||||
      bot: msg.author.bot,
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue