more utils

This commit is contained in:
Lio Young 2021-10-17 18:39:09 +02:00
parent 91fd17606e
commit 21656e3a5c
2 changed files with 24 additions and 0 deletions

20
src/utils/prefix.ts Normal file
View File

@ -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 }
}

4
src/utils/replace.ts Normal file
View File

@ -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)
}