Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 22 additions & 6 deletions src/Starter.discord.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Discord, Description, On, ArgsOf } from "@typeit/discord";
import { Discord, Description, On, ArgsOf, Client } from "@typeit/discord";
import { Logger } from "./services/logger.service";
import * as chalk from "chalk";
import * as Path from "path";
Expand All @@ -23,14 +23,17 @@ export abstract class Starter {
* When bot has logged in output bot is ready.
*/
@On("ready")
initialize(): void {
// eslint-disable-next-line no-empty-pattern
initialize([]: ArgsOf<"ready">, client: Client): void {
this.logger.info("info check");
this.logger.warn("warning check");
this.logger.error("error check");
this.logger.info(chalk.bold("BOT READY"));
this.logger.info(Path.join(__dirname, "commands", "*.ts"));
this.logger.info(Path.join(__dirname, "guild", "*.ts"));
this.logger.info(Path.join(__dirname, "member", "*.ts"));

this.changeStatus(client);
}

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

// @On("raw")
// async onEvent(event: any): Promise<any> {

// }
changeStatus(client: Client): void {
let status = 3;
const activities = [
'https://discord.js.org/',
'?help',
'https://github.com/OwenCalvin/discord.ts',
'',
'https://www.npmjs.com/package/@typeit/discord',
'?docs',
];
setInterval(() => {
client.user.setActivity(activities[status]);
this.logger.info(`Set status to : ${activities[status]}`);
status = Math.floor(Math.random() * activities.length);
}, 60000 * 15);
}

}
6 changes: 4 additions & 2 deletions src/commands/docs.command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { Logger } from "../services/logger.service";

export abstract class Docs {

logger = Logger.prototype.getInstance();
logger = Logger.prototype.getInstance();

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

command.reply({ embed }).then((messageSent) => {
command.channel.send({ embed }).then((messageSent) => {
this.logger.info(`Sent Docs : message id ${messageSent.id}`);
}).catch((error) => {
this.logger.error('Docs message : error', error);
});
}
}
42 changes: 42 additions & 0 deletions src/commands/help.command.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { Command, CommandMessage, Guard } from "@typeit/discord";
import { MessageEmbed } from "discord.js";
import { COLOR } from "../enums/colors.enum";
import { IMAGE } from "../enums/images.enum";
import { NotBot } from "../guards/NotABot.guard";
import { Logger } from "../services/logger.service";

export abstract class Help {

logger = Logger.prototype.getInstance();

/**
* @name help
* @param command
* object is command message from the author.
* @description
* Sends the list of commands as a dm to the author.
*/
@Command("help")
@Guard(NotBot)
async help(command: CommandMessage): Promise<void> {
this.logger.info("Sending Help");

const embed = new MessageEmbed();
embed
.setTitle(`Discord.TS Help`)
.setDescription(
`Here is a list of my available commands.\n**Prefix the command with** \`?\`**.**\nEx. \`?docs\``
)
.addField('docs', 'Provides a link to the __Discord TS__ and __Discord JS__ Documentation.')
.addField('help', 'Sends this list of my commands to the author.')
.addField('shard', 'Sends the __Discord TS__ and __Discord JS__ guides for sharding.')
.setColor(COLOR.BLUE)
.setThumbnail(IMAGE.ICON);

command.author.send({ embed }).then((messageSent) => {
this.logger.info(`Sent Help : message id ${messageSent.id}`);
}).catch((error) => {
this.logger.error('Help DM : error', error);
});
}
}
43 changes: 43 additions & 0 deletions src/commands/shard.command.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { Command, CommandMessage, Guard } from "@typeit/discord";
import { MessageEmbed } from "discord.js";
import { COLOR } from "../enums/colors.enum";
import { IMAGE } from "../enums/images.enum";
import { LINK } from "../enums/links.enum";
import { NotBot } from "../guards/NotABot.guard";
import { Logger } from "../services/logger.service";

export abstract class Help {

logger = Logger.prototype.getInstance();

/**
* @name shard
* @param command
* object is command message from the author.
* @description
* Sends the Discord.TS & Discord.JS Documentation link for sharding.
*/
@Command("shard")
@Guard(NotBot)
async shard(command: CommandMessage): Promise<void> {
this.logger.info("Sending Sharding Docs");

const embed = new MessageEmbed();
embed
.setTitle(`Discord.TS Sharding`)
.setURL(LINK.SHARDING_GUIDE)
.setDescription(
`If you are in **2,000** guilds and your bot compiles with **tsc** sharding is possible!\n` +
`Click the title to see the guide!\n` +
`Please read [discord.js sharding guide](${LINK.DISCORD_JS_SHARDING}) as well.`
)
.setColor(COLOR.BLUE)
.setThumbnail(IMAGE.ICON);

command.channel.send({ embed }).then((messageSent) => {
this.logger.info(`Sent Sharding Docs : message id ${messageSent.id}`);
}).catch((error) => {
this.logger.error('Sharding Docs message : error', error);
});
}
}
2 changes: 2 additions & 0 deletions src/enums/id.enum.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
export enum ID {
MEMBER_ROLE = "705440257428160573",
SERVER = "693401527494377482",
RULES_CHANNEL = "784689736161689600",
INFO_CHANNEL = "705567608031805521"
}
3 changes: 3 additions & 0 deletions src/enums/links.enum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ export enum LINK {
SIMPLE_STARTER_README = "https://github.com/OwenCalvin/discord.ts/tree/master/starter-projects/simple-bot#simple-bot",
SIMPLE_STARTER_DOWNLOAD = "https://github.com/OwenCalvin/discord.ts/raw/master/starter-projects/simple-bot/SimpleBot.zip",

SHARDING_GUIDE = "https://github.com/OwenCalvin/discord.ts/blob/master/guides/sharding.md",
DISCORD_JS_SHARDING = "https://discordjs.guide/sharding/#when-to-shard",

DISCORD_JS_DOCS = "https://discord.js.org/?source=post_page---------------------------#/docs/main/stable/general/welcome",

INVITE_LINK = "https://discord.gg/VDjwu8E",
Expand Down
19 changes: 18 additions & 1 deletion src/member/member-events.discord.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { Description, On, ArgsOf } from "@typeit/discord";
import { Role } from "discord.js";
import { MessageEmbed, Role } from "discord.js";
import { COLOR } from "../enums/colors.enum";
import { ID } from "../enums/id.enum";
import { IMAGE } from "../enums/images.enum";
import { Logger } from "../services/logger.service";

@Description("Discord Member Event Handlers")
Expand Down Expand Up @@ -32,5 +34,20 @@ export abstract class MemberEvents {
this.logger.error(`Failed to put member role on ${member.id}`);
});
});

const embed = new MessageEmbed();
embed
.setTitle(`Welcome to Discord.TS`)
.setDescription(
`Hello ${member}, Please take a look at <#${ID.RULES_CHANNEL}> and <#${ID.INFO_CHANNEL}>!\n` +
`If you have a question related to **Discord.TS** ask in one of the Help channels.`
)
.setColor(COLOR.BLUE)
.setThumbnail(IMAGE.ICON);
member.send({ embed }).then((messageSent) => {
this.logger.info(`Sent Welcome : message id ${messageSent.id}`);
}).catch((error) => {
this.logger.error('Welcome DM : error', error);
});
}
}
12 changes: 6 additions & 6 deletions src/services/logger.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ export class Logger {

private static logger: Logger;

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

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

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

getInstance(): Logger {
Expand Down