Skip to content

Commit

Permalink
Add more logs
Browse files Browse the repository at this point in the history
  • Loading branch information
SunburntRock89 committed May 18, 2023
1 parent 07cb926 commit e3b0a15
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 13 deletions.
8 changes: 5 additions & 3 deletions src/dtel.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Interaction, Message, Options, PartialMessage, Partials, Typing } from "discord.js";
import { Guild, Interaction, Message, Options, PartialMessage, Partials, Typing } from "discord.js";
import i18next from "i18next";

import Client from "./internals/client";
Expand All @@ -9,6 +9,8 @@ import InteractionEvent from "./events/interactionCreate";
import MessageCreateEvent from "./events/messageCreate";
import MessageDeleteEvent from "./events/messageDelete";
import MessageUpdateEvent from "./events/messageUpdate";
import GuildCreateEvent from "./events/guildCreate";
import GuildDeleteEvent from "./events/guildDelete";
import ReadyEvent from "./events/ready";
import TypingStartEvent from "./events/typingStart";

Expand Down Expand Up @@ -59,8 +61,8 @@ client.on("messageCreate", (msg: Message) => MessageCreateEvent(client, msg));
client.on("messageUpdate", (before: Message | PartialMessage, after: Message | PartialMessage) => MessageUpdateEvent(client, before as Message, after as Message));
client.on("messageDelete", (msg: Message | PartialMessage) => MessageDeleteEvent(client, msg as Message));
client.on("interactionCreate", (interaction: Interaction) => InteractionEvent(client, interaction));
// client.on("guildCreate", (guild: Guild) => GuildCreateEvent(guild));
// client.on("guildDelete", (guild: Guild) => GuildDeleteEvent(guild));
client.on("guildCreate", (guild: Guild) => GuildCreateEvent(client, guild));
client.on("guildDelete", (guild: Guild) => GuildDeleteEvent(client, guild));

client.on("typingStart", (typing: Typing) => TypingStartEvent(client, typing));

Expand Down
6 changes: 6 additions & 0 deletions src/events/guildCreate.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { Guild } from "discord.js";
import DTelClient from "../internals/client";

export default async(client: DTelClient, guild: Guild): Promise<void> => {
client.log(`📥 Joined guild \`${guild.name}\` (\`${guild.id}\`). Currently in \`${client.guilds.cache.size}\` servers on Shard ${client.shard!.count} and \`${client.getGuildCount()}\` servers total.`);
};
6 changes: 6 additions & 0 deletions src/events/guildDelete.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { Guild } from "discord.js";
import DTelClient from "../internals/client";

export default async(client: DTelClient, guild: Guild): Promise<void> => {
client.log(`📤 Left guild \`${guild.name}\` (\`${guild.id}\`). Currently in \`${client.guilds.cache.size}\` servers on Shard ${client.shard!.count} and \`${client.getGuildCount()}\` servers total.`);
};
6 changes: 3 additions & 3 deletions src/events/messageCreate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ export default async(client: DTelClient, message: Message): Promise<void> => {

const call = client.calls.find(c => c.to.channelID === message.channel.id || c.from.channelID === message.channel.id);
if (!call) {
if (message.content.startsWith(">ping") || message.content.startsWith(">call") || message.content.startsWith(">dial") || message.content.startsWith(">rdial")) {
if (message.content.startsWith(">ping") || message.content.startsWith(">call") || message.content.startsWith(">dial") || message.content.startsWith(">rdial") || message.content.startsWith(">daily")) {
const embed = new EmbedBuilder()
.setColor(config.colors.info)
.setTitle("DTel has moved to Slash Commands!")
.setDescription(`Type \`/\` in the chat to view the available commands. If you need help, please join our [support server](${config.guildInvite})!`);
message.reply({
message.channel.send({
embeds: [embed],
});
}).catch(() => null);
}
return;
} // We don't need to handle messages we have nothing to do with
Expand Down
7 changes: 7 additions & 0 deletions src/internals/callClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,10 @@ export default class CallClient implements CallsWithNumbers {
return;
}

if (this.randomCall) {
this.client.log(`☎️ Random Call \`${this.from.channelID}${this.to.channelID}\` has been established by ID: \`${this.started.by}\`\nCall ID: \`${this.id}\``);
}

this.client.calls.set(this.id, this);

if (!this.primary || config.shardCount == 1) this.setupPickupTimer(notificationMessageID);
Expand Down Expand Up @@ -384,6 +388,9 @@ export default class CallClient implements CallsWithNumbers {
// Ignore
}

if (this.randomCall) {
this.client.log(`❎ Random Call \`${this.from.channelID}${this.to.channelID}\` was not picked up.\nCall ID: \`${this.id}\``);
}
this.endHandler("missed");
}, 2 * 60 * 1000);
}
Expand Down
4 changes: 4 additions & 0 deletions src/internals/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,10 @@ class DTelClient extends Client<true> {
content: `\`[${time}]\` ${message}`,
}, this.config.supportGuild.channels.logs);
}

async getGuildCount(): Promise<number> {
return (await this.shard!.fetchClientValues("guilds.cache.size")).reduce((a, b) => (a as number) + (b as number), 0) as number;
}
}

export default DTelClient;
10 changes: 3 additions & 7 deletions src/internals/jobs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,18 @@ import { Range, scheduleJob } from "node-schedule";
import { client, winston } from "../dtel";
import auth from "../config/auth";
import config from "../config/config";
import { getOrCreateAccount } from "./utils";
import { db } from "../database/db";
import { EmbedBuilder, TextChannel } from "discord.js";
import { ArchivedCalls } from "@prisma/client";
import { EmbedBuilder } from "discord.js";

interface playingCtx {
guildCount: number
userCount: number
}

const getGuildCount = async() => (await client.shard!.fetchClientValues("guilds.cache.size")).reduce((a, b) => (a as number) + (b as number), 0) as number;

const playingJob = scheduleJob({
minute: new Range(0, 59, 15),
}, async() => {
const guildCount = await getGuildCount();
const guildCount = await client.getGuildCount();

const userCount = (await client.shard!.fetchClientValues("users.cache.size")).reduce((a, b) => (a as number) + (b as number), 0) as number;

Expand All @@ -39,7 +35,7 @@ const playingJob = scheduleJob({

let WCVotes = 0;
const votingJob = !config.devMode && scheduleJob("*/1 * * * *", async() => {
const guildCount = await getGuildCount();
const guildCount = await client.getGuildCount();

const updateResults = await fetch("https://discord.austinhuang.me/dtel", {
method: "POST",
Expand Down

0 comments on commit e3b0a15

Please sign in to comment.