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
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
141 commits
Select commit Hold shift + click to select a range
6f91ca5
New event handling system
JstnMcBrd Sep 25, 2022
85c2dd3
Replaced manual embeds with EmbedBuilder
JstnMcBrd Sep 25, 2022
9bede3d
Template literals
JstnMcBrd Sep 25, 2022
bf03544
Removed context for unwhitelisted channels
JstnMcBrd Sep 25, 2022
0da9846
Moved global variables to separate file
JstnMcBrd Sep 25, 2022
e4af6d4
Redesigned whitelist management
JstnMcBrd Sep 26, 2022
e3f71e6
Deleted .gitattributes
JstnMcBrd Sep 26, 2022
de175ff
Fixed interval actions bug
JstnMcBrd Sep 27, 2022
33510a4
Improved embeds from commands
JstnMcBrd Sep 27, 2022
848f6e9
Simplified deploy-commands
JstnMcBrd Sep 30, 2022
bf937b8
Moved message methods to separate script
JstnMcBrd Sep 30, 2022
2aec9fb
Index for event handlers
JstnMcBrd Sep 30, 2022
fbbf3bd
.eslintrc
JstnMcBrd Dec 8, 2022
c15ed17
Improve npm package details
JstnMcBrd Jan 12, 2023
be69085
Move source code into src folder
JstnMcBrd Jan 12, 2023
f5af62e
Add nvmrc
JstnMcBrd Jan 12, 2023
cbef21d
Update dependencies
JstnMcBrd Jan 12, 2023
4be68a9
Fix start script
JstnMcBrd Jan 12, 2023
1a1219a
Add TypeScript & fix bugs
JstnMcBrd Jan 12, 2023
2d446a2
Add eslint parsing for TypeScript
JstnMcBrd Jan 12, 2023
5bbadc7
Convert parameters.js to TypeScript
JstnMcBrd Jan 13, 2023
a6e6e56
Convert message-analyzer.js to TypeScript
JstnMcBrd Jan 13, 2023
e9c5d9d
Convert whitelist-manager.js to TypeScript
JstnMcBrd Jan 13, 2023
c31f99e
Convert deploy-commands.js to TypeScript
JstnMcBrd Jan 13, 2023
0406837
Misc changes
JstnMcBrd Jan 13, 2023
ee05de9
Abstract out logger
JstnMcBrd Jan 13, 2023
56e4c50
Abstract out error replying
JstnMcBrd Jan 13, 2023
7ad6cb7
Improve eslint rules
JstnMcBrd Jan 13, 2023
678af15
Convert events to TypeScript
JstnMcBrd Jan 13, 2023
99b9be4
Convert commands to TypeScript
JstnMcBrd Jan 14, 2023
22a81e8
Index for command handlers
JstnMcBrd Jan 14, 2023
acb5a6d
Convert main index to TypeScript
JstnMcBrd Jan 14, 2023
3aae664
Cleanup for events and commands
JstnMcBrd Jan 14, 2023
45c67f9
Fix bad imports
JstnMcBrd Jan 14, 2023
3b2e20e
Switch to discord.js mention formatters
JstnMcBrd Jan 14, 2023
8443473
Use discord.js colors
JstnMcBrd Jan 14, 2023
1412f8d
Rename files & make whitelistManager typescript-safe
JstnMcBrd Jan 14, 2023
462b50e
Move logger into src
JstnMcBrd Jan 14, 2023
bd113d6
Improve TypeScript usage
JstnMcBrd Jan 14, 2023
ef9d628
Cleanup initial debug output
JstnMcBrd Jan 14, 2023
e94a9b6
Move thinking to separate file
JstnMcBrd Jan 14, 2023
0e61df4
Move context and other helpers to separate files
JstnMcBrd Jan 14, 2023
5c3c504
Use map instead of record for context
JstnMcBrd Jan 14, 2023
caa1e73
Update dependencies
JstnMcBrd Jan 17, 2023
5e4393b
Abstract out setting activity
JstnMcBrd Jan 17, 2023
f61b384
Add version number to /help
JstnMcBrd Jan 17, 2023
976e41f
Update README
JstnMcBrd Jan 17, 2023
f9b5a82
Use path.join for file paths
JstnMcBrd Jan 17, 2023
d7d12aa
Better memory management
JstnMcBrd Jan 18, 2023
4e664f0
Rename files
JstnMcBrd Jan 23, 2023
b2f8d75
Fix retryWait bugs
JstnMcBrd Jan 23, 2023
84c6cdb
Improve magic number management
JstnMcBrd Jan 23, 2023
faa091d
Organize scripts
JstnMcBrd Jan 23, 2023
7f10828
Improve TypeScript configuration
JstnMcBrd Jan 23, 2023
240947e
Clean up comments
JstnMcBrd Mar 11, 2023
ea43417
Consolidate message cleaning methods
JstnMcBrd Mar 11, 2023
bd90cc9
Store context as Messages and...
JstnMcBrd Mar 11, 2023
725a5bc
Fix bug where context included failed messages
JstnMcBrd Mar 11, 2023
cbb8ca6
Generalized node version
JstnMcBrd Apr 15, 2023
90bf7c6
Remove support for js files
JstnMcBrd Apr 15, 2023
a97895f
Simplify TypeScript configuration
JstnMcBrd Apr 15, 2023
5245009
Remove support for js linting
JstnMcBrd Apr 15, 2023
0e5e71f
Update to TypeScript 5.0
JstnMcBrd May 24, 2023
ce223f9
Update dependencies
JstnMcBrd May 24, 2023
8cbd37f
Use Snowflake type for discord ID strings
JstnMcBrd May 24, 2023
1867b83
Make relative paths pwd-independent
JstnMcBrd May 30, 2023
647443f
Transition to ES modules
JstnMcBrd May 30, 2023
d0aed82
Update gitignore
JstnMcBrd May 30, 2023
e3c0903
Simplify context storage system
JstnMcBrd May 30, 2023
1b1ec48
Fix bug replacing emojis
JstnMcBrd May 31, 2023
c5e3fb3
Store whitelist as Channels
JstnMcBrd Jun 3, 2023
4f84c91
Fix duplicate message context bug
JstnMcBrd Jun 3, 2023
c67ce8d
Make /help reply ephemeral
JstnMcBrd Jun 3, 2023
b39b05e
Update context when update whitelist
JstnMcBrd Jun 3, 2023
5412d47
Fix context including messages from before channel was whitelisted
JstnMcBrd Jun 3, 2023
34d5aec
Fix event error reporting bug
JstnMcBrd Jun 3, 2023
ac6e6d7
Add automatic state refreshing
JstnMcBrd Jun 3, 2023
58bafc7
Add vscode setup
JstnMcBrd Jun 3, 2023
0a380a3
Add basic docker and devcontainer setup
JstnMcBrd Jun 3, 2023
42a463a
Use eslint flat config
JstnMcBrd Jun 3, 2023
da2f61e
Update linting rules
JstnMcBrd Jun 3, 2023
2df441f
Make project name lowercase
JstnMcBrd Jun 3, 2023
bd8926f
Update import ordering
JstnMcBrd Jun 3, 2023
f7fef35
Improve memory file types
JstnMcBrd Jun 3, 2023
a346413
Fix cleverbot-free typing issue
JstnMcBrd Jun 4, 2023
c406531
Update dependencies
JstnMcBrd Jun 4, 2023
de7ef53
Move files around
JstnMcBrd Jun 4, 2023
061227b
Fix bug with interaction errors
JstnMcBrd Jun 4, 2023
c429bf7
Backdate TypeScript to avoid build memory leak
JstnMcBrd Jun 4, 2023
ace655f
Move command error handling to CommandHandler
JstnMcBrd Jun 4, 2023
df83b9a
Use builder pattern for event handlers
JstnMcBrd Jun 4, 2023
13fab0b
Use example account for vscode launch
JstnMcBrd Jun 4, 2023
1dd29fa
Colocate types
JstnMcBrd Jun 7, 2023
4a5fb93
Add document for handler classes
JstnMcBrd Jun 7, 2023
b93192c
Make command redundant embeds ephemeral
JstnMcBrd Jun 7, 2023
20291bd
Add new /invite command
JstnMcBrd Jun 7, 2023
2b240f3
Remove unnecessary "clientId" from config
JstnMcBrd Jun 7, 2023
0c32e0c
Add command mentions to /help
JstnMcBrd Jun 7, 2023
1bf18e3
Replace config.json memory file with .env
JstnMcBrd Jun 9, 2023
30ef20f
Use user ID for memory location instead of username
JstnMcBrd Jun 9, 2023
20c2e0c
Load and populate whitelist at the same time
JstnMcBrd Jun 9, 2023
8c41dac
Clean up gitignore
JstnMcBrd Jun 9, 2023
311471d
Simplify docker setup
JstnMcBrd Jun 9, 2023
e1be75a
Add todo tree extension
JstnMcBrd Jun 9, 2023
73efebc
Improve documentation
JstnMcBrd Jun 9, 2023
c22dafc
Update dependencies
JstnMcBrd Jun 9, 2023
59795c5
Speed up refresh tasks with parallel promises
JstnMcBrd Jun 10, 2023
8ee5983
Improve cleverbot package error handling
JstnMcBrd Jun 10, 2023
7b72354
Remove all output/debugging
JstnMcBrd Jun 10, 2023
808b971
Move connect to separate script
JstnMcBrd Jun 10, 2023
7ae1803
Update cleverbot-free for better error handling
JstnMcBrd Jun 13, 2023
445bb50
Improve logger coloring
JstnMcBrd Jun 16, 2023
7fcc89c
Improve whitelist validation
JstnMcBrd Jun 16, 2023
8ca70ee
Remove context generation from messageCreate
JstnMcBrd Jun 16, 2023
0bd75b3
Add simple logging
JstnMcBrd Jun 16, 2023
6c5de20
Add sleep method
JstnMcBrd Jun 17, 2023
9f26610
Refactor messageCreate
JstnMcBrd Jun 17, 2023
cf7d7ec
Add thinking timeout
JstnMcBrd Jun 17, 2023
c60b98d
Fix event and command error handling
JstnMcBrd Jun 17, 2023
6cc19c6
Make file paths based off project root
JstnMcBrd Jun 17, 2023
4da0ee8
Move context formatting to messageCreate
JstnMcBrd Jun 17, 2023
bb4abbb
Rename helpers to utils
JstnMcBrd Jun 17, 2023
6b1cfa5
Replace isFromUser with isFromSelf
JstnMcBrd Jun 17, 2023
b1aa3fb
Fix sequential messages from self in context
JstnMcBrd Jun 17, 2023
273897f
Update ts and eslint configs
JstnMcBrd Jun 17, 2023
063d3e4
Import env secrets to local object
JstnMcBrd Jun 17, 2023
d36d165
Improve logger colors
JstnMcBrd Jun 17, 2023
5d4bcf9
Remove todo tree extension
JstnMcBrd Jun 17, 2023
299cfd7
Rename .env-example to .env.example
JstnMcBrd Jun 17, 2023
fd13b5a
Rename node version from v18 to 18
JstnMcBrd Jun 17, 2023
abb8c82
Increase typing speed
JstnMcBrd Jun 17, 2023
a6fd062
Remove connect script
JstnMcBrd Jun 17, 2023
02b5cb9
Cleanup
JstnMcBrd Jun 17, 2023
8e75a60
Standardize command mention system
JstnMcBrd Jun 17, 2023
d3ae8c6
Add command sync check
JstnMcBrd Jun 17, 2023
c6a02b3
Remove unnecessary typecasts
JstnMcBrd Jun 17, 2023
3e6397e
Update README
JstnMcBrd Jun 17, 2023
b304fbd
Cleanup
JstnMcBrd Jun 17, 2023
d28870c
Fix dotenv types
JstnMcBrd Jun 17, 2023
c539caa
Bump version and last updated
JstnMcBrd Jun 17, 2023
244e68f
Limit context length to 10
JstnMcBrd Jun 17, 2023
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: 28 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
// README at: https://github.com/devcontainers/templates/tree/main/src/typescript-node
{
"name": "discord-cleverbot",
// Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile
"image": "mcr.microsoft.com/devcontainers/typescript-node:0-18",

// Features to add to the dev container. More info: https://containers.dev/features.
// "features": {},

// Use 'forwardPorts' to make a list of ports inside the container available locally.
// "forwardPorts": [],

// Use 'postCreateCommand' to run commands after the container is created.
// "postCreateCommand": "npm install",

// Configure tool-specific properties.
"customizations": {
"vscode": {
"extensions": [
"dbaeumer.vscode-eslint"
]
}
}

// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
// "remoteUser": "root"
}
2 changes: 2 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# WARNING: keep this token secret, or your bot will be hacked!
TOKEN="example-bot-token"
49 changes: 0 additions & 49 deletions .eslintrc.json

This file was deleted.

2 changes: 0 additions & 2 deletions .gitattributes

This file was deleted.

8 changes: 5 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
node_modules
.outdated/
accounts/*
!accounts/ExampleUsername
dist
memory/*
!memory/example-user-id
.env
todo
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
18
6 changes: 6 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"recommendations": [
"ms-vscode-remote.remote-containers",
"dbaeumer.vscode-eslint",
],
}
17 changes: 17 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Launch Program",
"skipFiles": [
"<node_internals>/**"
],
"program": "./dist/main.js",
},
],
}
6 changes: 6 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"eslint.experimental.useFlatConfig": true,
"files.associations": {
".env.example": "properties"
},
}
45 changes: 30 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,37 +1,52 @@
# Discord-Cleverbot
# discord-cleverbot

## cleverbot-free
[![API Status](https://github.com/IntriguingTiles/cleverbot-free/workflows/API%20Status/badge.svg)](https://github.com/IntriguingTiles/cleverbot-free/actions/workflows/api.yml)

## About

Discord-Cleverbot is a [Discord](https://discord.com/) bot developed in JavaScript that uses the node.js library of [cleverbot-free](https://www.npmjs.com/package/cleverbot-free) to give Cleverbot a presence on Discord. Through the bot, users are able to converse with the [Cleverbot chat bot](https://www.cleverbot.com/). The bot also hosts other features that help integrate it with the Discord chat environment.
discord-cleverbot is a [Discord](https://discord.com/) bot that allows users to interact with the [Cleverbot chat bot](https://www.cleverbot.com/) on Discord. It is developed in [TypeScript](https://www.typescriptlang.org/) and relies on the [node.js](https://nodejs.org/) module of [cleverbot-free](https://www.npmjs.com/package/cleverbot-free).

This project was started in December 2017 and developed periodically until September 2021. This included several ground-up rewrites to improve functionality, efficiency, and simplicity, resulting in a comparatively simple design today.
It was originally started in December 2017 and has undergone several ground-up rewrites to improve functionality, efficiency, modernity, and simplicity.

## Licensing

Without a specific license, this code is the direct intellectual property of the original developer. It may not be used, modified, or shared without explicit permission.
Please see GitHub's [guide](https://docs.github.com/en/repositories/managing-your-repositorys-settings-and-features/customizing-your-repository/licensing-a-repository) on licensing.
Please see [GitHub's guide on licensing](https://docs.github.com/en/repositories/managing-your-repositorys-settings-and-features/customizing-your-repository/licensing-a-repository).

## Getting started

### Creating a bot

1. Create a new bot account in the [Discord developer portal](https://discord.com/developers/applications/)
2. Copy the access token and application ID of your bot for later
- Create a new bot account in the [Discord Developer Portal](https://discord.com/developers/applications/).
- Copy the access token of your bot for later.

### Setting up the code

3. Run `git pull https://github.com/JstnMcBrd/Discord-Cleverbot.git` to download the repo
4. Go into the `/accounts` directory, duplicate the `ExampleUsername` folder, and rename it as the username of your bot
5. Inside the new folder, edit `config.json` and replace `example-user-id` with the application ID and `example-token` with the access token
- You will need an environment with [node.js v18](https://nodejs.org/en/download) installed (or use the Dev Container - see the [Development](#development) section below).
- Run `git pull https://github.com/JstnMcBrd/discord-cleverbot.git` to clone the repo.
- Create a new file called `.env` and add your access token, using [`.env.example`](./.env.example) as an example.

### Running the code

6. In the top directory, run `npm install` to download all necessary packages
7. Run `node deploy-commands.js [bot username]` to register slash commands with Discord
8. Run `node index.js [bot username]` to start the bot
- In the top directory, run `npm install` to download all necessary packages.
- Run `npm run build` to build the project.
- Run `npm run commands` to register slash commands with Discord.
- Run `npm start` to start the bot.

### Interacting with the bot

9. Use the URL in `/accounts/[bot username]/config.json` to add your bot to a server
10. Use the `/whitelist` command in a channel to allow the bot to speak there
11. Send messages in the whitelisted channel and watch the bot respond!
- In the **OAuth2**>**URL Generator** tab in the Discord Developer Portal, generate an invite URL with the `applications.commands` scope.
- Use the invite URL to add the bot to a server.
- Use the `/whitelist` command in a channel to allow the bot to speak there.
- Send messages in the whitelisted channel and watch the bot respond!

## Development

- [Visual Studio Code](https://code.visualstudio.com/) is the recommended IDE for development.
- All settings are included as artifacts in the [`.vscode`](./.vscode) folder and will automatically apply.
- You can use the built-in debugger and set breakpoints to troubleshoot the code.

> If you want a standardized development environment, you can use the [Dev Containers extension](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers) with the given [`devcontainer.json`](./.devcontainer/devcontainer.json) config to develop inside a [Docker](https://www.docker.com/) container with all dependencies and recommended extensions pre-installed.
>
> Simply install the extension and use the **Dev Containers: Open Folder in Container** command.
5 changes: 0 additions & 5 deletions accounts/ExampleUsername/config.json

This file was deleted.

47 changes: 0 additions & 47 deletions commands/help.js

This file was deleted.

38 changes: 0 additions & 38 deletions commands/unwhitelist.js

This file was deleted.

38 changes: 0 additions & 38 deletions commands/whitelist.js

This file was deleted.

57 changes: 0 additions & 57 deletions deploy-commands.js

This file was deleted.

Loading