mirror of
https://github.com/NohamR/lanyard-profile-readme.git
synced 2026-05-25 20:00:40 +00:00
Feat: Refactoring
This commit is contained in:
@@ -1,16 +1,16 @@
|
||||
export const getFlags = (flag: number): string[] => {
|
||||
let flags: string[] = [];
|
||||
|
||||
if (flag & 1) flags.push("Discord_Employee")
|
||||
if (flag & 2) flags.push("Partnered_Server_Owner")
|
||||
if (flag & 4) flags.push("HypeSquad_Events")
|
||||
if (flag & 8) flags.push("Bug_Hunter_Level_1")
|
||||
if (flag & 64) flags.push("House_Bravery")
|
||||
if (flag & 128) flags.push("House_Brilliance")
|
||||
if (flag & 256) flags.push("House_Balance")
|
||||
if (flag & 512) flags.push("Early_Supporter")
|
||||
if (flag & 16384) flags.push("Bug_Hunter_Level_2")
|
||||
if (flag & 131072) flags.push("Early_Verified_Bot_Developer")
|
||||
if (flag & 1) flags.push("Discord_Employee");
|
||||
if (flag & 2) flags.push("Partnered_Server_Owner");
|
||||
if (flag & 4) flags.push("HypeSquad_Events");
|
||||
if (flag & 8) flags.push("Bug_Hunter_Level_1");
|
||||
if (flag & 64) flags.push("House_Bravery");
|
||||
if (flag & 128) flags.push("House_Brilliance");
|
||||
if (flag & 256) flags.push("House_Balance");
|
||||
if (flag & 512) flags.push("Early_Supporter");
|
||||
if (flag & 16384) flags.push("Bug_Hunter_Level_2");
|
||||
if (flag & 131072) flags.push("Early_Verified_Bot_Developer");
|
||||
|
||||
return flags;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1,47 +1,46 @@
|
||||
interface DeconstructedSnowflake {
|
||||
timestamp: number;
|
||||
date: Date;
|
||||
workerID: number;
|
||||
processID: number;
|
||||
increment: number;
|
||||
binary: string;
|
||||
timestamp: number;
|
||||
date: Date;
|
||||
workerID: number;
|
||||
processID: number;
|
||||
increment: number;
|
||||
binary: string;
|
||||
}
|
||||
|
||||
const EPOCH = 1420070400000; // Discord's EPOCH
|
||||
|
||||
export function isSnowflake(snowflake: string): boolean {
|
||||
const { timestamp } = deconstruct(snowflake);
|
||||
if (timestamp > EPOCH && timestamp <= 3619093655551) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
export const isSnowflake = (snowflake: string): boolean => {
|
||||
const { timestamp } = deconstruct(snowflake);
|
||||
if (timestamp > EPOCH && timestamp <= 3619093655551) return true;
|
||||
|
||||
function deconstruct(snowflake: string): DeconstructedSnowflake {
|
||||
const BINARY = idToBinary(snowflake).padStart(64, "0");
|
||||
return {
|
||||
timestamp: parseInt(BINARY.substring(0, 42), 2) + EPOCH,
|
||||
get date() {
|
||||
return new Date(this.timestamp);
|
||||
},
|
||||
workerID: parseInt(BINARY.substring(42, 47), 2),
|
||||
processID: parseInt(BINARY.substring(47, 52), 2),
|
||||
increment: parseInt(BINARY.substring(52, 64), 2),
|
||||
binary: BINARY,
|
||||
};
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
function idToBinary(snowflake: string): string {
|
||||
let bin = "";
|
||||
let high = parseInt(snowflake.slice(0, -10)) || 0;
|
||||
let low = parseInt(snowflake.slice(-10));
|
||||
while (low > 0 || high > 0) {
|
||||
bin = String(low & 1) + bin;
|
||||
low = Math.floor(low / 2);
|
||||
if (high > 0) {
|
||||
low += 5000000000 * (high % 2);
|
||||
high = Math.floor(high / 2);
|
||||
}
|
||||
}
|
||||
return bin;
|
||||
}
|
||||
const deconstruct = (snowflake: string): DeconstructedSnowflake => {
|
||||
const BINARY = idToBinary(snowflake).padStart(64, "0");
|
||||
return {
|
||||
timestamp: parseInt(BINARY.substring(0, 42), 2) + EPOCH,
|
||||
get date() {
|
||||
return new Date(this.timestamp);
|
||||
},
|
||||
workerID: parseInt(BINARY.substring(42, 47), 2),
|
||||
processID: parseInt(BINARY.substring(47, 52), 2),
|
||||
increment: parseInt(BINARY.substring(52, 64), 2),
|
||||
binary: BINARY,
|
||||
};
|
||||
};
|
||||
|
||||
const idToBinary = (snowflake: string): string => {
|
||||
let bin = "";
|
||||
let high = parseInt(snowflake.slice(0, -10)) || 0;
|
||||
let low = parseInt(snowflake.slice(-10));
|
||||
while (low > 0 || high > 0) {
|
||||
bin = String(low & 1) + bin;
|
||||
low = Math.floor(low / 2);
|
||||
if (high > 0) {
|
||||
low += 5000000000 * (high % 2);
|
||||
high = Math.floor(high / 2);
|
||||
}
|
||||
}
|
||||
return bin;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user