-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
347 additions
and
210 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import { BlacklistStore } from '../interfaces/blacklist-store.js'; | ||
import { getStorage, Storage } from "firebase-admin/storage"; | ||
import { Message } from 'discord.js'; | ||
|
||
export class FirebaseBlacklistStore implements BlacklistStore { | ||
private folderPath: string; | ||
private store: Storage; | ||
|
||
constructor(guildId: string) { | ||
this.folderPath = `guilds/${guildId}`; | ||
|
||
this.store = getStorage(); | ||
} | ||
|
||
async load(): Promise<{ blacklist: Map<string, string[]>; messages: Map<string, Message<boolean>>; }> { | ||
return { | ||
'blacklist': await this.loadBlacklist(), | ||
'messages': await this.loadMessages() | ||
}; | ||
} | ||
|
||
async loadBlacklist(): Promise<Map<string, string[]>> { | ||
const [contents] = await this.store.bucket().file(`${this.folderPath}/Blacklist.json`).download(); | ||
const fileContent = contents.toString(); | ||
return new Map(JSON.parse(fileContent)); | ||
} | ||
|
||
async loadMessages(): Promise<Map<string, Message>> { | ||
const [contents] = await this.store.bucket().file(`${this.folderPath}/messages.json`).download(); | ||
const fileContent = contents.toString(); | ||
return new Map(JSON.parse(fileContent)); | ||
} | ||
|
||
async loadConfig(): Promise<Map<string, string>> { | ||
const [contents] = await this.store.bucket().file(`${this.folderPath}/config.json`).download(); | ||
const fileContent = contents.toString(); | ||
return new Map(JSON.parse(fileContent)); | ||
} | ||
|
||
async loadByName(name: string): Promise<string | null> { | ||
const [contents] = await this.store.bucket().file(`${this.folderPath}/${name}.json`).download(); | ||
return contents.toString(); | ||
} | ||
|
||
async save(blacklist: Map<string, string[]>, messages: Map<string, Message>) { | ||
await this.saveBlacklist(blacklist); | ||
await this.saveMessages(messages); | ||
} | ||
|
||
async saveBlacklist(blacklist: Map<string, string[]>): Promise<void> { | ||
const file = this.store.bucket().file(`${this.folderPath}/Blacklist.json`); | ||
await file.save(JSON.stringify([...blacklist], null, 4), { | ||
gzip: true, | ||
contentType: 'application/json' | ||
}); | ||
} | ||
|
||
async saveMessages(messages: Map<string, Message<boolean>>) { | ||
const file = this.store.bucket().file(`${this.folderPath}/messages.json`); | ||
await file.save(JSON.stringify([...messages], null, 4), { | ||
gzip: true, | ||
contentType: 'application/json' | ||
}); | ||
} | ||
|
||
async saveConfig(config: Map<string, string>) { | ||
const file = this.store.bucket().file(`${this.folderPath}/config.json`); | ||
await file.save(JSON.stringify([...config], null, 4), { | ||
gzip: true, | ||
contentType: 'application/json' | ||
}); | ||
} | ||
|
||
async saveByName(name: string, data: string | Buffer) { | ||
const file = this.store.bucket().file(`${this.folderPath}/${name}.json`); | ||
await file.save(data, { | ||
gzip: true, | ||
contentType: 'application/json' | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { getStorage } from "firebase-admin/storage"; | ||
import { initializeApp } from "firebase-admin/app"; | ||
import { readdir } from "node:fs/promises"; | ||
|
||
|
||
// Initialize Firebase | ||
const app = initializeApp(); | ||
|
||
const storage = getStorage(app); | ||
|
||
const dir = await readdir('./guilds/'); | ||
|
||
for (const subDir of dir) { | ||
console.log(subDir); | ||
const files = await readdir(`./guilds/${subDir}`); | ||
for (const file of files) { | ||
console.log(file); | ||
const responce = await storage.bucket().upload(`guilds/${subDir}/${file}`, { | ||
destination: `guilds/${subDir}/${file}`, | ||
gzip: true, | ||
}); | ||
console.log(responce[0].publicUrl()); | ||
console.log(responce); | ||
console.log(); | ||
} | ||
} | ||
|
||
// const file = storage.bucket().file(`guilds/899233872447946804/Blacklist.json`); | ||
|
||
// file.download().then((data) => { | ||
// console.log(data[0].toString()); | ||
// // console.log(JSON.parse(data.toString())); | ||
// }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { Message } from "discord.js"; | ||
|
||
export interface BlacklistStore { | ||
load: () => Promise<{ blacklist: Map<string, string[]>; messages: Map<string, Message<boolean>>; }>; | ||
loadBlacklist: () => Promise<Map<string, string[]>>; | ||
loadMessages: () => Promise<Map<string, Message>>; | ||
loadConfig: () => Promise<Map<string, string>>; | ||
loadByName: (name: string) => Promise<string | null>; | ||
|
||
|
||
save: (blacklist: Map<string, string[]>, idMap: Map<string, Message>) => Promise<void>; | ||
saveBlacklist: (Blacklist: Map<string, string[]>) => Promise<void>; | ||
saveMessages: (idMap: Map<string, Message>) => Promise<void>; | ||
saveConfig: (config: Map<string, string>) => Promise<void>; | ||
saveByName: (name: string, file: string | Buffer) => Promise<void>; | ||
} |
Oops, something went wrong.