Skip to content

Commit

Permalink
Final changes before full rollout
Browse files Browse the repository at this point in the history
  • Loading branch information
SunburntRock89 committed May 17, 2023
1 parent a6f55e9 commit f5fd313
Show file tree
Hide file tree
Showing 13 changed files with 225 additions and 122 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ dist/
built/
build/

src/config/auth-*.ts
src/config/auth.ts
src/config/config-*.ts

.env

Expand Down
31 changes: 0 additions & 31 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 3 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,12 @@
"delay": 100
},
"dependencies": {
"@prisma/client": "^4.12.0",
"@prisma/client": "^4.14.1",
"bufferutil": "^4.0.7",
"cli-progress": "^3.12.0",
"dayjs": "^1.11.7",
"discord-api-types": "^0.37.38",
"discord.js": "^14.9.0",
"erlpack": "github:discordapp/erlpack",
"discord.js": "^14.11.0",
"i18next": "^21.10.0",
"node-schedule": "^2.1.1",
"re2": "^1.18.0",
Expand All @@ -63,7 +62,7 @@
"ansi-colors": "^4.1.3",
"cross-env": "^7.0.3",
"eslint": "^8.38.0",
"prisma": "^4.12.0",
"prisma": "^4.14.1",
"prisma-erd-generator": "^1.5.4",
"rethinkdb-ts": "^2.5.4",
"safe-regex": "^2.1.1",
Expand Down
18 changes: 5 additions & 13 deletions src/config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@ export default {
"137589790538334208", // Sun
"124989722668957700", // Mitchell
],
devMode: true,
devMode: false,
devOnlyMode: false,
shardCount: 1,
botID: "377609965554237453",
shardCount: 7,

// NUMBER ALIASES
aliasNumbers: {
Expand Down Expand Up @@ -52,16 +51,16 @@ export default {
// IDs
// TODO: Return IDs to their original values
supportGuild: {
id: "385862448747511812",
id: "281815661317980160",
channels: {
officesCategory: "355890256786227210",

announcement: "281816926144167946",
logs: "385870073442598912",
logs: "282253502779228160",
badLogs: "377945714166202368",
promote: "398569181097754624",
support: "281816105289515008",
management: "385862448747511814",
management: "326075875466412033",
},
roles: {
boss: "281815725365264385",
Expand Down Expand Up @@ -107,11 +106,4 @@ export default {
consoleLevel: "silly",
fileLevel: "silly",
},

// Cooldown times (s)
cooldowns: {
default: 5,
call: 20,
message: 120,
},
};
2 changes: 1 addition & 1 deletion src/database/db.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { PrismaClient } from "@prisma/client";
import { Collection } from "discord.js";
import { Collection } from "@discordjs/collection";
import { winston } from "../dtel";
const prisma = new PrismaClient();

Expand Down
35 changes: 35 additions & 0 deletions src/events/allShardsReady.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { winston } from "../dtel";
import CallClient from "../internals/callClient";
import DTelClient from "../internals/client";

export default async(client: DTelClient): Promise<void> => {
winston.info("Received the all clear! Starting calls...");

// const allCalls = await client.db.activeCalls.findMany({
// include: {
// to: {
// include: {
// guild: true,
// },
// },
// from: {
// include: {
// guild: true,
// },
// },
// },
// });

// for (const call of allCalls) {
// const doc = await CallClient.byID(client, {
// doc: call,
// side: "to",
// });

// client.calls.set(call.id, doc);
// }

if (process.env.SHARDS == "0") {
require("../internals/jobs");
}
};
36 changes: 9 additions & 27 deletions src/events/ready.ts
Original file line number Diff line number Diff line change
@@ -1,41 +1,23 @@
import DTelClient from "../internals/client";
import Commands from "../config/commands";
import CallClient from "../internals/callClient";
import config from "../config/config";

export default async(client: DTelClient): Promise<void> => {
client.winston.info(`Ready!`);
client.winston.info(`Logged in as ${client.user!.tag}`);

client.user!.setActivity({
name: `[${process.env.SHARDS}] Starting up...`,
});

// client.application.commands.set(client.commands);
if (process.env.SHARDS === "0") {
client.application!.commands.set(Commands, "385862448747511812");
client.application!.commands.set(Commands, "398980667553349649");

require("../internals/jobs");
}

const allCalls = await client.db.activeCalls.findMany({
include: {
to: {
include: {
guild: true,
},
},
from: {
include: {
guild: true,
},
},
},
});
client.application!.commands.set(Commands);
if (client.application.installParams) config.botInvite = client.generateInvite(client.application.installParams);

for (const call of allCalls) {
client.calls.set(call.id, await CallClient.byID(client, {
doc: call,
side: "to",
}));
// client.application!.commands.set(Commands, "385862448747511812");
// client.application!.commands.set(Commands, "398980667553349649");
}

if (client.application.installParams) config.botInvite = client.generateInvite(client.application.installParams);
client.shard!.send({ msg: "ready", shardID: Number(process.env.SHARDS) });
};
39 changes: 38 additions & 1 deletion src/events/sharderMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { TextBasedChannel } from "discord.js";
import { winston } from "../dtel";
import CallClient, { CallsWithNumbers } from "../internals/callClient";
import DTelClient from "../internals/client";
import allShardsReady from "./allShardsReady";

export default async(client: DTelClient, msg: Record<string, unknown>): Promise<void> => {
switch (msg.msg) {
Expand All @@ -22,7 +23,6 @@ export default async(client: DTelClient, msg: Record<string, unknown>): Promise<
break;
}
case "callRepropagate": {
// TODO: Efficiency boost?
const messageObject = JSON.parse(msg.callDBObject as string) as callRepropagate;
const call = client.calls.get(messageObject.callID);

Expand All @@ -39,6 +39,43 @@ export default async(client: DTelClient, msg: Record<string, unknown>): Promise<
client.calls.delete(typed.callID);
break;
}

case "allShardsSpawned": {
allShardsReady(client);
break;
}

case "resume": {
if (msg.shardID === Number(process.env.SHARDS)) {
allShardsReady(client);
winston.info("Received all clear for resume! Starting calls...");
}
break;
}

case "callResume": {
const callDoc = msg.callDoc as CallsWithNumbers;

if (msg.fromShard != Number(process.env.SHARDS) && msg.toShard != Number(process.env.SHARDS)) {
return;
} else if (msg.fromShard === msg.toShard) {
if (client.calls.get(callDoc.id)) {
winston.info(`Call ${callDoc.id} already exists on this shard, ignoring.`);
return;
}
}

winston.info(`Recovering call ID: ${callDoc.id}`);

const call = await CallClient.byID(client, {
side: msg.fromShard === Number(process.env.SHARDS) ? "from" : "to",
doc: callDoc,
id: callDoc.id,
});
client.calls.set(call.id, call);

break;
}
}
};

Expand Down
Loading

0 comments on commit f5fd313

Please sign in to comment.