Skip to content

Instantly share code, notes, and snippets.

@LaurenceJJones
Created September 2, 2022 12:57
Show Gist options
  • Save LaurenceJJones/28206209251f5179a56d60fd0848e107 to your computer and use it in GitHub Desktop.
Save LaurenceJJones/28206209251f5179a56d60fd0848e107 to your computer and use it in GitHub Desktop.
Rocketchat custom hook into crowdsec to ban ip from channel idea
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