diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..176a458 --- /dev/null +++ b/.gitattributes @@ -0,0 +1 @@ +* text=auto diff --git a/.github/delete-merged-branch-config.yml b/.github/delete-merged-branch-config.yml new file mode 100644 index 0000000..07d5b8b --- /dev/null +++ b/.github/delete-merged-branch-config.yml @@ -0,0 +1,5 @@ +exclude: + - main + - stable + - develop +delete_closed_pr: true diff --git a/.github/workflows/dependency-updates.yml b/.github/workflows/dependency-updates.yml new file mode 100644 index 0000000..c0dc604 --- /dev/null +++ b/.github/workflows/dependency-updates.yml @@ -0,0 +1,35 @@ +name: dependency-updates +on: + push: + branches: + - develop + schedule: + - cron: "0 */6 * * *" + workflow_dispatch: +jobs: + peertube-update: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: update peertube version + id: update + run: | + PT_VERSION="$( + git ls-remote --tags https://github.com/Chocobozzz/PeerTube \ + | cut -d/ -f3 \ + | sort -V \ + | tail -1 \ + | sed "s|\^{}||g" + )" + sed -i "s|PT_VERSION=.*|PT_VERSION=$PT_VERSION \\\|" ./Dockerfile + echo "version=$PT_VERSION" >> $GITHUB_OUTPUT + - name: Create Pull Request + uses: peter-evans/create-pull-request@v6 + with: + signoff: true + delete-branch: true + commit-message: update peertube version to ${{ steps.update.outputs.version }} + branch: update-peertube-version + title: update peertube version to ${{ steps.update.outputs.version }} + body: update peertube version to ${{ steps.update.outputs.version }} diff --git a/.github/workflows/docker-latest.yml b/.github/workflows/docker-latest.yml new file mode 100644 index 0000000..c8a26d1 --- /dev/null +++ b/.github/workflows/docker-latest.yml @@ -0,0 +1,26 @@ +name: Docker push develop to latest +on: + workflow_dispatch: +jobs: + docker: + runs-on: ubuntu-latest + steps: + - name: Login to DockerHub + if: github.event_name != 'pull_request' + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + - name: Convert Username + id: un + run: echo "un=$(echo "${{ github.repository_owner }}" | tr '[:upper:]' '[:lower:]')" >> $GITHUB_OUTPUT + - name: Login to GitHub Container Registry + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ steps.un.outputs.un }} + password: ${{ github.token }} + - name: Push develop to latest + run: | + docker buildx imagetools create --tag ${{ steps.un.outputs.un }}/${{ github.event.repository.name }}:latest ${{ steps.un.outputs.un }}/${{ github.event.repository.name }}:${{ github.ref_name }} + docker buildx imagetools create --tag ghcr.io/${{ steps.un.outputs.un }}/${{ github.event.repository.name }}:latest ghcr.io/${{ steps.un.outputs.un }}/${{ github.event.repository.name }}:${{ github.ref_name }} diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml new file mode 100644 index 0000000..654febe --- /dev/null +++ b/.github/workflows/docker.yml @@ -0,0 +1,77 @@ +name: Build Docker Image +on: +# schedule: +# - cron: "0 0 */6 * *" + push: + branches: + - latest + - develop + paths: + - Dockerfile + - .github/workflows/docker.yml + pull_request: + paths: + - Dockerfile + - .github/workflows/docker.yml + workflow_dispatch: +jobs: + build: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + with: + platforms: arm64 #all + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + with: + driver-opts: env.BUILDKIT_STEP_LOG_MAX_SIZE=-1 + - name: Login to DockerHub + if: ${{ github.event_name != 'pull_request' }} + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + - name: Convert Username + id: un + run: echo "un=$(echo "${{ github.repository_owner }}" | tr '[:upper:]' '[:lower:]')" >> $GITHUB_OUTPUT + - name: Login to GitHub Container Registry + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ steps.un.outputs.un }} + password: ${{ github.token }} + - name: Build + uses: docker/build-push-action@v6 + if: ${{ github.event_name != 'pull_request' }} + with: + context: . + file: ./Dockerfile + platforms: linux/amd64,linux/arm64 #,linux/amd64/v2,linux/amd64/v3,linux/amd64/v4 #,linux/ppc64le,linux/s390x,linux/386,linux/arm/v7,linux/arm/v6 + push: ${{ github.event_name != 'pull_request' }} + tags: | + ${{ steps.un.outputs.un }}/${{ github.event.repository.name }}:${{ github.ref_name }} + ${{ steps.un.outputs.un }}/${{ github.event.repository.name }}:${{ github.run_number }} + ghcr.io/${{ steps.un.outputs.un }}/${{ github.event.repository.name }}:${{ github.ref_name }} + ghcr.io/${{ steps.un.outputs.un }}/${{ github.event.repository.name }}:${{ github.run_number }} + - name: Set PR-Number (PR) + if: ${{ github.event_name == 'pull_request' }} + id: pr + run: echo "pr=$(echo pr-${{ github.ref_name }} | sed "s|refs/pull/:||g" | sed "s|/merge||g")" >> $GITHUB_OUTPUT + - name: Build (PR) + uses: docker/build-push-action@v6 + if: ${{ github.event_name == 'pull_request' }} + with: + context: . + file: ./Dockerfile + platforms: linux/amd64,linux/arm64 #,linux/amd64/v2,linux/amd64/v3,linux/amd64/v4 #,linux/ppc64le,linux/s390x,linux/386,linux/arm/v7,linux/arm/v6 + push: ${{ github.event_name == 'pull_request' }} + tags: ghcr.io/${{ steps.un.outputs.un }}/${{ github.event.repository.name }}:${{ steps.pr.outputs.pr }} + - name: add comment (PR) + uses: mshick/add-pr-comment@v2 + if: ${{ github.event_name == 'pull_request' }} + with: + message: "The Docker Image can now be found here: `ghcr.io/${{ steps.un.outputs.un }}/${{ github.event.repository.name }}:${{ steps.pr.outputs.pr }}`" + repo-token: ${{ github.token }} diff --git a/.github/workflows/dockerlint.yml b/.github/workflows/dockerlint.yml new file mode 100644 index 0000000..47508e9 --- /dev/null +++ b/.github/workflows/dockerlint.yml @@ -0,0 +1,28 @@ +name: Dockerlint +on: + push: + pull_request: + workflow_dispatch: +jobs: + docker-lint: + runs-on: ubuntu-latest + name: docker-lint + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Install hadolint + run: | + sudo wget https://github.com/hadolint/hadolint/releases/latest/download/hadolint-Linux-x86_64 -O /usr/bin/hadolint + sudo chmod +x /usr/bin/hadolint + - name: run lint + run: | + DOCKERFILES="$(find . -name "*Dockerfile*")" + for file in $(echo "$DOCKERFILES" | tr " " "\n"); do + # DL3003 warning: Use WORKDIR to switch to a directory + # DL3018 warning: Pin versions in apk add. Instead of `apk add ` use `apk add =` + # DL3013 warning: Pin versions in pip. Instead of `pip install ` use `pip install ==` or `pip install --requirement ` + hadolint "$file" --ignore DL3003 --ignore DL3013 --ignore DL3018 | tee -a hadolint.log + done + if grep -q "DL[0-9]\+\|SC[0-9]\+" hadolint.log; then + exit 1 + fi diff --git a/.github/workflows/json.yml b/.github/workflows/json.yml new file mode 100644 index 0000000..702313b --- /dev/null +++ b/.github/workflows/json.yml @@ -0,0 +1,14 @@ +name: JSON check +on: + push: + pull_request: + workflow_dispatch: +jobs: + test-json: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: json-syntax-check + uses: limitusus/json-syntax-check@v2 + with: + pattern: "\\.json" diff --git a/.github/workflows/spellcheck.yml b/.github/workflows/spellcheck.yml new file mode 100644 index 0000000..ccd319d --- /dev/null +++ b/.github/workflows/spellcheck.yml @@ -0,0 +1,18 @@ +name: spellcheck +on: + push: + pull_request: + workflow_dispatch: +jobs: + spellcheck: + name: spellcheck + runs-on: ubuntu-latest + steps: + - name: Check out code. + uses: actions/checkout@v4 + - name: Check spelling + uses: codespell-project/actions-codespell@v2 + with: + check_filenames: true + check_hidden: true + skip: .git,.gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..568d4b9 --- /dev/null +++ b/.gitignore @@ -0,0 +1,784 @@ +# User-specific stuff +.idea +desktop.files.json +package-lock.json +yarn.lock +desktop.ini + +### macOS ### +# General +.DS_Store +.AppleDouble +.LSOverride + +composer.phar +/vendor/ + +!/jobs +!/.gitignore +!/*.xml + +#ignore all files in jobs subdirectories except for folders +#note: git doesn't track folders, only file content +jobs/** +!jobs/**/ + +#uncomment the following line to save next build numbers with config +#!jobs/**/nextBuildNumber + +#exclude only config.xml files in repository subdirectories +!config.xml + +#don't track workspaces (when users build on the master) +jobs/**/*workspace + +*.iml +*.ipr +*.iws + +# IntelliJ +out + +# Compiled class file +*.class + +# Log file +*.log + +# BlueJ files +*.ctxt + +# Package Files # +*.jar +*.war +*.nar +*.ear +*.zip +*.tar.gz +*.rar + +# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml +hs_err_pid* + +*~ + +# temporary files which can be created if a process still has a handle open of a deleted file +.fuse_hidden* + +# KDE directory preferences +.directory + +# Linux trash folder which might appear on any partition or disk +.Trash-* + +# .nfs files are created when an open file is removed but is still being accessed +.nfs* + +# Icon must end with two \r +Icon + +# Thumbnails +._* + +# Files that might appear in the root of a volume +.DocumentRevisions-V100 +.fseventsd +.Spotlight-V100 +.TemporaryItems +.Trashes +.VolumeIcon.icns +.com.apple.timemachine.donotpresent + +# Directories potentially created on remote AFP share +.AppleDB +.AppleDesktop +Network Trash Folder +Temporary Items +.apdisk + +# Windows thumbnail cache files +Thumbs.db +Thumbs.db:encryptable +ehthumbs.db +ehthumbs_vista.db + +# Dump file +*.stackdump + +# Folder config file +[Dd]esktop.ini + +# Recycle Bin used on file shares +$RECYCLE.BIN + +# Windows Installer files +*.cab +*.msi +*.msix +*.msm +*.msp + +# Windows shortcuts +*.lnk + +.gradle +/build/ + +# Ignore Gradle GUI config +gradle-app.setting + +# Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored) +!gradle-wrapper.jar + +# Cache of project +.gradletasknamecache + +target/ +pom.xml.tag +pom.xml.releaseBackup +pom.xml.versionsBackup +pom.xml.next +release.properties +dependency-reduced-pom.xml +buildNumber.properties +.mvn/timing.properties +# https://github.com/takari/maven-wrapper#usage-without-binary-jar +.mvn/wrapper/maven-wrapper.jar +.flattened-pom.xml + +# Common working directory +run + +# Logs +logs +*.log +npm-debug.log* +yarn-debug.log* +yarn-error.log* +lerna-debug.log* + +# Diagnostic reports (https://nodejs.org/api/report.html) +report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json + +# Runtime data +pids +*.pid +*.seed +*.pid.lock + +# Directory for instrumented libs generated by jscoverage/JSCover +lib-cov + +# Coverage directory used by tools like istanbul +coverage +*.lcov + +# nyc test coverage +.nyc_output + +# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) +.grunt + +# Bower dependency directory (https://bower.io/) +bower_components + +# node-waf configuration +.lock-wscript + +# Compiled binary addons (https://nodejs.org/api/addons.html) +build/Release + +# Dependency directories +node_modules/ +jspm_packages/ + +# TypeScript v1 declaration files +typings/ + +# TypeScript cache +*.tsbuildinfo + +# Optional npm cache directory +.npm + +# Optional eslint cache +.eslintcache + +# Microbundle cache +.rpt2_cache/ +.rts2_cache_cjs/ +.rts2_cache_es/ +.rts2_cache_umd/ + +# Optional REPL history +.node_repl_history + +# Output of 'npm pack' +*.tgz + +# Yarn Integrity file +.yarn-integrity + +# dotenv environment variables file +.env +.env.test + +# parcel-bundler cache (https://parceljs.org/) +.cache + +# Next.js build output +.next + +# Nuxt.js build / generate output +.nuxt +dist + +# Gatsby files +.cache/ +# Comment in the public line in if your project uses Gatsby and *not* Next.js +# https://nextjs.org/blog/next-9-1#public-directory-support +# public + +# vuepress build output +.vuepress/dist + +# Serverless directories +.serverless/ + +# FuseBox cache +.fusebox/ + +# DynamoDB Local files +.dynamodb/ + +# TernJS port file +.tern-port + +/vendor/ +node_modules/ +npm-debug.log +yarn-error.log + +# Laravel 4 specific +bootstrap/compiled.php +app/storage/ + +# Laravel 5 & Lumen specific +public/storage +public/hot + +# Laravel 5 & Lumen specific with changed public path +public_html/storage +public_html/hot + +storage/*.key +.env +Homestead.yaml +Homestead.json +/.vagrant +.phpunit.result.cache + +# 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/ +pip-wheel-metadata/ +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/ + +# 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 +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# IPython +profile_default/ +ipython_config.py + +# pyenv +.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 + +# PEP 582; used by e.g. github.com/David-OConnor/pyflow +__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/ + +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. +## +## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore + +# User-specific files +*.rsuser +*.suo +*.user +*.userosscache +*.sln.docstates + +# User-specific files (MonoDevelop/Xamarin Studio) +*.userprefs + +# Mono auto generated files +mono_crash.* + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +[Rr]eleases/ +x64/ +x86/ +[Aa][Rr][Mm]/ +[Aa][Rr][Mm]64/ +bld/ +[Bb]in/ +[Oo]bj/ +[Ll]og/ +[Ll]ogs/ + +# Visual Studio 2015/2017 cache/options directory +.vs/ +# Uncomment if you have tasks that create the project's static files in wwwroot +#wwwroot/ + +# Visual Studio 2017 auto generated files +Generated\ Files/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +# NUnit +*.VisualState.xml +TestResult.xml +nunit-*.xml + +# Build Results of an ATL Project +[Dd]ebugPS/ +[Rr]eleasePS/ +dlldata.c + +# Benchmark Results +BenchmarkDotNet.Artifacts/ + +# .NET Core +project.lock.json +project.fragment.lock.json +artifacts/ + +# StyleCop +StyleCopReport.xml + +# Files built by Visual Studio +*_i.c +*_p.c +*_h.h +*.ilk +*.meta +*.obj +*.iobj +*.pch +*.pdb +*.ipdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*_wpftmp.csproj +*.log +*.vspscc +*.vssscc +.builds +*.pidb +*.svclog +*.scc + +# Chutzpah Test files +_Chutzpah* + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opendb +*.opensdf +*.sdf +*.cachefile +*.VC.db +*.VC.VC.opendb + +# Visual Studio profiler +*.psess +*.vsp +*.vspx +*.sap + +# Visual Studio Trace Files +*.e2e + +# TFS 2012 Local Workspace +$tf/ + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper +*.DotSettings.user + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# AxoCover is a Code Coverage Tool +.axoCover/* +!.axoCover/settings.json + +# Visual Studio code coverage results +*.coverage +*.coveragexml + +# NCrunch +_NCrunch_* +.*crunch*.local.xml +nCrunchTemp_* + +# MightyMoose +*.mm.* +AutoTest.Net/ + +# Web workbench (sass) +.sass-cache/ + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.[Pp]ublish.xml +*.azurePubxml +# Note: Comment the next line if you want to checkin your web deploy settings, +# but database connection strings (with potential passwords) will be unencrypted +*.pubxml +*.publishproj + +# Microsoft Azure Web App publish settings. Comment the next line if you want to +# checkin your Azure Web App publish settings, but sensitive information contained +# in these scripts will be unencrypted +PublishScripts/ + +# NuGet Packages +*.nupkg +# NuGet Symbol Packages +*.snupkg +# The packages folder can be ignored because of Package Restore +**/[Pp]ackages/* +# except build/, which is used as an MSBuild target. +!**/[Pp]ackages/build/ +# Uncomment if necessary however generally it will be regenerated when needed +#!**/[Pp]ackages/repositories.config +# NuGet v3's project.json files produces more ignorable files +*.nuget.props +*.nuget.targets + +# Microsoft Azure Build Output +csx/ +*.build.csdef + +# Microsoft Azure Emulator +ecf/ +rcf/ + +# Windows Store app package directories and files +AppPackages/ +BundleArtifacts/ +Package.StoreAssociation.xml +_pkginfo.txt +*.appx +*.appxbundle +*.appxupload + +# Visual Studio cache files +# files ending in .cache can be ignored +*.[Cc]ache +# but keep track of directories ending in .cache +!?*.[Cc]ache/ + +# Others +ClientBin/ +~$* +*~ +*.dbmdl +*.dbproj.schemaview +*.jfm +*.pfx +*.publishsettings +orleans.codegen.cs + +# Including strong name files can present a security risk +# (https://github.com/github/gitignore/pull/2483#issue-259490424) +#*.snk + +# Since there are multiple workflows, uncomment next line to ignore bower_components +# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) +#bower_components/ + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file +# to a newer Visual Studio version. Backup files are not needed, +# because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm +ServiceFabricBackup/ +*.rptproj.bak + +# SQL Server files +*.mdf +*.ldf +*.ndf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings +*.rptproj.rsuser +*- [Bb]ackup.rdl +*- [Bb]ackup ([0-9]).rdl +*- [Bb]ackup ([0-9][0-9]).rdl + +# Microsoft Fakes +FakesAssemblies/ + +# GhostDoc plugin setting file +*.GhostDoc.xml + +# Node.js Tools for Visual Studio +.ntvs_analysis.dat +node_modules/ + +# Visual Studio 6 build log +*.plg + +# Visual Studio 6 workspace options file +*.opt + +# Visual Studio 6 auto-generated workspace file (contains which files were open etc.) +*.vbw + +# Visual Studio LightSwitch build output +**/*.HTMLClient/GeneratedArtifacts +**/*.DesktopClient/GeneratedArtifacts +**/*.DesktopClient/ModelManifest.xml +**/*.Server/GeneratedArtifacts +**/*.Server/ModelManifest.xml +_Pvt_Extensions + +# Paket dependency manager +.paket/paket.exe +paket-files/ + +# FAKE - F# Make +.fake/ + +# CodeRush personal settings +.cr/personal + +# Python Tools for Visual Studio (PTVS) +__pycache__/ +*.pyc + +# Cake - Uncomment if you are using it +# tools/** +# !tools/packages.config + +# Tabs Studio +*.tss + +# Telerik's JustMock configuration file +*.jmconfig + +# BizTalk build output +*.btp.cs +*.btm.cs +*.odx.cs +*.xsd.cs + +# OpenCover UI analysis results +OpenCover/ + +# Azure Stream Analytics local run output +ASALocalRun/ + +# MSBuild Binary and Structured Log +*.binlog + +# NVidia Nsight GPU debugger configuration file +*.nvuser + +# MFractors (Xamarin productivity tool) working folder +.mfractor/ + +# Local History for Visual Studio +.localhistory/ + +# BeatPulse healthcheck temp database +healthchecksdb + +# Backup folder for Package Reference Convert tool in Visual Studio 2017 +MigrationBackup/ + +# Ionide (cross platform F# VS Code tools) working folder +.ionide/ + +# ignore everything in the root except the "wp-content" directory. +!wp-content/ + +# ignore everything in the "wp-content" directory, except: +# "mu-plugins", "plugins", "themes" directory +wp-content/* +!wp-content/mu-plugins/ +!wp-content/plugins/ +!wp-content/themes/ + +# ignore these plugins +wp-content/plugins/hello.php + +# ignore specific themes +wp-content/themes/twenty*/ + +# ignore node dependency directories +node_modules/ + +# ignore log files and databases +*.log +*.sql +*.sqlite \ No newline at end of file diff --git a/.imgbotconfig b/.imgbotconfig new file mode 100644 index 0000000..a31c6d4 --- /dev/null +++ b/.imgbotconfig @@ -0,0 +1,6 @@ +{ + "schedule": "daily", + "aggressiveCompression": "true", + "compressWiki": "true", + "minKBReduced": 0 +} diff --git a/.whitesource b/.whitesource new file mode 100644 index 0000000..adeb98e --- /dev/null +++ b/.whitesource @@ -0,0 +1,13 @@ +{ + "scanSettings": { + "baseBranches": [] + }, + "checkRunSettings": { + "vulnerableCheckRunConclusionLevel": "failure", + "displayMode": "diff" + }, + "issueSettings": { + "minSeverityLevel": "LOW", + "issueType": "DEPENDENCY" + } +} diff --git a/COPYING b/COPYING new file mode 100644 index 0000000..0a04128 --- /dev/null +++ b/COPYING @@ -0,0 +1,165 @@ + GNU LESSER GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + + This version of the GNU Lesser General Public License incorporates +the terms and conditions of version 3 of the GNU General Public +License, supplemented by the additional permissions listed below. + + 0. Additional Definitions. + + As used herein, "this License" refers to version 3 of the GNU Lesser +General Public License, and the "GNU GPL" refers to version 3 of the GNU +General Public License. + + "The Library" refers to a covered work governed by this License, +other than an Application or a Combined Work as defined below. + + An "Application" is any work that makes use of an interface provided +by the Library, but which is not otherwise based on the Library. +Defining a subclass of a class defined by the Library is deemed a mode +of using an interface provided by the Library. + + A "Combined Work" is a work produced by combining or linking an +Application with the Library. The particular version of the Library +with which the Combined Work was made is also called the "Linked +Version". + + The "Minimal Corresponding Source" for a Combined Work means the +Corresponding Source for the Combined Work, excluding any source code +for portions of the Combined Work that, considered in isolation, are +based on the Application, and not on the Linked Version. + + The "Corresponding Application Code" for a Combined Work means the +object code and/or source code for the Application, including any data +and utility programs needed for reproducing the Combined Work from the +Application, but excluding the System Libraries of the Combined Work. + + 1. Exception to Section 3 of the GNU GPL. + + You may convey a covered work under sections 3 and 4 of this License +without being bound by section 3 of the GNU GPL. + + 2. Conveying Modified Versions. + + If you modify a copy of the Library, and, in your modifications, a +facility refers to a function or data to be supplied by an Application +that uses the facility (other than as an argument passed when the +facility is invoked), then you may convey a copy of the modified +version: + + a) under this License, provided that you make a good faith effort to + ensure that, in the event an Application does not supply the + function or data, the facility still operates, and performs + whatever part of its purpose remains meaningful, or + + b) under the GNU GPL, with none of the additional permissions of + this License applicable to that copy. + + 3. Object Code Incorporating Material from Library Header Files. + + The object code form of an Application may incorporate material from +a header file that is part of the Library. You may convey such object +code under terms of your choice, provided that, if the incorporated +material is not limited to numerical parameters, data structure +layouts and accessors, or small macros, inline functions and templates +(ten or fewer lines in length), you do both of the following: + + a) Give prominent notice with each copy of the object code that the + Library is used in it and that the Library and its use are + covered by this License. + + b) Accompany the object code with a copy of the GNU GPL and this license + document. + + 4. Combined Works. + + You may convey a Combined Work under terms of your choice that, +taken together, effectively do not restrict modification of the +portions of the Library contained in the Combined Work and reverse +engineering for debugging such modifications, if you also do each of +the following: + + a) Give prominent notice with each copy of the Combined Work that + the Library is used in it and that the Library and its use are + covered by this License. + + b) Accompany the Combined Work with a copy of the GNU GPL and this license + document. + + c) For a Combined Work that displays copyright notices during + execution, include the copyright notice for the Library among + these notices, as well as a reference directing the user to the + copies of the GNU GPL and this license document. + + d) Do one of the following: + + 0) Convey the Minimal Corresponding Source under the terms of this + License, and the Corresponding Application Code in a form + suitable for, and under terms that permit, the user to + recombine or relink the Application with a modified version of + the Linked Version to produce a modified Combined Work, in the + manner specified by section 6 of the GNU GPL for conveying + Corresponding Source. + + 1) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (a) uses at run time + a copy of the Library already present on the user's computer + system, and (b) will operate properly with a modified version + of the Library that is interface-compatible with the Linked + Version. + + e) Provide Installation Information, but only if you would otherwise + be required to provide such information under section 6 of the + GNU GPL, and only to the extent that such information is + necessary to install and execute a modified version of the + Combined Work produced by recombining or relinking the + Application with a modified version of the Linked Version. (If + you use option 4d0, the Installation Information must accompany + the Minimal Corresponding Source and Corresponding Application + Code. If you use option 4d1, you must provide the Installation + Information in the manner specified by section 6 of the GNU GPL + for conveying Corresponding Source.) + + 5. Combined Libraries. + + You may place library facilities that are a work based on the +Library side by side in a single library together with other library +facilities that are not Applications and are not covered by this +License, and convey such a combined library under terms of your +choice, if you do both of the following: + + a) Accompany the combined library with a copy of the same work based + on the Library, uncombined with any other library facilities, + conveyed under the terms of this License. + + b) Give prominent notice with the combined library that part of it + is a work based on the Library, and explaining where to find the + accompanying uncombined form of the same work. + + 6. Revised Versions of the GNU Lesser General Public License. + + The Free Software Foundation may publish revised and/or new versions +of the GNU Lesser General Public License from time to time. Such new +versions will be similar in spirit to the present version, but may +differ in detail to address new problems or concerns. + + Each version is given a distinguishing version number. If the +Library as you received it specifies that a certain numbered version +of the GNU Lesser General Public License "or any later version" +applies to it, you have the option of following the terms and +conditions either of that published version or of any later version +published by the Free Software Foundation. If the Library as you +received it does not specify a version number of the GNU Lesser +General Public License, you may choose any version of the GNU Lesser +General Public License ever published by the Free Software Foundation. + + If the Library as you received it specifies that a proxy can decide +whether future versions of the GNU Lesser General Public License shall +apply, that proxy's public statement of acceptance of any version is +permanent authorization for you to choose that version for the +Library. diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..c1faab2 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,13 @@ +# syntax=docker/dockerfile:labs +FROM python:3.12.5-alpine3.20 AS pip +COPY requirements.txt requirements.txt +RUN apk upgrade --no-cache -a && \ + apk add --no-cache ca-certificates && \ + python3 -m venv /usr/local && \ + pip install --no-cache-dir -r requirements.txt + +FROM python:3.12.5-alpine3.20 +RUN apk upgrade --no-cache -a && \ + apk add --no-cache ca-certificates tzdata tini +COPY app.py /usr/local/bin/app.py +ENTRYPOINT ["tini", "--", "app.py"] diff --git a/README.md b/README.md new file mode 100644 index 0000000..befec86 --- /dev/null +++ b/README.md @@ -0,0 +1,5 @@ +# discord-ai-bot + +## How to use? + +See the compose.yaml. diff --git a/app.py b/app.py new file mode 100644 index 0000000..c00f617 --- /dev/null +++ b/app.py @@ -0,0 +1,365 @@ +#!/usr/bin/env python3 + +import base64 +import os + +import discord +import anthropic + +from math import ceil +from openai import OpenAI +from discord import default_permissions +from playwright.async_api import async_playwright + +oaiclient = OpenAI(api_key=os.environ["OAI_KEY"]) +aclient = anthropic.Anthropic(api_key=os.environ["A_KEY"]) + +bot = discord.Bot() +@bot.listen(once=True) +async def on_ready(): + await bot.change_presence(activity=discord.Game(name="Hi!")) + print("Bot is running!") + + +@bot.command(description="Hi! (gpt-4o-mini) 0,15$/0,6$", contexts={discord.InteractionContextType.guild, discord.InteractionContextType.private_channel}, integration_types={discord.IntegrationType.guild_install, discord.IntegrationType.user_install}) +async def mini(ctx, prompt: discord.Option(str, description="Der Prompt"), url: discord.Option(str, required=False, description="URL für file_search"), image: discord.Option(discord.Attachment, required=False, description="Bild"), filesearch: discord.Option(discord.Attachment, required=False, description="Datei für file_search"), codeinterpreter: discord.Option(discord.Attachment, required=False, description="Datei für code_interpreter")): + await ctx.defer() + print(prompt) + if url: + async with async_playwright() as playwright: + chromium = playwright.chromium + browser = await chromium.launch() + page = await browser.new_page() + await page.goto(url) + await page.emulate_media(media="screen") + pdf = await page.pdf(width="2160px", height="3840px", landscape=True) + await browser.close() + file = oaiclient.files.create(file=("website.pdf", pdf), purpose="assistants") + assistant = oaiclient.beta.assistants.create(model="gpt-4o-mini", tools=[{"type": "file_search"}], instructions="Du befolgst die dir gegebenen Anweisungen und beachtest dabei die Webseite, welche du als PDF-Datei im Anhang findest.") + thread = oaiclient.beta.threads.create() + oaiclient.beta.threads.messages.create(thread.id, role="user", content=prompt, attachments=[{"file_id": file.id, "tools": [{"type": "file_search"}]}]) + run = oaiclient.beta.threads.runs.create(thread.id, assistant_id=assistant.id) + while oaiclient.beta.threads.runs.retrieve(thread_id=thread.id, run_id=run.id).status != "completed": + pass + all_messages = oaiclient.beta.threads.messages.list(thread_id=thread.id) + print(all_messages.data[0].content[0].text.value) + oaiclient.files.delete(file.id) + oaiclient.beta.assistants.delete(assistant.id) + oaiclient.beta.threads.delete(thread.id) + for i in range(ceil(len(all_messages.data[0].content[0].text.value) / 4096)): + embed = discord.Embed(title="Hi! (gpt-4o-mini) 0,15$/0,6$") + embed.description = (all_messages.data[0].content[0].text.value[(4096*i):(4096*(i+1))]) + await ctx.respond(embed=embed) + elif filesearch: + filesearchfile = await filesearch.read() + file = oaiclient.files.create(file=(filesearch.filename, filesearchfile), purpose="assistants") + assistant = oaiclient.beta.assistants.create(model="gpt-4o-mini", tools=[{"type": "file_search"}], instructions="Du befolgst die dir gegebenen Anweisungen und beachtest dabei die Datei, welche du im Anhang findest.") + thread = oaiclient.beta.threads.create() + oaiclient.beta.threads.messages.create(thread.id, role="user", content=prompt, attachments=[{"file_id": file.id, "tools": [{"type": "file_search"}]}]) + run = oaiclient.beta.threads.runs.create(thread.id, assistant_id=assistant.id) + while oaiclient.beta.threads.runs.retrieve(thread_id=thread.id, run_id=run.id).status != "completed": + pass + all_messages = oaiclient.beta.threads.messages.list(thread_id=thread.id) + print(all_messages.data[0].content[0].text.value) + oaiclient.files.delete(file.id) + oaiclient.beta.assistants.delete(assistant.id) + oaiclient.beta.threads.delete(thread.id) + for i in range(ceil(len(all_messages.data[0].content[0].text.value) / 4096)): + embed = discord.Embed(title="Hi! (gpt-4o-mini) 0,15$/0,6$") + embed.description = (all_messages.data[0].content[0].text.value[(4096*i):(4096*(i+1))]) + await ctx.respond(embed=embed) + elif codeinterpreter: + codeinterpreterfile = await filesearch.read() + file = oaiclient.files.create(file=(filesearch.filename, codeinterpreterfile), purpose="assistants") + assistant = oaiclient.beta.assistants.create(model="gpt-4o-mini", tools=[{"type": "code_interpreter"}], instructions="Du befolgst die dir gegebenen Anweisungen und beachtest dabei die Datei, welche du im Anhang findest.") + thread = oaiclient.beta.threads.create() + oaiclient.beta.threads.messages.create(thread.id, role="user", content=prompt, attachments=[{"file_id": file.id, "tools": [{"type": "code_interpreter"}]}]) + run = oaiclient.beta.threads.runs.create(thread.id, assistant_id=assistant.id) + while oaiclient.beta.threads.runs.retrieve(thread_id=thread.id, run_id=run.id).status != "completed": + pass + all_messages = oaiclient.beta.threads.messages.list(thread_id=thread.id) + print(all_messages.data[0].content[0].text.value) + oaiclient.files.delete(file.id) + oaiclient.beta.assistants.delete(assistant.id) + oaiclient.beta.threads.delete(thread.id) + for i in range(ceil(len(all_messages.data[0].content[0].text.value) / 4096)): + embed = discord.Embed(title="Hi! (gpt-4o-mini) 0,15$/0,6$") + embed.description = (all_messages.data[0].content[0].text.value[(4096*i):(4096*(i+1))]) + await ctx.respond(embed=embed) + elif image: + imagefile = await image.read() + file = oaiclient.files.create(file=(image.filename, imagefile), purpose="assistants") + assistant = oaiclient.beta.assistants.create(model="gpt-4o-mini", instructions="Du befolgst die dir gegebenen Anweisungen und beachtest dabei das Bild, welche du im Anhang findest.") + thread = oaiclient.beta.threads.create() + oaiclient.beta.threads.messages.create(thread.id, role="user", content=[{"type": "text", "text": prompt}, {"type": "image_file", "image_file": {"file_id": file.id}}]) + run = oaiclient.beta.threads.runs.create(thread.id, assistant_id=assistant.id) + while oaiclient.beta.threads.runs.retrieve(thread_id=thread.id, run_id=run.id).status != "completed": + pass + all_messages = oaiclient.beta.threads.messages.list(thread_id=thread.id) + print(all_messages.data[0].content[0].text.value) + oaiclient.files.delete(file.id) + oaiclient.beta.assistants.delete(assistant.id) + oaiclient.beta.threads.delete(thread.id) + for i in range(ceil(len(all_messages.data[0].content[0].text.value) / 4096)): + embed = discord.Embed(title="Hi! (gpt-4o-mini) 0,15$/0,6$") + embed.description = (all_messages.data[0].content[0].text.value[(4096*i):(4096*(i+1))]) + await ctx.respond(embed=embed) + else: + message = await oaiclient.chat.completions.create( + model="gpt-4o-mini", + messages=[ + {"role": "system", "content": "Du befolgst die dir gegebenen Anweisungen."}, + {"role": "user", "content": prompt} + ] + ) + for i in range(ceil(len(message.choices[0].message.content) / 4096)): + embed = discord.Embed(title='Hi! (gpt-4o-mini) 0,15$/0,6$') + embed.description = (message.choices[0].message.content[(4096*i):(4096*(i+1))]) + await ctx.respond(embed=embed) + print("Hi! ^(gpt-4o-mini) 0,15$/0,6$^") + + +@bot.slash_command(description="Hi! (gpt-4o) 5$/15$", contexts={discord.InteractionContextType.guild, discord.InteractionContextType.private_channel}, integration_types={discord.IntegrationType.guild_install, discord.IntegrationType.user_install}) +@default_permissions(administrator=True) +async def gpt(ctx, prompt: discord.Option(str, description="Der Prompt"), url: discord.Option(str, required=False, description="URL für file_search"), image: discord.Option(discord.Attachment, required=False, description="Bild"), filesearch: discord.Option(discord.Attachment, required=False, description="Datei für file_search"), codeinterpreter: discord.Option(discord.Attachment, required=False, description="Datei für code_interpreter")): + await ctx.defer() + print(prompt) + if url: + async with async_playwright() as playwright: + chromium = playwright.chromium + browser = await chromium.launch() + page = await browser.new_page() + await page.goto(url) + await page.emulate_media(media="screen") + pdf = await page.pdf(width="2160px", height="3840px", landscape=True) + await browser.close() + file = oaiclient.files.create(file=("website.pdf", pdf), purpose="assistants") + assistant = oaiclient.beta.assistants.create(model="gpt-4o", tools=[{"type": "file_search"}], instructions="Du befolgst die dir gegebenen Anweisungen und beachtest dabei die Webseite, welche du als PDF-Datei im Anhang findest.") + thread = oaiclient.beta.threads.create() + oaiclient.beta.threads.messages.create(thread.id, role="user", content=prompt, attachments=[{"file_id": file.id, "tools": [{"type": "file_search"}]}]) + run = oaiclient.beta.threads.runs.create(thread.id, assistant_id=assistant.id) + while oaiclient.beta.threads.runs.retrieve(thread_id=thread.id, run_id=run.id).status != "completed": + pass + all_messages = oaiclient.beta.threads.messages.list(thread_id=thread.id) + print(all_messages.data[0].content[0].text.value) + oaiclient.files.delete(file.id) + oaiclient.beta.assistants.delete(assistant.id) + oaiclient.beta.threads.delete(thread.id) + for i in range(ceil(len(all_messages.data[0].content[0].text.value) / 4096)): + embed = discord.Embed(title="Hi! (gpt-4o) 5$/15$") + embed.description = (all_messages.data[0].content[0].text.value[(4096*i):(4096*(i+1))]) + await ctx.respond(embed=embed) + elif filesearch: + filesearchfile = await filesearch.read() + file = oaiclient.files.create(file=(filesearch.filename, filesearchfile), purpose="assistants") + assistant = oaiclient.beta.assistants.create(model="gpt-4o", tools=[{"type": "file_search"}], instructions="Du befolgst die dir gegebenen Anweisungen und beachtest dabei die Datei, welche du im Anhang findest.") + thread = oaiclient.beta.threads.create() + oaiclient.beta.threads.messages.create(thread.id, role="user", content=prompt, attachments=[{"file_id": file.id, "tools": [{"type": "file_search"}]}]) + run = oaiclient.beta.threads.runs.create(thread.id, assistant_id=assistant.id) + while oaiclient.beta.threads.runs.retrieve(thread_id=thread.id, run_id=run.id).status != "completed": + pass + all_messages = oaiclient.beta.threads.messages.list(thread_id=thread.id) + print(all_messages.data[0].content[0].text.value) + oaiclient.files.delete(file.id) + oaiclient.beta.assistants.delete(assistant.id) + oaiclient.beta.threads.delete(thread.id) + for i in range(ceil(len(all_messages.data[0].content[0].text.value) / 4096)): + embed = discord.Embed(title="Hi! (gpt-4o) 5$/15$") + embed.description = (all_messages.data[0].content[0].text.value[(4096*i):(4096*(i+1))]) + await ctx.respond(embed=embed) + elif codeinterpreter: + codeinterpreterfile = await filesearch.read() + file = oaiclient.files.create(file=(filesearch.filename, codeinterpreterfile), purpose="assistants") + assistant = oaiclient.beta.assistants.create(model="gpt-4o-mini", tools=[{"type": "code_interpreter"}], instructions="Du befolgst die dir gegebenen Anweisungen und beachtest dabei die Datei, welche du im Anhang findest.") + thread = oaiclient.beta.threads.create() + oaiclient.beta.threads.messages.create(thread.id, role="user", content=prompt, attachments=[{"file_id": file.id, "tools": [{"type": "code_interpreter"}]}]) + run = oaiclient.beta.threads.runs.create(thread.id, assistant_id=assistant.id) + while oaiclient.beta.threads.runs.retrieve(thread_id=thread.id, run_id=run.id).status != "completed": + pass + all_messages = oaiclient.beta.threads.messages.list(thread_id=thread.id) + print(all_messages.data[0].content[0].text.value) + oaiclient.files.delete(file.id) + oaiclient.beta.assistants.delete(assistant.id) + oaiclient.beta.threads.delete(thread.id) + for i in range(ceil(len(all_messages.data[0].content[0].text.value) / 4096)): + embed = discord.Embed(title="Hi! (gpt-4o) 5$/15$") + embed.description = (all_messages.data[0].content[0].text.value[(4096*i):(4096*(i+1))]) + await ctx.respond(embed=embed) + elif image: + imagefile = await image.read() + file = oaiclient.files.create(file=(image.filename, imagefile), purpose="assistants") + assistant = oaiclient.beta.assistants.create(model="gpt-4o", instructions="Du befolgst die dir gegebenen Anweisungen und beachtest dabei das Bild, welche du im Anhang findest.") + thread = oaiclient.beta.threads.create() + oaiclient.beta.threads.messages.create(thread.id, role="user", content=[{"type": "text", "text": prompt}, {"type": "image_file", "image_file": {"file_id": file.id}}]) + run = oaiclient.beta.threads.runs.create(thread.id, assistant_id=assistant.id) + while oaiclient.beta.threads.runs.retrieve(thread_id=thread.id, run_id=run.id).status != "completed": + pass + all_messages = oaiclient.beta.threads.messages.list(thread_id=thread.id) + print(all_messages.data[0].content[0].text.value) + oaiclient.files.delete(file.id) + oaiclient.beta.assistants.delete(assistant.id) + oaiclient.beta.threads.delete(thread.id) + for i in range(ceil(len(all_messages.data[0].content[0].text.value) / 4096)): + embed = discord.Embed(title="Hi! (gpt-4o) 5$/15$") + embed.description = (all_messages.data[0].content[0].text.value[(4096*i):(4096*(i+1))]) + await ctx.respond(embed=embed) + else: + message = await oaiclient.chat.completions.create( + model="gpt-4o", + messages=[ + {"role": "system", "content": "Du befolgst die dir gegebenen Anweisungen."}, + {"role": "user", "content": prompt} + ] + ) + for i in range(ceil(len(message.choices[0].message.content) / 4096)): + embed = discord.Embed(title="Hi! (gpt-4o) 5$/15$") + embed.description = (message.choices[0].message.content[(4096*i):(4096*(i+1))]) + await ctx.respond(embed=embed) + print("Hi! ^(gpt-4o) 5$/15$^") + + +@bot.slash_command(description="Hi! (claude-3-haiku) 0,25$/1,25$", contexts={discord.InteractionContextType.guild, discord.InteractionContextType.private_channel}, integration_types={discord.IntegrationType.guild_install, discord.IntegrationType.user_install}) +@default_permissions(administrator=True) +async def haiku(ctx, prompt: discord.Option(str, description="Der Prompt"), jpeg: discord.Option(discord.Attachment, required=False, description="Bild"), png: discord.Option(discord.Attachment, required=False, description="Bild"), gif: discord.Option(discord.Attachment, required=False, description="Bild"), webp: discord.Option(discord.Attachment, required=False, description="Bild")): + await ctx.defer() + print(prompt) + if jpeg: + imagefile = await jpeg.read() + message = aclient.messages.create( + model="claude-3-haiku-20240307", + max_tokens=4096, + system="u befolgst die dir gegebenen Anweisungen und beachtest dabei das Bild, welche du im Anhang findest.", + messages=[ + {"role": "user", "content": [{"type": "text", "text": prompt}, {"type": "image", "source": { "type": "base64", "media_type": "image/jpeg", "data": base64.b64encode(imagefile).decode("utf-8")}}]}] + ) + for i in range(ceil(len(message.content[0].text) / 4096)): + embed = discord.Embed(title="Hi! (claude-3-haiku) 0,25$/1,25$") + embed.description = (message.content[0].text[(4096*i):(4096*(i+1))]) + await ctx.respond(embed=embed) + elif png: + imagefile = await png.read() + message = aclient.messages.create( + model="claude-3-haiku-20240307", + max_tokens=4096, + system="u befolgst die dir gegebenen Anweisungen und beachtest dabei das Bild, welche du im Anhang findest.", + messages=[ + {"role": "user", "content": [{"type": "text", "text": prompt}, {"type": "image", "source": { "type": "base64", "media_type": "image/png", "data": base64.b64encode(imagefile).decode("utf-8")}}]}] + ) + for i in range(ceil(len(message.content[0].text) / 4096)): + embed = discord.Embed(title="Hi! (claude-3-haiku) 0,25$/1,25$") + embed.description = (message.content[0].text[(4096*i):(4096*(i+1))]) + await ctx.respond(embed=embed) + elif gif: + imagefile = await gif.read() + message = aclient.messages.create( + model="claude-3-haiku-20240307", + max_tokens=4096, + system="u befolgst die dir gegebenen Anweisungen und beachtest dabei das Bild, welche du im Anhang findest.", + messages=[ + {"role": "user", "content": [{"type": "text", "text": prompt}, {"type": "image", "source": { "type": "base64", "media_type": "image/gif", "data": base64.b64encode(imagefile).decode("utf-8")}}]}] + ) + for i in range(ceil(len(message.content[0].text) / 4096)): + embed = discord.Embed(title="Hi! (claude-3-haiku) 0,25$/1,25$") + embed.description = (message.content[0].text[(4096*i):(4096*(i+1))]) + await ctx.respond(embed=embed) + elif webp: + imagefile = await webp.read() + message = aclient.messages.create( + model="claude-3-haiku-20240307", + max_tokens=4096, + system="u befolgst die dir gegebenen Anweisungen und beachtest dabei das Bild, welche du im Anhang findest.", + messages=[ + {"role": "user", "content": [{"type": "text", "text": prompt}, {"type": "image", "source": { "type": "base64", "media_type": "image/webp", "data": base64.b64encode(imagefile).decode("utf-8")}}]}] + ) + for i in range(ceil(len(message.content[0].text) / 4096)): + embed = discord.Embed(title="Hi! (claude-3-haiku) 0,25$/1,25$") + embed.description = (message.content[0].text[(4096*i):(4096*(i+1))]) + await ctx.respond(embed=embed) + else: + message = aclient.messages.create( + model="claude-3-haiku-20240307", + max_tokens=4096, + system="Du befolgst die dir gegebenen Anweisungen.", + messages=[ + {"role": "user", "content": prompt} + ] + ) + for i in range(ceil(len(message.content[0].text) / 4096)): + embed = discord.Embed(title="Hi! (claude-3-haiku) 0,25$/1,25$") + embed.description = (message.content[0].text[(4096*i):(4096*(i+1))]) + await ctx.respond(embed=embed) + print("Hi! ^(claude-3-haiku) 0,25$/1,25$^") + +@bot.slash_command(description="Hi! (claude-3-5-sonnet) 3$/15$", contexts={discord.InteractionContextType.guild, discord.InteractionContextType.private_channel}, integration_types={discord.IntegrationType.guild_install, discord.IntegrationType.user_install}) +@default_permissions(administrator=True) +async def sonnet(ctx, prompt: discord.Option(str, description="Der Prompt"), jpeg: discord.Option(discord.Attachment, required=False, description="Bild"), png: discord.Option(discord.Attachment, required=False, description="Bild"), gif: discord.Option(discord.Attachment, required=False, description="Bild"), webp: discord.Option(discord.Attachment, required=False, description="Bild")): + await ctx.defer() + print(prompt) + if jpeg: + imagefile = await jpeg.read() + message = aclient.messages.create( + model="claude-3-5-sonnet-20240620", + max_tokens=4096, + system="u befolgst die dir gegebenen Anweisungen und beachtest dabei das Bild, welche du im Anhang findest.", + messages=[ + {"role": "user", "content": [{"type": "text", "text": prompt}, {"type": "image", "source": { "type": "base64", "media_type": "image/jpeg", "data": base64.b64encode(imagefile).decode("utf-8")}}]}] + ) + for i in range(ceil(len(message.content[0].text) / 4096)): + embed = discord.Embed(title="Hi! (claude-3-5-sonnet) 3$/15$") + embed.description = (message.content[0].text[(4096*i):(4096*(i+1))]) + await ctx.respond(embed=embed) + elif png: + imagefile = await png.read() + message = aclient.messages.create( + model="claude-3-5-sonnet-20240620", + max_tokens=4096, + system="u befolgst die dir gegebenen Anweisungen und beachtest dabei das Bild, welche du im Anhang findest.", + messages=[ + {"role": "user", "content": [{"type": "text", "text": prompt}, {"type": "image", "source": { "type": "base64", "media_type": "image/png", "data": base64.b64encode(imagefile).decode("utf-8")}}]}] + ) + for i in range(ceil(len(message.content[0].text) / 4096)): + embed = discord.Embed(title="Hi! (claude-3-5-sonnet) 3$/15$") + embed.description = (message.content[0].text[(4096*i):(4096*(i+1))]) + await ctx.respond(embed=embed) + elif gif: + imagefile = await gif.read() + message = aclient.messages.create( + model="claude-3-5-sonnet-20240620", + max_tokens=4096, + system="u befolgst die dir gegebenen Anweisungen und beachtest dabei das Bild, welche du im Anhang findest.", + messages=[ + {"role": "user", "content": [{"type": "text", "text": prompt}, {"type": "image", "source": { "type": "base64", "media_type": "image/gif", "data": base64.b64encode(imagefile).decode("utf-8")}}]}] + ) + for i in range(ceil(len(message.content[0].text) / 4096)): + embed = discord.Embed(title="Hi! (claude-3-5-sonnet) 3$/15$") + embed.description = (message.content[0].text[(4096*i):(4096*(i+1))]) + await ctx.respond(embed=embed) + elif webp: + imagefile = await webp.read() + message = aclient.messages.create( + model="claude-3-5-sonnet-20240620", + max_tokens=4096, + system="u befolgst die dir gegebenen Anweisungen und beachtest dabei das Bild, welche du im Anhang findest.", + messages=[ + {"role": "user", "content": [{"type": "text", "text": prompt}, {"type": "image", "source": { "type": "base64", "media_type": "image/webp", "data": base64.b64encode(imagefile).decode("utf-8")}}]}] + ) + for i in range(ceil(len(message.content[0].text) / 4096)): + embed = discord.Embed(title="Hi! (claude-3-5-sonnet) 3$/15$") + embed.description = (message.content[0].text[(4096*i):(4096*(i+1))]) + await ctx.respond(embed=embed) + else: + message = aclient.messages.create( + model="claude-3-5-sonnet-20240620", + max_tokens=4096, + system="Du befolgst die dir gegebenen Anweisungen.", + messages=[ + {"role": "user", "content": prompt} + ] + ) + for i in range(ceil(len(message.content[0].text) / 4096)): + embed = discord.Embed(title="Hi! (claude-3-5-sonnet) 3$/15$") + embed.description = (message.content[0].text[(4096*i):(4096*(i+1))]) + await ctx.respond(embed=embed) + print("Hi! ^(claude-3-5-sonnet) 3$/15$^") + +bot.run(os.environ["BOT_KEY"]) diff --git a/compose.yaml b/compose.yaml new file mode 100644 index 0000000..8ac831c --- /dev/null +++ b/compose.yaml @@ -0,0 +1,11 @@ +services: + discord-ai-bot: + container_name: discord-ai-bot + image: zoeyvid/discord-ai-bot + restart: always + network_mode: bridge + environment: + - "TZ=Europe/Berlin" + - "OAI_KEY=" + - "A_KEY=" + - "BOT_KEY=" diff --git a/renovate.json b/renovate.json new file mode 100644 index 0000000..2162be3 --- /dev/null +++ b/renovate.json @@ -0,0 +1,13 @@ +{ + "extends": [ + "config:base" + ], + "baseBranches": [], + "includeForks": true, + "automerge": false, + "branchPrefix": "renovate-deps-update-", + "rangeStrategy": "pin", + "digest": { + "enabled": true + } +} diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..66bc793 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,4 @@ +openai +py-cord +anthropic +playwright