Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor to TypeScript #19

Merged
merged 141 commits into from
Jun 17, 2023
Merged

Refactor to TypeScript #19

merged 141 commits into from
Jun 17, 2023

Conversation

JstnMcBrd
Copy link
Owner

@JstnMcBrd JstnMcBrd commented Jun 17, 2023

Changes

  • moved entire project to TypeScript (Migrate project to TypeScript #15)
  • moved entire project to ESM
  • moved all source code into ./src folder
  • reorganized and renamed most files
  • updated all dependencies

Commands

  • created CommandHandler class built off SlashCommandBuilder to standardize commands execution and error handling
  • added index.ts to manage command scripts
  • made /help replies and redundant /whitelist and /unwhitelist replies ephemeral
  • added npm package version number to /help embed
  • added new /invite command with automatic invite link generation
  • added automatic deployed commands sync checking
  • added command mentions to all embeds that mention commands

Events

  • created EventHandler builder class modeled after SlashCommandBuilder to standardize event execution and error handling
  • moved event handlers to separate folder with index.ts to manage them

Memory

  • added environment varaible management using dotenv
  • moved token field to environment variables instead of config.json memory file
  • added example .env
  • removed unnecessary config.json memory file
  • store memory using user ID instead of username
  • auto-generate whitelist memory file

Whitelist

  • moved to separate script
  • improved efficiency
  • store channels instead of channel IDs
  • added parallel promises for faster channel fetching/validating

Thinking

  • moved to separate script
  • added automatic timeout to prevent channels from being blocked forever

Context

  • moved to separate script
  • improved efficiency
  • store messages instead of strings
  • improved context generation
  • made resumeConversations use context instead of fetching messages manually (Have conversation resuming respond to oldest unresponded message, not most recent message #5)
  • limited context length to 10
  • automatic context generation for all whitelisted channels on startup
  • automatic context generation/deletion when whitelist is updated
  • removed redundant context generation when new message received
  • limited context to messages sent after the channel was whitelisted
  • added parallel promises for faster context generation

Activity

  • moved to separate script

Parameters

  • created script to store global parameters
  • made embeds use global embed colors in parameters.ts

DeployCommands

  • moved to official client application command setter
  • removed redundant reset option

Utils

  • abstract out helper methods to ./src/utils folder
  • replaced isFromUser() with isFromSelf()
  • replaced doesMentionUser() with doesMentionSelf()

Linting

  • added TypeScript linting
  • moved to eslint flat config file (eslint.config.js instead of .eslintrc.json)
  • simplified eslint rules

Logging

  • abstracted out logging
  • cleaned up and significantly reduced output
  • moved to type-safe colors import
  • improved coloration for output

Project

  • added more fields to package.json
  • bump version to 5.0.0
  • added .vscode settings and extensions and debugger setup
  • added devcontainer setup
  • added npm run commands script to deploy commands
  • added .nvmrc and engine field in package.json for node 18
  • made project name lowercase (discord-cleverbot instead of Discord-Cleverbot) to match npm project standards
  • cleaned up .gitignore
  • updated README
    • added cleverbot-free API status
    • added development section

Misc Improvements

  • replaced manual embeds with embed builders
  • replaced string concatenation with template literals
  • moved to discord.js mention formatters
  • moved to path.join for file paths instead of string concatenation
  • moved to Snowflake type for Discord IDs instead of basic strings
  • improved error handling of cleverbot-free (Throw error object instead of string IntriguingTiles/cleverbot-free#47)
  • enforced camelCase for all files
  • improved comments, including JSDoc for every method
  • standardized import ordering
  • moved to async/await rather than .then().catch()
  • removed unnecessary GuildTyping and DMTyping GatewayIntentBits from the client

Bug Fixes

Tweaks

  • increased typing speed from 6 char/sec to 8 char/sec

And much more!

- migrated all event handlers to separate files
- moved helper functions into Client for cross-file usability
- still very messy
- replaced all manual embed declarations with discord.js EmbedBuilder
- fixed bug in messageCreate handler
- moved to discord.js standard for partial imports
- cleaned up messy string concatenation with template literals and console.log argument stringing
- switched to EmbedBuilder in /help command
In whitelisted channels, the bot only responds when directly mentioned. In such scenarios, gathering the previous messages of the channel shouldn't be necessary.
- moved lastUpdated, typingSpeed, debugTheme to parameters.js
- made all scripts that need them pull from parameters.js
- created embedColors in parameters.js
- made all embeds pull colors from embedColors
- made whitelist/unwhitelist commands reference client's methods instead of "extraInfo"
- created a Whitelist Manager script
- moved all whitelist functions from client to manager
- made all whitelist usage reference the manager
- increased whitelist efficiency
Not sure where this came from or what it does, so I cleaned it up
Bot crashed when it tried to repeat setUserActivity and resumeConversations
- made all commands use methods to generate embeds
- made whitelist/unwhitelist only generate the embed they need
- switched to the official client application command setter instead of bootleg rest API
- removed reset option because it does that anyway
- created message-analyzer script
- removed message helper methods from client to analyzer
- made all helper method reference reference the analyzer
- created an index in the events folder
- moved all event file gathering + registering logic to the index
- moved event-related helper functions to index
- made all event-related requests reference the handler
- fix deploy-commands bug from moving to ./src
- add npm script to deploy commands
- update README to reflect changes
- improve README
- improve gitignore
- better method passing for client events
- abstracted out the logger
- standardized output
- moved to type-safe colors usage
@JstnMcBrd JstnMcBrd added bug Something isn't working documentation Improvements or additions to documentation enhancement New feature or request labels Jun 17, 2023
@JstnMcBrd JstnMcBrd self-assigned this Jun 17, 2023
@JstnMcBrd JstnMcBrd changed the title Complete refactor Refactor to TypeScript Jun 17, 2023
@JstnMcBrd JstnMcBrd merged commit 705d32f into main Jun 17, 2023
@JstnMcBrd JstnMcBrd deleted the refactor branch June 17, 2023 21:17
@JstnMcBrd JstnMcBrd added the dependencies Pull requests that update a dependency file label Nov 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working dependencies Pull requests that update a dependency file documentation Improvements or additions to documentation enhancement New feature or request
Projects
None yet
1 participant