Skip to content

Commit 4772188

Browse files
Merge pull request #2 from discord-typescript/develop
Merge - Develop Welcome, Help, Status update
2 parents 94defd7 + b1bc5e9 commit 4772188

File tree

8 files changed

+140
-15
lines changed

8 files changed

+140
-15
lines changed

src/Starter.discord.ts

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Discord, Description, On, ArgsOf } from "@typeit/discord";
1+
import { Discord, Description, On, ArgsOf, Client } from "@typeit/discord";
22
import { Logger } from "./services/logger.service";
33
import * as chalk from "chalk";
44
import * as Path from "path";
@@ -23,14 +23,17 @@ export abstract class Starter {
2323
* When bot has logged in output bot is ready.
2424
*/
2525
@On("ready")
26-
initialize(): void {
26+
// eslint-disable-next-line no-empty-pattern
27+
initialize([]: ArgsOf<"ready">, client: Client): void {
2728
this.logger.info("info check");
2829
this.logger.warn("warning check");
2930
this.logger.error("error check");
3031
this.logger.info(chalk.bold("BOT READY"));
3132
this.logger.info(Path.join(__dirname, "commands", "*.ts"));
3233
this.logger.info(Path.join(__dirname, "guild", "*.ts"));
3334
this.logger.info(Path.join(__dirname, "member", "*.ts"));
35+
36+
this.changeStatus(client);
3437
}
3538

3639
/**
@@ -43,8 +46,21 @@ export abstract class Starter {
4346
this.logger.error(`${chalk.bold("BOT ERROR")}: ${error}`);
4447
}
4548

46-
// @On("raw")
47-
// async onEvent(event: any): Promise<any> {
48-
49-
// }
49+
changeStatus(client: Client): void {
50+
let status = 3;
51+
const activities = [
52+
'https://discord.js.org/',
53+
'?help',
54+
'https://github.com/OwenCalvin/discord.ts',
55+
'',
56+
'https://www.npmjs.com/package/@typeit/discord',
57+
'?docs',
58+
];
59+
setInterval(() => {
60+
client.user.setActivity(activities[status]);
61+
this.logger.info(`Set status to : ${activities[status]}`);
62+
status = Math.floor(Math.random() * activities.length);
63+
}, 60000 * 15);
64+
}
65+
5066
}

src/commands/docs.command.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { Logger } from "../services/logger.service";
88

99
export abstract class Docs {
1010

11-
logger = Logger.prototype.getInstance();
11+
logger = Logger.prototype.getInstance();
1212

1313
/**
1414
* @name docs
@@ -32,8 +32,10 @@ export abstract class Docs {
3232
.setThumbnail(IMAGE.ICON)
3333
.setFooter("Clicking the blue text will take you to the docs.");
3434

35-
command.reply({ embed }).then((messageSent) => {
35+
command.channel.send({ embed }).then((messageSent) => {
3636
this.logger.info(`Sent Docs : message id ${messageSent.id}`);
37+
}).catch((error) => {
38+
this.logger.error('Docs message : error', error);
3739
});
3840
}
3941
}

src/commands/help.command.ts

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import { Command, CommandMessage, Guard } from "@typeit/discord";
2+
import { MessageEmbed } from "discord.js";
3+
import { COLOR } from "../enums/colors.enum";
4+
import { IMAGE } from "../enums/images.enum";
5+
import { NotBot } from "../guards/NotABot.guard";
6+
import { Logger } from "../services/logger.service";
7+
8+
export abstract class Help {
9+
10+
logger = Logger.prototype.getInstance();
11+
12+
/**
13+
* @name help
14+
* @param command
15+
* object is command message from the author.
16+
* @description
17+
* Sends the list of commands as a dm to the author.
18+
*/
19+
@Command("help")
20+
@Guard(NotBot)
21+
async help(command: CommandMessage): Promise<void> {
22+
this.logger.info("Sending Help");
23+
24+
const embed = new MessageEmbed();
25+
embed
26+
.setTitle(`Discord.TS Help`)
27+
.setDescription(
28+
`Here is a list of my available commands.\n**Prefix the command with** \`?\`**.**\nEx. \`?docs\``
29+
)
30+
.addField('docs', 'Provides a link to the __Discord TS__ and __Discord JS__ Documentation.')
31+
.addField('help', 'Sends this list of my commands to the author.')
32+
.addField('shard', 'Sends the __Discord TS__ and __Discord JS__ guides for sharding.')
33+
.setColor(COLOR.BLUE)
34+
.setThumbnail(IMAGE.ICON);
35+
36+
command.author.send({ embed }).then((messageSent) => {
37+
this.logger.info(`Sent Help : message id ${messageSent.id}`);
38+
}).catch((error) => {
39+
this.logger.error('Help DM : error', error);
40+
});
41+
}
42+
}

src/commands/shard.command.ts

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import { Command, CommandMessage, Guard } from "@typeit/discord";
2+
import { MessageEmbed } from "discord.js";
3+
import { COLOR } from "../enums/colors.enum";
4+
import { IMAGE } from "../enums/images.enum";
5+
import { LINK } from "../enums/links.enum";
6+
import { NotBot } from "../guards/NotABot.guard";
7+
import { Logger } from "../services/logger.service";
8+
9+
export abstract class Help {
10+
11+
logger = Logger.prototype.getInstance();
12+
13+
/**
14+
* @name shard
15+
* @param command
16+
* object is command message from the author.
17+
* @description
18+
* Sends the Discord.TS & Discord.JS Documentation link for sharding.
19+
*/
20+
@Command("shard")
21+
@Guard(NotBot)
22+
async shard(command: CommandMessage): Promise<void> {
23+
this.logger.info("Sending Sharding Docs");
24+
25+
const embed = new MessageEmbed();
26+
embed
27+
.setTitle(`Discord.TS Sharding`)
28+
.setURL(LINK.SHARDING_GUIDE)
29+
.setDescription(
30+
`If you are in **2,000** guilds and your bot compiles with **tsc** sharding is possible!\n` +
31+
`Click the title to see the guide!\n` +
32+
`Please read [discord.js sharding guide](${LINK.DISCORD_JS_SHARDING}) as well.`
33+
)
34+
.setColor(COLOR.BLUE)
35+
.setThumbnail(IMAGE.ICON);
36+
37+
command.channel.send({ embed }).then((messageSent) => {
38+
this.logger.info(`Sent Sharding Docs : message id ${messageSent.id}`);
39+
}).catch((error) => {
40+
this.logger.error('Sharding Docs message : error', error);
41+
});
42+
}
43+
}

src/enums/id.enum.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
export enum ID {
22
MEMBER_ROLE = "705440257428160573",
33
SERVER = "693401527494377482",
4+
RULES_CHANNEL = "784689736161689600",
5+
INFO_CHANNEL = "705567608031805521"
46
}

src/enums/links.enum.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ export enum LINK {
33
SIMPLE_STARTER_README = "https://github.com/OwenCalvin/discord.ts/tree/master/starter-projects/simple-bot#simple-bot",
44
SIMPLE_STARTER_DOWNLOAD = "https://github.com/OwenCalvin/discord.ts/raw/master/starter-projects/simple-bot/SimpleBot.zip",
55

6+
SHARDING_GUIDE = "https://github.com/OwenCalvin/discord.ts/blob/master/guides/sharding.md",
7+
DISCORD_JS_SHARDING = "https://discordjs.guide/sharding/#when-to-shard",
8+
69
DISCORD_JS_DOCS = "https://discord.js.org/?source=post_page---------------------------#/docs/main/stable/general/welcome",
710

811
INVITE_LINK = "https://discord.gg/VDjwu8E",

src/member/member-events.discord.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { Description, On, ArgsOf } from "@typeit/discord";
2-
import { Role } from "discord.js";
2+
import { MessageEmbed, Role } from "discord.js";
3+
import { COLOR } from "../enums/colors.enum";
34
import { ID } from "../enums/id.enum";
5+
import { IMAGE } from "../enums/images.enum";
46
import { Logger } from "../services/logger.service";
57

68
@Description("Discord Member Event Handlers")
@@ -32,5 +34,20 @@ export abstract class MemberEvents {
3234
this.logger.error(`Failed to put member role on ${member.id}`);
3335
});
3436
});
37+
38+
const embed = new MessageEmbed();
39+
embed
40+
.setTitle(`Welcome to Discord.TS`)
41+
.setDescription(
42+
`Hello ${member}, Please take a look at <#${ID.RULES_CHANNEL}> and <#${ID.INFO_CHANNEL}>!\n` +
43+
`If you have a question related to **Discord.TS** ask in one of the Help channels.`
44+
)
45+
.setColor(COLOR.BLUE)
46+
.setThumbnail(IMAGE.ICON);
47+
member.send({ embed }).then((messageSent) => {
48+
this.logger.info(`Sent Welcome : message id ${messageSent.id}`);
49+
}).catch((error) => {
50+
this.logger.error('Welcome DM : error', error);
51+
});
3552
}
3653
}

src/services/logger.service.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@ export class Logger {
44

55
private static logger: Logger;
66

7-
info(message: string): void {
8-
console.log(chalk.bgCyan(`✔ ${Date.now()} : `, chalk.underline(message)));
7+
info(...message: unknown[]): void {
8+
console.log(chalk.bgCyan(`✔ ${Date.now()} :`, chalk.underline(message)));
99
}
1010

11-
warn(message: string): void {
12-
console.log(chalk.bgYellow(chalk.black(`⚠ ${Date.now()} : `, chalk.underline(message))));
11+
warn(...message: unknown[]): void {
12+
console.log(chalk.bgYellow(chalk.black(`⚠ ${Date.now()} :`, chalk.underline(message))));
1313
}
1414

15-
error(message: string): void {
16-
console.log(chalk.bgRed(`⛔ ${Date.now()} : `, chalk.underline(message)));
15+
error(...message: unknown[]): void {
16+
console.log(chalk.bgRed(`⛔ ${Date.now()} :`, chalk.underline(message)));
1717
}
1818

1919
getInstance(): Logger {

0 commit comments

Comments
 (0)