From 99daca5fa67ed2c3fe33b9c42711c771e3587518 Mon Sep 17 00:00:00 2001 From: EvolutionX Date: Mon, 14 Feb 2022 13:42:20 +0530 Subject: [PATCH 1/4] added docs for functions in `messageHelpers` --- src/handler/utilities/messageHelpers.ts | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/src/handler/utilities/messageHelpers.ts b/src/handler/utilities/messageHelpers.ts index 85d43cf..f96a9bd 100644 --- a/src/handler/utilities/messageHelpers.ts +++ b/src/handler/utilities/messageHelpers.ts @@ -1,13 +1,30 @@ import type { Message } from 'discord.js'; - +/** + * Checks if the author of message is a bot or not + * ```typescript + * isBot(message) ? 'yes it is a bot' : 'no it is not a bot'; + * ``` + */ export function isBot(message: Message) { return message.author.bot; } - +/** + * Checks if the message **starts** with the prefix + * ```typescript + * hasPrefix(message, '!') ? 'yes it does' : 'no it does not'; + * ``` + */ export function hasPrefix(message: Message, prefix: string) { return message.content.slice(0, prefix.length).toLowerCase().trim() === prefix; } - +/** + * Removes the first character(s) _[depending on prefix length]_ of the message + * ```typescript + * message.content = '!ping'; + * console.log(fmt(message, '!')); + * // [ 'ping' ] + * ``` + */ export function fmt(msg: Message, prefix: string): string[] { return msg.content.slice(prefix.length).trim().split(/\s+/g); } From 9a3e9ed193059889f8f96822f44d92641f2fae0d Mon Sep 17 00:00:00 2001 From: EvolutionX Date: Mon, 14 Feb 2022 22:05:12 +0530 Subject: [PATCH 2/4] updated --- README.md | 86 ++++++++++++++++--------------------------------------- 1 file changed, 25 insertions(+), 61 deletions(-) diff --git a/README.md b/README.md index 3cc05e5..d5e3cbf 100644 --- a/README.md +++ b/README.md @@ -2,9 +2,9 @@ Sern is making easier to create & automate your discord bot with new version compatibility and full customization. -- A reincarnation of [this old project](https://github.com/jacoobes/sern_handler) +- A reincarnation of [this old project](https://github.com/jacoobes/sern_handler) -# Installation +## Installation ```sh npm install sern-handler @@ -16,78 +16,42 @@ yarn add sern-handler # Basic Usage -Typescript +### [Typescript](https://www.typescriptlang.org/) + ```ts -import { Client } from 'discord.js' -import { Intents } from 'discord.js' -import { prefix, token } from "../src/secrets.json" -import { Sern } from "sern-handler" +import { Client } from 'discord.js'; +import { Intents } from 'discord.js'; +import { prefix, token } from '../src/secrets.json'; +import { Sern } from 'sern-handler'; const client = new Client({ - intents: [ - Intents.FLAGS.GUILDS, - Intents.FLAGS.GUILD_MESSAGES, - Intents.FLAGS.GUILD_MEMBERS - ] + intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES, Intents.FLAGS.GUILD_MEMBERS], +}); -}) - - new Sern.Handler( { +new Sern.Handler({ client, prefix, - commands : 'dist/commands', - privateServers : [ + commands: 'dist/commands', // after compiling with tsc + privateServers: [ { - test : true, - id: 'server-id' - } + test: true, + id: 'server id', + }, ], - init: async (handler : Sern.Handler) => { - // Optional function to initialize anything else on bot startup + init: async (handler: Sern.Handler) => { + /* an optional function to initialize anything else on bot startup */ }, }); -``` - -JavaScript -```js -import { Client, Intents } from 'discord.js'; -import { Handler } from 'sern-handler'; -import { prefix, token } from '../src/secrets.json'; - -const client = new Client({ - intents: [ - Intents.FLAGS.GUILDS, - Intents.FLAGS.GUILD_MESSAGES, - Intents.FLAGS.GUILD_MEMBERS - ] -}); - -// Access handler anywhere -client.handler = new Handler({ - client, - prefix, - commands : 'dist/commands', - privateServers : [ - { - test : true, - id: 'server-id' - } - ], - init: async (handler) => { - // Optional function to initialize anything else on bot startup - }, -}); - client.login(token); ``` -# Links +## Links ![link](https://img.shields.io/badge/Coming-Soon-orange) -- 📑 [Official Documentation](https://sernhandler.js.org) -- 🎧 [Discord Server](https://discord.gg/QWQWQWQ) +- 📑 Official Documentation +- 🎧 Discord Server -# Contribute -- Pull up on issues and tell me if there are bugs. -- Check issues. -- Any contributions are open to suggestion! +## Contribute 😄 + +- Pull up on [issues](https://github.com/jacoobes/Sern/issues) and tell me if there are bugs +- All kinds of contributions are welcomed! From a47f6a1159c0eff1217c7d45b2c2731cd72a20f9 Mon Sep 17 00:00:00 2001 From: EvolutionX Date: Mon, 14 Feb 2022 22:10:08 +0530 Subject: [PATCH 3/4] added jsdocs --- src/handler/utilities/messageHelpers.ts | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/handler/utilities/messageHelpers.ts b/src/handler/utilities/messageHelpers.ts index f96a9bd..8fb4132 100644 --- a/src/handler/utilities/messageHelpers.ts +++ b/src/handler/utilities/messageHelpers.ts @@ -1,29 +1,34 @@ import type { Message } from 'discord.js'; /** * Checks if the author of message is a bot or not - * ```typescript + * @param message The message to check + * @returns `true` if the author of the message is a bot, `false` otherwise + * @example * isBot(message) ? 'yes it is a bot' : 'no it is not a bot'; - * ``` */ export function isBot(message: Message) { return message.author.bot; } /** * Checks if the message **starts** with the prefix - * ```typescript + * @param message The message to check + * @param prefix The prefix to check for + * @returns `true` if the message starts with the prefix, `false` otherwise + * @example * hasPrefix(message, '!') ? 'yes it does' : 'no it does not'; - * ``` */ export function hasPrefix(message: Message, prefix: string) { return message.content.slice(0, prefix.length).toLowerCase().trim() === prefix; } /** * Removes the first character(s) _[depending on prefix length]_ of the message - * ```typescript + * @param message The message to remove the prefix from + * @param prefix The prefix to remove + * @returns The message without the prefix + * @example * message.content = '!ping'; * console.log(fmt(message, '!')); * // [ 'ping' ] - * ``` */ export function fmt(msg: Message, prefix: string): string[] { return msg.content.slice(prefix.length).trim().split(/\s+/g); From dd1d1290638ba5e01e4a261da034e2a27a695707 Mon Sep 17 00:00:00 2001 From: jacoobes Date: Mon, 14 Feb 2022 11:15:24 -0600 Subject: [PATCH 4/4] git --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index d5e3cbf..6e75878 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Sern -Sern is making easier to create & automate your discord bot with new version compatibility and full customization. +Sern automates and streamlines development your discord bot with new version compatibility and full customization. - A reincarnation of [this old project](https://github.com/jacoobes/sern_handler) @@ -39,7 +39,7 @@ new Sern.Handler({ }, ], init: async (handler: Sern.Handler) => { - /* an optional function to initialize anything else on bot startup */ + /* An optional function to initialize anything else on bot startup */ }, });