feat: use a standard custom ID format in role buttons

This commit is contained in:
Dragory 2022-04-23 17:45:47 +03:00
parent 784c54b22a
commit b64611dd01
No known key found for this signature in database
GPG key ID: 5F387BA66DF8AAC1
4 changed files with 30 additions and 3 deletions

View file

@ -0,0 +1,3 @@
export function buildCustomId(namespace: string, data: any = {}) {
return `${namespace}:${Date.now()}:${JSON.stringify(data)}`;
}

View file

@ -0,0 +1,17 @@
const customIdFormat = /^([^:]+):\d+:(.*)$/;
export function parseCustomId(customId: string): { namespace: string; data: any } {
const parts = customId.match(customIdFormat);
if (!parts) {
return {
namespace: "",
data: null,
};
}
return {
namespace: parts[1],
// Skipping timestamp
data: JSON.parse(parts[2]),
};
}