Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Database {
- constructor(URL) {
- this.URL = URL;
- this.GuildInfo = {};
- this.Client;
- }
- setGuildInfo(GuildID, Info) {
- this.GuildInfo[GuildID] = Info;
- }
- getGuilds(Callback) {
- let Options = {
- url: (`${this.URL}/guilds`),
- method: "GET",
- headers: {
- "cache-control": "no-cache",
- "x-apikey": process.env.APIKEY
- }
- };
- request(Options, (Error, Response, Body) => {
- Callback(JSON.parse(Body));
- })
- }
- getGuildPrefix(GuildID) {
- let Prefix = this.GuildInfo[GuildID].prefix || false;
- if (Prefix) {
- return Prefix
- }
- else {
- this.updateGuilds();
- return "--";
- }
- }
- getGuildDocumentID(GuildID) {
- return this.GuildInfo[GuildID].docid || false;
- }
- setGuildPrefix(GuildID, NewPrefix) {
- let DocumentID = this.getGuildDocumentID(GuildID);
- if (DocumentID) {
- let Options = {
- method: "PUT",
- url: (`${this.URL}/guilds/${DocumentID}`),
- headers: {
- "cache-control": "no-cache",
- "x-apikey": process.env.APIKEY,
- "content-type": "application/json"
- },
- body: {prefix: NewPrefix || "--"},
- json: true
- }
- request(Options);
- this.updateGuilds();
- }
- }
- updateGuilds(UseClient) {
- this.getGuilds((Guilds) => {
- this.Client = UseClient || this.Client;
- Guilds.forEach((Guild) => {
- let Info = {
- id: Guild.id,
- name: Guild.name,
- prefix: Guild.prefix,
- docid: Guild._id
- }
- this.setGuildInfo(Guild.id, Info);
- });
- (UseClient || this.Client).guilds.cache.forEach((Guild) => {
- if (this.GuildInfo[Guild.id]) return;
- let Options = {
- url: (`${this.URL}/guilds`),
- method: "POST",
- headers: {
- "cache-control": "no-cache",
- "x-apikey": process.env.APIKEY,
- "content-type": "application/json"
- },
- body: Body,
- json: true
- }
- request(Options, (Error, Response, Body) => {
- let Info = {
- id: Guild.id,
- name: Guild.name,
- prefix: "--",
- docid: Body._id
- }
- this.setGuildInfo(Guild.id, Info);
- });
- });
- });
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement