diff --git a/bun.lockb b/bun.lockb new file mode 100755 index 0000000..34c1ebd Binary files /dev/null and b/bun.lockb differ diff --git a/package.json b/package.json index 615a272..e44d4eb 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,7 @@ "typescript-language-server": "^3.3.2" }, "dependencies": { - "revolt.js": "^7.0.0-beta.7", + "revolt.js": "^7.0.0-beta.9", "shlex": "^2.1.2", "sqlite3": "^5.1.6" } diff --git a/src/commands/colorAlterChange.ts~ b/src/commands/colorAlterChange.ts~ deleted file mode 100644 index 42fe4ad..0000000 --- a/src/commands/colorAlterChange.ts~ +++ /dev/null @@ -1 +0,0 @@ -export function colorAlterChange(userId: string, args: string[]){} diff --git a/src/commands/createAlter.ts b/src/commands/createAlter.ts index 93e648e..66baf22 100644 --- a/src/commands/createAlter.ts +++ b/src/commands/createAlter.ts @@ -31,24 +31,24 @@ export async function createAlter(userId: string, args: string[]){ && !alterNames.includes(args[0])) { alterRepo.addAlterForUser(model); - return "Alter < " + model.name + " > has been succefully created" + return {message: "Alter < " + model.name + " > has been succefully created", code: 0} } else { if (args.length != 2){ - return "Error: Insufficent arguments"; + return {message: "Error: Insufficent arguments", code: 1}; } if (args[1] === "text"){ - return "Error: Tag may not be only "; + return {message: "Error: Tag may not be only ", code: 2}; } if (!args[1].includes("text")) { - return "Error: This command requires a tag that contains in it"; + return {message: "Error: This command requires a tag that contains in it", code: 3}; } 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])) { - 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} } } } diff --git a/src/commands/help.ts b/src/commands/help.ts index b8a5f89..a2ef9e3 100644 --- a/src/commands/help.ts +++ b/src/commands/help.ts @@ -6,6 +6,10 @@ export function returnHelpText() { "### 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" + + "- 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" + - "- 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" } diff --git a/src/commands/migrateAlters.ts b/src/commands/migrateAlters.ts new file mode 100644 index 0000000..f348998 --- /dev/null +++ b/src/commands/migrateAlters.ts @@ -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" + } +} diff --git a/src/index.ts b/src/index.ts index f3d2bb4..8c489fc 100644 --- a/src/index.ts +++ b/src/index.ts @@ -11,7 +11,7 @@ client.on("ready", async () => { }); client.on("messageCreate", async (message: Message) => { - try{if (!message.author) {await client.users.fetch(message.authorId)} } + try{ if (!message.author) { await client.users.fetch(message.authorId) } } catch(e){console.log(e)} if (message.content === undefined) {return} diff --git a/src/utils/commandHandler.ts b/src/utils/commandHandler.ts index 8533f1a..ed77c86 100644 --- a/src/utils/commandHandler.ts +++ b/src/utils/commandHandler.ts @@ -5,6 +5,8 @@ import { createAlter } from "../commands/createAlter" import { deleteAlter } from "../commands/deleteAlter" import { avatarAlterChange } from "../commands/avatarAlterChange" import { colorAlterChange } from "../commands/colorAlterChange" +import migrationCommand from "../commands/migrateAlters" + import { split } from "shlex" export async function commandHandler(message : Message, _prefix : String) { @@ -15,7 +17,7 @@ export async function commandHandler(message : Message, _prefix : String) { switch(command) { case "help" : { - message.reply(returnHelpText()); + await message.reply(returnHelpText()); break; } case "list" : { @@ -23,7 +25,8 @@ export async function commandHandler(message : Message, _prefix : String) { break; } 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 } case "delete" : { @@ -34,9 +37,13 @@ export async function commandHandler(message : Message, _prefix : String) { await message.reply(await avatarAlterChange(message.author.id, args)); break } - case "color" : { - await message.reply(await colorAlterChange(message.author.id, args)); - break + case "color" : { + await message.reply(await colorAlterChange(message.author.id, args)); + break + } + case "tupper" : { + await message.reply(await migrationCommand(message.author.id, message.attachments, "placeholder")) + break } } }