Skip to content

Commit 705d32f

Browse files
authored
Refactor to TypeScript (#19)
See description of #19
1 parent b8d6603 commit 705d32f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+5708
-4205
lines changed

.devcontainer/devcontainer.json

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
2+
// README at: https://github.com/devcontainers/templates/tree/main/src/typescript-node
3+
{
4+
"name": "discord-cleverbot",
5+
// Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile
6+
"image": "mcr.microsoft.com/devcontainers/typescript-node:0-18",
7+
8+
// Features to add to the dev container. More info: https://containers.dev/features.
9+
// "features": {},
10+
11+
// Use 'forwardPorts' to make a list of ports inside the container available locally.
12+
// "forwardPorts": [],
13+
14+
// Use 'postCreateCommand' to run commands after the container is created.
15+
// "postCreateCommand": "npm install",
16+
17+
// Configure tool-specific properties.
18+
"customizations": {
19+
"vscode": {
20+
"extensions": [
21+
"dbaeumer.vscode-eslint"
22+
]
23+
}
24+
}
25+
26+
// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
27+
// "remoteUser": "root"
28+
}

.env.example

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# WARNING: keep this token secret, or your bot will be hacked!
2+
TOKEN="example-bot-token"

.eslintrc.json

-49
This file was deleted.

.gitignore

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
node_modules
2-
.outdated/
3-
accounts/*
4-
!accounts/ExampleUsername
2+
dist
3+
memory/*
4+
!memory/example-user-id
5+
.env
6+
todo

.nvmrc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
18

.vscode/extensions.json

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"recommendations": [
3+
"ms-vscode-remote.remote-containers",
4+
"dbaeumer.vscode-eslint",
5+
],
6+
}

.vscode/launch.json

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
// Use IntelliSense to learn about possible attributes.
3+
// Hover to view descriptions of existing attributes.
4+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5+
"version": "0.2.0",
6+
"configurations": [
7+
{
8+
"type": "node",
9+
"request": "launch",
10+
"name": "Launch Program",
11+
"skipFiles": [
12+
"<node_internals>/**"
13+
],
14+
"program": "./dist/main.js",
15+
},
16+
],
17+
}

.vscode/settings.json

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"eslint.experimental.useFlatConfig": true,
3+
"files.associations": {
4+
".env.example": "properties"
5+
},
6+
}

README.md

+30-15
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,52 @@
1-
# Discord-Cleverbot
1+
# discord-cleverbot
2+
3+
## cleverbot-free
4+
[![API Status](https://github.com/IntriguingTiles/cleverbot-free/workflows/API%20Status/badge.svg)](https://github.com/IntriguingTiles/cleverbot-free/actions/workflows/api.yml)
25

36
## About
47

5-
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.
8+
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).
69

7-
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.
10+
It was originally started in December 2017 and has undergone several ground-up rewrites to improve functionality, efficiency, modernity, and simplicity.
811

912
## Licensing
1013

1114
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.
12-
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.
15+
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).
1316

1417
## Getting started
1518

1619
### Creating a bot
1720

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

2124
### Setting up the code
2225

23-
3. Run `git pull https://github.com/JstnMcBrd/Discord-Cleverbot.git` to download the repo
24-
4. Go into the `/accounts` directory, duplicate the `ExampleUsername` folder, and rename it as the username of your bot
25-
5. Inside the new folder, edit `config.json` and replace `example-user-id` with the application ID and `example-token` with the access token
26+
- 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).
27+
- Run `git pull https://github.com/JstnMcBrd/discord-cleverbot.git` to clone the repo.
28+
- Create a new file called `.env` and add your access token, using [`.env.example`](./.env.example) as an example.
2629

2730
### Running the code
2831

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

3337
### Interacting with the bot
3438

35-
9. Use the URL in `/accounts/[bot username]/config.json` to add your bot to a server
36-
10. Use the `/whitelist` command in a channel to allow the bot to speak there
37-
11. Send messages in the whitelisted channel and watch the bot respond!
39+
- In the **OAuth2**>**URL Generator** tab in the Discord Developer Portal, generate an invite URL with the `applications.commands` scope.
40+
- Use the invite URL to add the bot to a server.
41+
- Use the `/whitelist` command in a channel to allow the bot to speak there.
42+
- Send messages in the whitelisted channel and watch the bot respond!
43+
44+
## Development
45+
46+
- [Visual Studio Code](https://code.visualstudio.com/) is the recommended IDE for development.
47+
- All settings are included as artifacts in the [`.vscode`](./.vscode) folder and will automatically apply.
48+
- You can use the built-in debugger and set breakpoints to troubleshoot the code.
49+
50+
> 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.
51+
>
52+
> Simply install the extension and use the **Dev Containers: Open Folder in Container** command.

accounts/ExampleUsername/config.json

-5
This file was deleted.

commands/help.js

-47
This file was deleted.

commands/unwhitelist.js

-38
This file was deleted.

commands/whitelist.js

-38
This file was deleted.

deploy-commands.js

-57
This file was deleted.

0 commit comments

Comments
 (0)