Skip to content
This repository has been archived by the owner on Oct 12, 2024. It is now read-only.

Commit

Permalink
Client: Initial client code
Browse files Browse the repository at this point in the history
  • Loading branch information
RadiatedExodus committed Feb 11, 2024
1 parent eb63248 commit 11e5ab8
Show file tree
Hide file tree
Showing 5 changed files with 951 additions and 11 deletions.
4 changes: 3 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
METEORIUM_POSTGRES_URL=
METEORIUM_BOT_TOKEN=
METEORIUM_APPLICATION_ID=
METEORIUM_HOLODEX_TOKEN=
METEORIUM_HOLODEX_APIKEY=
METEORIUM_GENIUS_APIKEY=
METEORIUM_APPDEPLOY_GUILDIDS=
METEORIUM_RUNTIMELOG_CHANNELIDS=
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
"chalk": "^5.3.0",
"discord.js": "^14.14.1",
"dotenv": "^16.4.2",
"moment": "^2.30.1"
"holodex.js": "^2.0.5",
"moment": "^2.30.1",
"noblox.js": "^4.15.1"
}
}
31 changes: 31 additions & 0 deletions src/classes/client.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { Client } from "discord.js";
import { config } from "dotenv";
import { PrismaClient } from "@prisma/client";
import { HolodexApiClient } from "holodex.js";

import Logging from "./logging.js";

function parseDotEnvConfig() {
if (!process.env.METEORIUM_BOT_TOKEN) config();
return {
BotToken: String(process.env.METEORIUM_BOT_TOKEN),
ApplicationId: String(process.env.METEORIUM_APPLICATION_ID),
HolodexApiKey: String(process.env.METEORIUM_HOLODEX_APIKEY),
GeniusApiKey: String(process.env.METEORIUM_GENIUS_APIKEY),
ApplicationDeployGuildIds: String(process.env.METEORIUM_APPDEPLOY_GUILDIDS).split(","),
RuntimeLogChannelIds: String(process.env.METEORIUM_RUNTIMELOG_CHANNELIDS).split(","),
};
}

export default class MeteoriumClient extends Client<true> {
public logging = new Logging("Meteorium");
public config = parseDotEnvConfig();
public db = new PrismaClient();
public holodex = new HolodexApiClient({ apiKey: this.config.HolodexApiKey });

public async login() {
const loginNS = this.logging.getNamespace("Login");
loginNS.info("Logging in to Discord");
return super.login(this.config.BotToken);
}
}
17 changes: 13 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
import Logging from "./classes/logging.js";
import MeteoriumClient from "./classes/client.js";
import { IntentsBitField } from "discord.js";

const logging = new Logging("Meteorium");
const mainNS = logging.registerNamespace("Main");
mainNS.info("Hello, world!");
const client = new MeteoriumClient({
intents: [
IntentsBitField.Flags.Guilds,
IntentsBitField.Flags.GuildMembers,
IntentsBitField.Flags.GuildMessages,
IntentsBitField.Flags.GuildModeration,
IntentsBitField.Flags.GuildVoiceStates,
],
});

await client.login();
Loading

0 comments on commit 11e5ab8

Please sign in to comment.