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

Commit

Permalink
Merge pull request #30 from RealEthanPlayzDev/rewrite
Browse files Browse the repository at this point in the history
v3
  • Loading branch information
RealEthanPlayzDev authored Apr 26, 2024
2 parents 16f7613 + 5ea7912 commit 5e7d290
Show file tree
Hide file tree
Showing 91 changed files with 3,244 additions and 6,571 deletions.
7 changes: 7 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[*]
charset = utf-8
insert_final_newline = true
end_of_line = lf
indent_style = space
indent_size = 4
max_line_length = 150
8 changes: 8 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
METEORIUM_POSTGRES_URL=
METEORIUM_BOT_TOKEN=
METEORIUM_APPLICATION_ID=
METEORIUM_HOLODEX_APIKEY=
METEORIUM_GENIUS_APIKEY=
METEORIUM_APPDEPLOY_GUILDIDS=
METEORIUM_RUNTIMELOG_CHANNELIDS=
METEORIUM_NOREG_TESTINTERACTIONS=
8 changes: 5 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
config.json
# Compile deps and results
node_modules
.ENV
dist
dist

# Configuration files
.env
4 changes: 3 additions & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,7 @@
"semi": true,
"singleQuote": false,
"useTabs": false,
"printWidth": 120
"printWidth": 120,
"endOfLine": "lf",
"trailingComma": "all"
}
3 changes: 3 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"recommendations": ["EditorConfig.EditorConfig", "esbenp.prettier-vscode", "mikestead.dotenv", "prisma.prisma"]
}
14 changes: 14 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "Build",
"type": "shell",
"command": "yarn compile",
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
693 changes: 19 additions & 674 deletions LICENSE

Large diffs are not rendered by default.

54 changes: 20 additions & 34 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,28 @@
# Meteorium

A Discord bot developed by RadiatedExodus (RealEthanPlayzDev) as a side (and personal) project, written in Javascript using Node.js and Discord.js, also being used as a way for me to learn JavaScript and TypeScript.
This is a hobby Discord bot I've written, the bot is only used for a few servers.
Feel free to look around, make suggestion, and report bugs.

Since the ts rewrite, some of the source might ressemble [PojavBot](https://github.com/PojavLauncherTeam/PojavBot) as I took several references from there.

## UNSTABLE - THIS IS A FULL REWRITE
## FULL REWRITE (v3)

This branch is a full rewrite, not all features have been implemented!

## Feature parity with v2

- [*] Moderation
- [ ] Music
- [ ] Info
- [ ] HolodexAPI
- [ ] MojangAPI
- [ ] RbxAPI
- [ ] ServerInfo
- [ ] UserInfo
- [ ] Tag
- [ ] Ping

## Installing required dependencies

Ensure `yarn` is installed (`npm install --global yarn`), then just run it at the root of the repository
Meteorium uses `yarn` to manage Node packages. Ensure `yarn` is installed (`npm install --global yarn`), then just run it at the root of the repository

```
yarn
Expand All @@ -33,34 +45,8 @@ yarn start

## Configuration file

The configuration file uses `dotenv`, create a file named ".ENV" on the project root and use the following example:

```
METEORIUMBOTTOKEN=bot_token_here
METEORIUMPOSTGRESURL=postgres_url_here
METEORIUMHOLODEXTOKEN=holodex_token_here_optional
METEORIUMAPPLICATIONID=bot_app_id_here
RATELIMITMAXLIMIT=rate_limit_maximum_limit_before_nodejs_terminates_PUT_A_NUMBER_HERE
RATELIMITMAXLIMITTIME=after_when_should_ratelimit_reset_PUT_A_NUMBER_HERE
DEPLOYGUILDIDS=guildids_for_deployment_seperated_by,commas,and_so_on
GENIUSAPIKEY=genius_api_key_here
```

## Credits

- [discord.js](https://github.com/discordjs/discord.js)
- [holodex.js](https://github.com/HolodexNet/holodex.js)
- [noblox.js](https://github.com/noblox/noblox.js)
- [Prisma](https://www.prisma.io)
- [dotenv](https://github.com/motdotla/dotenv)
See the `.env.example`

## Acknowledgements
## Special thanks

- All discord.js contributors and authors
- All holodex.js contributors and authors
- All noblox.js contributors and authors
- All mongodb contributors and authors
- All dotenv contributors and authors
- All Prisma contributors and authors
- All PostgreSQL contributors and authors
- Syjalo
- [@Abdelrahmanwalidhassan's `ms` fork](https://github.com/Abdelrahmanwalidhassan/ms)
40 changes: 18 additions & 22 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,47 +1,43 @@
{
"name": "meteorium",
"version": "2.0.0",
"description": "A Discord bot created by RadiatedExodus as a hobby project.",
"version": "3.0.0",
"description": "RadiatedExodus's hobby Discord bot project, built with TypeScript, Prisma, and DiscordJS.",
"main": "dist/index.js",
"type": "module",
"scripts": {
"compile": "tsc",
"start": "node --enable-source-maps --es-module-specifier-resolution=node ."
"start": "node dist",
"installUtils:fillMissingGuildData": "node ./dist/installUtils/fillMissingGuildData.js",
"installUtils:enableGuildFeature": "node ./dist/installUtils/enableGuildFeature.js"
},
"repository": {
"type": "git",
"url": "git+https://github.com/RealEthanPlayzDev/Meteorium.git"
},
"author": "RadiatedExodus",
"license": "GPL-3.0",
"license": "MIT",
"bugs": {
"url": "https://github.com/RealEthanPlayzDev/Meteorium/issues"
},
"homepage": "https://github.com/RealEthanPlayzDev/Meteorium#readme",
"homepage": "https://github.com/RealEthanPlayzDev/Meteorium",
"devDependencies": {
"prettier": "3.0.3",
"prisma": "^5.2.0",
"typescript": "^5.1.6"
"@types/node": "^20.11.17",
"prettier": "^3.2.5",
"prisma": "^5.9.1",
"typescript": "^5.3.3"
},
"dependencies": {
"@discord-player/extractor": "^4.4.6",
"@discordjs/opus": "^0.9.0",
"@discordjs/voice": "^0.16.1",
"@prisma/client": "^5.9.1",
"@types/ms": "^0.7.32",
"axios": "^1.6.3",
"chalk": "4.0.0",
"discord-player": "^6.6.7",
"bufferutil": "^4.0.8",
"chalk": "^5.3.0",
"discord.js": "^14.14.1",
"dotenv": "^16.0.3",
"dotenv": "^16.4.2",
"holodex.js": "^2.0.5",
"libsodium-wrappers": "^0.7.10",
"moment": "^2.29.4",
"ms": "^2.1.3",
"moment": "^2.30.1",
"noblox.js": "^4.15.1",
"play-dl": "^1.9.7",
"soundcloud-scraper": "^5.0.3",
"spotify-url-info": "^3.2.13",
"youtube-sr": "^4.3.10",
"ytdl-core": "^4.11.5"
"utf-8-validate": "^6.0.3",
"zlib-sync": "^0.1.9"
}
}
78 changes: 48 additions & 30 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,7 @@ generator client {

datasource db {
provider = "postgresql"
url = env("METEORIUMPOSTGRESURL")
}

model Guild {
GuildId String @unique
EnforceSayInExecutor Boolean @default(false)
DisabledCommands String[] @default([])
DisabledCommandCategories String[] @default([])
PublicModLogChannelId String @default("")
LoggingChannelId String @default("")
JoinLeaveLogChannelId String @default("")
CurrentCaseId Int @default(0)
BanAppealLink String @default("")
url = env("METEORIUM_POSTGRES_URL")
}

enum ModerationAction {
Expand All @@ -31,49 +19,79 @@ enum ModerationAction {
Unban
}

enum GuildFeatures {
Moderation
UserVerification
Tags
Music
DiscordInfo
HolodexAPI
MojangAPI
RobloxAPI
}

model Guild {
GuildId String @unique
EnforceSayInExecutor Boolean @default(false)
JoinLeaveLogChannelId String @default("")
PublicModLogChannelId String @default("")
LoggingChannelId String @default("")
BanAppealLink String @default("")
EnabledGuildFeatures GuildFeatures[]
ModerationCase ModerationCase[]
Tag Tag[]
}

model ModerationCase {
GlobalCaseId Int @id @default(autoincrement())
Guild Guild @relation(fields: [GuildId], references: [GuildId], onDelete: Cascade)
GuildId String
CaseId Int
Action ModerationAction
TargetUserId String
ModeratorUserId String
GuildId String
Reason String
AttachmentProof String
AttachmentProof String @default("")
Duration String @default("0")
CreatedAt DateTime @default(now())
ModeratorNote String @default("")
ModeratorAttachment String @default("")
NotAppealable Boolean @default(false)
Active Boolean @default(true) // Used in ban
RelatedCaseId Int @default(-1) // Used in ban, does NOT use GlobalCaseId
PublicModLogMsgId String @default("")
CreatedAt DateTime @default(now())
ActiveTempBans ActiveTempBans[]
ModerationCaseHistory ModerationCaseHistory[]
}
model Tag {
GlobalTagId Int @id @default(autoincrement())
TagName String
GuildId String
Content String
Image String
}

model ActiveTempBans {
ActiveTempBanId Int @id @default(autoincrement())
GlobalCaseId Int
Case ModerationCase @relation(fields: [GlobalCaseId], references: [GlobalCaseId], onDelete: Cascade)
@@unique(name: "UniqueCaseIdPerGuild", fields: [GuildId, CaseId])
}

model ModerationCaseHistory {
ModerationCaseHistoryId Int @id @default(autoincrement())
ModerationCase ModerationCase @relation(fields: [GlobalCaseId], references: [GlobalCaseId], onDelete: Cascade)
GlobalCaseId Int
EditedAt DateTime @default(now())
Editor String
EditorUserId String
Reason String?
AttachmentProof String?
Duration String?
ModeratorNote String?
ModeratorAttachment String?
NotAppealable Boolean?
Removed Boolean?
}

model ActiveTempBans {
ActiveTempBanId Int @id @default(autoincrement())
GlobalCaseId Int @unique
Case ModerationCase @relation(fields: [GlobalCaseId], references: [GlobalCaseId], onDelete: Cascade)
}

model Tag {
GlobalTagId Int @id @default(autoincrement())
Guild Guild @relation(fields: [GuildId], references: [GuildId], onDelete: Cascade)
GuildId String
TagName String
Content String
Attachment String @default("")
}
63 changes: 63 additions & 0 deletions src/classes/client.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import { Client, ClientOptions } from "discord.js";
import { config } from "dotenv";
import { PrismaClient } from "@prisma/client";
import { HolodexApiClient } from "holodex.js";

import Logging from "./logging.js";
import MeteoriumInteractionManager from "../interactions/index.js";
import MeteoriumEventManager from "../events/index.js";
import MeteoriumDatabaseUtilities from "./dbUtils.js";
import MeteoriumGuildFeatureManager from "./guildFeatureManager.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(","),
DontRegisterTestInteractions: Boolean(process.env.METEORIUM_NOREG_TESTINTERACTIONS),
};
}

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

public constructor(options: ClientOptions) {
super(options);

// Register all events and hook them
this.events.register();

// Register all interactions
this.interactions.registerAllInteractions();

return this;
}

public async login() {
const loginNS = this.logging.getNamespace("Login");

// Hook events
this.events.hook();

// Login
loginNS.info("Logging in to Discord");
return super.login(this.config.BotToken);
}

public async destroy() {
await super.destroy();
await this.db.$disconnect();
return;
}
}
Loading

0 comments on commit 5e7d290

Please sign in to comment.