Skip to content

Commit e9f003c

Browse files
committed
improve loggin and remove quote feature for now
1 parent 86bd881 commit e9f003c

File tree

15 files changed

+47
-72
lines changed

15 files changed

+47
-72
lines changed

src/api/discord/bans.ts

+2-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import express from "express";
22
import client from "src";
3+
import { log } from "utils";
34
const router = express.Router();
45

56
router.get("/", async (req, res) => {
@@ -10,12 +11,7 @@ router.get("/", async (req, res) => {
1011
const bans = await client.guilds.cache.get(req.query.server)?.bans.fetch()
1112
res.send(bans);
1213

13-
const time = new Date().toLocaleTimeString("en-US", {
14-
hour12: true,
15-
timeStyle: "medium",
16-
});
17-
18-
console.log(`[${time}] `, "Roles sent");
14+
log("Roles sent");
1915
});
2016

2117
export default router;

src/api/discord/channels.ts

+2-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import express from "express";
22
import client from "src";
3+
import { log } from "utils";
34
const router = express.Router();
45

56
router.get("/", async (req, res) => {
@@ -11,12 +12,7 @@ router.get("/", async (req, res) => {
1112

1213
res.send(channels);
1314

14-
const time = new Date().toLocaleTimeString("en-US", {
15-
hour12: true,
16-
timeStyle: "medium",
17-
});
18-
19-
console.log(`[${time}] `, "Roles sent");
15+
log("Roles sent");
2016
});
2117

2218
export default router;

src/api/discord/roles.ts

+2-6
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import express from "express";
22
import client from "src";
33
const router = express.Router();
44
import prm_client from "prom-client";
5+
import { log } from "utils";
56

67
const gauge_time = new prm_client.Gauge({
78
name: "api_role_time",
@@ -42,12 +43,7 @@ router.get("/", (req, res) => {
4243
end();
4344
gauge_count.inc(1);
4445

45-
const time = new Date().toLocaleTimeString("en-US", {
46-
hour12: true,
47-
timeStyle: "medium",
48-
});
49-
50-
console.log(`[${time}] `, "Roles sent");
46+
log("Roles sent");
5147
});
5248

5349
export default router;

src/api/discord/user.ts

+3-8
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import express from "express";
22
import client from "src";
33
import { User } from "discord.js";
4-
import { prisma } from "utils";
4+
import { prisma, log } from "utils";
55
import prm_client from "prom-client";
66

7+
78
const router = express.Router();
89

910
const gauge_time_user = new prm_client.Gauge({
@@ -63,15 +64,10 @@ router.post("/", async (req, res) => {
6364
})
6465
);
6566

66-
const time = new Date().toLocaleTimeString("en-US", {
67-
hour12: true,
68-
timeStyle: "medium",
69-
});
70-
7167
res.send(users);
7268
end_user();
7369
gauge_count_user.inc(1);
74-
console.log(`[${time}] `, "Users sent");
70+
log("Users sent");
7571
});
7672

7773
const gauge_time_detail = new prm_client.Gauge({
@@ -91,7 +87,6 @@ router.post("/details", async (req, res) => {
9187
gauge_time_detail.setToCurrentTime();
9288
const end_detail = gauge_time_user.startTimer();
9389
const UserArray = req.body as string[];
94-
console.log(UserArray);
9590

9691
if (
9792
!UserArray ||

src/api/experimental/index.ts

+4-19
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import express from "express";
22
import client from "src";
3-
import { prisma } from "utils";
3+
import { prisma, log } from "utils";
44

55
const router = express.Router();
66
const time = new Date().toLocaleTimeString("en-US", {
@@ -17,12 +17,7 @@ router.get("/users", async (req, res) => {
1717
await client.guilds.cache.get(req.query.server.trim())?.members.fetch()
1818
);
1919

20-
const time = new Date().toLocaleTimeString("en-US", {
21-
hour12: true,
22-
timeStyle: "medium",
23-
});
24-
25-
console.log(`[${time}] `, "Experimental Users sent");
20+
log("Experimental Users sent");
2621
});
2722

2823
router.get("/roles", async (req, res) => {
@@ -34,12 +29,7 @@ router.get("/roles", async (req, res) => {
3429
await client.guilds.cache.get(req.query.server.trim())?.roles.fetch()
3530
);
3631

37-
const time = new Date().toLocaleTimeString("en-US", {
38-
hour12: true,
39-
timeStyle: "medium",
40-
});
41-
42-
console.log(`[${time}] `, "Experimental Roles sent");
32+
log("Experimental Roles sent");
4333
});
4434

4535
router.get("/web", async (req, res) => {
@@ -109,12 +99,7 @@ router.get("/web", async (req, res) => {
10999

110100
res.send(data);
111101

112-
const time = new Date().toLocaleTimeString("en-US", {
113-
hour12: true,
114-
timeStyle: "medium",
115-
});
116-
117-
console.log(`[${time}] `, "Experimental Roles sent");
102+
log("Experimental Roles sent");
118103
});
119104

120105
export default router;

src/commands/context/emoji.ts

-2
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@ export default command(meta, async ({ interaction }) => {
2222
const emojiRegex = /(<:|<a:)([a-zA-Z]+)(:)(\d+)(>)/;
2323
const match = emojiRegex.exec(Interaction.targetMessage?.content || "");
2424

25-
console.log(match);
26-
2725
if (match?.[1] === "<a:") {
2826
interaction.reply({
2927
content: `https://cdn.discordapp.com/emojis/${match?.[4]}.gif`,

src/commands/context/itt.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { ApplicationCommandType, ContextMenuCommandBuilder } from "discord.js";
22
import type { MessageContextMenuCommandInteraction } from "discord.js";
3-
import { command } from "utils";
3+
import { command, log } from "utils";
44
import Tesseract from "tesseract.js";
55
import client from "prom-client";
66

@@ -26,7 +26,7 @@ export default command(meta, async ({ interaction }) => {
2626
const attachment = attachement.first();
2727
if (attachment?.contentType?.startsWith("image")) {
2828
Tesseract.recognize(attachment.url, "eng").then(({ data: { text } }) => {
29-
console.log(text);
29+
log(text);
3030
});
3131
}
3232
}

src/commands/misc/servers.ts

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { PermissionFlagsBits, SlashCommandBuilder } from "discord.js";
2-
import { command } from "utils";
2+
import { command, log } from "utils";
33
import client from "prom-client";
44

55
const gauge = new client.Counter({
@@ -14,7 +14,11 @@ const meta = new SlashCommandBuilder()
1414

1515
export default command(meta, async ({ interaction, client }) => {
1616
gauge.inc(1);
17-
const Servers = [...client.guilds.cache.map((g) => g.id)];
18-
console.log(Servers);
17+
const Servers = [...client.guilds.cache.map((g) => g)];
18+
19+
Servers.forEach((server) => {
20+
log(server)
21+
});
22+
1923
interaction.reply({ content: "dev", ephemeral: true });
2024
});

src/events/help/image.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
import { event } from "utils";
1+
import { event, log } from "utils";
22
import { createWorker } from "tesseract.js";
33

4-
export default event("messageCreate", async ({ log, client }, Message) => {
4+
export default event("messageCreate", async ({ client }, Message) => {
55
try {
66
if (Message.attachments.size > 0) {
77
const worker = await createWorker("eng");
88

99
const attachment = Message.attachments.first();
1010
if (attachment?.contentType?.startsWith("image")) {
1111
worker.recognize(attachment.url).then(({ data: { text } }) => {
12-
console.log(text);
12+
log(text);
1313
});
1414
}
1515
}

src/events/index.ts

-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import guildjoin from "./util/guildJoin";
2121

2222
const productionEvents: Event<any>[] = [
2323
ready,
24-
quote,
2524
guildjoin,
2625
interactionCreate,
2726
];

src/events/util/ready.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { event } from "utils";
22

33
export default event("ready", async ({ log }, client) => {
44
process.on("uncaughtException", (error) => {
5-
console.log(`uncaughtException: ${error} `);
5+
log(`uncaughtException: ${error} `);
66
});
77

88
log(

src/index.ts

+3-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Client, GatewayIntentBits, ActivityType, Partials } from "discord.js";
2-
import { registerEvents, apiToken, envCheck } from "utils";
2+
import { registerEvents, apiToken, envCheck, log } from "utils";
33
import events from "botevents";
44
import keys from "keys";
55
import process from "node:process";
@@ -17,10 +17,6 @@ import fs from "fs";
1717

1818
envCheck();
1919

20-
const time = new Date().toLocaleTimeString("en-US", {
21-
hour12: true,
22-
timeStyle: "medium",
23-
});
2420

2521
const client = new Client({
2622
shards: "auto",
@@ -94,10 +90,10 @@ client.on("ready", () => {
9490
const httpsServer = https.createServer(credentials, app);
9591

9692
httpServer.listen(8080, () => {
97-
console.log(`[${time}] `, "HTTP API started and is running on port 8080");
93+
log("HTTP API started and is running on port 8080");
9894
});
9995

10096
httpsServer.listen(8443, () => {
101-
console.log(`[${time}] `, "HTTPS API started and is running on port 8443");
97+
log("HTTPS API started and is running on port 8443");
10298
});
10399
});

src/scripts/deploy.ts

+9-8
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
1-
import { REST, Routes, APIUser } from 'discord.js';
2-
import commands from 'commands';
3-
import keys from 'keys';
1+
import { REST, Routes, APIUser } from "discord.js";
2+
import commands from "commands";
3+
import keys from "keys";
4+
import { log } from "utils";
45

56
const body = commands
67
.map(({ commands }) => commands.map(({ meta }) => meta))
78
.flat();
89

9-
const rest = new REST({ version: '10' }).setToken(keys.clientToken);
10+
const rest = new REST({ version: "10" }).setToken(keys.clientToken);
1011

1112
async function main() {
1213
const currentUser = (await rest.get(Routes.user())) as APIUser;
1314

1415
const endpoint =
15-
process.env.NODE_ENV === 'production'
16+
process.env.NODE_ENV === "production"
1617
? Routes.applicationCommands(currentUser.id)
1718
: Routes.applicationGuildCommands(currentUser.id, keys.guild);
1819

@@ -22,13 +23,13 @@ async function main() {
2223
}
2324

2425
main()
25-
.then(user => {
26+
.then((user) => {
2627
const tag = `${user.username}#${user.discriminator}`;
2728
const response =
28-
process.env.NODE_ENV === 'production'
29+
process.env.NODE_ENV === "production"
2930
? `Successfully released commands in production as ${tag}!`
3031
: `Successfully registered commands for development in ${keys.guild} as ${tag}`;
3132

32-
console.log(response);
33+
log(response);
3334
})
3435
.catch(console.error);

src/utils/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ export * from "./envCheck";
66
export * from "./apiToken";
77
export * from "./prismaUpsert";
88
export * from "./prismaClient";
9+
export * from "./logging";

src/utils/logging.ts

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
const time = new Date().toLocaleTimeString("en-US", {
2+
hour12: true,
3+
timeStyle: "medium",
4+
});
5+
6+
export function log(message: any) {
7+
console.log(`[${time}] `, message);
8+
}

0 commit comments

Comments
 (0)