Init Repo
This commit is contained in:
commit
ae3fc86691
243
.gitignore
vendored
Normal file
243
.gitignore
vendored
Normal file
|
|
@ -0,0 +1,243 @@
|
|||
# ---> Python
|
||||
# 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/
|
||||
|
||||
# ---> JetBrains
|
||||
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
|
||||
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
|
||||
|
||||
# User-specific stuff
|
||||
.idea/**/workspace.xml
|
||||
.idea/**/tasks.xml
|
||||
.idea/**/usage.statistics.xml
|
||||
.idea/**/dictionaries
|
||||
.idea/**/shelf
|
||||
|
||||
# AWS User-specific
|
||||
.idea/**/aws.xml
|
||||
|
||||
# Generated files
|
||||
.idea/**/contentModel.xml
|
||||
|
||||
# Sensitive or high-churn files
|
||||
.idea/**/dataSources/
|
||||
.idea/**/dataSources.ids
|
||||
.idea/**/dataSources.local.xml
|
||||
.idea/**/sqlDataSources.xml
|
||||
.idea/**/dynamic.xml
|
||||
.idea/**/uiDesigner.xml
|
||||
.idea/**/dbnavigator.xml
|
||||
|
||||
# Gradle
|
||||
.idea/**/gradle.xml
|
||||
.idea/**/libraries
|
||||
|
||||
# Gradle and Maven with auto-import
|
||||
# When using Gradle or Maven with auto-import, you should exclude module files,
|
||||
# since they will be recreated, and may cause churn. Uncomment if using
|
||||
# auto-import.
|
||||
# .idea/artifacts
|
||||
# .idea/compiler.xml
|
||||
# .idea/jarRepositories.xml
|
||||
# .idea/modules.xml
|
||||
# .idea/*.iml
|
||||
# .idea/modules
|
||||
# *.iml
|
||||
# *.ipr
|
||||
|
||||
# CMake
|
||||
cmake-build-*/
|
||||
|
||||
# Mongo Explorer plugin
|
||||
.idea/**/mongoSettings.xml
|
||||
|
||||
# File-based project format
|
||||
*.iws
|
||||
|
||||
# IntelliJ
|
||||
out/
|
||||
|
||||
# mpeltonen/sbt-idea plugin
|
||||
.idea_modules/
|
||||
|
||||
# JIRA plugin
|
||||
atlassian-ide-plugin.xml
|
||||
|
||||
# Cursive Clojure plugin
|
||||
.idea/replstate.xml
|
||||
|
||||
# SonarLint plugin
|
||||
.idea/sonarlint/
|
||||
|
||||
# Crashlytics plugin (for Android Studio and IntelliJ)
|
||||
com_crashlytics_export_strings.xml
|
||||
crashlytics.properties
|
||||
crashlytics-build.properties
|
||||
fabric.properties
|
||||
|
||||
# Editor-based Rest Client
|
||||
.idea/httpRequests
|
||||
|
||||
# Android studio 3.1+ serialized cache file
|
||||
.idea/caches/build_file_checksums.ser
|
||||
|
||||
/bot/configs/.env
|
||||
/bot/audio/*
|
||||
8
.idea/.gitignore
vendored
Normal file
8
.idea/.gitignore
vendored
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
# Editor-based HTTP Client requests
|
||||
/httpRequests/
|
||||
# Datasource local storage ignored files
|
||||
/dataSources/
|
||||
/dataSources.local.xml
|
||||
8
.idea/GPT-PyCord-Bot-GItHub.iml
Normal file
8
.idea/GPT-PyCord-Bot-GItHub.iml
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="PYTHON_MODULE" version="4">
|
||||
<component name="NewModuleRootManager">
|
||||
<content url="file://$MODULE_DIR$" />
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
||||
141
.idea/inspectionProfiles/Project_Default.xml
Normal file
141
.idea/inspectionProfiles/Project_Default.xml
Normal file
|
|
@ -0,0 +1,141 @@
|
|||
<component name="InspectionProjectProfileManager">
|
||||
<profile version="1.0">
|
||||
<option name="myName" value="Project Default" />
|
||||
<inspection_tool class="PyPackageRequirementsInspection" enabled="true" level="WARNING" enabled_by_default="true">
|
||||
<option name="ignoredPackages">
|
||||
<value>
|
||||
<list size="119">
|
||||
<item index="0" class="java.lang.String" itemvalue="TTS" />
|
||||
<item index="1" class="java.lang.String" itemvalue="numba" />
|
||||
<item index="2" class="java.lang.String" itemvalue="python-crfsuite" />
|
||||
<item index="3" class="java.lang.String" itemvalue="tzlocal" />
|
||||
<item index="4" class="java.lang.String" itemvalue="Babel" />
|
||||
<item index="5" class="java.lang.String" itemvalue="scikit-learn" />
|
||||
<item index="6" class="java.lang.String" itemvalue="PyYAML" />
|
||||
<item index="7" class="java.lang.String" itemvalue="nvidia-cuda-cupti-cu11" />
|
||||
<item index="8" class="java.lang.String" itemvalue="pycparser" />
|
||||
<item index="9" class="java.lang.String" itemvalue="umap-learn" />
|
||||
<item index="10" class="java.lang.String" itemvalue="starlette" />
|
||||
<item index="11" class="java.lang.String" itemvalue="nvidia-cufft-cu11" />
|
||||
<item index="12" class="java.lang.String" itemvalue="uvicorn" />
|
||||
<item index="13" class="java.lang.String" itemvalue="nvidia-cuda-runtime-cu11" />
|
||||
<item index="14" class="java.lang.String" itemvalue="torchaudio" />
|
||||
<item index="15" class="java.lang.String" itemvalue="pydantic" />
|
||||
<item index="16" class="java.lang.String" itemvalue="Werkzeug" />
|
||||
<item index="17" class="java.lang.String" itemvalue="jamo" />
|
||||
<item index="18" class="java.lang.String" itemvalue="audioread" />
|
||||
<item index="19" class="java.lang.String" itemvalue="click" />
|
||||
<item index="20" class="java.lang.String" itemvalue="contourpy" />
|
||||
<item index="21" class="java.lang.String" itemvalue="psutil" />
|
||||
<item index="22" class="java.lang.String" itemvalue="pysbd" />
|
||||
<item index="23" class="java.lang.String" itemvalue="regex" />
|
||||
<item index="24" class="java.lang.String" itemvalue="platformdirs" />
|
||||
<item index="25" class="java.lang.String" itemvalue="matplotlib" />
|
||||
<item index="26" class="java.lang.String" itemvalue="jsonlines" />
|
||||
<item index="27" class="java.lang.String" itemvalue="idna" />
|
||||
<item index="28" class="java.lang.String" itemvalue="gruut-lang-en" />
|
||||
<item index="29" class="java.lang.String" itemvalue="decorator" />
|
||||
<item index="30" class="java.lang.String" itemvalue="networkx" />
|
||||
<item index="31" class="java.lang.String" itemvalue="cffi" />
|
||||
<item index="32" class="java.lang.String" itemvalue="numpy" />
|
||||
<item index="33" class="java.lang.String" itemvalue="requests" />
|
||||
<item index="34" class="java.lang.String" itemvalue="sniffio" />
|
||||
<item index="35" class="java.lang.String" itemvalue="nvidia-cusparse-cu11" />
|
||||
<item index="36" class="java.lang.String" itemvalue="nvidia-nccl-cu11" />
|
||||
<item index="37" class="java.lang.String" itemvalue="nvidia-cudnn-cu11" />
|
||||
<item index="38" class="java.lang.String" itemvalue="itsdangerous" />
|
||||
<item index="39" class="java.lang.String" itemvalue="websockets" />
|
||||
<item index="40" class="java.lang.String" itemvalue="scipy" />
|
||||
<item index="41" class="java.lang.String" itemvalue="watchfiles" />
|
||||
<item index="42" class="java.lang.String" itemvalue="dateparser" />
|
||||
<item index="43" class="java.lang.String" itemvalue="torch" />
|
||||
<item index="44" class="java.lang.String" itemvalue="pytz-deprecation-shim" />
|
||||
<item index="45" class="java.lang.String" itemvalue="pandas" />
|
||||
<item index="46" class="java.lang.String" itemvalue="gruut-ipa" />
|
||||
<item index="47" class="java.lang.String" itemvalue="mpmath" />
|
||||
<item index="48" class="java.lang.String" itemvalue="cmake" />
|
||||
<item index="49" class="java.lang.String" itemvalue="typing_extensions" />
|
||||
<item index="50" class="java.lang.String" itemvalue="tensorboardX" />
|
||||
<item index="51" class="java.lang.String" itemvalue="pytz" />
|
||||
<item index="52" class="java.lang.String" itemvalue="Pillow" />
|
||||
<item index="53" class="java.lang.String" itemvalue="protobuf" />
|
||||
<item index="54" class="java.lang.String" itemvalue="mecab-python3" />
|
||||
<item index="55" class="java.lang.String" itemvalue="joblib" />
|
||||
<item index="56" class="java.lang.String" itemvalue="threadpoolctl" />
|
||||
<item index="57" class="java.lang.String" itemvalue="g2pkk" />
|
||||
<item index="58" class="java.lang.String" itemvalue="nltk" />
|
||||
<item index="59" class="java.lang.String" itemvalue="python-dateutil" />
|
||||
<item index="60" class="java.lang.String" itemvalue="python-dotenv" />
|
||||
<item index="61" class="java.lang.String" itemvalue="h11" />
|
||||
<item index="62" class="java.lang.String" itemvalue="cycler" />
|
||||
<item index="63" class="java.lang.String" itemvalue="MarkupSafe" />
|
||||
<item index="64" class="java.lang.String" itemvalue="httptools" />
|
||||
<item index="65" class="java.lang.String" itemvalue="fsspec" />
|
||||
<item index="66" class="java.lang.String" itemvalue="nvidia-cusolver-cu11" />
|
||||
<item index="67" class="java.lang.String" itemvalue="nvidia-curand-cu11" />
|
||||
<item index="68" class="java.lang.String" itemvalue="docopt" />
|
||||
<item index="69" class="java.lang.String" itemvalue="filelock" />
|
||||
<item index="70" class="java.lang.String" itemvalue="lit" />
|
||||
<item index="71" class="java.lang.String" itemvalue="certifi" />
|
||||
<item index="72" class="java.lang.String" itemvalue="anyio" />
|
||||
<item index="73" class="java.lang.String" itemvalue="gruut-lang-de" />
|
||||
<item index="74" class="java.lang.String" itemvalue="pyparsing" />
|
||||
<item index="75" class="java.lang.String" itemvalue="pypinyin" />
|
||||
<item index="76" class="java.lang.String" itemvalue="sympy" />
|
||||
<item index="77" class="java.lang.String" itemvalue="uvloop" />
|
||||
<item index="78" class="java.lang.String" itemvalue="triton" />
|
||||
<item index="79" class="java.lang.String" itemvalue="anyascii" />
|
||||
<item index="80" class="java.lang.String" itemvalue="nvidia-cuda-nvrtc-cu11" />
|
||||
<item index="81" class="java.lang.String" itemvalue="pynndescent" />
|
||||
<item index="82" class="java.lang.String" itemvalue="kiwisolver" />
|
||||
<item index="83" class="java.lang.String" itemvalue="unidic-lite" />
|
||||
<item index="84" class="java.lang.String" itemvalue="fonttools" />
|
||||
<item index="85" class="java.lang.String" itemvalue="nvidia-nvtx-cu11" />
|
||||
<item index="86" class="java.lang.String" itemvalue="coqpit" />
|
||||
<item index="87" class="java.lang.String" itemvalue="resampy" />
|
||||
<item index="88" class="java.lang.String" itemvalue="charset-normalizer" />
|
||||
<item index="89" class="java.lang.String" itemvalue="librosa" />
|
||||
<item index="90" class="java.lang.String" itemvalue="jieba" />
|
||||
<item index="91" class="java.lang.String" itemvalue="llvmlite" />
|
||||
<item index="92" class="java.lang.String" itemvalue="Jinja2" />
|
||||
<item index="93" class="java.lang.String" itemvalue="nvidia-cublas-cu11" />
|
||||
<item index="94" class="java.lang.String" itemvalue="num2words" />
|
||||
<item index="95" class="java.lang.String" itemvalue="trainer" />
|
||||
<item index="96" class="java.lang.String" itemvalue="urllib3" />
|
||||
<item index="97" class="java.lang.String" itemvalue="Cython" />
|
||||
<item index="98" class="java.lang.String" itemvalue="Flask" />
|
||||
<item index="99" class="java.lang.String" itemvalue="six" />
|
||||
<item index="100" class="java.lang.String" itemvalue="gruut" />
|
||||
<item index="101" class="java.lang.String" itemvalue="tzdata" />
|
||||
<item index="102" class="java.lang.String" itemvalue="packaging" />
|
||||
<item index="103" class="java.lang.String" itemvalue="pooch" />
|
||||
<item index="104" class="java.lang.String" itemvalue="tqdm" />
|
||||
<item index="105" class="java.lang.String" itemvalue="fastapi" />
|
||||
<item index="106" class="java.lang.String" itemvalue="soundfile" />
|
||||
<item index="107" class="java.lang.String" itemvalue="inflect" />
|
||||
<item index="108" class="java.lang.String" itemvalue="openai" />
|
||||
<item index="109" class="java.lang.String" itemvalue="async-timeout" />
|
||||
<item index="110" class="java.lang.String" itemvalue="PyNaCl" />
|
||||
<item index="111" class="java.lang.String" itemvalue="colorama" />
|
||||
<item index="112" class="java.lang.String" itemvalue="aiohttp" />
|
||||
<item index="113" class="java.lang.String" itemvalue="multidict" />
|
||||
<item index="114" class="java.lang.String" itemvalue="yarl" />
|
||||
<item index="115" class="java.lang.String" itemvalue="aiosignal" />
|
||||
<item index="116" class="java.lang.String" itemvalue="attrs" />
|
||||
<item index="117" class="java.lang.String" itemvalue="frozenlist" />
|
||||
<item index="118" class="java.lang.String" itemvalue="py-cord" />
|
||||
</list>
|
||||
</value>
|
||||
</option>
|
||||
</inspection_tool>
|
||||
<inspection_tool class="PyPep8Inspection" enabled="true" level="WEAK WARNING" enabled_by_default="true">
|
||||
<option name="ignoredErrors">
|
||||
<list>
|
||||
<option value="E303" />
|
||||
<option value="E302" />
|
||||
<option value="E305" />
|
||||
</list>
|
||||
</option>
|
||||
</inspection_tool>
|
||||
</profile>
|
||||
</component>
|
||||
6
.idea/inspectionProfiles/profiles_settings.xml
Normal file
6
.idea/inspectionProfiles/profiles_settings.xml
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
<component name="InspectionProjectProfileManager">
|
||||
<settings>
|
||||
<option name="USE_PROJECT_PROFILE" value="false" />
|
||||
<version value="1.0" />
|
||||
</settings>
|
||||
</component>
|
||||
7
.idea/misc.xml
Normal file
7
.idea/misc.xml
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="MarkdownSettingsMigration">
|
||||
<option name="stateVersion" value="1" />
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" project-jdk-name="/usr/bin/python3" project-jdk-type="Python SDK" />
|
||||
</project>
|
||||
8
.idea/modules.xml
Normal file
8
.idea/modules.xml
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/.idea/GPT-PyCord-Bot-GItHub.iml" filepath="$PROJECT_DIR$/.idea/GPT-PyCord-Bot-GItHub.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
||||
6
.idea/vcs.xml
Normal file
6
.idea/vcs.xml
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
||||
24
Dockerfile
Normal file
24
Dockerfile
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
# Use an official Python runtime as a parent image
|
||||
FROM python:3.10-alpine
|
||||
|
||||
# Set max Memory Usage for Container
|
||||
ENV MAX_MEMORY_USAGE=2048
|
||||
|
||||
RUN mkdir -p /usr/share/dcbot
|
||||
|
||||
# Set the working directory to /usr/share/dcbot
|
||||
WORKDIR /usr/share/dcbot
|
||||
|
||||
# Copy the requirements file to the working directory
|
||||
COPY requirements.txt .
|
||||
|
||||
RUN pip install --upgrade pip
|
||||
#RUN pip install --no-cache-dir TTS
|
||||
# Install any needed packages specified in requirements.txt
|
||||
RUN pip install --no-cache-dir -r requirements.txt
|
||||
|
||||
COPY bot/ ./
|
||||
|
||||
VOLUME ["/usr/share/dcbot/configs", "/usr/share/dcbot/chats"]
|
||||
|
||||
CMD ["python", "bot.py"]
|
||||
158
LICENSE
Normal file
158
LICENSE
Normal file
|
|
@ -0,0 +1,158 @@
|
|||
Creative Commons Attribution-NonCommercial 4.0 International
|
||||
|
||||
Creative Commons Corporation (“Creative Commons”) is not a law firm and does not provide legal services or legal advice. Distribution of Creative Commons public licenses does not create a lawyer-client or other relationship. Creative Commons makes its licenses and related information available on an “as-is” basis. Creative Commons gives no warranties regarding its licenses, any material licensed under their terms and conditions, or any related information. Creative Commons disclaims all liability for damages resulting from their use to the fullest extent possible.
|
||||
|
||||
Using Creative Commons Public Licenses
|
||||
|
||||
Creative Commons public licenses provide a standard set of terms and conditions that creators and other rights holders may use to share original works of authorship and other material subject to copyright and certain other rights specified in the public license below. The following considerations are for informational purposes only, are not exhaustive, and do not form part of our licenses.
|
||||
|
||||
Considerations for licensors: Our public licenses are intended for use by those authorized to give the public permission to use material in ways otherwise restricted by copyright and certain other rights. Our licenses are irrevocable. Licensors should read and understand the terms and conditions of the license they choose before applying it. Licensors should also secure all rights necessary before applying our licenses so that the public can reuse the material as expected. Licensors should clearly mark any material not subject to the license. This includes other CC-licensed material, or material used under an exception or limitation to copyright. More considerations for licensors.
|
||||
|
||||
Considerations for the public: By using one of our public licenses, a licensor grants the public permission to use the licensed material under specified terms and conditions. If the licensor’s permission is not necessary for any reason–for example, because of any applicable exception or limitation to copyright–then that use is not regulated by the license. Our licenses grant only permissions under copyright and certain other rights that a licensor has authority to grant. Use of the licensed material may still be restricted for other reasons, including because others have copyright or other rights in the material. A licensor may make special requests, such as asking that all changes be marked or described. Although not required by our licenses, you are encouraged to respect those requests where reasonable. More considerations for the public.
|
||||
|
||||
Creative Commons Attribution-NonCommercial 4.0 International Public License
|
||||
|
||||
By exercising the Licensed Rights (defined below), You accept and agree to be bound by the terms and conditions of this Creative Commons Attribution-NonCommercial 4.0 International Public License ("Public License"). To the extent this Public License may be interpreted as a contract, You are granted the Licensed Rights in consideration of Your acceptance of these terms and conditions, and the Licensor grants You such rights in consideration of benefits the Licensor receives from making the Licensed Material available under these terms and conditions.
|
||||
|
||||
Section 1 – Definitions.
|
||||
|
||||
a. Adapted Material means material subject to Copyright and Similar Rights that is derived from or based upon the Licensed Material and in which the Licensed Material is translated, altered, arranged, transformed, or otherwise modified in a manner requiring permission under the Copyright and Similar Rights held by the Licensor. For purposes of this Public License, where the Licensed Material is a musical work, performance, or sound recording, Adapted Material is always produced where the Licensed Material is synched in timed relation with a moving image.
|
||||
|
||||
b. Adapter's License means the license You apply to Your Copyright and Similar Rights in Your contributions to Adapted Material in accordance with the terms and conditions of this Public License.
|
||||
|
||||
c. Copyright and Similar Rights means copyright and/or similar rights closely related to copyright including, without limitation, performance, broadcast, sound recording, and Sui Generis Database Rights, without regard to how the rights are labeled or categorized. For purposes of this Public License, the rights specified in Section 2(b)(1)-(2) are not Copyright and Similar Rights.
|
||||
|
||||
d. Effective Technological Measures means those measures that, in the absence of proper authority, may not be circumvented under laws fulfilling obligations under Article 11 of the WIPO Copyright Treaty adopted on December 20, 1996, and/or similar international agreements.
|
||||
|
||||
e. Exceptions and Limitations means fair use, fair dealing, and/or any other exception or limitation to Copyright and Similar Rights that applies to Your use of the Licensed Material.
|
||||
|
||||
f. Licensed Material means the artistic or literary work, database, or other material to which the Licensor applied this Public License.
|
||||
|
||||
g. Licensed Rights means the rights granted to You subject to the terms and conditions of this Public License, which are limited to all Copyright and Similar Rights that apply to Your use of the Licensed Material and that the Licensor has authority to license.
|
||||
|
||||
h. Licensor means the individual(s) or entity(ies) granting rights under this Public License.
|
||||
|
||||
i. NonCommercial means not primarily intended for or directed towards commercial advantage or monetary compensation. For purposes of this Public License, the exchange of the Licensed Material for other material subject to Copyright and Similar Rights by digital file-sharing or similar means is NonCommercial provided there is no payment of monetary compensation in connection with the exchange.
|
||||
|
||||
j. Share means to provide material to the public by any means or process that requires permission under the Licensed Rights, such as reproduction, public display, public performance, distribution, dissemination, communication, or importation, and to make material available to the public including in ways that members of the public may access the material from a place and at a time individually chosen by them.
|
||||
|
||||
k. Sui Generis Database Rights means rights other than copyright resulting from Directive 96/9/EC of the European Parliament and of the Council of 11 March 1996 on the legal protection of databases, as amended and/or succeeded, as well as other essentially equivalent rights anywhere in the world.
|
||||
|
||||
l. You means the individual or entity exercising the Licensed Rights under this Public License. Your has a corresponding meaning.
|
||||
|
||||
Section 2 – Scope.
|
||||
|
||||
a. License grant.
|
||||
|
||||
1. Subject to the terms and conditions of this Public License, the Licensor hereby grants You a worldwide, royalty-free, non-sublicensable, non-exclusive, irrevocable license to exercise the Licensed Rights in the Licensed Material to:
|
||||
|
||||
A. reproduce and Share the Licensed Material, in whole or in part, for NonCommercial purposes only; and
|
||||
|
||||
B. produce, reproduce, and Share Adapted Material for NonCommercial purposes only.
|
||||
|
||||
2. Exceptions and Limitations. For the avoidance of doubt, where Exceptions and Limitations apply to Your use, this Public License does not apply, and You do not need to comply with its terms and conditions.
|
||||
|
||||
3. Term. The term of this Public License is specified in Section 6(a).
|
||||
|
||||
4. Media and formats; technical modifications allowed. The Licensor authorizes You to exercise the Licensed Rights in all media and formats whether now known or hereafter created, and to make technical modifications necessary to do so. The Licensor waives and/or agrees not to assert any right or authority to forbid You from making technical modifications necessary to exercise the Licensed Rights, including technical modifications necessary to circumvent Effective Technological Measures. For purposes of this Public License, simply making modifications authorized by this Section 2(a)(4) never produces Adapted Material.
|
||||
|
||||
5. Downstream recipients.
|
||||
|
||||
A. Offer from the Licensor – Licensed Material. Every recipient of the Licensed Material automatically receives an offer from the Licensor to exercise the Licensed Rights under the terms and conditions of this Public License.
|
||||
|
||||
B. No downstream restrictions. You may not offer or impose any additional or different terms or conditions on, or apply any Effective Technological Measures to, the Licensed Material if doing so restricts exercise of the Licensed Rights by any recipient of the Licensed Material.
|
||||
|
||||
6. No endorsement. Nothing in this Public License constitutes or may be construed as permission to assert or imply that You are, or that Your use of the Licensed Material is, connected with, or sponsored, endorsed, or granted official status by, the Licensor or others designated to receive attribution as provided in Section 3(a)(1)(A)(i).
|
||||
|
||||
b. Other rights.
|
||||
|
||||
1. Moral rights, such as the right of integrity, are not licensed under this Public License, nor are publicity, privacy, and/or other similar personality rights; however, to the extent possible, the Licensor waives and/or agrees not to assert any such rights held by the Licensor to the limited extent necessary to allow You to exercise the Licensed Rights, but not otherwise.
|
||||
|
||||
2. Patent and trademark rights are not licensed under this Public License.
|
||||
|
||||
3. To the extent possible, the Licensor waives any right to collect royalties from You for the exercise of the Licensed Rights, whether directly or through a collecting society under any voluntary or waivable statutory or compulsory licensing scheme. In all other cases the Licensor expressly reserves any right to collect such royalties, including when the Licensed Material is used other than for NonCommercial purposes.
|
||||
|
||||
Section 3 – License Conditions.
|
||||
|
||||
Your exercise of the Licensed Rights is expressly made subject to the following conditions.
|
||||
|
||||
a. Attribution.
|
||||
|
||||
1. If You Share the Licensed Material (including in modified form), You must:
|
||||
|
||||
A. retain the following if it is supplied by the Licensor with the Licensed Material:
|
||||
|
||||
i. identification of the creator(s) of the Licensed Material and any others designated to receive attribution, in any reasonable manner requested by the Licensor (including by pseudonym if designated);
|
||||
|
||||
ii. a copyright notice;
|
||||
|
||||
iii. a notice that refers to this Public License;
|
||||
|
||||
iv. a notice that refers to the disclaimer of warranties;
|
||||
|
||||
v. a URI or hyperlink to the Licensed Material to the extent reasonably practicable;
|
||||
|
||||
B. indicate if You modified the Licensed Material and retain an indication of any previous modifications; and
|
||||
|
||||
C. indicate the Licensed Material is licensed under this Public License, and include the text of, or the URI or hyperlink to, this Public License.
|
||||
|
||||
2. You may satisfy the conditions in Section 3(a)(1) in any reasonable manner based on the medium, means, and context in which You Share the Licensed Material. For example, it may be reasonable to satisfy the conditions by providing a URI or hyperlink to a resource that includes the required information.
|
||||
|
||||
3. If requested by the Licensor, You must remove any of the information required by Section 3(a)(1)(A) to the extent reasonably practicable.
|
||||
|
||||
4. If You Share Adapted Material You produce, the Adapter's License You apply must not prevent recipients of the Adapted Material from complying with this Public License.
|
||||
|
||||
Section 4 – Sui Generis Database Rights.
|
||||
|
||||
Where the Licensed Rights include Sui Generis Database Rights that apply to Your use of the Licensed Material:
|
||||
|
||||
a. for the avoidance of doubt, Section 2(a)(1) grants You the right to extract, reuse, reproduce, and Share all or a substantial portion of the contents of the database for NonCommercial purposes only;
|
||||
|
||||
b. if You include all or a substantial portion of the database contents in a database in which You have Sui Generis Database Rights, then the database in which You have Sui Generis Database Rights (but not its individual contents) is Adapted Material; and
|
||||
|
||||
c. You must comply with the conditions in Section 3(a) if You Share all or a substantial portion of the contents of the database.
|
||||
For the avoidance of doubt, this Section 4 supplements and does not replace Your obligations under this Public License where the Licensed Rights include other Copyright and Similar Rights.
|
||||
|
||||
Section 5 – Disclaimer of Warranties and Limitation of Liability.
|
||||
|
||||
a. Unless otherwise separately undertaken by the Licensor, to the extent possible, the Licensor offers the Licensed Material as-is and as-available, and makes no representations or warranties of any kind concerning the Licensed Material, whether express, implied, statutory, or other. This includes, without limitation, warranties of title, merchantability, fitness for a particular purpose, non-infringement, absence of latent or other defects, accuracy, or the presence or absence of errors, whether or not known or discoverable. Where disclaimers of warranties are not allowed in full or in part, this disclaimer may not apply to You.
|
||||
|
||||
b. To the extent possible, in no event will the Licensor be liable to You on any legal theory (including, without limitation, negligence) or otherwise for any direct, special, indirect, incidental, consequential, punitive, exemplary, or other losses, costs, expenses, or damages arising out of this Public License or use of the Licensed Material, even if the Licensor has been advised of the possibility of such losses, costs, expenses, or damages. Where a limitation of liability is not allowed in full or in part, this limitation may not apply to You.
|
||||
|
||||
c. The disclaimer of warranties and limitation of liability provided above shall be interpreted in a manner that, to the extent possible, most closely approximates an absolute disclaimer and waiver of all liability.
|
||||
|
||||
Section 6 – Term and Termination.
|
||||
|
||||
a. This Public License applies for the term of the Copyright and Similar Rights licensed here. However, if You fail to comply with this Public License, then Your rights under this Public License terminate automatically.
|
||||
|
||||
b. Where Your right to use the Licensed Material has terminated under Section 6(a), it reinstates:
|
||||
|
||||
1. automatically as of the date the violation is cured, provided it is cured within 30 days of Your discovery of the violation; or
|
||||
|
||||
2. upon express reinstatement by the Licensor.
|
||||
|
||||
For the avoidance of doubt, this Section 6(b) does not affect any right the Licensor may have to seek remedies for Your violations of this Public License.
|
||||
|
||||
c. For the avoidance of doubt, the Licensor may also offer the Licensed Material under separate terms or conditions or stop distributing the Licensed Material at any time; however, doing so will not terminate this Public License.
|
||||
|
||||
d. Sections 1, 5, 6, 7, and 8 survive termination of this Public License.
|
||||
|
||||
Section 7 – Other Terms and Conditions.
|
||||
|
||||
a. The Licensor shall not be bound by any additional or different terms or conditions communicated by You unless expressly agreed.
|
||||
|
||||
b. Any arrangements, understandings, or agreements regarding the Licensed Material not stated herein are separate from and independent of the terms and conditions of this Public License.
|
||||
|
||||
Section 8 – Interpretation.
|
||||
|
||||
a. For the avoidance of doubt, this Public License does not, and shall not be interpreted to, reduce, limit, restrict, or impose conditions on any use of the Licensed Material that could lawfully be made without permission under this Public License.
|
||||
|
||||
b. To the extent possible, if any provision of this Public License is deemed unenforceable, it shall be automatically reformed to the minimum extent necessary to make it enforceable. If the provision cannot be reformed, it shall be severed from this Public License without affecting the enforceability of the remaining terms and conditions.
|
||||
|
||||
c. No term or condition of this Public License will be waived and no failure to comply consented to unless expressly agreed to by the Licensor.
|
||||
|
||||
d. Nothing in this Public License constitutes or may be interpreted as a limitation upon, or waiver of, any privileges and immunities that apply to the Licensor or You, including from the legal processes of any jurisdiction or authority.
|
||||
|
||||
Creative Commons is not a party to its public licenses. Notwithstanding, Creative Commons may elect to apply one of its public licenses to material it publishes and in those instances will be considered the “Licensor.” Except for the limited purpose of indicating that material is shared under a Creative Commons public license or as otherwise permitted by the Creative Commons policies published at creativecommons.org/policies, Creative Commons does not authorize the use of the trademark “Creative Commons” or any other trademark or logo of Creative Commons without its prior written consent including, without limitation, in connection with any unauthorized modifications to any of its public licenses or any other arrangements, understandings, or agreements concerning use of licensed material. For the avoidance of doubt, this paragraph does not form part of the public licenses.
|
||||
|
||||
Creative Commons may be contacted at creativecommons.org.
|
||||
89
README.md
Normal file
89
README.md
Normal file
|
|
@ -0,0 +1,89 @@
|
|||
# GPT-3.5 PyCord Discord Bot
|
||||
|
||||
|
||||
|
||||
This is a Discord Bot that Uses OpenAI's new Chat API-Endpoint to generate text like ChatGPT
|
||||
|
||||
## How to use
|
||||
|
||||
This Bot uses the PyCord Library ([PyCord](https://pycord.dev/)) and the OpenAI Python Library ([OpenAI](https://platform.openai.com/docs/libraries))
|
||||
|
||||
There are two ways to use this bot:
|
||||
|
||||
Using Docker or without Docker.
|
||||
|
||||
### The No Docker Way
|
||||
|
||||
1. Clone the Repo
|
||||
2. Install the requirements using `pip install -r requirements.txt`. Preferably in a virtual environment like `venv`.
|
||||
3. Get a Discord Bot Token from the [Discord Developer Portal](https://discord.com/developers/applications)
|
||||
- Create a new Application
|
||||
- Go to the Bot Tab and create a new Bot
|
||||
- Copy the Token
|
||||
- Also Check under Privileged Gateway Intents the following:
|
||||
- Server Members Intent
|
||||
- Message Content Intent
|
||||
4. Get an OpenAI API Key from [OpenAI](https://platform.openai.com/account/api-keys)
|
||||
6. Go to the `configs`-folder and create a file called `.env` in the config folder and add the following:
|
||||
|
||||
```shell
|
||||
DISCORD_TOKEN=Your_Bot_Token
|
||||
OPENAI_API_KEY=Your_OpenAI_API_Key
|
||||
```
|
||||
|
||||
6. Run the bot using `python main.py` or `python3 main.py`
|
||||
- To keep the Bot running in the background use `nohup python3 main.py &`
|
||||
- To stop the Bot use `pkill -f main.py`
|
||||
|
||||
### The Docker Way
|
||||
|
||||
1. Clone the Repo
|
||||
2. Get a Discord Bot Token from the [Discord Developer Portal](https://discord.com/developers/applications)
|
||||
- Create a new Application
|
||||
- Go to the Bot Tab and create a new Bot
|
||||
- Copy the Token
|
||||
- Also Check under Privileged Gateway Intents the following:
|
||||
- Server Members Intent
|
||||
- Message Content Intent
|
||||
3. Get an OpenAI API Key from [OpenAI](https://platform.openai.com/account/api-keys)
|
||||
4. Use `docker build -t discord-bot .` to build the Docker Image
|
||||
5. Make a folder called `chat`
|
||||
6. Make a folder called `config` and create a file called `.env` in the configs folder and add the following:
|
||||
|
||||
```shell
|
||||
DISCORD_TOKEN=Your_Bot_Token
|
||||
OPENAI_API_KEY=Your_OpenAI_API_Key
|
||||
```
|
||||
|
||||
7. Run the bot using `docker run -v /path/to/config:/usr/share/dcbot/configs -v /path/to/chat:/usr/share/dcbot/chats -d --name discord-bot discord-bot`
|
||||
8. To stop the Bot use `docker stop <container-id>`
|
||||
|
||||
## How to use the Bot
|
||||
|
||||
Once the Bot is running and you have invited it to your Server, you can use the following commands:
|
||||
|
||||
- /add text (channel-id) to Add the Bot to listen in a channel. The Bot will listen to all messages in that channel and answer them using GPT-3.5. The Bot will ignore Messages with a Prefix (Default - $)
|
||||
- /add prefix (channel-id) to Add the Bot to listen in a channel. The Bot will listen to all messages in that channel that start with the prefix and answer them using GPT-3.5 (Default - !)
|
||||
- /remove text/prefix (channel-id) to remove the Bot from listening in a channel.
|
||||
- /list text/prefix to list all channels the Bot is listening in.
|
||||
- /delete to delete the bots history from specific channels.
|
||||
- /help to get a list of all commands.
|
||||
- /ping to check if the Bot is online.
|
||||
- /setup (channelid) (System-Message) Changes the System-Message. See OenAI's Documentation for more information. [OpenAI Docs](https://platform.openai.com/docs/guides/chat/instructing-chat-models)
|
||||
|
||||
|
||||
### Future Improvements
|
||||
|
||||
- Currently I am working on an SQLite DB to store all information needed (eg. Servers, Channels, Configs, etc)
|
||||
- Also I am working on a way to toggle between GPT 3.5-turbo and GPT-4
|
||||
- Need to find and fix Bugs
|
||||
|
||||
### How to Contribute
|
||||
|
||||
If you want to contribute to this project, feel free to open a PR or Issue.
|
||||
|
||||
### Credits
|
||||
|
||||
- [OpenAI](https://openai.com/) for the GPT API
|
||||
- [PyCord](https://pycord.dev/) for the Discord API Wrapper
|
||||
- [Drone](https://drone.io/) for the CI/CD
|
||||
157
bot/bot.py
Normal file
157
bot/bot.py
Normal file
|
|
@ -0,0 +1,157 @@
|
|||
import asyncio
|
||||
import discord
|
||||
from discord.ext import commands
|
||||
from dotenv import load_dotenv
|
||||
import os
|
||||
import modules.gpt as gpt
|
||||
import modules.tts as tts
|
||||
import modules.summarize as summarize
|
||||
import modules.channelconfig as config
|
||||
|
||||
description = "ChatGPT Bot for Discord"
|
||||
configfolder = "configs"
|
||||
audiofolder = "audio"
|
||||
|
||||
load_dotenv(dotenv_path=os.path.join(configfolder, ".env"))
|
||||
|
||||
text_channels, prefix_channels = config.load_config()
|
||||
tts_language = "de-DE"
|
||||
|
||||
intents = discord.Intents.default()
|
||||
intents.message_content = True
|
||||
intents.members = True
|
||||
|
||||
bot = discord.Bot(
|
||||
command_prefix=commands.when_mentioned_or("!"),
|
||||
description=description,
|
||||
intents=intents,
|
||||
)
|
||||
|
||||
|
||||
@bot.event
|
||||
async def on_ready():
|
||||
print(f"We have logged in as {bot.user}")
|
||||
|
||||
|
||||
@bot.event
|
||||
async def on_message(message):
|
||||
if message.author == bot.user:
|
||||
return
|
||||
|
||||
if str(message.channel.id) in text_channels and not message.content.startswith("$"):
|
||||
await message.channel.trigger_typing()
|
||||
print(f'{message.author} asked: {message.content}')
|
||||
answer = await gpt.get_answer(message.channel.id, message.author, message.content)
|
||||
print(f'Answer: {answer}')
|
||||
await message.channel.send(answer)
|
||||
|
||||
if str(message.channel.id) in prefix_channels:
|
||||
if message.content.startswith("!"):
|
||||
msg_split = message.content.split("!")[1]
|
||||
await message.channel.trigger_typing()
|
||||
print(f'{message.author} asked: {message.content}')
|
||||
answer = await gpt.get_answer(message.channel.id, message.author, msg_split)
|
||||
print(f'Answer: {answer}')
|
||||
await message.channel.send(answer)
|
||||
|
||||
|
||||
@bot.command(name="add", description="Used to add Bot answering to specific Channels")
|
||||
async def add(
|
||||
ctx: discord.ApplicationContext,
|
||||
option: discord.Option(str, choices=["text","prefix"], description="Type of Channel to Add"),
|
||||
id: discord.Option(str, description="Channel-ID -> Activate Developer-Options to Copy")):
|
||||
|
||||
if ctx.author.guild_permissions.administrator:
|
||||
try:
|
||||
config.add_channel(option, id)
|
||||
|
||||
if option == "text":
|
||||
text_channels.append(id)
|
||||
|
||||
elif option == "prefix":
|
||||
prefix_channels.append(id)
|
||||
|
||||
await ctx.respond(f'{option} channel {id} added', ephemeral=True)
|
||||
except ValueError as e:
|
||||
await ctx.respond(f'Error: {e}', ephemeral=True)
|
||||
else:
|
||||
await ctx.respond(f'Error: You need to be an Administrator to use this command', ephemeral=True)
|
||||
|
||||
@bot.command(name="remove", description="Used to remove Bot answering to specific Channels")
|
||||
async def remove(
|
||||
ctx: discord.ApplicationContext,
|
||||
option: discord.Option(str, choices=["text", "prefix"], description="Type of Channel to Add"),
|
||||
id: discord.Option(str, description="Channel-ID -> Activate Developer-Options to Copy")):
|
||||
if ctx.author.guild_permissions.administrator:
|
||||
try:
|
||||
config.remove_channel(option, id)
|
||||
|
||||
if option == "text":
|
||||
text_channels.remove(id)
|
||||
|
||||
elif option == "prefix":
|
||||
prefix_channels.remove(id)
|
||||
|
||||
await ctx.respond(f'{option} channel {id} removed', ephemeral=True)
|
||||
except ValueError as e:
|
||||
await ctx.respond(f'Error: {e}', ephemeral=True)
|
||||
else:
|
||||
await ctx.respond(f'Error: You need to be an Administrator to use this command', ephemeral=True)
|
||||
|
||||
@bot.command(name="list", description="Used to list all Channels the Bot is answering to")
|
||||
async def list(
|
||||
ctx: discord.ApplicationContext,
|
||||
option: discord.Option(str, choices=["text", "prefix"], description="Type of Channels to List")):
|
||||
|
||||
if ctx.author.guild_permissions.administrator:
|
||||
if option == "text":
|
||||
await ctx.respond(f'{option} channels: {str(text_channels)}', ephemeral=True)
|
||||
elif option == "prefix":
|
||||
await ctx.respond(f'{option} channels: {str(prefix_channels)}', ephemeral=True)
|
||||
else:
|
||||
await ctx.respond(f'Error: You need to be an Administrator to use this command', ephemeral=True)
|
||||
|
||||
@bot.command(name="delete", description="Used to delete chat history of specific Channels/Users")
|
||||
async def delete(
|
||||
ctx: discord.ApplicationContext,
|
||||
option: discord.Option(str, choices=["text", "prefix"], description="Type of Channel to Delete"),
|
||||
id: discord.Option(str, description="Channel-ID -> Activate Developer-Options to Copy")):
|
||||
|
||||
if ctx.author.guild_permissions.administrator:
|
||||
try:
|
||||
gpt.delete_history(id)
|
||||
await ctx.respond(f'{option} channel {id} history deleted', ephemeral=True)
|
||||
except Exception as e:
|
||||
await ctx.respond(f'Error: {e}', ephemeral=True)
|
||||
else:
|
||||
await ctx.respond(f'Error: You need to be an Administrator to use this command', ephemeral=True)
|
||||
|
||||
@bot.command(name="help", description="Used to get help")
|
||||
async def help(ctx: discord.ApplicationContext):
|
||||
await ctx.respond(f'Here is a list of all commands:\n'
|
||||
f'/ping\n'
|
||||
f'/setup <channel-id> <system-message>\n'
|
||||
f'/add <text/prefix> <channel-id>\n'
|
||||
f'/remove <text/prefix> <channel-id>\n'
|
||||
f'/list <text/prefix>\n'
|
||||
f'/delete <text/prefix> <channel-id>\n'
|
||||
f'/help', ephemeral=True)
|
||||
|
||||
@bot.command(name="ping", description="Used to check if the bot is alive")
|
||||
async def ping(ctx: discord.ApplicationContext):
|
||||
await ctx.respond(f'pong', ephemeral=True)
|
||||
|
||||
@bot.command(name="setup", description="Used to setup the bot with a custom system message")
|
||||
async def setup(ctx: discord.ApplicationContext,
|
||||
id: discord.Option(str, description="Channel-ID -> Activate Developer-Options to Copy"),
|
||||
message: discord.Option(str, description="System Message")):
|
||||
if ctx.author.guild_permissions.administrator:
|
||||
try:
|
||||
gpt.setup_history(id, message)
|
||||
await ctx.respond(f'Setup successful', ephemeral=True)
|
||||
except Exception as e:
|
||||
await ctx.respond(f'Error: {e}', ephemeral=True)
|
||||
else:
|
||||
await ctx.respond(f'Error: You need to be an Administrator to use this command', ephemeral=True)
|
||||
|
||||
bot.run(str(os.environ.get('DISCORD_TOKEN')))
|
||||
0
bot/configs/prefix_channels.txt
Normal file
0
bot/configs/prefix_channels.txt
Normal file
0
bot/configs/text_channels.txt
Normal file
0
bot/configs/text_channels.txt
Normal file
51
bot/featuretest.py
Normal file
51
bot/featuretest.py
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
import modules.channelconfig as config
|
||||
import modules.gpt as gpt
|
||||
import os
|
||||
|
||||
text_channels = config.load_config()
|
||||
|
||||
def listen_input(username, channel):
|
||||
message = input(f'{username} {channel}: ')
|
||||
if message.startswith("/"):
|
||||
print(slash_command(username, channel, message))
|
||||
elif message.startswith("$") and channel in text_channels:
|
||||
ask_gpt(username, channel, message)
|
||||
else:
|
||||
print(log_message(username, channel, message))
|
||||
|
||||
|
||||
def log_message(user, channel, message):
|
||||
return f'User {user} sent "{message}" in {channel}'
|
||||
|
||||
# Slash Command Wrapper
|
||||
def slash_command(user, channel, message):
|
||||
message = message.split("/")[1].split(" ")
|
||||
# Add Channels to Config
|
||||
if message[0] == "add":
|
||||
pass
|
||||
if message[1] == "text":
|
||||
config.add_channel("text", message[2])
|
||||
print("Added Channel to Config")
|
||||
|
||||
# Remove Channels from Config
|
||||
elif message[0] == "remove":
|
||||
if message[1] == "text":
|
||||
return config.remove_channel("text", message[2])
|
||||
# Reload Config
|
||||
elif message[0] == "reload":
|
||||
text_channels = config.load_config()
|
||||
return text_channels
|
||||
else:
|
||||
return "Invalid Command"
|
||||
|
||||
def ask_gpt(user, id, message):
|
||||
message = message.split('$')[1]
|
||||
answer = gpt.get_answer(id, user, message)
|
||||
print(answer)
|
||||
|
||||
username = "XYZ"
|
||||
channel = "112233445566"
|
||||
|
||||
while True:
|
||||
text_channels = config.load_config()
|
||||
listen_input(username, channel)
|
||||
88
bot/modules/channelconfig.py
Normal file
88
bot/modules/channelconfig.py
Normal file
|
|
@ -0,0 +1,88 @@
|
|||
# Rewrite of Channelmgmt
|
||||
from os import path
|
||||
|
||||
folder = "configs"
|
||||
text_channel_file = "text_channels.txt"
|
||||
prefix_channel_file = "prefix_channels.txt"
|
||||
|
||||
def load_config():
|
||||
# Load Text-Channel Config
|
||||
try:
|
||||
with open(path.join(folder,text_channel_file), "r") as f:
|
||||
text_channels = f.read().split("\n")
|
||||
except Exception as error:
|
||||
print(f'File not Fount, creating new. {error}')
|
||||
with open(path.join(folder,text_channel_file), "w") as f:
|
||||
f.write('')
|
||||
text_channels = []
|
||||
# Load Prefix-Channel Config
|
||||
try:
|
||||
with open(path.join(folder, prefix_channel_file), "r") as f:
|
||||
prefix_channels = f.read().split("\n")
|
||||
except Exception as error:
|
||||
print(f'File not Fount, creating new. {error}')
|
||||
with open(path.join(folder, prefix_channel_file), "w") as f:
|
||||
f.write('')
|
||||
prefix_channels = []
|
||||
|
||||
return text_channels, prefix_channels
|
||||
|
||||
# Add Channel to Config
|
||||
def add_channel(type, id):
|
||||
try:
|
||||
if type == "text":
|
||||
text_channels = load_config()
|
||||
if id in text_channels:
|
||||
# Throw Error if already in List
|
||||
raise ValueError("Channel already in List")
|
||||
else:
|
||||
with open(path.join(folder, text_channel_file), 'a') as f:
|
||||
f.write(f'{id}\n')
|
||||
return True
|
||||
elif type == "prefix":
|
||||
prefix_channels = load_config()
|
||||
if id in prefix_channels:
|
||||
# Throw Error if already in List
|
||||
raise ValueError("Channel already in List")
|
||||
else:
|
||||
with open(path.join(folder, prefix_channel_file), 'a') as f:
|
||||
f.write(f'{id}\n')
|
||||
return True
|
||||
|
||||
except FileNotFoundError as error:
|
||||
load_config()
|
||||
add_channel(type, id)
|
||||
|
||||
def remove_channel(type, id):
|
||||
try:
|
||||
if type == "text":
|
||||
text_channels = load_config()
|
||||
if id in text_channels:
|
||||
text_channels.remove(id)
|
||||
new_conf = ""
|
||||
for x in text_channels:
|
||||
new_conf += f'{x}\n'
|
||||
|
||||
with open(path.join(folder, text_channel_file), 'w') as f:
|
||||
f.write(new_conf)
|
||||
return True
|
||||
else:
|
||||
raise ValueError("Channel not in List")
|
||||
|
||||
elif type == "prefix":
|
||||
prefix_channels = load_config()
|
||||
if id in prefix_channels:
|
||||
prefix_channels.remove(id)
|
||||
new_conf = ""
|
||||
for x in prefix_channels:
|
||||
new_conf += f'{x}\n'
|
||||
|
||||
with open(path.join(folder, prefix_channel_file), 'w') as f:
|
||||
f.write(new_conf)
|
||||
return True
|
||||
else:
|
||||
raise ValueError("Channel not in List")
|
||||
|
||||
except Exception as error:
|
||||
print(error)
|
||||
return False
|
||||
111
bot/modules/gpt.py
Normal file
111
bot/modules/gpt.py
Normal file
|
|
@ -0,0 +1,111 @@
|
|||
import openai
|
||||
import json
|
||||
import os
|
||||
from dotenv import load_dotenv
|
||||
import modules.summarize as summarize
|
||||
import asyncio
|
||||
|
||||
load_dotenv(os.path.join("configs", ".env"))
|
||||
openai.api_key = os.environ.get('OPENAI_API_KEY')
|
||||
folder = 'chats'
|
||||
|
||||
|
||||
def load_history(id):
|
||||
filename = f'{id}.json'
|
||||
try:
|
||||
with open(os.path.join(folder, filename), 'r') as f:
|
||||
json.load(f)
|
||||
|
||||
except FileNotFoundError as error:
|
||||
print(f'File not Found, creating... {error}')
|
||||
if id == "199":
|
||||
data = 'summarize:'
|
||||
setup_history(id, data)
|
||||
else:
|
||||
data = 'default:'
|
||||
setup_history(id, data)
|
||||
|
||||
except json.JSONDecodeError as error:
|
||||
os.remove(os.path.join(folder, filename))
|
||||
print(f'File is empty, creating... {error}')
|
||||
load_history(id)
|
||||
|
||||
with open(os.path.join(folder, filename), 'r') as f:
|
||||
f = json.load(f)
|
||||
|
||||
return f
|
||||
|
||||
def update_history(id, data):
|
||||
filename = f'{id}.json'
|
||||
try:
|
||||
with open(os.path.join(folder, filename), "r") as f:
|
||||
loaded = json.load(f)
|
||||
loaded.append(data)
|
||||
|
||||
with open(os.path.join(folder, filename), "w") as f:
|
||||
json.dump(loaded, f)
|
||||
|
||||
except Exception as error:
|
||||
print(error)
|
||||
|
||||
def delete_history(id):
|
||||
filename = f'{id}.json'
|
||||
try:
|
||||
os.remove(os.path.join(folder, filename))
|
||||
return "Successfully deleted"
|
||||
except Exception as error:
|
||||
return error
|
||||
|
||||
async def get_answer(id, user, message):
|
||||
try:
|
||||
history = load_history(id)
|
||||
add_history = {"role": "user", "content": f'{user}: {message}'}
|
||||
update_history(id, add_history)
|
||||
history.append(add_history)
|
||||
answer = openai.ChatCompletion.create(
|
||||
model="gpt-3.5-turbo",
|
||||
messages=history
|
||||
)
|
||||
answer = answer['choices'][0]['message']['content']
|
||||
update_history(id, {"role": "assistant", "content": f"{answer}"})
|
||||
if len(history) >= 26:
|
||||
await summarize.summarize(id)
|
||||
|
||||
return answer
|
||||
except Exception as error:
|
||||
return "Error while trying to use ChatAPI: " + str(error)
|
||||
|
||||
# def get_answergpt4(id, user, message):
|
||||
# try:
|
||||
# update_history(id, {"role": "user", "content": f'{user}: {message}'})
|
||||
# history = load_history(id)
|
||||
# answer = openai.ChatCompletion.create(
|
||||
# model="gpt-4",
|
||||
# messages=history
|
||||
# )
|
||||
# answer = answer['choices'][0]['message']['content']
|
||||
# update_history(id, {"role": "assistant", "content": f"{answer}"})
|
||||
# print(len(history))
|
||||
# if len(history) >= 23:
|
||||
# summarize.summarize(id)
|
||||
#
|
||||
# return answer
|
||||
# except Exception as error:
|
||||
# return "Error while trying to use ChatAPI " + str(error)
|
||||
|
||||
def setup_history(id, message):
|
||||
filename = f'{id}.json'
|
||||
|
||||
if message == "summarize":
|
||||
message = [{"role": "system", "content": "You summarize conversation. You keep the most important things. Everything else can be removed."}]
|
||||
elif message == "default":
|
||||
message = [{"role": "system", "content": "You are an helpful assistant. Every Message the user writes starts with their username, the numbers and # must be ignored"}]
|
||||
else:
|
||||
message = [{"role": "system", "content": f"The Username consists of a name#numbers. The numbers can be ignored. {message}"}]
|
||||
|
||||
# If file exists, delete it
|
||||
if os.path.exists(os.path.join(folder, filename)):
|
||||
os.remove(os.path.join(folder, filename))
|
||||
# Create new file
|
||||
with open(os.path.join(folder, filename), "w") as f:
|
||||
json.dump(message, f)
|
||||
34
bot/modules/summarize.py
Normal file
34
bot/modules/summarize.py
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
import modules.gpt as gpt
|
||||
import json
|
||||
import os
|
||||
import asyncio
|
||||
|
||||
folder = 'chats'
|
||||
async def summarize(id):
|
||||
filename = f'{id}.json'
|
||||
history = gpt.load_history(id)
|
||||
new_string = ''
|
||||
if history[1]['role'] == 'system':
|
||||
new_string += f"System: {history[1]['content']}\n"
|
||||
|
||||
for x in history[:-15]:
|
||||
if x['role'] == "assistant":
|
||||
new_string += f"Assistant: {x['content']}\n"
|
||||
elif x['role'] == "user":
|
||||
new_string += f"{x['content']}\n"
|
||||
|
||||
message = f'Please Summarize following Conversation:\n\n{new_string}'
|
||||
|
||||
summarised = await gpt.get_answer('199', '', message)
|
||||
|
||||
new_systemmsg = {'role': 'system', 'content': f'You got the following Summary of previous conversations:\n\n {summarised}'}
|
||||
history[1] = new_systemmsg
|
||||
|
||||
history = history[:2] + history[-15:]
|
||||
|
||||
with open(os.path.join(folder, filename), 'w') as f:
|
||||
json.dump(history, f)
|
||||
|
||||
os.remove(os.path.join(folder, '199.json'))
|
||||
|
||||
return summarised
|
||||
24
bot/modules/tts.py
Normal file
24
bot/modules/tts.py
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
# from TTS.api import TTS
|
||||
# import uuid
|
||||
# import os
|
||||
# import asyncio
|
||||
#
|
||||
# # Use Model tts_models/de/thorsten/tacotron2-DCA
|
||||
# # coqui-ai
|
||||
#
|
||||
# async def generate_audio(text):
|
||||
# loop = asyncio.get_event_loop()
|
||||
# folder = "audio"
|
||||
# filename = f"{uuid.uuid4().hex}.wav"
|
||||
# path = os.path.join(folder, filename)
|
||||
#
|
||||
# try:
|
||||
# def tts_to_file_blocking():
|
||||
# tts = TTS(model_name="tts_models/de/thorsten/tacotron2-DDC", progress_bar=True, gpu=False)
|
||||
# tts.tts_to_file(text=text, file_path=path)
|
||||
#
|
||||
# await loop.run_in_executor(None, tts_to_file_blocking)
|
||||
# return path
|
||||
# except Exception as e:
|
||||
# print(e)
|
||||
# return str(e)
|
||||
24
bot/summary.py
Normal file
24
bot/summary.py
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
import modules.summarize as summarize
|
||||
import modules.gpt as gpt
|
||||
|
||||
|
||||
history = gpt.load_history('112233445566')
|
||||
|
||||
#print(summarize.summarize('112233445566'))
|
||||
|
||||
new_string = ''
|
||||
if history[1]['role'] == 'system':
|
||||
new_string += f"System:{history[1]['content']}\n"
|
||||
|
||||
for x in history[:-3]:
|
||||
if x['role'] == "assistant":
|
||||
new_string += f"Assistant: {x['content']}\n"
|
||||
elif x['role'] == "user":
|
||||
new_string += f"{x['content']}\n"
|
||||
|
||||
print(new_string)
|
||||
print(history[1])
|
||||
|
||||
history[1] = {'test'}
|
||||
|
||||
print(history)
|
||||
19
requirements.txt
Normal file
19
requirements.txt
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
aiohttp==3.8.4
|
||||
aiosignal==1.3.1
|
||||
async-timeout==4.0.2
|
||||
attrs==22.2.0
|
||||
certifi==2022.12.7
|
||||
charset-normalizer==3.1.0
|
||||
colorama==0.4.6
|
||||
frozenlist==1.3.3
|
||||
idna==3.4
|
||||
multidict==6.0.4
|
||||
openai==0.27.2
|
||||
py-cord==2.4.0
|
||||
python-dotenv==1.0.0
|
||||
requests==2.28.2
|
||||
tqdm==4.65.0
|
||||
typing_extensions==4.5.0
|
||||
urllib3==1.26.15
|
||||
yarl==1.8.2
|
||||
PyNaCl==1.5.0
|
||||
69
todo.txt
Normal file
69
todo.txt
Normal file
|
|
@ -0,0 +1,69 @@
|
|||
General:
|
||||
(x) - Bot Functionality
|
||||
(x) - Docker-Container
|
||||
() - Add PyTests#
|
||||
() - Add sqlite3 or other DB
|
||||
|
||||
channelconfig.py:
|
||||
(x) - Return True/False if prcoessed wrong/right
|
||||
(x) - Confirmial/Denial Message inside Bot
|
||||
|
||||
Feature Testing:
|
||||
|
||||
() - Slash Commands
|
||||
(X) - Add Text Channel
|
||||
(X) - Remove Text Channel
|
||||
() - list Text Channels
|
||||
() - Toggle/Change Prefix
|
||||
() - Switch GPT3-5 / GPT-4
|
||||
() - Clear History
|
||||
|
||||
Test-Discord Bot:
|
||||
|
||||
() - Slash Commands
|
||||
(x) - Add Text Channel
|
||||
(x) - Remove Text Channel
|
||||
(x) - list Text Channels
|
||||
(x) - delete Chat history
|
||||
(x) - Custom System Messages per Channel
|
||||
(x) - Toggle Prefix
|
||||
() - Change Prefix -> Needs SQLite DB
|
||||
() - Switch GPT3-5 / GPT-4
|
||||
(x) - Clear History
|
||||
(x) - Bot Functionality
|
||||
(x) - Docker-Container
|
||||
|
||||
Discord Bot:
|
||||
|
||||
() - Slash Commands
|
||||
(X) - Add Text Channel
|
||||
(X) - Remove Text Channel
|
||||
() - Toggle/Change Prefix
|
||||
() - Switch GPT3-5 / GPT-4
|
||||
() - Clear History
|
||||
() - Bot Functionality
|
||||
() - Docker-Container
|
||||
() - Add PyTests
|
||||
|
||||
Important Files:
|
||||
|
||||
.drone.yml | 92 Lines
|
||||
Dockerfile | 8 Lines
|
||||
requirements.txt | 18 Lines
|
||||
README.md | 2 Lines
|
||||
todo.txt | 69 Lines
|
||||
bot/ |
|
||||
bot.py | 75 Lines
|
||||
testbot.py | 154 Lines
|
||||
modules/ |
|
||||
channelconfig.py | 88 Lines
|
||||
gpt.py | 101 Lines
|
||||
summarize.py | 30 Lines
|
||||
configs/ |
|
||||
.env | 2 Lines
|
||||
text_channels.txt |
|
||||
prefix_channels.txt |
|
||||
chats/ |
|
||||
channelid.json |
|
||||
{...} _________________________
|
||||
All Lines | 639 Lines
|
||||
Loading…
Reference in New Issue
Block a user