Created
September 2, 2022 12:57
-
-
Save LaurenceJJones/28206209251f5179a56d60fd0848e107 to your computer and use it in GitHub Desktop.
Rocketchat custom hook into crowdsec to ban ip from channel idea
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const str = 'ban 1.1.1.1 duration 6h source capi' | |
const [verb, ip, ...args] = str.split(' ') | |
const splitToChunks = (arr, chunkSize, acc = []) => ( | |
arr.length > chunkSize ? | |
splitToChunks( | |
arr.slice(chunkSize), | |
chunkSize, | |
[...acc, arr.slice(0, chunkSize)] | |
) : | |
[...acc, arr] | |
); | |
const argObject = Object.fromEntries(splitToChunks(args, 2)) | |
console.log(verb, ip, argObject) | |
/* | |
"ban", "1.1.1.1", { | |
duration: "6h", | |
source: "capi" | |
} */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment