FEAT: added tupper migrations from json file
This commit is contained in:
parent
fa072fd9bf
commit
80b9aab3f7
8 changed files with 60 additions and 15 deletions
BIN
bun.lockb
Executable file
BIN
bun.lockb
Executable file
Binary file not shown.
|
@ -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"
|
||||
}
|
||||
|
|
|
@ -1 +0,0 @@
|
|||
export function colorAlterChange(userId: string, args: string[]){}
|
|
@ -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 <text>";
|
||||
return {message: "Error: Tag may not be only <text>", code: 2};
|
||||
}
|
||||
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])) {
|
||||
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}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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"
|
||||
}
|
||||
|
|
35
src/commands/migrateAlters.ts
Normal file
35
src/commands/migrateAlters.ts
Normal 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"
|
||||
}
|
||||
}
|
|
@ -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}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue