utility.flagdump: big message check
This commit is contained in:
		
							parent
							
								
									43354bcbca
								
							
						
					
					
						commit
						ef5eb3608f
					
				
					 1 changed files with 20 additions and 5 deletions
				
			
		| 
						 | 
				
			
			@ -22,13 +22,14 @@ flagdump.callback = async function (msg, line, [numOrMention], {id, list}) {
 | 
			
		|||
  if (!line || line == "") numOrMention = `<@${msg.author.id}>`;
 | 
			
		||||
 | 
			
		||||
  const num = BigInt(numOrMention);
 | 
			
		||||
  let out = "";
 | 
			
		||||
  if (list) {
 | 
			
		||||
    let allFlags = 0n;
 | 
			
		||||
    for (const index in UserFlagsMapped) {
 | 
			
		||||
      if (UserFlagsMapped[index] == undefined) continue;
 | 
			
		||||
      allFlags += 1n << BigInt(index);
 | 
			
		||||
    }
 | 
			
		||||
    return `All flags:\n\`\`\`${flagsFromInt(allFlags, UserFlagsMapped)}\`\`\``;
 | 
			
		||||
    out = `All flags:\n\`\`\`${flagsFromInt(allFlags, UserFlagsMapped)}\`\`\``;
 | 
			
		||||
  } else if (/<@!?(\d+)>/.test(numOrMention) || SNOWFLAKE_REGEX.test(id)) {
 | 
			
		||||
    const targetId = id ?? numOrMention.match(/<@!?(\d+)>/)?.[1];
 | 
			
		||||
    if (!targetId) return "Got null ID.";
 | 
			
		||||
| 
						 | 
				
			
			@ -37,20 +38,34 @@ flagdump.callback = async function (msg, line, [numOrMention], {id, list}) {
 | 
			
		|||
    if (!user) user = await hf.bot.requestHandler.request("GET", APIEndpoints.USER(targetId), true).catch(() => {});
 | 
			
		||||
 | 
			
		||||
    if (!user) {
 | 
			
		||||
      return "Failed to get user.";
 | 
			
		||||
      out = "Failed to get user.";
 | 
			
		||||
    } else {
 | 
			
		||||
      return `\`${formatUsername(user)}\`'s public flags:\n\`\`\`${flagsFromInt(
 | 
			
		||||
      out = `\`${formatUsername(user)}\`'s public flags:\n\`\`\`${flagsFromInt(
 | 
			
		||||
        user.public_flags ?? user.publicFlags,
 | 
			
		||||
        UserFlagsMapped
 | 
			
		||||
      )}\`\`\``;
 | 
			
		||||
    }
 | 
			
		||||
  } else if (!Number.isNaN(num)) {
 | 
			
		||||
    return `\`\`\`\n${flagsFromInt(num, UserFlagsMapped)}\`\`\``;
 | 
			
		||||
    out = `\`\`\`\n${flagsFromInt(num, UserFlagsMapped)}\`\`\``;
 | 
			
		||||
  } else {
 | 
			
		||||
    return `\`${formatUsername(msg.author)}\`'s public flags:\n\`\`\`${flagsFromInt(
 | 
			
		||||
    out = `\`${formatUsername(msg.author)}\`'s public flags:\n\`\`\`${flagsFromInt(
 | 
			
		||||
      msg.author.publicFlags,
 | 
			
		||||
      UserFlagsMapped
 | 
			
		||||
    )}\`\`\``;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  if (out.length > 2000) {
 | 
			
		||||
    return {
 | 
			
		||||
      content: `Output too long to send in a message:`,
 | 
			
		||||
      attachments: [
 | 
			
		||||
        {
 | 
			
		||||
          file: out,
 | 
			
		||||
          filename: "message.txt",
 | 
			
		||||
        },
 | 
			
		||||
      ],
 | 
			
		||||
    };
 | 
			
		||||
  } else {
 | 
			
		||||
    return out;
 | 
			
		||||
  }
 | 
			
		||||
};
 | 
			
		||||
hf.registerCommand(flagdump);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue