changed alter to model and started implementation of autoproxy

This commit is contained in:
Ale 2024-03-15 19:57:42 +01:00
parent 87e8a4295d
commit 327ba2c089
5 changed files with 35 additions and 7 deletions

View file

@ -3,9 +3,11 @@ import { commandHandler } from "./utils/commandHandler"
import { nonCommandHandler } from "./utils/nonCommandHandler" import { nonCommandHandler } from "./utils/nonCommandHandler"
import { Database } from "sqlite3"; import { Database } from "sqlite3";
import config from "../config.json" import config from "../config.json"
import dbInit from "utils/dbInit";
const client : Client = new Client({ eagerFetching: false }); const client : Client = new Client({ eagerFetching: false });
const db = new Database(config.databaseName); const db = new Database(config.databaseName);
dbInit(db);
client.on("ready", async () => { client.on("ready", async () => {
console.info(`logged in as ${client.user.username}!`) console.info(`logged in as ${client.user.username}!`)

View file

@ -1,5 +1,6 @@
interface UserModel { interface UserModel {
id: number, id: number,
revolt_id: string,
autoProxy: boolean, autoProxy: boolean,
autoProxyMember: number autoProxyMember: number
} }

View file

@ -6,11 +6,10 @@ export class MemberRepo {
constructor(database_instance: Database) { constructor(database_instance: Database) {
this.db = database_instance; this.db = database_instance;
this.db.run("CREATE TABLE IF NOT EXISTS alters (id INTEGER PRIMARY KEY AUTOINCREMENT, owner TEXT, prefix TEXT, name TEXT, profile_pic_url TEXT, color TEXT)");
} }
async getAltersByUserId(userId : string) : Promise<MemberModel[]> { async getAltersByUserId(userId : string) : Promise<MemberModel[]> {
const query : string = 'SELECT * FROM alters WHERE alters.owner = "' + userId + '"' const query : string = 'SELECT * FROM members WHERE members.owner = "' + userId + '"'
let result: MemberModel[] = await new Promise((resolve, reject) => { let result: MemberModel[] = await new Promise((resolve, reject) => {
this.db.all(query, (err, row: MemberModel[]) => { this.db.all(query, (err, row: MemberModel[]) => {
@ -23,17 +22,17 @@ export class MemberRepo {
} }
addAlterForUser(alter: MemberModel){ addAlterForUser(alter: MemberModel){
this.db.run("INSERT INTO alters (owner, prefix, name, profile_pic_url, color) VALUES(?, ?, ?, ?, ?)", this.db.run("INSERT INTO members (owner, prefix, name, profile_pic_url, color) VALUES(?, ?, ?, ?, ?)",
[alter.owner, alter.prefix, alter.name, alter.profile_pic_url]) [alter.owner, alter.prefix, alter.name, alter.profile_pic_url])
} }
editAlter(alter: MemberModel){ editAlter(alter: MemberModel){
this.db.run("UPDATE alters SET owner=?, prefix=?, name=?, profile_pic_url=?, color=? WHERE alters.id ='" + alter.id + "'", this.db.run("UPDATE members SET owner=?, prefix=?, name=?, profile_pic_url=?, color=? WHERE members.id ='" + alter.id + "'",
[alter.owner, alter.prefix, alter.name, alter.profile_pic_url, alter.color]) [alter.owner, alter.prefix, alter.name, alter.profile_pic_url, alter.color])
} }
delete(alterId: number) { delete(alterId: number) {
this.db.run("DELETE FROM alters WHERE alters.id='"+ alterId + "'") this.db.run("DELETE FROM members WHERE members.id='"+ alterId + "'")
} }
} }

View file

@ -0,0 +1,14 @@
import { Database } from "sqlite3";
class UserRepo {
db: Database
constructor(database: Database) {
this.db = database
}
getById() {}
new() {}
delete() {}
}

View file

@ -1,5 +1,17 @@
import { Database } from "sqlite3";
function dbInit(database: Database){
database.run("CREATE TABLE IF NOT EXISTS members (id INTEGER PRIMARY KEY AUTOINCREMENT, owner TEXT, prefix TEXT, name TEXT, profile_pic_url TEXT, color TEXT)");
export function dbInit(){ database.run(`
CREATE TABLE IF NOT EXISTS users(
id INTEGER PRIMARY KEY AUTOINCREMENT,
revolt_id TEXT NOT NULL,
auto_proxy BOOLEAN NOT NULL,
auto_proxy_member INTEGER,
FOREIGN KEY (auto_proxy_member)
REFERENCES members (id))
`);
} }
export default dbInit