1
0
Fork 0
mirror of https://github.com/NovaGM/Modules.git synced 2024-08-14 22:47:01 +00:00

Compare commits

..

2 commits

Author SHA1 Message Date
フズキ
04e817908e
Updated Module Settings Experiment 2021-03-25 14:42:24 +01:00
e1667e6865
Added SnowflakeInfo module. 2021-03-25 13:14:49 +01:00
5 changed files with 126 additions and 5 deletions

View file

@ -0,0 +1,11 @@
{
"main": "index.js",
"name": "SnowflakeInfo",
"description": "Returns info about a given snowflake.",
"tags": ["commands"],
"authors": ["717352467280691331"],
"version": "1.0.0"
}

87
SnowflakeInfo/index.js Normal file
View file

@ -0,0 +1,87 @@
import { commands, internalMessage } from '@goosemod/patcher';
const discordEpoch = Number(1420070400000);
const idToBinary = (num) => {
let bin = '';
let high = parseInt(num.slice(0, -10)) || 0;
let low = parseInt(num.slice(-10));
try {
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);
}
}
} catch (e) {
console.error(e);
}
return bin;
};
export default {
goosemodHandlers: {
onImport: () => {
commands.add(
'echo',
"Prints out all of the message's text in an internal message.",
(args) => {
internalMessage(args.text[0].text);
console.log(args);
},
[
{
type: 3,
name: 'text',
description: 'Text to be printed in an internal message.',
required: true,
},
],
);
commands.add(
'snowflake',
'Returns info about a given snowflake.',
(args) => {
// Check if the supplied argument is actually a snowflake or not
if (!/\d{1,20}/.test(args.snowflake[0].text)) {
internalMessage('The provided argument is not a snowflake.');
} else {
const binary = idToBinary(args.snowflake[0].text).toString(2).padStart(64, '0');
const res = {
timestamp: parseInt(binary.substring(0, 42), 2) + discordEpoch,
workerID: parseInt(binary.substring(42, 47), 2),
processID: parseInt(binary.substring(47, 52), 2),
increment: parseInt(binary.substring(52, 64), 2),
binary: binary,
};
internalMessage(
`Snowflake info for \`${args.snowflake[0].text}\`\n\n` +
`**Timestamp**: ${new Date(res.timestamp).toUTCString()} (${res.timestamp})\n` +
`**Worker ID**: ${res.workerID}\n` +
`**Process ID**: ${res.processID}\n` +
`**Increment**: ${res.increment}\n` +
`**Binary**: ${res.binary}\n`,
);
}
},
[
{
type: 3,
name: 'snowflake',
description: 'Snowflake to decrypt.',
required: true,
},
],
);
},
onRemove: () => {
commands.remove('echo');
commands.remove('snowflake');
},
},
};

View file

@ -22,7 +22,6 @@ export function textInputField(text, subtext, placeholder, onApply, initialValue
inputEl.classList.add('inputDefault-_djjkz', 'input-cIJ7To'); inputEl.classList.add('inputDefault-_djjkz', 'input-cIJ7To');
inputEl.placeholder = placeholder; inputEl.placeholder = placeholder;
inputEl.type = 'text'; inputEl.type = 'text';
inputEl.value = initialValue ? initialValue : '';
inputWrapEl.appendChild(inputEl); inputWrapEl.appendChild(inputEl);
@ -47,6 +46,16 @@ export function textInputField(text, subtext, placeholder, onApply, initialValue
dividerEl.classList.add('divider-3573oO', 'dividerDefault-3rvLe-'); dividerEl.classList.add('divider-3573oO', 'dividerDefault-3rvLe-');
dividerEl.style.marginTop = subtext ? '20px' : '45px'; dividerEl.style.marginTop = subtext ? '20px' : '45px';
// Insertion checker
// A bit hacky...
// But works :)
let insertCheckId = setInterval(() => {
if (el.parentNode != null) {
inputEl.value = initialValue != undefined ? initialValue() : '';
clearInterval(insertCheckId);
}
}, 1000);
el.appendChild(textEl); el.appendChild(textEl);
el.appendChild(buttonEl); el.appendChild(buttonEl);
el.appendChild(inputWrapEl); el.appendChild(inputWrapEl);

View file

@ -7,5 +7,5 @@
"authors": ["186496078273708033"], "authors": ["186496078273708033"],
"version": "1.0.0" "version": "1.1.0"
} }

View file

@ -6,6 +6,7 @@ import { textInputField } from './custom-settings.js';
let settingsPage = "Settings Experiment"; let settingsPage = "Settings Experiment";
let settings; let settings;
let defaultSettings = { let defaultSettings = {
inputText: "Default value"
}; };
export default { export default {
@ -130,13 +131,26 @@ export default {
{ {
type: "custom", type: "custom",
element: textInputField( element: textInputField(
"Text Input", "Text Input (static initial value)",
"Prototype", "Prototype",
"Placeholder", "Placeholder",
value => { value => {
showToast(`Text Input: ${value}`); showToast(`Text Input: ${value}`);
}, },
"Preset value" () => "Preset value"
)
},
{
type: "custom",
element: textInputField(
"Text Input (loading from and saving to settings)",
"Prototype",
"Placeholder",
value => {
showToast(`Text Input: ${value}`);
settings.inputText = value;
},
() => settings.inputText
) )
} }
]); ]);