-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: allow using different prefixes to trigger commands (#233)
- Loading branch information
Showing
3 changed files
with
36 additions
and
5 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,11 @@ | ||
// Internal dependencies | ||
export { config } from "https://deno.land/[email protected]/dotenv/mod.ts"; | ||
export { cleanEnv, num, str } from "https://deno.land/x/[email protected]/mod.ts"; | ||
export { | ||
cleanEnv, | ||
makeValidator, | ||
num, | ||
str, | ||
} from "https://deno.land/x/[email protected]/mod.ts"; | ||
export { | ||
dirname, | ||
fromFileUrl, | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,34 @@ | ||
import { cleanEnv, config, num, str } from "./deps.ts"; | ||
import { cleanEnv, config, makeValidator, num, str } from "./deps.ts"; | ||
|
||
await config({ export: true }); | ||
|
||
// https://stackoverflow.com/a/54256858/12250600 | ||
const PREFIX_REGEX = /^[^\p{L}\d\s@#\$]$/u; | ||
|
||
const cmdPrefix = makeValidator((input) => { | ||
if (PREFIX_REGEX.test(input)) { | ||
return input; | ||
} | ||
console.warn( | ||
"Falling back to '\\' for COMMAND_PREFIX, a single symbol excluding @, #, $ was expected", | ||
); | ||
return "\\"; | ||
}); | ||
|
||
const inputPrefix = makeValidator((input) => { | ||
if (PREFIX_REGEX.test(input) && input !== Deno.env.get("COMMAND_PREFIX")) { | ||
return input; | ||
} | ||
console.warn( | ||
"Falling back to '>' for INPUT_PREFIX, a single symbol excluding @, #, $ and COMMAND_PREFIX was expected", | ||
); | ||
return "\\"; | ||
}); | ||
|
||
export default cleanEnv(Deno.env.toObject(), { | ||
STRING_SESSION: str(), | ||
APP_ID: num(), | ||
APP_HASH: str(), | ||
COMMAND_PREFIX: cmdPrefix({ default: "\\" }), | ||
INPUT_PREFIX: inputPrefix({ default: ">" }), | ||
}); |
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