-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 7efb4b4
Showing
6 changed files
with
539 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,160 @@ | ||
# Byte-compiled / optimized / DLL files | ||
__pycache__/ | ||
*.py[cod] | ||
*$py.class | ||
|
||
# C extensions | ||
*.so | ||
|
||
# Distribution / packaging | ||
.Python | ||
build/ | ||
develop-eggs/ | ||
dist/ | ||
downloads/ | ||
eggs/ | ||
.eggs/ | ||
lib/ | ||
lib64/ | ||
parts/ | ||
sdist/ | ||
var/ | ||
wheels/ | ||
share/python-wheels/ | ||
*.egg-info/ | ||
.installed.cfg | ||
*.egg | ||
MANIFEST | ||
|
||
# PyInstaller | ||
# Usually these files are written by a python script from a template | ||
# before PyInstaller builds the exe, so as to inject date/other infos into it. | ||
*.manifest | ||
*.spec | ||
|
||
# Installer logs | ||
pip-log.txt | ||
pip-delete-this-directory.txt | ||
|
||
# Unit test / coverage reports | ||
htmlcov/ | ||
.tox/ | ||
.nox/ | ||
.coverage | ||
.coverage.* | ||
.cache | ||
nosetests.xml | ||
coverage.xml | ||
*.cover | ||
*.py,cover | ||
.hypothesis/ | ||
.pytest_cache/ | ||
cover/ | ||
|
||
# Translations | ||
*.mo | ||
*.pot | ||
|
||
# Django stuff: | ||
*.log | ||
local_settings.py | ||
db.sqlite3 | ||
db.sqlite3-journal | ||
|
||
# Flask stuff: | ||
instance/ | ||
.webassets-cache | ||
|
||
# Scrapy stuff: | ||
.scrapy | ||
|
||
# Sphinx documentation | ||
docs/_build/ | ||
|
||
# PyBuilder | ||
.pybuilder/ | ||
target/ | ||
|
||
# Jupyter Notebook | ||
.ipynb_checkpoints | ||
|
||
# IPython | ||
profile_default/ | ||
ipython_config.py | ||
|
||
# pyenv | ||
# For a library or package, you might want to ignore these files since the code is | ||
# intended to run in multiple environments; otherwise, check them in: | ||
# .python-version | ||
|
||
# pipenv | ||
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. | ||
# However, in case of collaboration, if having platform-specific dependencies or dependencies | ||
# having no cross-platform support, pipenv may install dependencies that don't work, or not | ||
# install all needed dependencies. | ||
#Pipfile.lock | ||
|
||
# poetry | ||
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control. | ||
# This is especially recommended for binary packages to ensure reproducibility, and is more | ||
# commonly ignored for libraries. | ||
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control | ||
#poetry.lock | ||
|
||
# pdm | ||
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control. | ||
#pdm.lock | ||
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it | ||
# in version control. | ||
# https://pdm.fming.dev/#use-with-ide | ||
.pdm.toml | ||
|
||
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm | ||
__pypackages__/ | ||
|
||
# Celery stuff | ||
celerybeat-schedule | ||
celerybeat.pid | ||
|
||
# SageMath parsed files | ||
*.sage.py | ||
|
||
# Environments | ||
.env | ||
.venv | ||
env/ | ||
venv/ | ||
ENV/ | ||
env.bak/ | ||
venv.bak/ | ||
|
||
# Spyder project settings | ||
.spyderproject | ||
.spyproject | ||
|
||
# Rope project settings | ||
.ropeproject | ||
|
||
# mkdocs documentation | ||
/site | ||
|
||
# mypy | ||
.mypy_cache/ | ||
.dmypy.json | ||
dmypy.json | ||
|
||
# Pyre type checker | ||
.pyre/ | ||
|
||
# pytype static type analyzer | ||
.pytype/ | ||
|
||
# Cython debug symbols | ||
cython_debug/ | ||
|
||
# PyCharm | ||
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can | ||
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore | ||
# and can be added to the global gitignore or merged into this file. For a more nuclear | ||
# option (not recommended) you can uncomment the following to ignore the entire idea folder. | ||
#.idea/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
This is free and unencumbered software released into the public domain. | ||
|
||
Anyone is free to copy, modify, publish, use, compile, sell, or | ||
distribute this software, either in source code form or as a compiled | ||
binary, for any purpose, commercial or non-commercial, and by any | ||
means. | ||
|
||
In jurisdictions that recognize copyright laws, the author or authors | ||
of this software dedicate any and all copyright interest in the | ||
software to the public domain. We make this dedication for the benefit | ||
of the public at large and to the detriment of our heirs and | ||
successors. We intend this dedication to be an overt act of | ||
relinquishment in perpetuity of all present and future rights to this | ||
software under copyright law. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | ||
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR | ||
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, | ||
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR | ||
OTHER DEALINGS IN THE SOFTWARE. | ||
|
||
For more information, please refer to <https://unlicense.org> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
# Description | ||
|
||
This is a Python script for a Discord bot that uses OpenAI's GPT API to generate responses to user messages. The bot can be configured to listen to specific channels and respond to direct messages. The bot also has a rate limit to prevent spamming and can maintain a per user conversational history to improve response quality which is only limited by the `GPT_TOKENS` value. | ||
|
||
# Requirements | ||
|
||
- Python 3.6 or higher | ||
- discord.py | ||
- openai | ||
|
||
# Installation | ||
|
||
1. Clone the repository to your local machine. | ||
2. Install the required packages using pip: `pip install -r requirements.txt` | ||
3. Rename `config.ini.example` to `config.ini` and fill in the required configuration details. | ||
|
||
# Configuration | ||
|
||
The `config.ini` file contains the following configuration sections: | ||
|
||
### Discord | ||
|
||
- `DISCORD_TOKEN`: The Discord bot token. | ||
- `ALLOWED_CHANNELS`: A comma-separated list of channel names that the bot is allowed to listen to. | ||
- `BOT_PRESENCE`: The presence of the bot (e.g. online, offline, idle). | ||
- `ACTIVITY_TYPE`: The type of activity for the bot (e.g. playing, streaming, listening, watching, custom, competing). | ||
- `ACTIVITY_STATUS`: The activity status of the bot (e.g. Humans). | ||
|
||
### OpenAI | ||
|
||
- `OPENAI_API_KEY`: The OpenAI API key. | ||
- `OPENAI_TIMEOUT`: The OpenAI API timeout in seconds. (default: 30) | ||
- `GPT_MODEL`: The GPT model to use (default: gpt-3.5-turbo). | ||
- `GPT_TOKENS`: The maximum number of tokens to generate in the GPT response (default: 3072). | ||
- `SYSTEM_MESSAGE`: The message to send to the GPT model before the user's message. | ||
|
||
### Limits | ||
|
||
- `RATE_LIMIT`: The number of messages a user can send within `RATE_LIMIT_PER` seconds (default: 2). | ||
- `RATE_LIMIT_PER`: The time period in seconds for the rate limit (default: 10). | ||
|
||
### Logging | ||
|
||
- `LOG_FILE`: The path to the log file (default: bot.log). | ||
|
||
Here is an example `config.ini` file: | ||
|
||
```ini | ||
[Discord] | ||
DISCORD_TOKEN = <your_discord_bot_token> | ||
ALLOWED_CHANNELS = <allowed_channel_id_1>, <allowed_channel_id_2>, ... | ||
BOT_PRESENCE = online | ||
# ACTIVITY_TYPE Options | ||
# playing, streaming, listening, watching, custom, competing | ||
ACTIVITY_TYPE=listening | ||
ACTIVITY_STATUS=Humans | ||
|
||
[OpenAI] | ||
OPENAI_API_KEY = <your_openai_api_key> | ||
OPENAI_TIMEOUT=30 | ||
GPT_MODEL=gpt-3.5-turbo | ||
GPT_TOKENS=3072 | ||
SYSTEM_MESSAGE = You are a helpful AI assistant. | ||
|
||
[Limits] | ||
RATE_LIMIT = 2 | ||
RATE_LIMIT_PER = 10 | ||
|
||
[Logging] | ||
LOG_FILE = bot.log | ||
``` | ||
|
||
# Discord Bot Setup | ||
|
||
To use this bot, you will need to create a Discord bot and invite it to your server. Here are the steps to do so: | ||
|
||
1. Go to the [Discord Developer Portal](https://discord.com/developers/applications) and create a new application. | ||
2. Click on the "Bot" tab and then click "Add Bot". | ||
3. Copy the bot token and paste it into the `DISCORD_TOKEN` field in the `config.ini` file. | ||
4. Under the "OAuth2" tab, select the "bot" scope and then select the permissions you want the bot to have. | ||
5. Copy the generated OAuth2 URL and paste it into your web browser. This will allow you to invite the bot to your server. | ||
|
||
# Usage | ||
|
||
To start the bot, run the following command: | ||
|
||
``` | ||
python bot.py --conf config.ini | ||
``` | ||
|
||
The bot will log in to Discord and start listening for messages in the configured channels. When a message is received, the bot will send the message to the OpenAI API and wait for a response. The response will be sent back to the user who sent the message. | ||
|
||
# Contributing | ||
|
||
Contributions are welcome! Please open an issue or pull request on the GitHub repository. | ||
|
||
# Contact | ||
|
||
If you have any questions or concerns, please contact us at [email protected] | ||
|
||
# License | ||
|
||
This project is licensed under the Unlicense - see the [LICENSE](LICENSE) file for details. |
Oops, something went wrong.