2023-09-02 23:21:55 +02:00
|
|
|
import { AlterRepo } from "../repositories/AlterRepo";
|
|
|
|
import { AlterModel } from "models/alterModel"
|
|
|
|
|
|
|
|
export async function createAlter(userId: string, args: string[]){
|
|
|
|
const alterRepo = new AlterRepo();
|
|
|
|
|
|
|
|
const model: AlterModel = {
|
|
|
|
owner: userId,
|
|
|
|
name: args[0],
|
|
|
|
prefix: args[1],
|
|
|
|
profile_pic_url: "https://tse3.mm.bing.net/th?id=OIP.yte7rRnbCnWi1giriwTOvwHaHa&pid=15.1"
|
|
|
|
}
|
|
|
|
|
|
|
|
let userAlters: AlterModel[];
|
|
|
|
await alterRepo.getAltersByUserId(userId).then(result => userAlters = result)
|
|
|
|
|
|
|
|
let alterTags : string[] = [];
|
|
|
|
userAlters.forEach( alter => {
|
|
|
|
alterTags.push(alter.prefix)
|
|
|
|
})
|
|
|
|
|
|
|
|
let alterNames : string[] = [];
|
|
|
|
userAlters.forEach ( alter => {
|
|
|
|
alterNames.push(alter.name)
|
|
|
|
})
|
|
|
|
|
|
|
|
if (args.length == 2
|
|
|
|
&& args[1].includes("text")
|
|
|
|
&& !alterTags.includes(args[1])
|
|
|
|
&& args[1] != "text"
|
|
|
|
&& !alterNames.includes(args[0])) {
|
|
|
|
|
|
|
|
alterRepo.addAlterForUser(model);
|
2024-01-08 13:43:05 +01:00
|
|
|
return {message: "Member < " + model.name + " > has been succefully created", code: 0}
|
2023-09-02 23:21:55 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (args.length != 2){
|
2023-12-09 22:46:55 +01:00
|
|
|
return {message: "Error: Insufficent arguments", code: 1};
|
2023-09-02 23:21:55 +02:00
|
|
|
}
|
|
|
|
if (args[1] === "text"){
|
2023-12-09 22:46:55 +01:00
|
|
|
return {message: "Error: Tag may not be only <text>", code: 2};
|
2023-09-02 23:21:55 +02:00
|
|
|
}
|
|
|
|
if (!args[1].includes("text")) {
|
2023-12-09 22:46:55 +01:00
|
|
|
return {message: "Error: This command requires a tag that contains <text> in it", code: 3};
|
2023-09-02 23:21:55 +02:00
|
|
|
}
|
|
|
|
if (alterTags.includes(args[1])) {
|
2024-01-08 13:43:05 +01:00
|
|
|
return {message: "Error: You already have a Member with that tag", code: 4}
|
2023-09-02 23:21:55 +02:00
|
|
|
}
|
|
|
|
if (alterNames.includes(args[0])) {
|
2024-01-08 13:43:05 +01:00
|
|
|
return {message: "Error: You can only have one Member with that name", code: 5}
|
2023-09-02 23:21:55 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|