FEAT: added tupper migrations from json file

This commit is contained in:
Ale 2023-12-09 22:46:55 +01:00
parent fa072fd9bf
commit 80b9aab3f7
8 changed files with 60 additions and 15 deletions

BIN
bun.lockb Executable file

Binary file not shown.

View file

@ -14,7 +14,7 @@
"typescript-language-server": "^3.3.2" "typescript-language-server": "^3.3.2"
}, },
"dependencies": { "dependencies": {
"revolt.js": "^7.0.0-beta.7", "revolt.js": "^7.0.0-beta.9",
"shlex": "^2.1.2", "shlex": "^2.1.2",
"sqlite3": "^5.1.6" "sqlite3": "^5.1.6"
} }

View file

@ -1 +0,0 @@
export function colorAlterChange(userId: string, args: string[]){}

View file

@ -31,24 +31,24 @@ export async function createAlter(userId: string, args: string[]){
&& !alterNames.includes(args[0])) { && !alterNames.includes(args[0])) {
alterRepo.addAlterForUser(model); alterRepo.addAlterForUser(model);
return "Alter < " + model.name + " > has been succefully created" return {message: "Alter < " + model.name + " > has been succefully created", code: 0}
} }
else { else {
if (args.length != 2){ if (args.length != 2){
return "Error: Insufficent arguments"; return {message: "Error: Insufficent arguments", code: 1};
} }
if (args[1] === "text"){ if (args[1] === "text"){
return "Error: Tag may not be only <text>"; return {message: "Error: Tag may not be only <text>", code: 2};
} }
if (!args[1].includes("text")) { if (!args[1].includes("text")) {
return "Error: This command requires a tag that contains <text> in it"; return {message: "Error: This command requires a tag that contains <text> in it", code: 3};
} }
if (alterTags.includes(args[1])) { if (alterTags.includes(args[1])) {
return "Error: You already have an Alter with that tag" return {message: "Error: You already have an Alter with that tag", code: 4}
} }
if (alterNames.includes(args[0])) { if (alterNames.includes(args[0])) {
return "Error: You can only have one Alter with that name" return {message: "Error: You can only have one Alter with that name", code: 5}
} }
} }
} }

View file

@ -6,6 +6,10 @@ export function returnHelpText() {
"### Alters:\n" + "### Alters:\n" +
"- list | allows you to see your currently available alters.\n" + "- list | allows you to see your currently available alters.\n" +
"- create <'name of the alter'> <'your alter s tag'>| Allows you to create your Alters\n" + "- create <'name of the alter'> <'your alter s tag'>| Allows you to create your Alters\n" +
"- delete <'name of the alter'> | Deletes the choosen Alter\n" +
"- name <'name of the alter'> | Changes the choosen Alter's name\n" +
"- avatar <'Alter's name'> <'picture url'> | Allows you to edit your alter's profile picture\n" + "- avatar <'Alter's name'> <'picture url'> | Allows you to edit your alter's profile picture\n" +
"- color <'Alter's name'> <'color hex'> | Allows you to change the color of your alter ( may be integrated with the website )" "- color <'Alter's name'> <'color hex'> | Allows you to change the color of your alter ( may be integrated with the future website )\n"+
"### Migrations\n"+
"- pluralkit < Json file attached > | Migrates your alters from pluralkit to pluralcake"
} }

View file

@ -0,0 +1,35 @@
import { File } from "revolt.js"
import { createAlter } from "./createAlter"
export default async function migrateAlters(author: string, attachments: File[] | undefined, source: String) {
// source is not utilized for now, it is put as an argument in case the bot evolves further
let file = attachments[0]
if (file.contentType === "text/plain") {
const fileResponse = await fetch(file.url)
const fileResponseBlob = await fileResponse.blob()
const textFromBlob = fileResponseBlob.text()
const jsonFromText = JSON.parse(await textFromBlob)
if (jsonFromText.tuppers === "undefined"){
return "wrong json file, be certain that this is a tupperbox migration file"
}
const tuppers = jsonFromText.tuppers
tuppers.forEach(async element => {
let name = element.name
let brackets = element.brackets[0] + "text" + element.brackets[1]
const createResult = await createAlter(author, [name, brackets])
let tupperStruct = {tupper: name, message: createResult}
console.log(tupperStruct)
});
return "Migration finished, check your tuppers to confirm"
}
else {
return "This is not a valid json file"
}
}

View file

@ -5,6 +5,8 @@ import { createAlter } from "../commands/createAlter"
import { deleteAlter } from "../commands/deleteAlter" import { deleteAlter } from "../commands/deleteAlter"
import { avatarAlterChange } from "../commands/avatarAlterChange" import { avatarAlterChange } from "../commands/avatarAlterChange"
import { colorAlterChange } from "../commands/colorAlterChange" import { colorAlterChange } from "../commands/colorAlterChange"
import migrationCommand from "../commands/migrateAlters"
import { split } from "shlex" import { split } from "shlex"
export async function commandHandler(message : Message, _prefix : String) { export async function commandHandler(message : Message, _prefix : String) {
@ -15,7 +17,7 @@ export async function commandHandler(message : Message, _prefix : String) {
switch(command) { switch(command) {
case "help" : { case "help" : {
message.reply(returnHelpText()); await message.reply(returnHelpText());
break; break;
} }
case "list" : { case "list" : {
@ -23,7 +25,8 @@ export async function commandHandler(message : Message, _prefix : String) {
break; break;
} }
case "create" : { case "create" : {
await message.reply(await createAlter(message.author.id, args)); const commandResponse = await createAlter(message.author.id, args);
await message.reply (commandResponse.message)
break break
} }
case "delete" : { case "delete" : {
@ -38,5 +41,9 @@ export async function commandHandler(message : Message, _prefix : String) {
await message.reply(await colorAlterChange(message.author.id, args)); await message.reply(await colorAlterChange(message.author.id, args));
break break
} }
case "tupper" : {
await message.reply(await migrationCommand(message.author.id, message.attachments, "placeholder"))
break
}
} }
} }