From 21656e3a5cfe241fcd97f2403acc1dc3216b7f0b Mon Sep 17 00:00:00 2001 From: Lio Young Date: Sun, 17 Oct 2021 18:39:09 +0200 Subject: [PATCH] more utils --- src/utils/prefix.ts | 20 ++++++++++++++++++++ src/utils/replace.ts | 4 ++++ 2 files changed, 24 insertions(+) create mode 100644 src/utils/prefix.ts create mode 100644 src/utils/replace.ts diff --git a/src/utils/prefix.ts b/src/utils/prefix.ts new file mode 100644 index 0000000..0ede4d9 --- /dev/null +++ b/src/utils/prefix.ts @@ -0,0 +1,20 @@ +import modulus from "./modulus"; +import config from "./config"; + +export default async function prefix(id: string, message: string) { + let server = await modulus.server(id) + // @ts-ignore + let prefixes: string[] = [...config.prefixes, ...server.prefix] + let prefix: string + let exists: boolean + for (const p in prefixes) { + if (message.startsWith(prefixes[p])) { + prefix = p + exists = true + } + } + if (!exists) return { success: false } + const args = message.slice(prefixes[prefix].length).trim().split(/ +/g) + const command = args.shift().toLowerCase() + return { success: true, command, args, prefix } +} \ No newline at end of file diff --git a/src/utils/replace.ts b/src/utils/replace.ts new file mode 100644 index 0000000..ebd80c1 --- /dev/null +++ b/src/utils/replace.ts @@ -0,0 +1,4 @@ +export default function replace(to_replace: any, replace_with: string, full_string: string) { + + return full_string.replace(to_replace, replace_with) +} \ No newline at end of file