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

Commit

Permalink
Added c-client and logging system | v1.0.1-beta
Browse files Browse the repository at this point in the history
  • Loading branch information
CrawlTheDev committed May 29, 2021
1 parent a2c421a commit a521513
Show file tree
Hide file tree
Showing 14 changed files with 527 additions and 70 deletions.
5 changes: 4 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
"prettier"
],
"rules": {
"prettier/prettier": 2 // Means error
"@typescript-eslint/no-non-null-assertion": 0,
"@typescript-eslint/no-explicit-any": 0,
"@typescript-eslint/explicit-module-boundary-types": 0,
"prettier/prettier": 2
}
}
132 changes: 130 additions & 2 deletions package-lock.json

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

6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pbot-plus/bot",
"version": "1.0.0-beta",
"version": "1.0.1-beta",
"description": "A multi-purpose Discord bot with Typescript",
"main": "src/main.ts",
"scripts": {
Expand All @@ -24,12 +24,16 @@
},
"devDependencies": {
"@types/node": "^15.6.1",
"@types/node-fetch": "^2.5.10",
"@typescript-eslint/eslint-plugin": "^4.25.0",
"@typescript-eslint/parser": "^4.25.0",
"eslint": "^7.27.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-prettier": "^3.4.0",
"prettier": "^2.3.0",
"typescript": "^4.3.2"
},
"dependencies": {
"discord.js-light": "^3.5.11"
}
}
75 changes: 75 additions & 0 deletions src/bot.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import { Client, Constants, Message, MessageEmbed } from 'discord.js-light';

import { ILogger, Logger, Config } from './services';

export default class PbotPlus {
/**
* Custom logger for Pbot-plus
*/
public logger: ILogger = Logger;

/**
* Configuration files for Pbot-plus
*/
public readonly config = Config;

/**
* @param client Client
*/
constructor(private client: Client) {}

/**
* Initialize the bot
*/
public async initialize(): Promise<void> {
try {
this.registerListeners();
await this.client.login(this.config.client.token);
} catch (err) {
this.logger.error('Failed while initializing to the bot', err);
}
}

/**
* Register listeners
*/
private registerListeners(): void {
// on message
this.client.on(Constants.Events.MESSAGE_CREATE, (message: Message) =>
this.onMessage(message)
);

// on ready
this.client.on(Constants.Events.CLIENT_READY, () => this.onReady());
}

/**
* On message
* @param message
* @returns
*/
private onMessage(message: Message): void {
if (message.author.bot ?? !message.guild?.member) return;

const DevelopingErrorEmbed = new MessageEmbed({
color: this.config.color.error,
description:
'I am currently under development so only my developers can use my commands'
});

if (
message.content.match(new RegExp(`^<@!?${this.client.user?.id}>( |)$`))
) {
message.channel.send(DevelopingErrorEmbed);
} else if (message.content.startsWith(this.config.client.prefix)) {
message.channel.send(DevelopingErrorEmbed);
}
}

/**
* On ready
*/
private onReady(): void {
this.logger.info(`Signed in as ${this.client.user?.tag}`);
}
}
26 changes: 26 additions & 0 deletions src/extensions/custom-client/custom-client.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import {
ActivityType,
Client,
ClientOptions,
Presence
} from 'discord.js-light';

export class CustomClient extends Client {
constructor(clientOptions: ClientOptions) {
super(clientOptions);
}

public async setPresence(
type: ActivityType,
name: string,
url: string
): Promise<Presence> {
return await this.user!.setPresence({
activity: {
type,
name,
url
}
});
}
}
1 change: 1 addition & 0 deletions src/extensions/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { CustomClient } from './custom-client/custom-client';
Loading

0 comments on commit a521513

Please sign in to comment.