This repository has been archived by the owner on Jan 26, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added c-client and logging system |
v1.0.1-beta
- Loading branch information
CrawlTheDev
committed
May 29, 2021
1 parent
a2c421a
commit a521513
Showing
14 changed files
with
527 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}`); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { CustomClient } from './custom-client/custom-client'; |
Oops, something went wrong.