mirror of
https://github.com/monkeytypegame/monkeytype.git
synced 2024-09-20 15:26:15 +08:00
Ip (#3784) egorguslyan
* Finishing logic * Numbers + layoutfluid * One interface * Filter results * tts error on undefined Extencions like NoScript can partly block scripts on the page. If speech synthesis is not loaded, notification shows up without freezing the page * Improved randomcase * Prevent dublicates in command line * Change filter logic * Prettier * Convert numbers * num * Quote and zen modes * withWords * Misc * Expand funboxes list for pb saving * Move list to backend * Move to constants * Async withWords, checkFunbox tweak * Prettier * Forbid nonexistent funboxes * Disable speech if language is ignored TtS's init() uses setLanguage() * canGetPb * Less circular imports * Ligatures typo * Simon says blocks word highlight * blockWordHighlight backend * Changed imports * usesLayout * JSON schema * IP funbox * Split * Display notification instead of reseting * canGetPB * One getWordHtml * Dividing properties * No sync * blockedModes * forcedConfig * Infinitness parameter, list sync * applyConfig, memory Remove extra applyConfig somewhere; Memory in quotes and custom modes * I lost this code after merging * Remove arrowKeys * isFunboxCompatible * Fix logic * sync canGetPb * remove FunboxObjectType * baloons * moved cangetpb function to pb utils * updated the pb check to be easier to understand * Refactor isFunboxCompatible * Check modes conflicts * Strict highlightMode type * Only one allowed or blocked highlight mode * More checks * Undefined only, not false * Prettier * Highlight modes * added intersect helper function * reworked forced config - storing allowed modes as an array, not string - first value will be used if config is outside of the allowed values - instead of checking if highlight mode is allowed, checking if the whole config is available - removed the "Finite" forced config and replaced it with "noInfiniteDuration" property - config event listener now checks every config change, not just highlight mode. this will ensure any future forced configs will work straight out of the box * ManualRestart in commandline * fixed funbox commands not correctly showing which funbox is active * Upd list * Merge * canGetPB for ip * Reduce list * split funbox into smaller files moved funbox files into its own folder * missing none command * added function to convert camel case to space separated words * changed config validation to be blocking the change rather than reacting to the change * reduced code duplication * allowing sub color flash * moved keymap key higlighting and flashing into an observable event * moved tts into a observable event * passing funbox into config validation funcitons * replaced getActive with get * only keeping functions structure in the list, moved the actual function bodies to funbox.ts done to remove a circular dependency still need to finish the rest of the funboxes * removed empty function definitions (typing issues) * removed unnecessary type * unnecessary check * moved mode checking to config validation * longer notification * checking funboxes before changing mode * moved more functions * fixed incorrect type * checking funboxes when setting punctuation and numbers * Rest of funboxes * fixed funbox commands showing tags text and icon * checking if funbox can be set with the current config * better error message * validating with setting time and words importing from a new file * added a function to capitalise the first letter of a string * using function from a new file new parameters * moved test length check to a function in a different file * moved some funbox validation into its own file * only showing notifications if the setWordCount returned true * moved funbox validation to its own file * setting manual restart when trying to set funbox to nonoe * moving this validation to before activating the funbox * returning forcedConfigs along side if current value is allowed moved infinite check to checkFunboxForcedConfigs * removed function, replaced by funox validation * removing duplicates * throwing if no intersection * wrong type * always allowing setting funbox sometimes it might be possible to update the config * checking forced configs first, and updating config if possible only setting funbox to none when couldnt update config * basic difficulty levels * xp funbox bonus * Delete old file * Difficulty level * removed console logs * renamed import, renamed type * lowercase b for consistency across the codebase * renamed variable for readability * renamed for clarity * converted metadata to object * changed from beforesubgroup on the command to before list on the subgroup * using code suggested by bruce * renamed type * removed console log * merch banner fix * important animation * updating the icon of "none" funbox command * removed unnecessary import * lowercase b * updated description Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Miodec <jack@monkeytype.com>
This commit is contained in:
parent
351f1995bf
commit
618c9ec931
|
@ -107,6 +107,14 @@ const Funboxes: Record<string, MonkeyTypes.FunboxMetadata> = {
|
|||
canGetPb: false,
|
||||
difficultyLevel: 0,
|
||||
},
|
||||
IPv4: {
|
||||
canGetPb: false,
|
||||
difficultyLevel: 1,
|
||||
},
|
||||
IPv6: {
|
||||
canGetPb: false,
|
||||
difficultyLevel: 1,
|
||||
},
|
||||
};
|
||||
|
||||
export default Funboxes;
|
||||
|
|
|
@ -181,6 +181,24 @@ const list: MonkeyTypes.FunboxMetadata[] = [
|
|||
info: "Nonsense words that look like the current language.",
|
||||
properties: ["unspeakable"],
|
||||
},
|
||||
{
|
||||
name: "IPv4",
|
||||
alias: "network",
|
||||
info: "For sysadmins.",
|
||||
properties: ["ignoresLanguage", "ignoresLayout", "noLetters"],
|
||||
forcedConfig: {
|
||||
numbers: [false],
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "IPv6",
|
||||
alias: "network",
|
||||
info: "For sysadmins with a long beard.",
|
||||
properties: ["ignoresLanguage", "ignoresLayout", "noLetters"],
|
||||
forcedConfig: {
|
||||
numbers: [false],
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
export function getAll(): MonkeyTypes.FunboxMetadata[] {
|
||||
|
|
|
@ -13,6 +13,7 @@ import * as TestInput from "../test-input";
|
|||
import * as WeakSpot from "../weak-spot";
|
||||
import { getPoem } from "../poetry";
|
||||
import { getSection } from "../wikipedia";
|
||||
import * as IPGenerator from "../ip-addresses";
|
||||
import {
|
||||
areFunboxesCompatible,
|
||||
checkFunboxForcedConfigs,
|
||||
|
@ -473,6 +474,46 @@ FunboxList.setFunboxFunctions("pseudolang", {
|
|||
},
|
||||
});
|
||||
|
||||
FunboxList.setFunboxFunctions("IPv4", {
|
||||
getWord(): string {
|
||||
return IPGenerator.getRandomIPv4address();
|
||||
},
|
||||
punctuateWord(word: string): string {
|
||||
let w = word;
|
||||
if (Math.random() < 0.25) {
|
||||
w = IPGenerator.addressToCIDR(word);
|
||||
}
|
||||
return w;
|
||||
},
|
||||
rememberSettings(): void {
|
||||
save("numbers", Config.numbers, UpdateConfig.setNumbers);
|
||||
},
|
||||
});
|
||||
|
||||
FunboxList.setFunboxFunctions("IPv6", {
|
||||
getWord(): string {
|
||||
return IPGenerator.getRandomIPv6address();
|
||||
},
|
||||
punctuateWord(word: string): string {
|
||||
let w = word;
|
||||
if (Math.random() < 0.25) {
|
||||
w = IPGenerator.addressToCIDR(word);
|
||||
}
|
||||
// Compress
|
||||
if (w.includes(":")) {
|
||||
w = w
|
||||
.replace(/\b(?:0+:){2,}/, "::")
|
||||
.split(":")
|
||||
.map((a) => a.replace(/\b0+/g, ""))
|
||||
.join(":");
|
||||
}
|
||||
return w;
|
||||
},
|
||||
rememberSettings(): void {
|
||||
save("numbers", Config.numbers, UpdateConfig.setNumbers);
|
||||
},
|
||||
});
|
||||
|
||||
export function toggleScript(...params: string[]): void {
|
||||
FunboxList.get(Config.funbox).forEach((funbox) => {
|
||||
if (funbox.functions?.toggleScript) funbox.functions.toggleScript(params);
|
||||
|
|
60
frontend/src/ts/test/ip-addresses.ts
Normal file
60
frontend/src/ts/test/ip-addresses.ts
Normal file
|
@ -0,0 +1,60 @@
|
|||
import { randomIntFromRange } from "../utils/misc";
|
||||
|
||||
function getRandomIPvXaddress(
|
||||
bits: number,
|
||||
parts: number,
|
||||
base: number,
|
||||
separator: string
|
||||
): string {
|
||||
const addr: string[] = [];
|
||||
const b = Math.round(bits / parts);
|
||||
for (let i = 0; i < parts; i++) {
|
||||
const n = randomIntFromRange(0, 2 ** b - 1);
|
||||
addr.push(n.toString(base));
|
||||
}
|
||||
return addr.join(separator);
|
||||
}
|
||||
|
||||
function getIPCidr(
|
||||
bits: number,
|
||||
parts: number,
|
||||
base: number,
|
||||
separator: string,
|
||||
address: string,
|
||||
maskSize: number
|
||||
): string {
|
||||
const addr = address.split(separator).map((a) => parseInt(a, base));
|
||||
const b = Math.round(bits / parts);
|
||||
let bitsLeft = maskSize;
|
||||
for (let i = 0; i < parts; i++) {
|
||||
bitsLeft -= b;
|
||||
if (bitsLeft < 0) {
|
||||
if (-bitsLeft <= b) {
|
||||
addr[i] &= (2 ** b - 1) ^ (2 ** -bitsLeft - 1);
|
||||
} else {
|
||||
addr[i] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
return (
|
||||
addr.map((a) => a.toString(base)).join(separator) +
|
||||
"/" +
|
||||
maskSize.toString()
|
||||
);
|
||||
}
|
||||
|
||||
export function getRandomIPv4address(): string {
|
||||
return getRandomIPvXaddress(32, 4, 10, ".");
|
||||
}
|
||||
|
||||
export function getRandomIPv6address(): string {
|
||||
return getRandomIPvXaddress(128, 8, 16, ":");
|
||||
}
|
||||
|
||||
export function addressToCIDR(addr: string): string {
|
||||
if (addr.includes(":")) {
|
||||
return getIPCidr(128, 8, 16, ":", addr, randomIntFromRange(16, 32) * 4);
|
||||
} else {
|
||||
return getIPCidr(32, 4, 10, ".", addr, randomIntFromRange(8, 32));
|
||||
}
|
||||
}
|
|
@ -134,5 +134,17 @@
|
|||
"name": "pseudolang",
|
||||
"info": "Nonsense words that look like the current language.",
|
||||
"canGetPb": false
|
||||
},
|
||||
{
|
||||
"name": "IPv4",
|
||||
"alias": "network",
|
||||
"info": "For sysadmins.",
|
||||
"canGetPb": false
|
||||
},
|
||||
{
|
||||
"name": "IPv6",
|
||||
"alias": "network",
|
||||
"info": "For sysadmins with a long beard.",
|
||||
"canGetPb": false
|
||||
}
|
||||
]
|
||||
|
|
|
@ -117,4 +117,4 @@
|
|||
"with_log",
|
||||
"with"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue