├── autohelp ├── ci ├── LICENSE ├── kord │ ├── README.md │ ├── build.gradle.kts │ └── src │ │ └── main │ │ └── kotlin │ │ └── me │ │ └── schlaubi │ │ └── autohelp │ │ └── kord │ │ ├── Builder.kt │ │ └── KordUpdateEventSource.kt ├── README.md ├── src │ └── main │ │ ├── resources │ │ └── me │ │ │ └── schlaubi │ │ │ └── autohelp │ │ │ └── AutoHelpVersion.properties │ │ ├── kotlin │ │ └── me │ │ │ └── schlaubi │ │ │ └── autohelp │ │ │ ├── help │ │ │ ├── HtmlRenderer.kt │ │ │ └── MessageRenderer.kt │ │ │ ├── source │ │ │ ├── EventFilter.kt │ │ │ ├── EventSource.kt │ │ │ ├── EventContext.kt │ │ │ └── ReceivedMessage.kt │ │ │ ├── tags │ │ │ └── TagSupplier.kt │ │ │ ├── internal │ │ │ ├── ParentAwareChildren.kt │ │ │ └── AutoHelpImpl.kt │ │ │ └── AutoHelp.kt │ │ └── java │ │ └── me │ │ └── schlaubi │ │ └── autohelp │ │ └── AutoHelpVersion.java ├── build.gradle.kts └── publishing.gradle.kts ├── docs ├── docs │ ├── CNAME │ ├── assets │ │ ├── tag │ │ │ ├── example_tag.png │ │ │ ├── example_tag_info.png │ │ │ ├── example_create_tag.png │ │ │ ├── example_delete_tag.png │ │ │ ├── example_create_alias.png │ │ │ └── example_delete_alias.png │ │ ├── jdoodle │ │ │ ├── bash_example.png │ │ │ ├── cpp_example.png │ │ │ ├── go_example.png │ │ │ ├── java_example.png │ │ │ ├── kotlin_example.png │ │ │ └── python_example.png │ │ ├── google │ │ │ └── google_example.png │ │ └── javadoc │ │ │ ├── alldocs_example.png │ │ │ └── javadoc_example.png │ ├── features │ │ ├── google.md │ │ ├── javadoc.md │ │ ├── jdoodle.md │ │ └── tags.md │ └── index.md ├── mkdocs.yml └── overrides │ └── main.html ├── .idea ├── copyright │ ├── profiles_settings.xml │ ├── MIT_License.xml │ └── AGPL.xml ├── codeStyles │ ├── codeStyleConfig.xml │ └── Project.xml ├── compiler.xml ├── GradleUpdaterPlugin.xml ├── .gitignore ├── vcs.xml ├── jarRepositories.xml └── libraries-with-intellij-classes.xml ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── Dockerfile ├── docker-compose.yml ├── .github └── workflows │ ├── docs-deploy.yml │ ├── ci.yml │ ├── deployment.yml │ └── autohelp-ci.yml ├── src └── main │ ├── antlr │ └── Calculation.g4 │ └── kotlin │ └── de │ └── nycode │ └── bankobot │ ├── variables │ ├── Expression.kt │ ├── parsers │ │ ├── calc │ │ │ ├── CalculationException.kt │ │ │ └── CalcExpressionParser.kt │ │ ├── InvalidExpressionException.kt │ │ └── http │ │ │ ├── HttpExpression.kt │ │ │ └── HttpExpressionParser.kt │ ├── ExpressionParser.kt │ └── TagVariables.kt │ ├── twitch │ ├── TwitchUserResponse.kt │ ├── TwitchStream.kt │ └── Authentication.kt │ ├── command │ ├── CommandBuilder.kt │ ├── permissions │ │ ├── PermissionHandler.kt │ │ └── DebugPermissionHandler.kt │ ├── ContextUtils.kt │ ├── slashcommands │ │ ├── Ephemeral.kt │ │ ├── IgnoreSlashCommands.kt │ │ ├── InteractionEventSource.kt │ │ ├── SlashArgument.kt │ │ └── arguments │ │ │ ├── RoleArgument.kt │ │ │ ├── BooleanArgument.kt │ │ │ ├── IntArgument.kt │ │ │ ├── ChannelArgument.kt │ │ │ ├── StringArgument.kt │ │ │ └── AbstractSlashCommandArgument.kt │ ├── MessageCommandEventSource.kt │ ├── AbstractKordFilter.kt │ ├── Description.kt │ ├── MathExpressionArgument.kt │ ├── Extensions.kt │ └── Prefix.kt │ ├── utils │ ├── Constants.kt │ ├── KordBugFix.kt │ ├── CodeBlockUtil.kt │ ├── Emotes.kt │ ├── Colors.kt │ ├── HastebinUtil.kt │ ├── ModuleModifiers.kt │ ├── StringUtil.kt │ └── GoogleUtils.kt │ ├── commands │ ├── Modules.kt │ ├── tag │ │ ├── EmptyTag.kt │ │ ├── TagChange.kt │ │ ├── commands │ │ │ └── TagRawCommand.kt │ │ └── TagArgument.kt │ ├── general │ │ └── DCommand.kt │ ├── TestCommand.kt │ └── dev │ │ └── VarCommand.kt │ ├── Launcher.kt │ ├── listeners │ ├── SelfMentionListener.kt │ └── LightshotListener.kt │ ├── serialization │ ├── SnowflakeSerializer.kt │ └── LocalDateTimeSerializer.kt │ └── docdex │ └── DocDex.kt ├── README.md ├── .env.example ├── gradle.properties ├── settings.gradle.kts └── gradlew.bat /autohelp/ci: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /docs/docs/CNAME: -------------------------------------------------------------------------------- 1 | bankobot.nycode.de 2 | -------------------------------------------------------------------------------- /autohelp/LICENSE: -------------------------------------------------------------------------------- 1 | Same as FORP: https://github.com/DRSchlaubi/furry-okto-rotary-phone/blob/main/LICENSE -------------------------------------------------------------------------------- /.idea/copyright/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /autohelp/kord/README.md: -------------------------------------------------------------------------------- 1 | # autohelp-kord 2 | 3 | [Kord](https://github.com/kordlib/kord) implementation of autohelp. 4 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bankobotv14/BankoBot/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /docs/docs/assets/tag/example_tag.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bankobotv14/BankoBot/HEAD/docs/docs/assets/tag/example_tag.png -------------------------------------------------------------------------------- /docs/docs/assets/jdoodle/bash_example.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bankobotv14/BankoBot/HEAD/docs/docs/assets/jdoodle/bash_example.png -------------------------------------------------------------------------------- /docs/docs/assets/jdoodle/cpp_example.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bankobotv14/BankoBot/HEAD/docs/docs/assets/jdoodle/cpp_example.png -------------------------------------------------------------------------------- /docs/docs/assets/jdoodle/go_example.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bankobotv14/BankoBot/HEAD/docs/docs/assets/jdoodle/go_example.png -------------------------------------------------------------------------------- /docs/docs/assets/jdoodle/java_example.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bankobotv14/BankoBot/HEAD/docs/docs/assets/jdoodle/java_example.png -------------------------------------------------------------------------------- /docs/docs/assets/tag/example_tag_info.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bankobotv14/BankoBot/HEAD/docs/docs/assets/tag/example_tag_info.png -------------------------------------------------------------------------------- /docs/docs/assets/google/google_example.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bankobotv14/BankoBot/HEAD/docs/docs/assets/google/google_example.png -------------------------------------------------------------------------------- /docs/docs/assets/jdoodle/kotlin_example.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bankobotv14/BankoBot/HEAD/docs/docs/assets/jdoodle/kotlin_example.png -------------------------------------------------------------------------------- /docs/docs/assets/jdoodle/python_example.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bankobotv14/BankoBot/HEAD/docs/docs/assets/jdoodle/python_example.png -------------------------------------------------------------------------------- /docs/docs/assets/tag/example_create_tag.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bankobotv14/BankoBot/HEAD/docs/docs/assets/tag/example_create_tag.png -------------------------------------------------------------------------------- /docs/docs/assets/tag/example_delete_tag.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bankobotv14/BankoBot/HEAD/docs/docs/assets/tag/example_delete_tag.png -------------------------------------------------------------------------------- /docs/docs/assets/javadoc/alldocs_example.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bankobotv14/BankoBot/HEAD/docs/docs/assets/javadoc/alldocs_example.png -------------------------------------------------------------------------------- /docs/docs/assets/javadoc/javadoc_example.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bankobotv14/BankoBot/HEAD/docs/docs/assets/javadoc/javadoc_example.png -------------------------------------------------------------------------------- /docs/docs/assets/tag/example_create_alias.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bankobotv14/BankoBot/HEAD/docs/docs/assets/tag/example_create_alias.png -------------------------------------------------------------------------------- /docs/docs/assets/tag/example_delete_alias.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bankobotv14/BankoBot/HEAD/docs/docs/assets/tag/example_delete_alias.png -------------------------------------------------------------------------------- /.idea/codeStyles/codeStyleConfig.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | -------------------------------------------------------------------------------- /.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /docs/mkdocs.yml: -------------------------------------------------------------------------------- 1 | site_name: BankoBot 2 | theme: 3 | name: material 4 | custom_dir: overrides 5 | icon: 6 | repo: fontawesome/brands/github 7 | repo_url: https://github.com/bankobotv14/BankoBot 8 | repo_name: bankobotv14/BankoBot 9 | 10 | markdown_extensions: 11 | - attr_list 12 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM adoptopenjdk/openjdk15-openj9 as builder 2 | 3 | COPY . . 4 | 5 | RUN ./gradlew --no-daemon installDist 6 | 7 | FROM adoptopenjdk/openjdk15-openj9 8 | 9 | WORKDIR /user/app 10 | 11 | COPY --from=builder build/install/BankoBot ./ 12 | 13 | ENTRYPOINT ["/user/app/bin/BankoBot"] -------------------------------------------------------------------------------- /docs/docs/features/google.md: -------------------------------------------------------------------------------- 1 | # Google Search 2 | 3 | You can do google a search right from discord. Just enter your search query and the bot will show you the result. You can browse trough that results using the reactions on the message. 4 | ![Google Example](/assets/google/google_example.png){ loading=lazy } -------------------------------------------------------------------------------- /.idea/GradleUpdaterPlugin.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | -------------------------------------------------------------------------------- /autohelp/README.md: -------------------------------------------------------------------------------- 1 | # Autohelp 2 | 3 | Autohelp is a Kotlin Library for Discord bots which want to automatically send dynamic help messages whenever someone 4 | sends something providing a JVM Stacktrace. 5 | 6 | This is powered by [DRSchlaubi/furry-okto-rotary-phone](https://github.com/DRSchlaubi/furry-okto-rotary-phone/) 7 | -------------------------------------------------------------------------------- /.idea/.gitignore: -------------------------------------------------------------------------------- 1 | # Default ignored files 2 | /shelf/ 3 | /workspace.xml 4 | # Datasource local storage ignored files 5 | /../../../../../../:\Users\Nico\Projekte\BankoBot\.idea/dataSources/ 6 | /dataSources.local.xml 7 | # Editor-based HTTP Client requests 8 | /httpRequests/ 9 | artifacts 10 | detekt.xml 11 | discord.xml 12 | -------------------------------------------------------------------------------- /docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: "3.1" 2 | 3 | services: 4 | bot: 5 | container_name: bankobot 6 | image: ghcr.io/bankobotv14/bankobot/bot 7 | volumes: 8 | - "/etc/timezone:/etc/timezone:ro" 9 | - "/etc/localtime:/etc/localtime:ro" 10 | - ./logs:/user/app/logs 11 | env_file: 12 | - .env 13 | ports: 14 | - 127.0.0.1:8045:80 15 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /.github/workflows/docs-deploy.yml: -------------------------------------------------------------------------------- 1 | name: Deploy Docs 2 | 3 | on: 4 | workflow_dispatch: 5 | push: 6 | branches: 7 | - master 8 | - main 9 | paths: 10 | - docs/** 11 | 12 | jobs: 13 | deploy: 14 | runs-on: ubuntu-latest 15 | steps: 16 | - uses: actions/checkout@v2 17 | - uses: actions/setup-python@v2 18 | with: 19 | python-version: 3.x 20 | - run: pip install mkdocs-material 21 | - run: cd docs && mkdocs gh-deploy --force -------------------------------------------------------------------------------- /src/main/antlr/Calculation.g4: -------------------------------------------------------------------------------- 1 | grammar Calculation; 2 | 3 | root: expression; 4 | 5 | expression: '(' expression ')' #Parentheses 6 | | left=expression operator='^' right=expression #Squared 7 | | left=expression operator='*' right=expression #Multiply 8 | | left=expression operator='/' right=expression #Divide 9 | | left=expression operator='+' right=expression #Plus 10 | | left=expression operator='-' right=expression #Minus 11 | | NUMBER #Number 12 | ; 13 | 14 | NUMBER: [0-9]+('.'[0-9]+)?; 15 | WHITESPACE: [ \t\r\n]+ -> skip; 16 | -------------------------------------------------------------------------------- /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | on: 2 | push: 3 | pull_request: 4 | types: 5 | - opened 6 | - synchronize 7 | 8 | jobs: 9 | build: 10 | runs-on: ubuntu-20.04 11 | if: "!contains(github.event.commits[0].message, '[skip ci]')" 12 | steps: 13 | - uses: actions/checkout@v2 14 | - name: Setup JDK 15 | uses: actions/setup-java@v1 16 | with: 17 | java-version: 11 18 | - name: Cache Gradle packages 19 | uses: actions/cache@v2 20 | with: 21 | key: "$GITHUB_SHA" 22 | path: | 23 | ~/builds 24 | ~/build 25 | ~/.gradle 26 | - name: Build with Gradle 27 | run: ./gradlew compileKotlin detekt check 28 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Banko Bot 2 | 3 | ![CI](https://github.com/bankobotv14/BankoBot/workflows/.github/workflows/ci.yml/badge.svg) 4 | 5 | # Requirements 6 | - [Mongo DB server](https://docs.mongodb.com/manual/tutorial/install-mongodb-on-windows/) 7 | - [JDoodle API key](https://www.jdoodle.com/compiler-api/) (Optional: needed for eval command) 8 | - [Google Custom Search Key](https://cse.google.com/cse/all) (Optional: needed for find command) 9 | - [Twitch API application](https://dev.twitch.tv/console) (Optional: Required for stream status feature) 10 | - HTTPS Reverse Proxy (Optional: needed for Twitch) 11 | 12 | # Env config 13 | 14 | Example Config can be found [here](https://github.com/bankobotv14/BankoBot/blob/main/.env.example). 15 | 16 | # Build 17 | ```bash 18 | gradlew build 19 | ``` 20 | 21 | # Run 22 | ```bash 23 | docker-compose up -d 24 | ``` 25 | -------------------------------------------------------------------------------- /docs/docs/features/javadoc.md: -------------------------------------------------------------------------------- 1 | # Javadoc 2 | 3 | You can lookup supported Javadoc with the bot. We recommend using the slash commands since they provide autocompletion for the available docs. 4 | 5 | Here's an example: 6 | 7 | ![Javadoc Example](/assets/javadoc/javadoc_example.png){ loading=lazy } 8 | 9 | You can view the supported Javadocs via `/alldocs`: 10 | 11 | ![Alldocs Example](/assets/javadoc/alldocs_example.png){ loading=lazy } 12 | 13 | Currently we are supporting 5 different Javadocs. Feel free to [open an issue](https://github.com/bankobotv14/BankoBot/issues/new) to add another. 14 | 15 | * [JDK 11](https://docs.oracle.com/en/java/javase/11/docs/api/) 16 | * [JDK 8](https://docs.oracle.com/javase/8/docs/api/) (pls don't use Java 8) 17 | * [JDA](https://ci.dv8tion.net/job/JDA/javadoc/) 18 | * [Spigot](https://hub.spigotmc.org/javadocs/spigot/) 19 | * [Paper](https://papermc.io/javadocs/paper/1.16/) -------------------------------------------------------------------------------- /.github/workflows/deployment.yml: -------------------------------------------------------------------------------- 1 | name: Docs Server CI 2 | 3 | on: 4 | push: 5 | branches: 6 | - main 7 | 8 | jobs: 9 | release: 10 | name: Publish Docker image 11 | runs-on: ubuntu-latest 12 | if: "!contains(github.event.commits[0].message, '[skip ci]')" 13 | steps: 14 | - uses: actions/checkout@v2 15 | with: 16 | submodules: true 17 | - name: Login 18 | env: 19 | GITHUB_TOKEN: ${{ secrets.WHATEVER }} 20 | run: docker login ghcr.io --username phanatic --password "$GITHUB_TOKEN" 21 | - name: Build & Tag 22 | run: docker build -t ghcr.io/bankobotv14/bankobot/bot:latest -t ghcr.io/bankobotv14/bankobot/bot:"$GITHUB_SHA" . 23 | - name: Push 24 | run: docker push ghcr.io/bankobotv14/bankobot/bot:latest 25 | - name: Push specific tag 26 | run: docker push ghcr.io/bankobotv14/bankobot/bot:"$GITHUB_SHA" 27 | 28 | -------------------------------------------------------------------------------- /docs/docs/features/jdoodle.md: -------------------------------------------------------------------------------- 1 | # JDoodle 2 | 3 | One of the bots most powerful features is the JDoodle command. It integrates the Online IDE [JDoodle](https://www.jdoodle.com/) with Discord. 4 | 5 | You can send some code in a code block to JDoodle and it will execute it for you and show you the log. **Make sure you provide the correct language in the code block!** 6 | 7 | ## Examples: 8 | **There are way more supported languages than shown examples here. Check out the full list at [jdoodle.com](https://jdoodle.com).** 9 | 10 | ### Kotlin 11 | ![Kotlin Example](/assets/jdoodle/kotlin_example.png) 12 | 13 | ### C++ 14 | ![C++ Example](/assets/jdoodle/cpp_example.png) 15 | 16 | ### Bash 17 | ![Bash Example](/assets/jdoodle/bash_example.png) 18 | 19 | ### Java 20 | ![Java Example](/assets/jdoodle/java_example.png) 21 | 22 | ### Go 23 | ![Go Example](/assets/jdoodle/go_example.png) 24 | 25 | ### Python 26 | ![Python Example](/assets/jdoodle/python_example.png) -------------------------------------------------------------------------------- /.idea/codeStyles/Project.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | 7 | 17 | 18 | -------------------------------------------------------------------------------- /.env.example: -------------------------------------------------------------------------------- 1 | # LOG_LEVEL= // default = INFO 2 | # ENVIRONMENT= // default = PRODUCTION> 3 | 4 | # HASTE_HOST= // default = https://pasta.with-rice.by.devs-from.asia/ 5 | 6 | # SENTRY_TOKEN= // optional 7 | DISCORD_TOKEN= 8 | 9 | # DOCDEX_URL= // default = https://docs-repository.schlaubi.net/ 10 | 11 | MONGO_DATABASE= 12 | MONGO_URL= 13 | 14 | GOOGLE_API_KEY= 15 | GOOGLE_CX_CODE= 16 | 17 | JDOODLE_SECRET= 18 | JDOODLE_ID= 19 | # JDOODLE_REQUESTS_MAX= // default = 200 20 | 21 | MODERATOR_ROLE= 22 | ADMIN_ROLE= 23 | 24 | # DEV_GUILD_ID= // optional 25 | 26 | TWITCH_CLIENT_ID= 27 | TWITCH_CLIENT_SECRET= 28 | TWITCH_CHANNEL= 29 | 30 | WEBHOOK_URL= 31 | WEBHOOK_SECRET= 32 | 33 | MATHJS_SERVER_URL= 34 | 35 | # REGISTER_SLASH_COMMANDS= // default = true 36 | # ENABLE_TWITCH_WEBHOOKS= // default = true -------------------------------------------------------------------------------- /docs/docs/index.md: -------------------------------------------------------------------------------- 1 | # Welcome to the BankoBot Documentation 2 | 3 | [![Discord](https://img.shields.io/discord/571784654550466561?color=%237289da&label=Discord&logo=discord&style=flat-square)](https://banko.tv/discord) 4 | [![CI Status](https://github.com/bankobotv14/BankoBot/actions/workflows/ci.yml/badge.svg)](https://github.com/bankobotv14/BankoBot/actions/workflows/ci.yml) 5 | ![GitHub release (latest by date)](https://img.shields.io/github/v/release/bankobotv14/BankoBot?style=flat-square) 6 | ![GitHub](https://img.shields.io/github/license/bankobotv14/BankoBot?style=flat-square) 7 | ![GitHub issues](https://img.shields.io/github/issues/bankobotv14/BankoBot?style=flat-square) 8 | 9 | The bot is written in the [Kotlin programming language](https://kotlinlang.org) using the discord library [Kord](https://github.com/kordlib/kord). 10 | If you have a feature idea, feel free to [create an issue](https://github.com/bankobotv14/BankoBot/issues/new) and share your idea with us. 11 | Contributions are welcome! 12 | You can view the projects source on [GitHub](https://github.com/bankobotv14/BankoBot). 13 | -------------------------------------------------------------------------------- /docs/docs/features/tags.md: -------------------------------------------------------------------------------- 1 | # Tags 2 | 3 | The bot has a powerful system with repeatable text snippets called 'tags'. Everyone is allowed to create a new tag. Pointless tags will be removed by moderators. 4 | 5 | ## Create Tag 6 | You can easily create a new tag with the `create-tag` command. 7 | 8 | ![Create Tag Example](/assets/tag/example_create_tag.png){ loading=lazy } 9 | 10 | ## Get Tag 11 | You can easily get that tag by using the `tag` command or for a shorter version just use `xdt `. 12 | 13 | ![Get Tag Example](/assets/tag/example_tag.png){ loading=lazy } 14 | 15 | ## Create Alias 16 | You can create an alias for that tag for accessing a tag with multiple keys. 17 | 18 | ![Create Alias Example](/assets/tag/example_create_alias.png){ loading=lazy } 19 | 20 | ## Delete Alias 21 | You can delete that alias with the `delete-alias` command. 22 | 23 | ![Delete Alias Example](/assets/tag/example_delete_alias.png){ loading=lazy } 24 | 25 | ## Tag Info 26 | You can get more information about a tag with the `tag-info` command. 27 | 28 | ![Tag Info Example](/assets/tag/example_tag_info.png){ loading=lazy } 29 | 30 | ## Delete Tag 31 | You can easily delete a tag with the `delete-tag` command. 32 | 33 | ![Tag Delete Example](/assets/tag/example_delete_tag.png){ loading=lazy } -------------------------------------------------------------------------------- /.github/workflows/autohelp-ci.yml: -------------------------------------------------------------------------------- 1 | name: AutoHelp CI 2 | 3 | on: 4 | push: 5 | paths: 6 | - autohelp/** 7 | pull_request: 8 | paths: 9 | - autohelp/** 10 | types: 11 | - opened 12 | - synchronize 13 | 14 | jobs: 15 | build: 16 | runs-on: ubuntu-20.04 17 | steps: 18 | - uses: actions/checkout@v2 19 | - name: Setup JDK 20 | uses: actions/setup-java@v1 21 | with: 22 | java-version: 11 23 | - name: Build with Gradle 24 | run: ./gradlew autohelp:build autohelp:kord:build 25 | release: 26 | name: Publish maven artifact 27 | runs-on: ubuntu-latest 28 | if: github.ref == 'refs/heads/main' 29 | needs: build 30 | env: 31 | BINTRAY_KEY: ${{ secrets.BINTRAY_KEY }} 32 | BINTRAY_USER: ${{ secrets.BINTRAY_USER }} 33 | ORG_GRADLE_PROJECT_signingKey: ${{ secrets.signingKey }} 34 | ORG_GRADLE_PROJECT_signingPassword: ${{ secrets.signingPassword }} 35 | ACTIONS_ALLOW_UNSECURE_COMMANDS: true 36 | steps: 37 | - uses: actions/checkout@v2 38 | - name: Setup JDK 39 | uses: actions/setup-java@v1 40 | with: 41 | java-version: 11 42 | - run: git checkout HEAD 43 | - name: Build with Gradle 44 | run: ./gradlew autohelp:publish autohelp:kord:publish 45 | -------------------------------------------------------------------------------- /autohelp/src/main/resources/me/schlaubi/autohelp/AutoHelpVersion.properties: -------------------------------------------------------------------------------- 1 | # 2 | # MIT License 3 | # 4 | # Copyright (c) 2021 BankoBot Contributors 5 | # 6 | # Permission is hereby granted, free of charge, to any person obtaining a copy 7 | # of this software and associated documentation files (the "Software"), to deal 8 | # in the Software without restriction, including without limitation the rights 9 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | # copies of the Software, and to permit persons to whom the Software is 11 | # furnished to do so, subject to the following conditions: 12 | # 13 | # The above copyright notice and this permission notice shall be included in all 14 | # copies or substantial portions of the Software. 15 | # 16 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | # SOFTWARE. 23 | # 24 | # 25 | 26 | version=@version@ 27 | commit_hash=@commit_hash@ 28 | -------------------------------------------------------------------------------- /.idea/copyright/MIT_License.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | -------------------------------------------------------------------------------- /autohelp/src/main/kotlin/me/schlaubi/autohelp/help/HtmlRenderer.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2021 BankoBot Contributors 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | * 24 | */ 25 | 26 | package me.schlaubi.autohelp.help 27 | 28 | /** 29 | * Functional interface for converting javadoc HTML to Markdown. 30 | */ 31 | public fun interface HtmlRenderer { 32 | /** 33 | * Converts this HTML-formatted string to Markdown. 34 | */ 35 | public fun String.toMarkdown(): String 36 | } 37 | -------------------------------------------------------------------------------- /autohelp/src/main/kotlin/me/schlaubi/autohelp/source/EventFilter.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2021 BankoBot Contributors 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | * 24 | */ 25 | 26 | package me.schlaubi.autohelp.source 27 | 28 | /** 29 | * Filters incoming events to determine whether to autohelp or not. 30 | */ 31 | public fun interface EventFilter { 32 | /** 33 | * Whether [event] should get processed or not. 34 | */ 35 | public fun validateEvent(event: T): Boolean 36 | } 37 | -------------------------------------------------------------------------------- /autohelp/src/main/kotlin/me/schlaubi/autohelp/source/EventSource.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2021 BankoBot Contributors 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | * 24 | */ 25 | 26 | package me.schlaubi.autohelp.source 27 | 28 | import kotlinx.coroutines.flow.Flow 29 | 30 | /** 31 | * Provides a [Flow] of potential auto-help events. 32 | * 33 | * @see EventContext 34 | */ 35 | public interface EventSource { 36 | /** 37 | * A [Flow] of potential incoming auto-help events. 38 | */ 39 | public val events: Flow 40 | } 41 | -------------------------------------------------------------------------------- /autohelp/src/main/kotlin/me/schlaubi/autohelp/tags/TagSupplier.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2021 BankoBot Contributors 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | * 24 | */ 25 | 26 | package me.schlaubi.autohelp.tags 27 | 28 | import dev.schlaubi.forp.parser.stacktrace.StackTrace 29 | 30 | /** 31 | * Optional support for a tag system providing custom explanation for auto-help. 32 | */ 33 | public fun interface TagSupplier { 34 | /** 35 | * Finds a tag that explains [exception] or `null` if none was found. 36 | */ 37 | public fun findTagForException(exception: StackTrace): String? 38 | } 39 | -------------------------------------------------------------------------------- /.idea/copyright/AGPL.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | -------------------------------------------------------------------------------- /autohelp/build.gradle.kts: -------------------------------------------------------------------------------- 1 | import java.io.ByteArrayOutputStream 2 | 3 | plugins { 4 | kotlin("jvm") 5 | } 6 | 7 | group = "me.schlaubi" 8 | version = "2.0.0-RC.6" 9 | 10 | repositories { 11 | mavenCentral() 12 | maven("https://schlaubi.jfrog.io/artifactory/forp") 13 | maven("https://oss.sonatype.org/content/repositories/snapshots") 14 | } 15 | 16 | dependencies { 17 | api("dev.schlaubi.forp", "forp-analyze-api-jvm", "1.0-SNAPSHOT") 18 | api("dev.kord.x", "emoji", "0.5.0") 19 | implementation("io.github.microutils", "kotlin-logging", "2.0.10") 20 | } 21 | 22 | kotlin { 23 | explicitApi() 24 | } 25 | 26 | tasks { 27 | withType { 28 | kotlinOptions { 29 | jvmTarget = "11" 30 | freeCompilerArgs = freeCompilerArgs + "-Xopt-in=kotlin.RequiresOptIn" + 31 | "-Xopt-in=kotlin.time.ExperimentalTime" 32 | } 33 | } 34 | 35 | processResources { 36 | from(sourceSets.main.get().resources) { 37 | duplicatesStrategy = DuplicatesStrategy.INCLUDE 38 | val hash = try { 39 | ByteArrayOutputStream().use { out -> 40 | exec { 41 | commandLine("git", "rev-parse", "--short", "HEAD") 42 | standardOutput = out 43 | } 44 | 45 | out.toString().trim() 46 | } 47 | } catch (e: Throwable) { 48 | System.getenv("GITHUB_SHA") ?: "" 49 | } 50 | 51 | val tokens = mapOf( 52 | "version" to version, 53 | "commit_hash" to hash 54 | ) 55 | filter(org.apache.tools.ant.filters.ReplaceTokens::class, mapOf("tokens" to tokens)) 56 | } 57 | } 58 | } 59 | 60 | apply(from = "publishing.gradle.kts") 61 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # 2 | # This file is part of the BankoBot Project. 3 | # Copyright (C) 2021 BankoBot Contributors 4 | # 5 | # This program is free software: you can redistribute it and/or modify 6 | # it under the terms of the GNU Affero General Public License as published 7 | # by the Free Software Foundation, either version 3 of the License, or 8 | # (at your option) any later version. 9 | # 10 | # This program is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU Affero General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU Affero General Public License 16 | # along with this program. If not, see . 17 | # 18 | # Also add information on how to contact you by electronic and paper mail. 19 | # 20 | # If your software can interact with users remotely through a computer 21 | # network, you should also make sure that it provides a way for users to 22 | # get its source. For example, if your program is a web application, its 23 | # interface could display a "Source" link that leads users to an archive 24 | # of the code. There are many ways you could offer source, and different 25 | # solutions will be better for different programs; see section 13 for the 26 | # specific requirements. 27 | # 28 | # You should also get your employer (if you work as a programmer) or school, 29 | # if any, to sign a "copyright disclaimer" for the program, if necessary. 30 | # For more information on this, and how to apply and follow the GNU AGPL, see 31 | # . 32 | # 33 | # 34 | 35 | kotlin.mpp.stability.nowarn=true 36 | # Some weird java compiler stuff makes kapt run out of metaspace 37 | org.gradle.jvmargs=-XX:MaxMetaspaceSize=1024m 38 | 39 | -------------------------------------------------------------------------------- /src/main/kotlin/de/nycode/bankobot/variables/Expression.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the BankoBot Project. 3 | * Copyright (C) 2021 BankoBot Contributors 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero General Public License as published 7 | * by the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Affero General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Affero General Public License 16 | * along with this program. If not, see . 17 | * 18 | * Also add information on how to contact you by electronic and paper mail. 19 | * 20 | * If your software can interact with users remotely through a computer 21 | * network, you should also make sure that it provides a way for users to 22 | * get its source. For example, if your program is a web application, its 23 | * interface could display a "Source" link that leads users to an archive 24 | * of the code. There are many ways you could offer source, and different 25 | * solutions will be better for different programs; see section 13 for the 26 | * specific requirements. 27 | * 28 | * You should also get your employer (if you work as a programmer) or school, 29 | * if any, to sign a "copyright disclaimer" for the program, if necessary. 30 | * For more information on this, and how to apply and follow the GNU AGPL, see 31 | * . 32 | * 33 | */ 34 | 35 | package de.nycode.bankobot.variables 36 | 37 | interface Expression { 38 | 39 | suspend fun getResult(): R? 40 | } 41 | -------------------------------------------------------------------------------- /src/main/kotlin/de/nycode/bankobot/variables/parsers/calc/CalculationException.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the BankoBot Project. 3 | * Copyright (C) 2021 BankoBot Contributors 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero General Public License as published 7 | * by the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Affero General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Affero General Public License 16 | * along with this program. If not, see . 17 | * 18 | * Also add information on how to contact you by electronic and paper mail. 19 | * 20 | * If your software can interact with users remotely through a computer 21 | * network, you should also make sure that it provides a way for users to 22 | * get its source. For example, if your program is a web application, its 23 | * interface could display a "Source" link that leads users to an archive 24 | * of the code. There are many ways you could offer source, and different 25 | * solutions will be better for different programs; see section 13 for the 26 | * specific requirements. 27 | * 28 | * You should also get your employer (if you work as a programmer) or school, 29 | * if any, to sign a "copyright disclaimer" for the program, if necessary. 30 | * For more information on this, and how to apply and follow the GNU AGPL, see 31 | * . 32 | * 33 | */ 34 | 35 | package de.nycode.bankobot.variables.parsers.calc 36 | 37 | class CalculationException(message: String, val position: Int = 0) : Exception(message) 38 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | 2 | # 3 | # This file is part of the BankoBot Project. 4 | # Copyright (C) 2021 BankoBot Contributors 5 | # 6 | # This program is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU Affero General Public License as published 8 | # by the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # This program is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU Affero General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU Affero General Public License 17 | # along with this program. If not, see . 18 | # 19 | # Also add information on how to contact you by electronic and paper mail. 20 | # 21 | # If your software can interact with users remotely through a computer 22 | # network, you should also make sure that it provides a way for users to 23 | # get its source. For example, if your program is a web application, its 24 | # interface could display a "Source" link that leads users to an archive 25 | # of the code. There are many ways you could offer source, and different 26 | # solutions will be better for different programs; see section 13 for the 27 | # specific requirements. 28 | # 29 | # You should also get your employer (if you work as a programmer) or school, 30 | # if any, to sign a "copyright disclaimer" for the program, if necessary. 31 | # For more information on this, and how to apply and follow the GNU AGPL, see 32 | # . 33 | # 34 | # 35 | 36 | distributionBase=GRADLE_USER_HOME 37 | distributionPath=wrapper/dists 38 | distributionUrl=https\://services.gradle.org/distributions/gradle-7.1.1-all.zip 39 | zipStoreBase=GRADLE_USER_HOME 40 | zipStorePath=wrapper/dists 41 | -------------------------------------------------------------------------------- /src/main/kotlin/de/nycode/bankobot/twitch/TwitchUserResponse.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the BankoBot Project. 3 | * Copyright (C) 2021 BankoBot Contributors 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero General Public License as published 7 | * by the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Affero General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Affero General Public License 16 | * along with this program. If not, see . 17 | * 18 | * Also add information on how to contact you by electronic and paper mail. 19 | * 20 | * If your software can interact with users remotely through a computer 21 | * network, you should also make sure that it provides a way for users to 22 | * get its source. For example, if your program is a web application, its 23 | * interface could display a "Source" link that leads users to an archive 24 | * of the code. There are many ways you could offer source, and different 25 | * solutions will be better for different programs; see section 13 for the 26 | * specific requirements. 27 | * 28 | * You should also get your employer (if you work as a programmer) or school, 29 | * if any, to sign a "copyright disclaimer" for the program, if necessary. 30 | * For more information on this, and how to apply and follow the GNU AGPL, see 31 | * . 32 | * 33 | */ 34 | 35 | package de.nycode.bankobot.twitch 36 | 37 | import kotlinx.serialization.Serializable 38 | 39 | @Serializable 40 | data class TwitchUserResponse(val data: List) 41 | -------------------------------------------------------------------------------- /src/main/kotlin/de/nycode/bankobot/variables/parsers/InvalidExpressionException.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the BankoBot Project. 3 | * Copyright (C) 2021 BankoBot Contributors 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero General Public License as published 7 | * by the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Affero General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Affero General Public License 16 | * along with this program. If not, see . 17 | * 18 | * Also add information on how to contact you by electronic and paper mail. 19 | * 20 | * If your software can interact with users remotely through a computer 21 | * network, you should also make sure that it provides a way for users to 22 | * get its source. For example, if your program is a web application, its 23 | * interface could display a "Source" link that leads users to an archive 24 | * of the code. There are many ways you could offer source, and different 25 | * solutions will be better for different programs; see section 13 for the 26 | * specific requirements. 27 | * 28 | * You should also get your employer (if you work as a programmer) or school, 29 | * if any, to sign a "copyright disclaimer" for the program, if necessary. 30 | * For more information on this, and how to apply and follow the GNU AGPL, see 31 | * . 32 | * 33 | */ 34 | 35 | package de.nycode.bankobot.variables.parsers 36 | 37 | class InvalidExpressionException(reason: String?, val position: Int, cause: Throwable? = null) : 38 | Exception(reason, cause) 39 | -------------------------------------------------------------------------------- /src/main/kotlin/de/nycode/bankobot/command/CommandBuilder.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the BankoBot Project. 3 | * Copyright (C) 2021 BankoBot Contributors 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero General Public License as published 7 | * by the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Affero General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Affero General Public License 16 | * along with this program. If not, see . 17 | * 18 | * Also add information on how to contact you by electronic and paper mail. 19 | * 20 | * If your software can interact with users remotely through a computer 21 | * network, you should also make sure that it provides a way for users to 22 | * get its source. For example, if your program is a web application, its 23 | * interface could display a "Source" link that leads users to an archive 24 | * of the code. There are many ways you could offer source, and different 25 | * solutions will be better for different programs; see section 13 for the 26 | * specific requirements. 27 | * 28 | * You should also get your employer (if you work as a programmer) or school, 29 | * if any, to sign a "copyright disclaimer" for the program, if necessary. 30 | * For more information on this, and how to apply and follow the GNU AGPL, see 31 | * . 32 | * 33 | */ 34 | 35 | package de.nycode.bankobot.command 36 | 37 | import dev.kord.core.event.message.MessageCreateEvent 38 | import dev.kord.x.commands.model.command.CommandBuilder 39 | 40 | typealias CommandBuilder = CommandBuilder 41 | -------------------------------------------------------------------------------- /src/main/kotlin/de/nycode/bankobot/utils/Constants.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the BankoBot Project. 3 | * Copyright (C) 2021 BankoBot Contributors 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero General Public License as published 7 | * by the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Affero General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Affero General Public License 16 | * along with this program. If not, see . 17 | * 18 | * Also add information on how to contact you by electronic and paper mail. 19 | * 20 | * If your software can interact with users remotely through a computer 21 | * network, you should also make sure that it provides a way for users to 22 | * get its source. For example, if your program is a web application, its 23 | * interface could display a "Source" link that leads users to an archive 24 | * of the code. There are many ways you could offer source, and different 25 | * solutions will be better for different programs; see section 13 for the 26 | * specific requirements. 27 | * 28 | * You should also get your employer (if you work as a programmer) or school, 29 | * if any, to sign a "copyright disclaimer" for the program, if necessary. 30 | * For more information on this, and how to apply and follow the GNU AGPL, see 31 | * . 32 | * 33 | */ 34 | 35 | package de.nycode.bankobot.utils 36 | 37 | /** 38 | * Max length for embed title. 39 | */ 40 | const val EMBED_TITLE_MAX_LENGTH: Int = 1024 41 | 42 | const val JDOODLE_LANGUAGE_INVALID_CODE: Int = -100 43 | const val JDOODLE_CREDITS_USED_INVALID_CODE: Int = -200 44 | -------------------------------------------------------------------------------- /autohelp/kord/build.gradle.kts: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2021 BankoBot Contributors 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | * 24 | */ 25 | 26 | plugins { 27 | kotlin("jvm") 28 | } 29 | 30 | group = "me.schlaubi.autohelp" 31 | version = rootProject.version 32 | 33 | repositories { 34 | mavenCentral() 35 | maven("https://schlaubi.jfrog.io/artifactory/forp") 36 | maven("https://oss.sonatype.org/content/repositories/snapshots") 37 | } 38 | 39 | dependencies { 40 | api(project(":autohelp")) 41 | api("dev.kord", "kord-core", "0.8.0-M7") 42 | } 43 | 44 | tasks { 45 | withType { 46 | kotlinOptions { 47 | jvmTarget = "15" 48 | } 49 | } 50 | } 51 | 52 | java { 53 | toolchain { 54 | languageVersion.set(JavaLanguageVersion.of(15)) // kapt dies on JDK 16 55 | } 56 | } 57 | 58 | kotlin { 59 | explicitApi() 60 | } 61 | 62 | apply(from = "../publishing.gradle.kts") 63 | -------------------------------------------------------------------------------- /src/main/kotlin/de/nycode/bankobot/variables/ExpressionParser.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the BankoBot Project. 3 | * Copyright (C) 2021 BankoBot Contributors 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero General Public License as published 7 | * by the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Affero General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Affero General Public License 16 | * along with this program. If not, see . 17 | * 18 | * Also add information on how to contact you by electronic and paper mail. 19 | * 20 | * If your software can interact with users remotely through a computer 21 | * network, you should also make sure that it provides a way for users to 22 | * get its source. For example, if your program is a web application, its 23 | * interface could display a "Source" link that leads users to an archive 24 | * of the code. There are many ways you could offer source, and different 25 | * solutions will be better for different programs; see section 13 for the 26 | * specific requirements. 27 | * 28 | * You should also get your employer (if you work as a programmer) or school, 29 | * if any, to sign a "copyright disclaimer" for the program, if necessary. 30 | * For more information on this, and how to apply and follow the GNU AGPL, see 31 | * . 32 | * 33 | */ 34 | 35 | package de.nycode.bankobot.variables 36 | 37 | /** 38 | * Parses an expression to an [Expression] result 39 | * @param R the Result type 40 | */ 41 | interface ExpressionParser { 42 | 43 | fun isMatching(command: String): Boolean 44 | 45 | fun parseExpression(input: String): Expression 46 | } 47 | -------------------------------------------------------------------------------- /autohelp/src/main/kotlin/me/schlaubi/autohelp/help/MessageRenderer.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2021 BankoBot Contributors 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | * 24 | */ 25 | 26 | package me.schlaubi.autohelp.help 27 | 28 | /** 29 | * Interface for a Discord message that can be edited. 30 | * 31 | * @see MessageRenderer 32 | */ 33 | public interface EditableMessage { 34 | 35 | /** 36 | * Edits the content of this message to [message]. 37 | * @see OutgoingMessage 38 | */ 39 | public suspend fun edit(message: OutgoingMessage) 40 | } 41 | 42 | /** 43 | * Interface for sending messages into a channel. 44 | * 45 | * @see EditableMessage 46 | */ 47 | public interface MessageRenderer { 48 | /** 49 | * Sends [message] into [channelId] on [guildId] 50 | * 51 | * @return an [EditableMessage] 52 | * 53 | * @see EditableMessage 54 | * @see OutgoingMessage 55 | */ 56 | public suspend fun sendMessage(guildId: Long, channelId: Long, message: OutgoingMessage): EditableMessage 57 | } 58 | -------------------------------------------------------------------------------- /src/main/kotlin/de/nycode/bankobot/twitch/TwitchStream.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the BankoBot Project. 3 | * Copyright (C) 2021 BankoBot Contributors 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero General Public License as published 7 | * by the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Affero General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Affero General Public License 16 | * along with this program. If not, see . 17 | * 18 | * Also add information on how to contact you by electronic and paper mail. 19 | * 20 | * If your software can interact with users remotely through a computer 21 | * network, you should also make sure that it provides a way for users to 22 | * get its source. For example, if your program is a web application, its 23 | * interface could display a "Source" link that leads users to an archive 24 | * of the code. There are many ways you could offer source, and different 25 | * solutions will be better for different programs; see section 13 for the 26 | * specific requirements. 27 | * 28 | * You should also get your employer (if you work as a programmer) or school, 29 | * if any, to sign a "copyright disclaimer" for the program, if necessary. 30 | * For more information on this, and how to apply and follow the GNU AGPL, see 31 | * . 32 | * 33 | */ 34 | 35 | package de.nycode.bankobot.twitch 36 | 37 | import kotlinx.serialization.Serializable 38 | 39 | @Serializable 40 | data class TwitchStreamsResponse( 41 | val data: List 42 | ) 43 | 44 | @Serializable 45 | data class TwitchStream( 46 | val type: String = "", 47 | val title: String = "" 48 | ) { 49 | val isLive: Boolean 50 | get() = type == "live" 51 | } 52 | -------------------------------------------------------------------------------- /autohelp/src/main/kotlin/me/schlaubi/autohelp/source/EventContext.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2021 BankoBot Contributors 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | * 24 | */ 25 | 26 | package me.schlaubi.autohelp.source 27 | 28 | import kotlinx.coroutines.CoroutineScope 29 | import kotlinx.coroutines.ExperimentalCoroutinesApi 30 | import kotlinx.coroutines.flow.* 31 | import kotlin.coroutines.CoroutineContext 32 | 33 | /** 34 | * Combination of a list of [EventSource]s and [EventFilter]. 35 | */ 36 | @OptIn(ExperimentalCoroutinesApi::class) 37 | public class EventContext( 38 | sources: List>, 39 | public val filters: List>, override val coroutineContext: CoroutineContext, 40 | ) : EventSource, CoroutineScope { 41 | 42 | /** 43 | * A [Flow] of events provided by all sources and matching all [filters]. 44 | */ 45 | override val events: Flow = sources.asSequence() 46 | .map(EventSource::events) 47 | .asIterable() 48 | .merge() 49 | .filter { event -> 50 | filters.all { it.validateEvent(event) } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /.idea/jarRepositories.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 9 | 10 | 14 | 15 | 19 | 20 | 24 | 25 | 29 | 30 | 34 | 35 | 39 | 40 | 44 | 45 | 49 | 50 | -------------------------------------------------------------------------------- /src/main/kotlin/de/nycode/bankobot/utils/KordBugFix.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the BankoBot Project. 3 | * Copyright (C) 2021 BankoBot Contributors 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero General Public License as published 7 | * by the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Affero General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Affero General Public License 16 | * along with this program. If not, see . 17 | * 18 | * Also add information on how to contact you by electronic and paper mail. 19 | * 20 | * If your software can interact with users remotely through a computer 21 | * network, you should also make sure that it provides a way for users to 22 | * get its source. For example, if your program is a web application, its 23 | * interface could display a "Source" link that leads users to an archive 24 | * of the code. There are many ways you could offer source, and different 25 | * solutions will be better for different programs; see section 13 for the 26 | * specific requirements. 27 | * 28 | * You should also get your employer (if you work as a programmer) or school, 29 | * if any, to sign a "copyright disclaimer" for the program, if necessary. 30 | * For more information on this, and how to apply and follow the GNU AGPL, see 31 | * . 32 | * 33 | */ 34 | 35 | package de.nycode.bankobot.utils 36 | 37 | import dev.kord.core.behavior.channel.createMessage 38 | import dev.kord.core.entity.Message 39 | import dev.kord.rest.builder.message.create.MessageCreateBuilder 40 | import dev.kord.x.commands.kord.model.KordEvent 41 | 42 | /** 43 | * Creates a message in the [KordEvent.channel] configured by the [builder]. 44 | */ 45 | suspend inline fun KordEvent.respond(builder: MessageCreateBuilder.() -> Unit): Message { 46 | return message.channel.createMessage(builder) 47 | } 48 | -------------------------------------------------------------------------------- /src/main/kotlin/de/nycode/bankobot/command/permissions/PermissionHandler.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the BankoBot Project. 3 | * Copyright (C) 2021 BankoBot Contributors 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero General Public License as published 7 | * by the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Affero General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Affero General Public License 16 | * along with this program. If not, see . 17 | * 18 | * Also add information on how to contact you by electronic and paper mail. 19 | * 20 | * If your software can interact with users remotely through a computer 21 | * network, you should also make sure that it provides a way for users to 22 | * get its source. For example, if your program is a web application, its 23 | * interface could display a "Source" link that leads users to an archive 24 | * of the code. There are many ways you could offer source, and different 25 | * solutions will be better for different programs; see section 13 for the 26 | * specific requirements. 27 | * 28 | * You should also get your employer (if you work as a programmer) or school, 29 | * if any, to sign a "copyright disclaimer" for the program, if necessary. 30 | * For more information on this, and how to apply and follow the GNU AGPL, see 31 | * . 32 | * 33 | */ 34 | 35 | package de.nycode.bankobot.command.permissions 36 | 37 | import dev.kord.core.entity.Member 38 | import dev.kord.x.commands.model.command.CommandEvent 39 | import dev.kord.x.commands.model.precondition.Precondition 40 | 41 | /** 42 | * Interface for permission checks. 43 | * 44 | * @see Precondition 45 | * @see AbstractPermissionHandler 46 | */ 47 | interface PermissionHandler : Precondition { 48 | suspend fun isCovered(member: Member, permission: PermissionLevel): Boolean 49 | } 50 | -------------------------------------------------------------------------------- /src/main/kotlin/de/nycode/bankobot/variables/TagVariables.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the BankoBot Project. 3 | * Copyright (C) 2021 BankoBot Contributors 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero General Public License as published 7 | * by the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Affero General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Affero General Public License 16 | * along with this program. If not, see . 17 | * 18 | * Also add information on how to contact you by electronic and paper mail. 19 | * 20 | * If your software can interact with users remotely through a computer 21 | * network, you should also make sure that it provides a way for users to 22 | * get its source. For example, if your program is a web application, its 23 | * interface could display a "Source" link that leads users to an archive 24 | * of the code. There are many ways you could offer source, and different 25 | * solutions will be better for different programs; see section 13 for the 26 | * specific requirements. 27 | * 28 | * You should also get your employer (if you work as a programmer) or school, 29 | * if any, to sign a "copyright disclaimer" for the program, if necessary. 30 | * For more information on this, and how to apply and follow the GNU AGPL, see 31 | * . 32 | * 33 | */ 34 | 35 | package de.nycode.bankobot.variables 36 | 37 | import de.nycode.bankobot.commands.tag.TagEntry 38 | import de.nycode.bankobot.variables.VariableParser.replaceVariables 39 | 40 | private val regex = "(?. 19 | ~ 20 | ~ Also add information on how to contact you by electronic and paper mail. 21 | ~ 22 | ~ If your software can interact with users remotely through a computer 23 | ~ network, you should also make sure that it provides a way for users to 24 | ~ get its source. For example, if your program is a web application, its 25 | ~ interface could display a "Source" link that leads users to an archive 26 | ~ of the code. There are many ways you could offer source, and different 27 | ~ solutions will be better for different programs; see section 13 for the 28 | ~ specific requirements. 29 | ~ 30 | ~ You should also get your employer (if you work as a programmer) or school, 31 | ~ if any, to sign a "copyright disclaimer" for the program, if necessary. 32 | ~ For more information on this, and how to apply and follow the GNU AGPL, see 33 | ~ . 34 | ~ 35 | --> 36 | 37 | 38 | 43 | 44 | {% endblock %} 45 | -------------------------------------------------------------------------------- /src/main/kotlin/de/nycode/bankobot/variables/parsers/http/HttpExpression.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the BankoBot Project. 3 | * Copyright (C) 2021 BankoBot Contributors 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero General Public License as published 7 | * by the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Affero General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Affero General Public License 16 | * along with this program. If not, see . 17 | * 18 | * Also add information on how to contact you by electronic and paper mail. 19 | * 20 | * If your software can interact with users remotely through a computer 21 | * network, you should also make sure that it provides a way for users to 22 | * get its source. For example, if your program is a web application, its 23 | * interface could display a "Source" link that leads users to an archive 24 | * of the code. There are many ways you could offer source, and different 25 | * solutions will be better for different programs; see section 13 for the 26 | * specific requirements. 27 | * 28 | * You should also get your employer (if you work as a programmer) or school, 29 | * if any, to sign a "copyright disclaimer" for the program, if necessary. 30 | * For more information on this, and how to apply and follow the GNU AGPL, see 31 | * . 32 | * 33 | */ 34 | 35 | package de.nycode.bankobot.variables.parsers.http 36 | 37 | import de.nycode.bankobot.BankoBot 38 | import de.nycode.bankobot.variables.Expression 39 | import io.ktor.client.request.* 40 | 41 | class HttpExpression(val url: String) : Expression { 42 | 43 | private var result: String? = null 44 | 45 | override suspend fun getResult(): String? { 46 | if (result == null) { 47 | result = BankoBot.httpClient.get(url) 48 | } 49 | return result 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /settings.gradle.kts: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the BankoBot Project. 3 | * Copyright (C) 2021 BankoBot Contributors 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero General Public License as published 7 | * by the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Affero General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Affero General Public License 16 | * along with this program. If not, see . 17 | * 18 | * Also add information on how to contact you by electronic and paper mail. 19 | * 20 | * If your software can interact with users remotely through a computer 21 | * network, you should also make sure that it provides a way for users to 22 | * get its source. For example, if your program is a web application, its 23 | * interface could display a "Source" link that leads users to an archive 24 | * of the code. There are many ways you could offer source, and different 25 | * solutions will be better for different programs; see section 13 for the 26 | * specific requirements. 27 | * 28 | * You should also get your employer (if you work as a programmer) or school, 29 | * if any, to sign a "copyright disclaimer" for the program, if necessary. 30 | * For more information on this, and how to apply and follow the GNU AGPL, see 31 | * . 32 | * 33 | */ 34 | 35 | rootProject.name = "BankoBot" 36 | 37 | pluginManagement { 38 | resolutionStrategy { 39 | eachPlugin { 40 | repositories { 41 | jcenter { 42 | content { 43 | // just allow to include kotlinx projects 44 | // detekt needs 'kotlinx-html' for the html report 45 | includeGroup("org.jetbrains.kotlinx") 46 | } 47 | } 48 | } 49 | } 50 | } 51 | } 52 | include("autohelp") 53 | include("autohelp:kord") 54 | -------------------------------------------------------------------------------- /src/main/kotlin/de/nycode/bankobot/command/ContextUtils.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the BankoBot Project. 3 | * Copyright (C) 2021 BankoBot Contributors 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero General Public License as published 7 | * by the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Affero General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Affero General Public License 16 | * along with this program. If not, see . 17 | * 18 | * Also add information on how to contact you by electronic and paper mail. 19 | * 20 | * If your software can interact with users remotely through a computer 21 | * network, you should also make sure that it provides a way for users to 22 | * get its source. For example, if your program is a web application, its 23 | * interface could display a "Source" link that leads users to an archive 24 | * of the code. There are many ways you could offer source, and different 25 | * solutions will be better for different programs; see section 13 for the 26 | * specific requirements. 27 | * 28 | * You should also get your employer (if you work as a programmer) or school, 29 | * if any, to sign a "copyright disclaimer" for the program, if necessary. 30 | * For more information on this, and how to apply and follow the GNU AGPL, see 31 | * . 32 | * 33 | */ 34 | 35 | package de.nycode.bankobot.command 36 | 37 | import de.nycode.bankobot.command.slashcommands.SlashCommandContext 38 | import kotlin.contracts.ExperimentalContracts 39 | import kotlin.contracts.contract 40 | 41 | @OptIn(ExperimentalContracts::class) 42 | fun Context.isSlashCommandContext(): Boolean { 43 | contract { 44 | returns(true) implies (this@isSlashCommandContext is SlashCommandContext) 45 | } 46 | 47 | return this is SlashCommandContext 48 | } 49 | 50 | fun Context.isMessageCommandContext(): Boolean = !isSlashCommandContext() 51 | -------------------------------------------------------------------------------- /src/main/kotlin/de/nycode/bankobot/utils/CodeBlockUtil.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the BankoBot Project. 3 | * Copyright (C) 2021 BankoBot Contributors 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero General Public License as published 7 | * by the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Affero General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Affero General Public License 16 | * along with this program. If not, see . 17 | * 18 | * Also add information on how to contact you by electronic and paper mail. 19 | * 20 | * If your software can interact with users remotely through a computer 21 | * network, you should also make sure that it provides a way for users to 22 | * get its source. For example, if your program is a web application, its 23 | * interface could display a "Source" link that leads users to an archive 24 | * of the code. There are many ways you could offer source, and different 25 | * solutions will be better for different programs; see section 13 for the 26 | * specific requirements. 27 | * 28 | * You should also get your employer (if you work as a programmer) or school, 29 | * if any, to sign a "copyright disclaimer" for the program, if necessary. 30 | * For more information on this, and how to apply and follow the GNU AGPL, see 31 | * . 32 | * 33 | */ 34 | 35 | package de.nycode.bankobot.utils 36 | 37 | import org.intellij.lang.annotations.Language 38 | 39 | // https://regex101.com/r/euvYm9/3 40 | @Language("RegExp") 41 | val CODEBLOCK_REGEX: Regex = """```(?:([a-zA-Z]+)\s|\s)?([\s\S]+?(?=```))```""".toRegex() 42 | 43 | fun String.toCodeBlock(): CodeBlock? { 44 | val match = CODEBLOCK_REGEX.find(this) ?: return null 45 | val (_, language, code) = match.groupValues 46 | 47 | return CodeBlock(language.asNullable(), code) 48 | } 49 | 50 | data class CodeBlock(val language: String?, val code: String) 51 | -------------------------------------------------------------------------------- /src/main/kotlin/de/nycode/bankobot/variables/parsers/calc/CalcExpressionParser.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the BankoBot Project. 3 | * Copyright (C) 2021 BankoBot Contributors 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero General Public License as published 7 | * by the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Affero General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Affero General Public License 16 | * along with this program. If not, see . 17 | * 18 | * Also add information on how to contact you by electronic and paper mail. 19 | * 20 | * If your software can interact with users remotely through a computer 21 | * network, you should also make sure that it provides a way for users to 22 | * get its source. For example, if your program is a web application, its 23 | * interface could display a "Source" link that leads users to an archive 24 | * of the code. There are many ways you could offer source, and different 25 | * solutions will be better for different programs; see section 13 for the 26 | * specific requirements. 27 | * 28 | * You should also get your employer (if you work as a programmer) or school, 29 | * if any, to sign a "copyright disclaimer" for the program, if necessary. 30 | * For more information on this, and how to apply and follow the GNU AGPL, see 31 | * . 32 | * 33 | */ 34 | 35 | package de.nycode.bankobot.variables.parsers.calc 36 | 37 | import de.nycode.bankobot.variables.Expression 38 | import de.nycode.bankobot.variables.ExpressionParser 39 | 40 | object CalcExpressionParser : ExpressionParser { 41 | override fun isMatching(command: String): Boolean { 42 | return command in arrayOf("calc", "calculate", "math") 43 | } 44 | 45 | override fun parseExpression(input: String): Expression { 46 | return CalcExpression(input) 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /autohelp/src/main/kotlin/me/schlaubi/autohelp/internal/ParentAwareChildren.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2021 BankoBot Contributors 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | * 24 | */ 25 | 26 | package me.schlaubi.autohelp.internal 27 | 28 | import dev.schlaubi.forp.parser.stacktrace.CausedStackTrace 29 | import dev.schlaubi.forp.parser.stacktrace.RootStackTrace 30 | import dev.schlaubi.forp.parser.stacktrace.StackTrace 31 | 32 | internal class ParentAwareChildren( 33 | private val delegate: CausedStackTrace, 34 | private val root: RootStackTrace 35 | ) : CausedStackTrace by delegate { 36 | override val parent: StackTrace 37 | get() = root.findParentOf(this) ?: this 38 | 39 | // this makes the indexOf() check work 40 | override fun equals(other: Any?): Boolean { 41 | // It is sus but there is no way around it 42 | @Suppress("SuspiciousEqualsCombination") 43 | return this === other || delegate == other 44 | } 45 | 46 | override fun hashCode(): Int = delegate.hashCode() 47 | } 48 | 49 | internal fun RootStackTrace.findParentOf(child: StackTrace): StackTrace? = 50 | when (val me = children.indexOf(child)) { 51 | 0 -> this 52 | -1 -> null 53 | else -> children.getOrNull(me - 1) 54 | } 55 | -------------------------------------------------------------------------------- /autohelp/src/main/java/me/schlaubi/autohelp/AutoHelpVersion.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2021 BankoBot Contributors 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | * 24 | */ 25 | 26 | package me.schlaubi.autohelp; 27 | 28 | import org.slf4j.Logger; 29 | import org.slf4j.LoggerFactory; 30 | 31 | import java.io.IOException; 32 | import java.util.Properties; 33 | 34 | /** 35 | * The version of this AutoHelp artifact. 36 | */ 37 | public class AutoHelpVersion { 38 | 39 | private static final Logger LOG = LoggerFactory.getLogger(AutoHelpVersion.class); 40 | private static final Properties PROPERTIES = new Properties(); 41 | 42 | static { 43 | try { 44 | PROPERTIES.load(AutoHelpVersion.class.getResourceAsStream("AutoHelpVersion.properties")); 45 | } catch (IOException e) { 46 | LOG.warn("Could not load project meta", e); 47 | } 48 | } 49 | 50 | /** 51 | * The release name of this release. 52 | */ 53 | public static final String VERSION = PROPERTIES.getProperty("version"); 54 | 55 | /** 56 | * The commit hash in the AutoHelp repo 57 | */ 58 | public static final String COMMIT_HASH = PROPERTIES.getProperty("commit_hash"); 59 | 60 | } 61 | -------------------------------------------------------------------------------- /src/main/kotlin/de/nycode/bankobot/commands/Modules.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the BankoBot Project. 3 | * Copyright (C) 2021 BankoBot Contributors 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero General Public License as published 7 | * by the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Affero General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Affero General Public License 16 | * along with this program. If not, see . 17 | * 18 | * Also add information on how to contact you by electronic and paper mail. 19 | * 20 | * If your software can interact with users remotely through a computer 21 | * network, you should also make sure that it provides a way for users to 22 | * get its source. For example, if your program is a web application, its 23 | * interface could display a "Source" link that leads users to an archive 24 | * of the code. There are many ways you could offer source, and different 25 | * solutions will be better for different programs; see section 13 for the 26 | * specific requirements. 27 | * 28 | * You should also get your employer (if you work as a programmer) or school, 29 | * if any, to sign a "copyright disclaimer" for the program, if necessary. 30 | * For more information on this, and how to apply and follow the GNU AGPL, see 31 | * . 32 | * 33 | */ 34 | 35 | @file:Suppress("TopLevelPropertyNaming") 36 | 37 | package de.nycode.bankobot.commands 38 | 39 | /** 40 | * Name for the general module. 41 | */ 42 | const val GeneralModule: String = "General" 43 | 44 | /** 45 | * Name for moderation module. 46 | */ 47 | const val ModerationModule: String = "Moderation" 48 | 49 | /** 50 | * Name for the tag module. 51 | */ 52 | const val TagModule: String = "Tag" 53 | 54 | /** 55 | * Name for the bot owner module. 56 | */ 57 | const val BotOwnerModule: String = "BotOwner" 58 | 59 | /** 60 | * Name for the fun module. 61 | */ 62 | const val FunModule: String = "Fun" 63 | -------------------------------------------------------------------------------- /src/main/kotlin/de/nycode/bankobot/command/slashcommands/Ephemeral.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the BankoBot Project. 3 | * Copyright (C) 2021 BankoBot Contributors 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero General Public License as published 7 | * by the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Affero General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Affero General Public License 16 | * along with this program. If not, see . 17 | * 18 | * Also add information on how to contact you by electronic and paper mail. 19 | * 20 | * If your software can interact with users remotely through a computer 21 | * network, you should also make sure that it provides a way for users to 22 | * get its source. For example, if your program is a web application, its 23 | * interface could display a "Source" link that leads users to an archive 24 | * of the code. There are many ways you could offer source, and different 25 | * solutions will be better for different programs; see section 13 for the 26 | * specific requirements. 27 | * 28 | * You should also get your employer (if you work as a programmer) or school, 29 | * if any, to sign a "copyright disclaimer" for the program, if necessary. 30 | * For more information on this, and how to apply and follow the GNU AGPL, see 31 | * . 32 | * 33 | */ 34 | 35 | package de.nycode.bankobot.command.slashcommands 36 | 37 | import dev.kord.x.commands.model.command.Command 38 | import dev.kord.x.commands.model.command.CommandBuilder 39 | import dev.kord.x.commands.model.metadata.Metadata 40 | 41 | private object Ephemeral : Metadata.Key 42 | 43 | /** 44 | * Whether a Command supports slash commands or not 45 | */ 46 | val Command<*>.ephemeral: Boolean 47 | get() = data.metadata[Ephemeral] == true 48 | 49 | /** 50 | * Disables slash commands for this command. 51 | */ 52 | fun CommandBuilder<*, *, *>.useEphemeral() { 53 | metaData[Ephemeral] = true 54 | } 55 | -------------------------------------------------------------------------------- /src/main/kotlin/de/nycode/bankobot/utils/Emotes.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the BankoBot Project. 3 | * Copyright (C) 2021 BankoBot Contributors 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero General Public License as published 7 | * by the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Affero General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Affero General Public License 16 | * along with this program. If not, see . 17 | * 18 | * Also add information on how to contact you by electronic and paper mail. 19 | * 20 | * If your software can interact with users remotely through a computer 21 | * network, you should also make sure that it provides a way for users to 22 | * get its source. For example, if your program is a web application, its 23 | * interface could display a "Source" link that leads users to an archive 24 | * of the code. There are many ways you could offer source, and different 25 | * solutions will be better for different programs; see section 13 for the 26 | * specific requirements. 27 | * 28 | * You should also get your employer (if you work as a programmer) or school, 29 | * if any, to sign a "copyright disclaimer" for the program, if necessary. 30 | * For more information on this, and how to apply and follow the GNU AGPL, see 31 | * . 32 | * 33 | */ 34 | 35 | package de.nycode.bankobot.utils 36 | 37 | /** 38 | * Useful collection of Discord emotes. 39 | * 40 | * 41 | * Designed by [Rxsto#1337](https://rxsto.me) 42 | * Bot needs to be on [https://discord.gg/8phqcej](https://discord.gg/8phqcej) 43 | */ 44 | @Suppress("KDocMissingDocumentation") 45 | object Emotes { 46 | const val LOADING: String = "" 47 | const val ERROR: String = "<:error:535827110489620500>" 48 | const val WARN: String = "<:warn:535832532365737987>" 49 | const val INFO: String = "<:info:535828529573789696>" 50 | const val SUCCESS: String = "<:success:535827110552666112>" 51 | } 52 | -------------------------------------------------------------------------------- /src/main/kotlin/de/nycode/bankobot/Launcher.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the BankoBot Project. 3 | * Copyright (C) 2021 BankoBot Contributors 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero General Public License as published 7 | * by the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Affero General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Affero General Public License 16 | * along with this program. If not, see . 17 | * 18 | * Also add information on how to contact you by electronic and paper mail. 19 | * 20 | * If your software can interact with users remotely through a computer 21 | * network, you should also make sure that it provides a way for users to 22 | * get its source. For example, if your program is a web application, its 23 | * interface could display a "Source" link that leads users to an archive 24 | * of the code. There are many ways you could offer source, and different 25 | * solutions will be better for different programs; see section 13 for the 26 | * specific requirements. 27 | * 28 | * You should also get your employer (if you work as a programmer) or school, 29 | * if any, to sign a "copyright disclaimer" for the program, if necessary. 30 | * For more information on this, and how to apply and follow the GNU AGPL, see 31 | * . 32 | * 33 | */ 34 | 35 | package de.nycode.bankobot 36 | 37 | import ch.qos.logback.classic.Logger 38 | import de.nycode.bankobot.config.Config 39 | import mu.KotlinLogging 40 | import org.slf4j.LoggerFactory 41 | 42 | private val LOG = KotlinLogging.logger { } 43 | 44 | suspend fun main() { 45 | initializeLogging() 46 | Thread.setDefaultUncaughtExceptionHandler { thread, throwable -> 47 | LOG.error(throwable) { "Got unhandled error on $thread" } 48 | } 49 | BankoBot() 50 | } 51 | 52 | private fun initializeLogging() { 53 | val rootLogger = LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME) as Logger 54 | rootLogger.level = Config.LOG_LEVEL 55 | } 56 | -------------------------------------------------------------------------------- /src/main/kotlin/de/nycode/bankobot/listeners/SelfMentionListener.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the BankoBot Project. 3 | * Copyright (C) 2021 BankoBot Contributors 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero General Public License as published 7 | * by the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Affero General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Affero General Public License 16 | * along with this program. If not, see . 17 | * 18 | * Also add information on how to contact you by electronic and paper mail. 19 | * 20 | * If your software can interact with users remotely through a computer 21 | * network, you should also make sure that it provides a way for users to 22 | * get its source. For example, if your program is a web application, its 23 | * interface could display a "Source" link that leads users to an archive 24 | * of the code. There are many ways you could offer source, and different 25 | * solutions will be better for different programs; see section 13 for the 26 | * specific requirements. 27 | * 28 | * You should also get your employer (if you work as a programmer) or school, 29 | * if any, to sign a "copyright disclaimer" for the program, if necessary. 30 | * For more information on this, and how to apply and follow the GNU AGPL, see 31 | * . 32 | * 33 | */ 34 | 35 | package de.nycode.bankobot.listeners 36 | 37 | import de.nycode.bankobot.BankoBot 38 | import de.nycode.bankobot.commands.general.sendInfo 39 | import de.nycode.bankobot.utils.Embeds.createEmbed 40 | import de.nycode.bankobot.utils.Embeds.editEmbed 41 | import dev.kord.core.Kord 42 | import dev.kord.core.event.message.MessageCreateEvent 43 | import dev.kord.core.on 44 | 45 | private val mentionRegex by lazy { "<@!?${BankoBot.kord.selfId.asString}>".toRegex() } 46 | 47 | internal fun Kord.selfMentionListener() = on { 48 | if (message.content.matches(mentionRegex)) { 49 | sendInfo({ message.channel.createEmbed(it) }) { editEmbed(it) } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/main/kotlin/de/nycode/bankobot/commands/tag/EmptyTag.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the BankoBot Project. 3 | * Copyright (C) 2021 BankoBot Contributors 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero General Public License as published 7 | * by the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Affero General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Affero General Public License 16 | * along with this program. If not, see . 17 | * 18 | * Also add information on how to contact you by electronic and paper mail. 19 | * 20 | * If your software can interact with users remotely through a computer 21 | * network, you should also make sure that it provides a way for users to 22 | * get its source. For example, if your program is a web application, its 23 | * interface could display a "Source" link that leads users to an archive 24 | * of the code. There are many ways you could offer source, and different 25 | * solutions will be better for different programs; see section 13 for the 26 | * specific requirements. 27 | * 28 | * You should also get your employer (if you work as a programmer) or school, 29 | * if any, to sign a "copyright disclaimer" for the program, if necessary. 30 | * For more information on this, and how to apply and follow the GNU AGPL, see 31 | * . 32 | * 33 | */ 34 | 35 | package de.nycode.bankobot.commands.tag 36 | 37 | import de.nycode.bankobot.command.Context 38 | import de.nycode.bankobot.utils.Embeds 39 | 40 | object EmptyTag : Tag 41 | 42 | internal suspend fun Context.checkEmpty(tag: Tag, name: String? = null): Boolean { 43 | val isEmpty = tag.isEmpty() 44 | 45 | if (isEmpty) { 46 | if (name == null) { 47 | sendResponse(Embeds.error("Tag nicht gefunden!", "Der Tag konnte nicht gefunden werden!")) 48 | } else { 49 | sendResponse(Embeds.error("Tag nicht gefunden!", "Der Tag \"$name\" konnte nicht gefunden werden!")) 50 | } 51 | } 52 | return isEmpty 53 | } 54 | 55 | internal fun Tag.isEmpty() = this is EmptyTag 56 | -------------------------------------------------------------------------------- /src/main/kotlin/de/nycode/bankobot/command/MessageCommandEventSource.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the BankoBot Project. 3 | * Copyright (C) 2021 BankoBot Contributors 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero General Public License as published 7 | * by the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Affero General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Affero General Public License 16 | * along with this program. If not, see . 17 | * 18 | * Also add information on how to contact you by electronic and paper mail. 19 | * 20 | * If your software can interact with users remotely through a computer 21 | * network, you should also make sure that it provides a way for users to 22 | * get its source. For example, if your program is a web application, its 23 | * interface could display a "Source" link that leads users to an archive 24 | * of the code. There are many ways you could offer source, and different 25 | * solutions will be better for different programs; see section 13 for the 26 | * specific requirements. 27 | * 28 | * You should also get your employer (if you work as a programmer) or school, 29 | * if any, to sign a "copyright disclaimer" for the program, if necessary. 30 | * For more information on this, and how to apply and follow the GNU AGPL, see 31 | * . 32 | * 33 | */ 34 | 35 | package de.nycode.bankobot.command 36 | 37 | import dev.kord.core.Kord 38 | import dev.kord.core.event.message.MessageCreateEvent 39 | import dev.kord.x.commands.model.processor.EventSource 40 | import dev.kord.x.commands.model.processor.ProcessorContext 41 | import kotlinx.coroutines.channels.Channel 42 | import kotlinx.coroutines.flow.Flow 43 | import kotlinx.coroutines.flow.buffer 44 | import kotlinx.coroutines.flow.filterIsInstance 45 | 46 | class MessageCommandEventSource( 47 | val kord: Kord 48 | ) : EventSource { 49 | override val context: ProcessorContext 50 | get() = BankoBotContext 51 | 52 | override val events: Flow 53 | get() = kord.events.buffer(Channel.UNLIMITED).filterIsInstance() 54 | } 55 | -------------------------------------------------------------------------------- /src/main/kotlin/de/nycode/bankobot/commands/general/DCommand.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the BankoBot Project. 3 | * Copyright (C) 2021 BankoBot Contributors 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero General Public License as published 7 | * by the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Affero General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Affero General Public License 16 | * along with this program. If not, see . 17 | * 18 | * Also add information on how to contact you by electronic and paper mail. 19 | * 20 | * If your software can interact with users remotely through a computer 21 | * network, you should also make sure that it provides a way for users to 22 | * get its source. For example, if your program is a web application, its 23 | * interface could display a "Source" link that leads users to an archive 24 | * of the code. There are many ways you could offer source, and different 25 | * solutions will be better for different programs; see section 13 for the 26 | * specific requirements. 27 | * 28 | * You should also get your employer (if you work as a programmer) or school, 29 | * if any, to sign a "copyright disclaimer" for the program, if necessary. 30 | * For more information on this, and how to apply and follow the GNU AGPL, see 31 | * . 32 | * 33 | */ 34 | 35 | package de.nycode.bankobot.commands.general 36 | 37 | import de.nycode.bankobot.command.Context 38 | import de.nycode.bankobot.command.command 39 | import de.nycode.bankobot.command.description 40 | import de.nycode.bankobot.commands.GeneralModule 41 | import dev.kord.x.commands.annotation.AutoWired 42 | import dev.kord.x.commands.annotation.ModuleName 43 | import dev.kord.x.commands.model.command.invoke 44 | 45 | @ModuleName(GeneralModule) 46 | @AutoWired 47 | fun dCommand() = command("dddd") { 48 | alias("d", "dd", "ddd") 49 | description("They don't know :pepeLaugh:") 50 | 51 | invoke { 52 | specificCommand() 53 | } 54 | } 55 | 56 | private suspend fun Context.specificCommand() { 57 | sendResponse { 58 | title = "Imagine using xd in 2k21... oh wait" 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /autohelp/src/main/kotlin/me/schlaubi/autohelp/AutoHelp.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2021 BankoBot Contributors 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | * 24 | */ 25 | 26 | package me.schlaubi.autohelp 27 | 28 | import dev.schlaubi.forp.analyze.StackTraceAnalyzer 29 | import me.schlaubi.autohelp.help.HtmlRenderer 30 | import me.schlaubi.autohelp.help.MessageRenderer 31 | import me.schlaubi.autohelp.tags.TagSupplier 32 | import kotlin.time.Duration 33 | 34 | /** 35 | * Autohelp instance. 36 | * 37 | * @see AutoHelpBuilder 38 | * @see autoHelp 39 | */ 40 | public interface AutoHelp { 41 | /** 42 | * [StackTraceAnalyzer] used to power analysis of exceptions. 43 | */ 44 | public val analyzer: StackTraceAnalyzer 45 | 46 | /** 47 | * [TagSupplier] used to provide custom explanations. 48 | */ 49 | public val tagSupplier: TagSupplier 50 | 51 | /** 52 | * [MessageRenderer] used to send messages. 53 | */ 54 | public val messageRenderer: MessageRenderer 55 | 56 | /** 57 | * [HtmlRenderer] used to render javadocs. 58 | */ 59 | public val htmlRenderer: HtmlRenderer 60 | 61 | /** 62 | * The [Duration] after which all conversation should be closed 63 | */ 64 | public val cleanUpTime: Duration 65 | 66 | /** 67 | * Closes all resources needed by autohelp. 68 | */ 69 | public suspend fun close() 70 | 71 | /** 72 | * Text supposed to show loading (might be emote). 73 | */ 74 | public val loadingEmote: String 75 | } 76 | -------------------------------------------------------------------------------- /src/main/kotlin/de/nycode/bankobot/commands/TestCommand.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the BankoBot Project. 3 | * Copyright (C) 2021 BankoBot Contributors 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero General Public License as published 7 | * by the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Affero General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Affero General Public License 16 | * along with this program. If not, see . 17 | * 18 | * Also add information on how to contact you by electronic and paper mail. 19 | * 20 | * If your software can interact with users remotely through a computer 21 | * network, you should also make sure that it provides a way for users to 22 | * get its source. For example, if your program is a web application, its 23 | * interface could display a "Source" link that leads users to an archive 24 | * of the code. There are many ways you could offer source, and different 25 | * solutions will be better for different programs; see section 13 for the 26 | * specific requirements. 27 | * 28 | * You should also get your employer (if you work as a programmer) or school, 29 | * if any, to sign a "copyright disclaimer" for the program, if necessary. 30 | * For more information on this, and how to apply and follow the GNU AGPL, see 31 | * . 32 | * 33 | */ 34 | 35 | package de.nycode.bankobot.commands 36 | 37 | import de.nycode.bankobot.command.command 38 | import de.nycode.bankobot.command.permissions.PermissionLevel 39 | import de.nycode.bankobot.command.permissions.permission 40 | import de.nycode.bankobot.utils.paginator.paginate 41 | import dev.kord.x.commands.annotation.AutoWired 42 | import dev.kord.x.commands.annotation.ModuleName 43 | import dev.kord.x.commands.model.command.invoke 44 | 45 | @Suppress("TopLevelPropertyNaming") 46 | const val TestModule = "Test" 47 | 48 | @Suppress("MagicNumber") 49 | @AutoWired 50 | @ModuleName(TestModule) 51 | fun paginatorCommand() = command("paginator-test") { 52 | permission(PermissionLevel.BOT_OWNER) 53 | 54 | invoke { 55 | val items = "1".repeat(20).split("") 56 | items.paginate(channel, "Test liste") 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/main/kotlin/de/nycode/bankobot/variables/parsers/http/HttpExpressionParser.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the BankoBot Project. 3 | * Copyright (C) 2021 BankoBot Contributors 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero General Public License as published 7 | * by the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Affero General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Affero General Public License 16 | * along with this program. If not, see . 17 | * 18 | * Also add information on how to contact you by electronic and paper mail. 19 | * 20 | * If your software can interact with users remotely through a computer 21 | * network, you should also make sure that it provides a way for users to 22 | * get its source. For example, if your program is a web application, its 23 | * interface could display a "Source" link that leads users to an archive 24 | * of the code. There are many ways you could offer source, and different 25 | * solutions will be better for different programs; see section 13 for the 26 | * specific requirements. 27 | * 28 | * You should also get your employer (if you work as a programmer) or school, 29 | * if any, to sign a "copyright disclaimer" for the program, if necessary. 30 | * For more information on this, and how to apply and follow the GNU AGPL, see 31 | * . 32 | * 33 | */ 34 | 35 | package de.nycode.bankobot.variables.parsers.http 36 | 37 | import de.nycode.bankobot.variables.Expression 38 | import de.nycode.bankobot.variables.ExpressionParser 39 | import de.nycode.bankobot.variables.parsers.InvalidExpressionException 40 | 41 | object HttpExpressionParser : ExpressionParser { 42 | private val urlRegex = "^https://[-a-zA-Z0-9+&@#/%?=~_|!:,.;]*[-a-zA-Z0-9+&@#/%=~_|]".toRegex() 43 | 44 | override fun isMatching(command: String): Boolean { 45 | return command in arrayOf("http") 46 | } 47 | 48 | override fun parseExpression(input: String): Expression { 49 | if (!input.matches(urlRegex)) { 50 | throw InvalidExpressionException("Invalid url! (Only https is allowed!)", 0) 51 | } 52 | 53 | return HttpExpression(input) 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/main/kotlin/de/nycode/bankobot/serialization/SnowflakeSerializer.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the BankoBot Project. 3 | * Copyright (C) 2021 BankoBot Contributors 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero General Public License as published 7 | * by the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Affero General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Affero General Public License 16 | * along with this program. If not, see . 17 | * 18 | * Also add information on how to contact you by electronic and paper mail. 19 | * 20 | * If your software can interact with users remotely through a computer 21 | * network, you should also make sure that it provides a way for users to 22 | * get its source. For example, if your program is a web application, its 23 | * interface could display a "Source" link that leads users to an archive 24 | * of the code. There are many ways you could offer source, and different 25 | * solutions will be better for different programs; see section 13 for the 26 | * specific requirements. 27 | * 28 | * You should also get your employer (if you work as a programmer) or school, 29 | * if any, to sign a "copyright disclaimer" for the program, if necessary. 30 | * For more information on this, and how to apply and follow the GNU AGPL, see 31 | * . 32 | * 33 | */ 34 | 35 | package de.nycode.bankobot.serialization 36 | 37 | import dev.kord.common.entity.Snowflake 38 | import kotlinx.serialization.KSerializer 39 | import kotlinx.serialization.descriptors.PrimitiveKind 40 | import kotlinx.serialization.descriptors.PrimitiveSerialDescriptor 41 | import kotlinx.serialization.descriptors.SerialDescriptor 42 | import kotlinx.serialization.encoding.Decoder 43 | import kotlinx.serialization.encoding.Encoder 44 | 45 | object SnowflakeSerializer : KSerializer { 46 | override val descriptor: SerialDescriptor 47 | get() = PrimitiveSerialDescriptor("Kord.Snowflake", PrimitiveKind.LONG) 48 | 49 | override fun deserialize(decoder: Decoder): Snowflake = Snowflake(decoder.decodeLong()) 50 | 51 | override fun serialize(encoder: Encoder, value: Snowflake) = encoder.encodeLong(value.value) 52 | } 53 | -------------------------------------------------------------------------------- /src/main/kotlin/de/nycode/bankobot/command/AbstractKordFilter.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the BankoBot Project. 3 | * Copyright (C) 2021 BankoBot Contributors 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero General Public License as published 7 | * by the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Affero General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Affero General Public License 16 | * along with this program. If not, see . 17 | * 18 | * Also add information on how to contact you by electronic and paper mail. 19 | * 20 | * If your software can interact with users remotely through a computer 21 | * network, you should also make sure that it provides a way for users to 22 | * get its source. For example, if your program is a web application, its 23 | * interface could display a "Source" link that leads users to an archive 24 | * of the code. There are many ways you could offer source, and different 25 | * solutions will be better for different programs; see section 13 for the 26 | * specific requirements. 27 | * 28 | * You should also get your employer (if you work as a programmer) or school, 29 | * if any, to sign a "copyright disclaimer" for the program, if necessary. 30 | * For more information on this, and how to apply and follow the GNU AGPL, see 31 | * . 32 | * 33 | */ 34 | 35 | package de.nycode.bankobot.command 36 | 37 | import dev.kord.core.event.Event 38 | import dev.kord.x.commands.model.command.CommandEvent 39 | import dev.kord.x.commands.model.context.CommonContext 40 | import dev.kord.x.commands.model.eventFilter.EventFilter 41 | import dev.kord.x.commands.model.precondition.Precondition 42 | import dev.kord.x.commands.model.processor.ProcessorContext 43 | 44 | /** 45 | * Abstract implementation of [EventFilter] for Kord. 46 | */ 47 | abstract class AbstractKordFilter : EventFilter { 48 | override val context: ProcessorContext = CommonContext 49 | } 50 | 51 | /** 52 | * Abstract implementation of [Precondition] for Kord. 53 | */ 54 | abstract class AbstractKordPrecondition : Precondition { 55 | override val context: ProcessorContext<*, *, CommandEvent> = CommonContext 56 | } 57 | -------------------------------------------------------------------------------- /src/main/kotlin/de/nycode/bankobot/command/slashcommands/IgnoreSlashCommands.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the BankoBot Project. 3 | * Copyright (C) 2021 BankoBot Contributors 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero General Public License as published 7 | * by the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Affero General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Affero General Public License 16 | * along with this program. If not, see . 17 | * 18 | * Also add information on how to contact you by electronic and paper mail. 19 | * 20 | * If your software can interact with users remotely through a computer 21 | * network, you should also make sure that it provides a way for users to 22 | * get its source. For example, if your program is a web application, its 23 | * interface could display a "Source" link that leads users to an archive 24 | * of the code. There are many ways you could offer source, and different 25 | * solutions will be better for different programs; see section 13 for the 26 | * specific requirements. 27 | * 28 | * You should also get your employer (if you work as a programmer) or school, 29 | * if any, to sign a "copyright disclaimer" for the program, if necessary. 30 | * For more information on this, and how to apply and follow the GNU AGPL, see 31 | * . 32 | * 33 | */ 34 | 35 | package de.nycode.bankobot.command.slashcommands 36 | 37 | import dev.kord.x.commands.model.command.Command 38 | import dev.kord.x.commands.model.command.CommandBuilder 39 | import dev.kord.x.commands.model.metadata.Metadata 40 | 41 | private object IgnoreAsSlashCommand : Metadata.Key 42 | 43 | /** 44 | * Whether a Command supports slash commands or not 45 | */ 46 | val CommandBuilder<*, *, *>.supportsSlashCommands: Boolean 47 | get() = metaData[IgnoreAsSlashCommand] != true 48 | 49 | /** 50 | * Whether a Command supports slash commands or not 51 | */ 52 | val Command<*>.supportsSlashCommands: Boolean 53 | get() = data.metadata[IgnoreAsSlashCommand] != true 54 | 55 | /** 56 | * Disables slash commands for this command. 57 | */ 58 | fun CommandBuilder<*, *, *>.disableSlashCommands() { 59 | metaData[IgnoreAsSlashCommand] = true 60 | } 61 | -------------------------------------------------------------------------------- /src/main/kotlin/de/nycode/bankobot/command/Description.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the BankoBot Project. 3 | * Copyright (C) 2021 BankoBot Contributors 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero General Public License as published 7 | * by the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Affero General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Affero General Public License 16 | * along with this program. If not, see . 17 | * 18 | * Also add information on how to contact you by electronic and paper mail. 19 | * 20 | * If your software can interact with users remotely through a computer 21 | * network, you should also make sure that it provides a way for users to 22 | * get its source. For example, if your program is a web application, its 23 | * interface could display a "Source" link that leads users to an archive 24 | * of the code. There are many ways you could offer source, and different 25 | * solutions will be better for different programs; see section 13 for the 26 | * specific requirements. 27 | * 28 | * You should also get your employer (if you work as a programmer) or school, 29 | * if any, to sign a "copyright disclaimer" for the program, if necessary. 30 | * For more information on this, and how to apply and follow the GNU AGPL, see 31 | * . 32 | * 33 | */ 34 | 35 | package de.nycode.bankobot.command 36 | 37 | import dev.kord.x.commands.model.command.Command 38 | import dev.kord.x.commands.model.command.CommandBuilder 39 | import dev.kord.x.commands.model.command.CommandEvent 40 | import dev.kord.x.commands.model.metadata.Metadata 41 | 42 | private object CommandDescription : Metadata.Key 43 | 44 | /** 45 | * The description of a command. 46 | */ 47 | val Command<*>.description: String? 48 | get() = data.metadata[CommandDescription] 49 | 50 | /** 51 | * The description of a command. 52 | */ 53 | val CommandBuilder<*, *, *>.description: String? 54 | get() = metaData[CommandDescription] 55 | 56 | /** 57 | * Sets the description of a command to [description]. 58 | */ 59 | fun CommandBuilder.description(description: String): Unit = 60 | metaData.set(CommandDescription, description) 61 | -------------------------------------------------------------------------------- /src/main/kotlin/de/nycode/bankobot/utils/Colors.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the BankoBot Project. 3 | * Copyright (C) 2021 BankoBot Contributors 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero General Public License as published 7 | * by the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Affero General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Affero General Public License 16 | * along with this program. If not, see . 17 | * 18 | * Also add information on how to contact you by electronic and paper mail. 19 | * 20 | * If your software can interact with users remotely through a computer 21 | * network, you should also make sure that it provides a way for users to 22 | * get its source. For example, if your program is a web application, its 23 | * interface could display a "Source" link that leads users to an archive 24 | * of the code. There are many ways you could offer source, and different 25 | * solutions will be better for different programs; see section 13 for the 26 | * specific requirements. 27 | * 28 | * You should also get your employer (if you work as a programmer) or school, 29 | * if any, to sign a "copyright disclaimer" for the program, if necessary. 30 | * For more information on this, and how to apply and follow the GNU AGPL, see 31 | * . 32 | * 33 | */ 34 | 35 | package de.nycode.bankobot.utils 36 | 37 | import dev.kord.common.Color 38 | 39 | /** 40 | * Wrapper for [Discordapp.com/branding][https://discordapp.com/branding] colors and some other colors: 41 | */ 42 | @Suppress("KDocMissingDocumentation", "unused", "MagicNumber") 43 | object Colors { 44 | // Discord 45 | val BLURLPLE: Color = Color(114, 137, 218) 46 | val FULL_WHITE: Color = Color(255, 255, 255) 47 | val GREYPLE: Color = Color(153, 170, 181) 48 | val DARK_BUT_NOT_BLACK: Color = Color(44, 47, 51) 49 | val NOT_QUITE_BLACK: Color = Color(33, 39, 42) 50 | 51 | // Other colors 52 | val LIGHT_RED: Color = Color(231, 76, 60) 53 | val DARK_RED: Color = Color(192, 57, 43) 54 | val LIGHT_GREEN: Color = Color(46, 204, 113) 55 | val DARK_GREEN: Color = Color(39, 174, 96) 56 | val BLUE: Color = Color(52, 152, 219) 57 | val YELLOW: Color = Color(241, 196, 15) 58 | } 59 | -------------------------------------------------------------------------------- /src/main/kotlin/de/nycode/bankobot/twitch/Authentication.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the BankoBot Project. 3 | * Copyright (C) 2021 BankoBot Contributors 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero General Public License as published 7 | * by the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Affero General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Affero General Public License 16 | * along with this program. If not, see . 17 | * 18 | * Also add information on how to contact you by electronic and paper mail. 19 | * 20 | * If your software can interact with users remotely through a computer 21 | * network, you should also make sure that it provides a way for users to 22 | * get its source. For example, if your program is a web application, its 23 | * interface could display a "Source" link that leads users to an archive 24 | * of the code. There are many ways you could offer source, and different 25 | * solutions will be better for different programs; see section 13 for the 26 | * specific requirements. 27 | * 28 | * You should also get your employer (if you work as a programmer) or school, 29 | * if any, to sign a "copyright disclaimer" for the program, if necessary. 30 | * For more information on this, and how to apply and follow the GNU AGPL, see 31 | * . 32 | * 33 | */ 34 | 35 | package de.nycode.bankobot.twitch 36 | 37 | import de.nycode.bankobot.BankoBot 38 | import de.nycode.bankobot.config.Config 39 | import io.ktor.client.request.* 40 | import kotlinx.serialization.SerialName 41 | import kotlinx.serialization.Serializable 42 | 43 | /** 44 | * Fetches an app access token from the Twitch API 45 | */ 46 | internal suspend fun fetchAccessToken(): TwitchAccessTokenResponse = 47 | BankoBot.httpClient.post(TOKEN_URL) { 48 | parameter(CLIENT_ID, Config.TWITCH_CLIENT_ID) 49 | parameter(CLIENT_SECRET, Config.TWITCH_CLIENT_SECRET) 50 | parameter(GRANT_TYPE, CLIENT_CREDENTIALS) 51 | } 52 | 53 | @Serializable 54 | data class TwitchAccessTokenResponse( 55 | @SerialName("access_token") 56 | val accessToken: String, 57 | @SerialName("expires_in") 58 | val expiresIn: Int, 59 | @SerialName("token_type") 60 | val tokenType: String 61 | ) 62 | -------------------------------------------------------------------------------- /src/main/kotlin/de/nycode/bankobot/utils/HastebinUtil.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the BankoBot Project. 3 | * Copyright (C) 2021 BankoBot Contributors 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero General Public License as published 7 | * by the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Affero General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Affero General Public License 16 | * along with this program. If not, see . 17 | * 18 | * Also add information on how to contact you by electronic and paper mail. 19 | * 20 | * If your software can interact with users remotely through a computer 21 | * network, you should also make sure that it provides a way for users to 22 | * get its source. For example, if your program is a web application, its 23 | * interface could display a "Source" link that leads users to an archive 24 | * of the code. There are many ways you could offer source, and different 25 | * solutions will be better for different programs; see section 13 for the 26 | * specific requirements. 27 | * 28 | * You should also get your employer (if you work as a programmer) or school, 29 | * if any, to sign a "copyright disclaimer" for the program, if necessary. 30 | * For more information on this, and how to apply and follow the GNU AGPL, see 31 | * . 32 | * 33 | */ 34 | 35 | package de.nycode.bankobot.utils 36 | 37 | import de.nycode.bankobot.BankoBot 38 | import de.nycode.bankobot.config.Config 39 | import io.ktor.client.request.* 40 | import io.ktor.http.* 41 | import kotlinx.serialization.Serializable 42 | 43 | /** 44 | * Util for interacting with Hastebin. 45 | * @see Config.HASTE_HOST 46 | */ 47 | object HastebinUtil { 48 | 49 | /** 50 | * Posts the [text] to [Config.HASTE_HOST] 51 | * @return the haste-url 52 | */ 53 | suspend fun postToHastebin(text: String): String { 54 | val response: HasteBinResponse = BankoBot.httpClient.post { 55 | url(URLBuilder(Config.HASTE_HOST).path("documents").build()) 56 | body = text 57 | } 58 | 59 | return URLBuilder(Config.HASTE_HOST).path(response.key).buildString() 60 | } 61 | } 62 | 63 | @Serializable 64 | private data class HasteBinResponse(val key: String) 65 | -------------------------------------------------------------------------------- /src/main/kotlin/de/nycode/bankobot/utils/ModuleModifiers.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the BankoBot Project. 3 | * Copyright (C) 2021 BankoBot Contributors 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero General Public License as published 7 | * by the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Affero General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Affero General Public License 16 | * along with this program. If not, see . 17 | * 18 | * Also add information on how to contact you by electronic and paper mail. 19 | * 20 | * If your software can interact with users remotely through a computer 21 | * network, you should also make sure that it provides a way for users to 22 | * get its source. For example, if your program is a web application, its 23 | * interface could display a "Source" link that leads users to an archive 24 | * of the code. There are many ways you could offer source, and different 25 | * solutions will be better for different programs; see section 13 for the 26 | * specific requirements. 27 | * 28 | * You should also get your employer (if you work as a programmer) or school, 29 | * if any, to sign a "copyright disclaimer" for the program, if necessary. 30 | * For more information on this, and how to apply and follow the GNU AGPL, see 31 | * . 32 | * 33 | */ 34 | 35 | package de.nycode.bankobot.utils 36 | 37 | import dev.kord.x.commands.model.module.ModuleBuilder 38 | import dev.kord.x.commands.model.module.ModuleModifier 39 | import dev.kord.x.commands.model.processor.ModuleContainer 40 | import kotlin.reflect.KProperty1 41 | import kotlin.reflect.full.declaredMemberProperties 42 | 43 | inline fun afterAll( 44 | crossinline modification: suspend Collection>.() -> Unit 45 | ): ModuleModifier = object : ModuleModifier { 46 | @Suppress("UNCHECKED_CAST") 47 | override suspend fun apply(container: ModuleContainer) { 48 | val properties = 49 | container::class.declaredMemberProperties.first { it.name == "modules" } 50 | as KProperty1>> 51 | 52 | val modules = properties.get(container) 53 | 54 | modification(modules.values) 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/main/kotlin/de/nycode/bankobot/command/permissions/DebugPermissionHandler.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the BankoBot Project. 3 | * Copyright (C) 2021 BankoBot Contributors 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero General Public License as published 7 | * by the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Affero General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Affero General Public License 16 | * along with this program. If not, see . 17 | * 18 | * Also add information on how to contact you by electronic and paper mail. 19 | * 20 | * If your software can interact with users remotely through a computer 21 | * network, you should also make sure that it provides a way for users to 22 | * get its source. For example, if your program is a web application, its 23 | * interface could display a "Source" link that leads users to an archive 24 | * of the code. There are many ways you could offer source, and different 25 | * solutions will be better for different programs; see section 13 for the 26 | * specific requirements. 27 | * 28 | * You should also get your employer (if you work as a programmer) or school, 29 | * if any, to sign a "copyright disclaimer" for the program, if necessary. 30 | * For more information on this, and how to apply and follow the GNU AGPL, see 31 | * . 32 | * 33 | */ 34 | 35 | package de.nycode.bankobot.command.permissions 36 | 37 | import de.nycode.bankobot.BankoBot 38 | import de.nycode.bankobot.config.Environment 39 | import dev.kord.core.entity.Member 40 | import kotlinx.coroutines.runBlocking 41 | 42 | /** 43 | * Implementation of [PermissionHandler] which denies all command executions of non bot team members. 44 | * 45 | * Used with [Environment.DEVELOPMENT] 46 | */ 47 | object DebugPermissionHandler : AbstractPermissionHandler() { 48 | 49 | private val authorizedMembers by lazy { 50 | runBlocking { 51 | val application = BankoBot.kord.getApplicationInfo() 52 | application.team?.run { members.map { it.userId } } ?: listOf(application.ownerId) 53 | } 54 | } 55 | 56 | // TODO: Fix this 57 | override suspend fun isCovered(member: Member, permission: PermissionLevel): Boolean = 58 | member.id in authorizedMembers 59 | } 60 | -------------------------------------------------------------------------------- /src/main/kotlin/de/nycode/bankobot/serialization/LocalDateTimeSerializer.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the BankoBot Project. 3 | * Copyright (C) 2021 BankoBot Contributors 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero General Public License as published 7 | * by the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Affero General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Affero General Public License 16 | * along with this program. If not, see . 17 | * 18 | * Also add information on how to contact you by electronic and paper mail. 19 | * 20 | * If your software can interact with users remotely through a computer 21 | * network, you should also make sure that it provides a way for users to 22 | * get its source. For example, if your program is a web application, its 23 | * interface could display a "Source" link that leads users to an archive 24 | * of the code. There are many ways you could offer source, and different 25 | * solutions will be better for different programs; see section 13 for the 26 | * specific requirements. 27 | * 28 | * You should also get your employer (if you work as a programmer) or school, 29 | * if any, to sign a "copyright disclaimer" for the program, if necessary. 30 | * For more information on this, and how to apply and follow the GNU AGPL, see 31 | * . 32 | * 33 | */ 34 | 35 | package de.nycode.bankobot.serialization 36 | 37 | import kotlinx.datetime.LocalDateTime 38 | import kotlinx.serialization.KSerializer 39 | import kotlinx.serialization.descriptors.PrimitiveKind 40 | import kotlinx.serialization.descriptors.PrimitiveSerialDescriptor 41 | import kotlinx.serialization.descriptors.SerialDescriptor 42 | import kotlinx.serialization.encoding.Decoder 43 | import kotlinx.serialization.encoding.Encoder 44 | 45 | object LocalDateTimeSerializer : KSerializer { 46 | override val descriptor: SerialDescriptor = 47 | PrimitiveSerialDescriptor("kotlinx.datetime.LocalDateTime", PrimitiveKind.STRING) 48 | 49 | override fun deserialize(decoder: Decoder): LocalDateTime { 50 | return LocalDateTime.parse(decoder.decodeString()) 51 | } 52 | 53 | override fun serialize(encoder: Encoder, value: LocalDateTime) { 54 | encoder.encodeString(value.toString()) 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/main/kotlin/de/nycode/bankobot/utils/StringUtil.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the BankoBot Project. 3 | * Copyright (C) 2021 BankoBot Contributors 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero General Public License as published 7 | * by the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Affero General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Affero General Public License 16 | * along with this program. If not, see . 17 | * 18 | * Also add information on how to contact you by electronic and paper mail. 19 | * 20 | * If your software can interact with users remotely through a computer 21 | * network, you should also make sure that it provides a way for users to 22 | * get its source. For example, if your program is a web application, its 23 | * interface could display a "Source" link that leads users to an archive 24 | * of the code. There are many ways you could offer source, and different 25 | * solutions will be better for different programs; see section 13 for the 26 | * specific requirements. 27 | * 28 | * You should also get your employer (if you work as a programmer) or school, 29 | * if any, to sign a "copyright disclaimer" for the program, if necessary. 30 | * For more information on this, and how to apply and follow the GNU AGPL, see 31 | * . 32 | * 33 | */ 34 | 35 | package de.nycode.bankobot.utils 36 | 37 | import java.security.MessageDigest 38 | 39 | /** 40 | * Limits this string to [maxLength] and adds [truncate] at the end if the string was shortened- 41 | */ 42 | fun String.limit(maxLength: Int, truncate: String = "..."): String = if (length > maxLength) { 43 | substring(0, maxLength - truncate.length) + truncate 44 | } else { 45 | this 46 | } 47 | 48 | fun List.format(transform: (T) -> CharSequence = { it.toString() }): String = 49 | joinToString(prefix = "`", separator = "`, `", postfix = "`", transform = transform) 50 | 51 | fun String.asNullable(): String? = ifBlank { null } 52 | 53 | fun String.sha256(): String { 54 | return hashString(this, "SHA-256") 55 | } 56 | 57 | private fun hashString(input: String, algorithm: String): String { 58 | return MessageDigest 59 | .getInstance(algorithm) 60 | .digest(input.toByteArray()) 61 | .fold("", { str, it -> str + "%02x".format(it) }) 62 | } 63 | -------------------------------------------------------------------------------- /autohelp/src/main/kotlin/me/schlaubi/autohelp/internal/AutoHelpImpl.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2021 BankoBot Contributors 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | * 24 | */ 25 | 26 | package me.schlaubi.autohelp.internal 27 | 28 | import dev.schlaubi.forp.analyze.StackTraceAnalyzer 29 | import kotlinx.coroutines.CoroutineScope 30 | import kotlinx.coroutines.coroutineScope 31 | import kotlinx.coroutines.flow.launchIn 32 | import kotlinx.coroutines.flow.onEach 33 | import kotlinx.coroutines.launch 34 | import me.schlaubi.autohelp.AutoHelp 35 | import me.schlaubi.autohelp.help.HtmlRenderer 36 | import me.schlaubi.autohelp.help.MessageRenderer 37 | import me.schlaubi.autohelp.source.EventContext 38 | import me.schlaubi.autohelp.tags.TagSupplier 39 | import kotlin.coroutines.CoroutineContext 40 | import kotlin.time.Duration 41 | 42 | @Suppress("LongParameterList") 43 | internal class AutoHelpImpl( 44 | override val analyzer: StackTraceAnalyzer, contexts: List>, 45 | override val coroutineContext: CoroutineContext, 46 | override val tagSupplier: TagSupplier, 47 | override val cleanUpTime: Duration, 48 | override val messageRenderer: MessageRenderer, 49 | override val htmlRenderer: HtmlRenderer, 50 | override val loadingEmote: String, 51 | ) : AutoHelp, CoroutineScope { 52 | 53 | private val listeners = contexts.map { 54 | it.events.onEach { message -> 55 | message.handle(this) 56 | }.launchIn(this) 57 | } 58 | 59 | 60 | override suspend fun close() { 61 | coroutineScope { 62 | listeners.forEach { 63 | launch { it.cancel() } 64 | } 65 | } 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /src/main/kotlin/de/nycode/bankobot/commands/dev/VarCommand.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the BankoBot Project. 3 | * Copyright (C) 2021 BankoBot Contributors 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero General Public License as published 7 | * by the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Affero General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Affero General Public License 16 | * along with this program. If not, see . 17 | * 18 | * Also add information on how to contact you by electronic and paper mail. 19 | * 20 | * If your software can interact with users remotely through a computer 21 | * network, you should also make sure that it provides a way for users to 22 | * get its source. For example, if your program is a web application, its 23 | * interface could display a "Source" link that leads users to an archive 24 | * of the code. There are many ways you could offer source, and different 25 | * solutions will be better for different programs; see section 13 for the 26 | * specific requirements. 27 | * 28 | * You should also get your employer (if you work as a programmer) or school, 29 | * if any, to sign a "copyright disclaimer" for the program, if necessary. 30 | * For more information on this, and how to apply and follow the GNU AGPL, see 31 | * . 32 | * 33 | */ 34 | 35 | package de.nycode.bankobot.commands.dev 36 | 37 | import de.nycode.bankobot.command.command 38 | import de.nycode.bankobot.command.permissions.PermissionLevel 39 | import de.nycode.bankobot.command.permissions.permission 40 | import de.nycode.bankobot.command.slashcommands.arguments.asSlashArgument 41 | import de.nycode.bankobot.commands.BotOwnerModule 42 | import de.nycode.bankobot.variables.VariableParser.replaceVariables 43 | import dev.kord.x.commands.annotation.AutoWired 44 | import dev.kord.x.commands.annotation.ModuleName 45 | import dev.kord.x.commands.argument.text.StringArgument 46 | import dev.kord.x.commands.model.command.invoke 47 | import dev.kord.x.commands.model.module.CommandSet 48 | 49 | @PublishedApi 50 | @ModuleName(BotOwnerModule) 51 | @AutoWired 52 | internal fun varCommand(): CommandSet = command("var") { 53 | permission(PermissionLevel.BOT_OWNER) 54 | invoke(StringArgument.asSlashArgument("Der Ausdruck")) { 55 | sendResponse(it.replaceVariables()) 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/main/kotlin/de/nycode/bankobot/command/slashcommands/InteractionEventSource.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the BankoBot Project. 3 | * Copyright (C) 2021 BankoBot Contributors 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero General Public License as published 7 | * by the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Affero General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Affero General Public License 16 | * along with this program. If not, see . 17 | * 18 | * Also add information on how to contact you by electronic and paper mail. 19 | * 20 | * If your software can interact with users remotely through a computer 21 | * network, you should also make sure that it provides a way for users to 22 | * get its source. For example, if your program is a web application, its 23 | * interface could display a "Source" link that leads users to an archive 24 | * of the code. There are many ways you could offer source, and different 25 | * solutions will be better for different programs; see section 13 for the 26 | * specific requirements. 27 | * 28 | * You should also get your employer (if you work as a programmer) or school, 29 | * if any, to sign a "copyright disclaimer" for the program, if necessary. 30 | * For more information on this, and how to apply and follow the GNU AGPL, see 31 | * . 32 | * 33 | */ 34 | 35 | package de.nycode.bankobot.command.slashcommands 36 | 37 | import dev.kord.common.annotation.KordPreview 38 | import dev.kord.core.Kord 39 | import dev.kord.core.event.interaction.InteractionCreateEvent 40 | import dev.kord.x.commands.model.processor.EventSource 41 | import dev.kord.x.commands.model.processor.ProcessorContext 42 | import kotlinx.coroutines.channels.Channel 43 | import kotlinx.coroutines.flow.Flow 44 | import kotlinx.coroutines.flow.buffer 45 | import kotlinx.coroutines.flow.filterIsInstance 46 | 47 | /** 48 | * Implementation of [EventSource] sourcing [InteractionCreateEvent] (slash commands). 49 | */ 50 | @OptIn(KordPreview::class) 51 | class InteractionEventSource(private val kord: Kord) : EventSource { 52 | override val context: ProcessorContext 53 | get() = InteractionContext 54 | override val events: Flow 55 | get() = kord.events.buffer(Channel.UNLIMITED).filterIsInstance() 56 | } 57 | -------------------------------------------------------------------------------- /src/main/kotlin/de/nycode/bankobot/listeners/LightshotListener.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the BankoBot Project. 3 | * Copyright (C) 2021 BankoBot Contributors 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero General Public License as published 7 | * by the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Affero General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Affero General Public License 16 | * along with this program. If not, see . 17 | * 18 | * Also add information on how to contact you by electronic and paper mail. 19 | * 20 | * If your software can interact with users remotely through a computer 21 | * network, you should also make sure that it provides a way for users to 22 | * get its source. For example, if your program is a web application, its 23 | * interface could display a "Source" link that leads users to an archive 24 | * of the code. There are many ways you could offer source, and different 25 | * solutions will be better for different programs; see section 13 for the 26 | * specific requirements. 27 | * 28 | * You should also get your employer (if you work as a programmer) or school, 29 | * if any, to sign a "copyright disclaimer" for the program, if necessary. 30 | * For more information on this, and how to apply and follow the GNU AGPL, see 31 | * . 32 | * 33 | */ 34 | 35 | package de.nycode.bankobot.listeners 36 | 37 | import de.nycode.bankobot.utils.Embeds 38 | import dev.kord.core.Kord 39 | import dev.kord.core.behavior.reply 40 | import dev.kord.core.event.message.MessageCreateEvent 41 | import dev.kord.core.on 42 | 43 | // https://regex101.com/r/BPg9DR/1 44 | private val lightshotRegex by lazy { "(?:http[s]?://)?(?:prnt\\.sc|prntscr\\.com)".toRegex() } 45 | 46 | internal fun Kord.lightshotListener() = on { 47 | if (message.content.contains(lightshotRegex)) { 48 | message.reply { 49 | embeds.add( 50 | Embeds.info( 51 | "Lightshot erkannt!", """Du scheinst Lightshot zu verwenden. 52 | |Aus vielen Gründen möchten wir dich bitten Lightshot nicht mehr zu verwenden. 53 | | 54 | |Eine deutlich bessere Alternative zu Lightshot ist [ShareX](https://getsharex.com) 55 | """.trimMargin() 56 | ) 57 | ) 58 | } 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/main/kotlin/de/nycode/bankobot/command/slashcommands/SlashArgument.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the BankoBot Project. 3 | * Copyright (C) 2021 BankoBot Contributors 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero General Public License as published 7 | * by the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Affero General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Affero General Public License 16 | * along with this program. If not, see . 17 | * 18 | * Also add information on how to contact you by electronic and paper mail. 19 | * 20 | * If your software can interact with users remotely through a computer 21 | * network, you should also make sure that it provides a way for users to 22 | * get its source. For example, if your program is a web application, its 23 | * interface could display a "Source" link that leads users to an archive 24 | * of the code. There are many ways you could offer source, and different 25 | * solutions will be better for different programs; see section 13 for the 26 | * specific requirements. 27 | * 28 | * You should also get your employer (if you work as a programmer) or school, 29 | * if any, to sign a "copyright disclaimer" for the program, if necessary. 30 | * For more information on this, and how to apply and follow the GNU AGPL, see 31 | * . 32 | * 33 | */ 34 | 35 | package de.nycode.bankobot.command.slashcommands 36 | 37 | import dev.kord.common.annotation.KordPreview 38 | import dev.kord.rest.builder.interaction.BaseApplicationBuilder 39 | import dev.kord.x.commands.argument.Argument 40 | import de.nycode.bankobot.command.slashcommands.arguments.AbstractSlashCommandArgument 41 | import java.util.* 42 | 43 | /** 44 | * [Argument] which is compatible with slash commands. 45 | * 46 | * @property description the description of the argument 47 | * @property required whether the property is required or not 48 | * 49 | * @see Argument 50 | * @see AbstractSlashCommandArgument 51 | */ 52 | @OptIn(KordPreview::class) 53 | interface SlashArgument : Argument { 54 | val description: String 55 | val required: Boolean 56 | override val name: String 57 | get() = name.lowercase(Locale.getDefault()) 58 | 59 | /** 60 | * Applies the argument configuration to the [BaseApplicationBuilder] 61 | */ 62 | fun BaseApplicationBuilder.applyArgument() 63 | } 64 | -------------------------------------------------------------------------------- /autohelp/src/main/kotlin/me/schlaubi/autohelp/source/ReceivedMessage.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2021 BankoBot Contributors 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | * 24 | */ 25 | 26 | package me.schlaubi.autohelp.source 27 | 28 | import dev.kord.x.emoji.DiscordEmoji 29 | import dev.schlaubi.forp.fetch.input.FileInput 30 | import io.ktor.utils.io.* 31 | 32 | /** 33 | * Representation of a received Discord message. 34 | */ 35 | public interface ReceivedMessage { 36 | 37 | /** 38 | * The id of the guild the message was received on. 39 | */ 40 | public val guildId: Long 41 | 42 | /** 43 | * The id of the channel the message was received in. 44 | */ 45 | public val channelId: Long 46 | 47 | /** 48 | * The id of the user authoring the message. 49 | */ 50 | public val authorId: Long? 51 | 52 | /** 53 | * The content of the message. 54 | */ 55 | public val content: String? 56 | 57 | /** 58 | * A list of files attached to the message. 59 | */ 60 | public val files: List 61 | 62 | /** 63 | * Adds [emoji] to the message. 64 | * 65 | * @see DiscordEmoji.unicode for non kord users 66 | */ 67 | public suspend fun react(emoji: DiscordEmoji) 68 | 69 | /** 70 | * Representation of a file attachment. 71 | */ 72 | public interface ReceivedFile { 73 | /** 74 | * The type of the file. 75 | * 76 | * @see FileInput.FileType 77 | */ 78 | public val type: FileInput.FileType 79 | 80 | /** 81 | * Downloads the contents of the file and buffers it in a [ByteReadChannel]. 82 | */ 83 | public suspend fun download(): ByteReadChannel 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /src/main/kotlin/de/nycode/bankobot/commands/tag/TagChange.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the BankoBot Project. 3 | * Copyright (C) 2021 BankoBot Contributors 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero General Public License as published 7 | * by the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Affero General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Affero General Public License 16 | * along with this program. If not, see . 17 | * 18 | * Also add information on how to contact you by electronic and paper mail. 19 | * 20 | * If your software can interact with users remotely through a computer 21 | * network, you should also make sure that it provides a way for users to 22 | * get its source. For example, if your program is a web application, its 23 | * interface could display a "Source" link that leads users to an archive 24 | * of the code. There are many ways you could offer source, and different 25 | * solutions will be better for different programs; see section 13 for the 26 | * specific requirements. 27 | * 28 | * You should also get your employer (if you work as a programmer) or school, 29 | * if any, to sign a "copyright disclaimer" for the program, if necessary. 30 | * For more information on this, and how to apply and follow the GNU AGPL, see 31 | * . 32 | * 33 | */ 34 | 35 | package de.nycode.bankobot.commands.tag 36 | 37 | import dev.kord.common.entity.Snowflake 38 | import kotlinx.serialization.Contextual 39 | import kotlinx.serialization.Serializable 40 | 41 | @Serializable 42 | sealed class TagChange { 43 | abstract val field: String 44 | } 45 | 46 | @Serializable 47 | data class AuthorChange( 48 | @Contextual 49 | val oldAuthor: Snowflake, 50 | @Contextual 51 | val newAuthor: Snowflake 52 | ) : TagChange() { 53 | override val field = "author" 54 | } 55 | 56 | @Serializable 57 | data class NameChange( 58 | val oldName: String, 59 | val newName: String 60 | ) : TagChange() { 61 | override val field = "name" 62 | } 63 | 64 | @Serializable 65 | data class TextChange( 66 | val oldText: String, 67 | val newText: String 68 | ) : TagChange() { 69 | override val field = "text" 70 | } 71 | 72 | @Serializable 73 | data class AliasesChange( 74 | val oldAliases: List, 75 | val newAliases: List 76 | ) : TagChange() { 77 | override val field = "aliases" 78 | } 79 | -------------------------------------------------------------------------------- /src/main/kotlin/de/nycode/bankobot/command/MathExpressionArgument.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the BankoBot Project. 3 | * Copyright (C) 2021 BankoBot Contributors 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero General Public License as published 7 | * by the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Affero General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Affero General Public License 16 | * along with this program. If not, see . 17 | * 18 | * Also add information on how to contact you by electronic and paper mail. 19 | * 20 | * If your software can interact with users remotely through a computer 21 | * network, you should also make sure that it provides a way for users to 22 | * get its source. For example, if your program is a web application, its 23 | * interface could display a "Source" link that leads users to an archive 24 | * of the code. There are many ways you could offer source, and different 25 | * solutions will be better for different programs; see section 13 for the 26 | * specific requirements. 27 | * 28 | * You should also get your employer (if you work as a programmer) or school, 29 | * if any, to sign a "copyright disclaimer" for the program, if necessary. 30 | * For more information on this, and how to apply and follow the GNU AGPL, see 31 | * . 32 | * 33 | */ 34 | 35 | package de.nycode.bankobot.command 36 | 37 | import de.nycode.bankobot.variables.parsers.calc.CalcExpression 38 | import dev.kord.core.event.message.MessageCreateEvent 39 | import dev.kord.x.commands.argument.Argument 40 | import dev.kord.x.commands.argument.result.ArgumentResult 41 | 42 | val MathExpressionArgument: Argument = 43 | InternalMathExpressionArgument() 44 | 45 | internal class InternalMathExpressionArgument(override val name: String = "expression") : 46 | Argument { 47 | override suspend fun parse( 48 | text: String, 49 | fromIndex: Int, 50 | context: MessageCreateEvent 51 | ): ArgumentResult { 52 | val expression = CalcExpression(text.substring(fromIndex)) 53 | val (result, isError) = expression.getResult() 54 | 55 | return if (isError) { 56 | ArgumentResult.Failure(result, text.length - fromIndex) 57 | } else { 58 | ArgumentResult.Success(expression, text.length - fromIndex) 59 | } 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/main/kotlin/de/nycode/bankobot/utils/GoogleUtils.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the BankoBot Project. 3 | * Copyright (C) 2021 BankoBot Contributors 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero General Public License as published 7 | * by the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Affero General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Affero General Public License 16 | * along with this program. If not, see . 17 | * 18 | * Also add information on how to contact you by electronic and paper mail. 19 | * 20 | * If your software can interact with users remotely through a computer 21 | * network, you should also make sure that it provides a way for users to 22 | * get its source. For example, if your program is a web application, its 23 | * interface could display a "Source" link that leads users to an archive 24 | * of the code. There are many ways you could offer source, and different 25 | * solutions will be better for different programs; see section 13 for the 26 | * specific requirements. 27 | * 28 | * You should also get your employer (if you work as a programmer) or school, 29 | * if any, to sign a "copyright disclaimer" for the program, if necessary. 30 | * For more information on this, and how to apply and follow the GNU AGPL, see 31 | * . 32 | * 33 | */ 34 | 35 | package de.nycode.bankobot.utils 36 | 37 | import de.nycode.bankobot.BankoBot 38 | import de.nycode.bankobot.config.Config 39 | import io.ktor.client.features.* 40 | import io.ktor.client.request.* 41 | import io.ktor.client.statement.* 42 | import kotlinx.serialization.Serializable 43 | 44 | object GoogleUtil { 45 | 46 | suspend fun getResults(search: String): Array? { 47 | val response: GoogleResponse = 48 | BankoBot.httpClient.get("https://www.googleapis.com/customsearch/v1") { 49 | parameter("q", search) 50 | parameter("key", Config.GOOGLE_API_KEY) 51 | parameter("cx", Config.GOOGLE_CX_CODE) 52 | } 53 | 54 | val items = response.items 55 | return if (response.kind == "customsearch#search") items 56 | else null 57 | } 58 | } 59 | 60 | @Serializable 61 | class GoogleResponse( 62 | val kind: String, 63 | val items: Array 64 | ) 65 | 66 | @Serializable 67 | class GoogleResult( 68 | val kind: String, 69 | val title: String, 70 | val link: String, 71 | val snippet: String 72 | ) 73 | -------------------------------------------------------------------------------- /src/main/kotlin/de/nycode/bankobot/commands/tag/commands/TagRawCommand.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the BankoBot Project. 3 | * Copyright (C) 2021 BankoBot Contributors 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero General Public License as published 7 | * by the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Affero General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Affero General Public License 16 | * along with this program. If not, see . 17 | * 18 | * Also add information on how to contact you by electronic and paper mail. 19 | * 20 | * If your software can interact with users remotely through a computer 21 | * network, you should also make sure that it provides a way for users to 22 | * get its source. For example, if your program is a web application, its 23 | * interface could display a "Source" link that leads users to an archive 24 | * of the code. There are many ways you could offer source, and different 25 | * solutions will be better for different programs; see section 13 for the 26 | * specific requirements. 27 | * 28 | * You should also get your employer (if you work as a programmer) or school, 29 | * if any, to sign a "copyright disclaimer" for the program, if necessary. 30 | * For more information on this, and how to apply and follow the GNU AGPL, see 31 | * . 32 | * 33 | */ 34 | 35 | package de.nycode.bankobot.commands.tag.commands 36 | 37 | import de.nycode.bankobot.command.command 38 | import de.nycode.bankobot.commands.TagModule 39 | import de.nycode.bankobot.commands.tag.TagArgument 40 | import de.nycode.bankobot.commands.tag.TagEntry 41 | import de.nycode.bankobot.commands.tag.checkEmpty 42 | import de.nycode.bankobot.utils.Embeds 43 | import de.nycode.bankobot.utils.HastebinUtil 44 | import dev.kord.x.commands.annotation.AutoWired 45 | import dev.kord.x.commands.annotation.ModuleName 46 | import dev.kord.x.commands.model.command.invoke 47 | import dev.kord.x.commands.model.module.CommandSet 48 | 49 | @PublishedApi 50 | @AutoWired 51 | @ModuleName(TagModule) 52 | internal fun tagRawCommand(): CommandSet = command("tag-raw") { 53 | alias("raw") 54 | 55 | invoke(TagArgument) { tag -> 56 | 57 | if (checkEmpty(tag)) { 58 | return@invoke 59 | } 60 | 61 | tag as TagEntry 62 | 63 | val url = HastebinUtil.postToHastebin(tag.text) 64 | sendResponse(Embeds.info("Raw-Inhalt", "Den Raw-Inhalt vom Tag \"${tag.name}\" findest du [hier]($url)")) 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /src/main/kotlin/de/nycode/bankobot/command/Extensions.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the BankoBot Project. 3 | * Copyright (C) 2021 BankoBot Contributors 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero General Public License as published 7 | * by the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Affero General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Affero General Public License 16 | * along with this program. If not, see . 17 | * 18 | * Also add information on how to contact you by electronic and paper mail. 19 | * 20 | * If your software can interact with users remotely through a computer 21 | * network, you should also make sure that it provides a way for users to 22 | * get its source. For example, if your program is a web application, its 23 | * interface could display a "Source" link that leads users to an archive 24 | * of the code. There are many ways you could offer source, and different 25 | * solutions will be better for different programs; see section 13 for the 26 | * specific requirements. 27 | * 28 | * You should also get your employer (if you work as a programmer) or school, 29 | * if any, to sign a "copyright disclaimer" for the program, if necessary. 30 | * For more information on this, and how to apply and follow the GNU AGPL, see 31 | * . 32 | * 33 | */ 34 | 35 | package de.nycode.bankobot.command 36 | 37 | import de.nycode.bankobot.commands.general.sourceCommand 38 | import dev.kord.x.commands.model.command.Command 39 | import dev.kord.x.commands.model.context.CommonContext 40 | import dev.kord.x.commands.model.metadata.Metadata 41 | import dev.kord.x.commands.model.module.CommandSet 42 | 43 | @PublishedApi 44 | internal object CallbackData : Metadata.Key 45 | 46 | data class CommandExecutionCallback(val stack: StackTraceElement) 47 | 48 | @Suppress("UnsafeCallOnNullableType") // we know it's not null 49 | val Command<*>.callback: CommandExecutionCallback 50 | get() = data.metadata[CallbackData]!! 51 | 52 | /** 53 | * Replacement of [dev.kord.x.commands.model.module.command] which stores some data required for [sourceCommand] 54 | */ 55 | fun command( 56 | name: String, 57 | builder: CommandBuilder.() -> Unit, 58 | ): CommandSet { 59 | val stack = Exception().stackTrace[1] 60 | val configure: CommandBuilder.() -> Unit = { 61 | metaData[CallbackData] = CommandExecutionCallback(stack) 62 | builder(this) 63 | } 64 | return dev.kord.x.commands.model.module.command(CommonContext, name, configure) 65 | } 66 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | 17 | @if "%DEBUG%" == "" @echo off 18 | @rem ########################################################################## 19 | @rem 20 | @rem Gradle startup script for Windows 21 | @rem 22 | @rem ########################################################################## 23 | 24 | @rem Set local scope for the variables with windows NT shell 25 | if "%OS%"=="Windows_NT" setlocal 26 | 27 | set DIRNAME=%~dp0 28 | if "%DIRNAME%" == "" set DIRNAME=. 29 | set APP_BASE_NAME=%~n0 30 | set APP_HOME=%DIRNAME% 31 | 32 | @rem Resolve any "." and ".." in APP_HOME to make it shorter. 33 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi 34 | 35 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 36 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 37 | 38 | @rem Find java.exe 39 | if defined JAVA_HOME goto findJavaFromJavaHome 40 | 41 | set JAVA_EXE=java.exe 42 | %JAVA_EXE% -version >NUL 2>&1 43 | if "%ERRORLEVEL%" == "0" goto execute 44 | 45 | echo. 46 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 47 | echo. 48 | echo Please set the JAVA_HOME variable in your environment to match the 49 | echo location of your Java installation. 50 | 51 | goto fail 52 | 53 | :findJavaFromJavaHome 54 | set JAVA_HOME=%JAVA_HOME:"=% 55 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 56 | 57 | if exist "%JAVA_EXE%" goto execute 58 | 59 | echo. 60 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 61 | echo. 62 | echo Please set the JAVA_HOME variable in your environment to match the 63 | echo location of your Java installation. 64 | 65 | goto fail 66 | 67 | :execute 68 | @rem Setup the command line 69 | 70 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 71 | 72 | 73 | @rem Execute Gradle 74 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* 75 | 76 | :end 77 | @rem End local scope for the variables with windows NT shell 78 | if "%ERRORLEVEL%"=="0" goto mainEnd 79 | 80 | :fail 81 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 82 | rem the _cmd.exe /c_ return code! 83 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 84 | exit /b 1 85 | 86 | :mainEnd 87 | if "%OS%"=="Windows_NT" endlocal 88 | 89 | :omega 90 | -------------------------------------------------------------------------------- /autohelp/kord/src/main/kotlin/me/schlaubi/autohelp/kord/Builder.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2021 BankoBot Contributors 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | * 24 | */ 25 | 26 | package me.schlaubi.autohelp.kord 27 | 28 | import dev.kord.core.Kord 29 | import dev.kord.core.event.message.MessageCreateEvent 30 | import dev.kord.core.event.message.MessageUpdateEvent 31 | import me.schlaubi.autohelp.AutoHelp 32 | import me.schlaubi.autohelp.help.MessageRenderer 33 | import me.schlaubi.autohelp.source.EventSource 34 | import me.schlaubi.autohelp.AutoHelpBuilder 35 | import me.schlaubi.autohelp.ContextBuilder 36 | 37 | /** 38 | * Creates the default Kord autohelp and applies [block] to it. 39 | */ 40 | public fun Kord.autoHelp(block: AutoHelpBuilder.() -> Unit = {}): AutoHelp = me.schlaubi.autohelp.autoHelp { 41 | useKordMessageRenderer(this@autoHelp) 42 | kordContext { 43 | kordEventSource(this@autoHelp) 44 | } 45 | 46 | block() 47 | } 48 | 49 | /** 50 | * Adds a [MessageRenderer] which uses [kord] to send messages. 51 | */ 52 | public fun AutoHelpBuilder.useKordMessageRenderer(kord: Kord) { 53 | messageRenderer = KordMessageRenderer(kord) 54 | } 55 | 56 | /** 57 | * Adds an [EventSource] which listens for [MessageCreateEvents][MessageCreateEvent]. 58 | * 59 | * @param kord the [Kord] instance providing the event. 60 | */ 61 | public fun ContextBuilder.kordEventSource(kord: Kord): Unit = +KordEventSource(kord) 62 | 63 | /** 64 | * Adds an [EventSource] which listens for [MessageUpdateEvents][MessageUpdateEvent]. 65 | * 66 | * @param kord the [Kord] instance providing the event. 67 | */ 68 | public fun ContextBuilder.kordEditEventSource(kord: Kord): Unit = +KordUpdateEventSource(kord) 69 | 70 | /** 71 | * Builds a new Kord based context. 72 | */ 73 | public fun AutoHelpBuilder.kordContext(builder: ContextBuilder.() -> Unit): Unit = context(builder) 74 | -------------------------------------------------------------------------------- /autohelp/kord/src/main/kotlin/me/schlaubi/autohelp/kord/KordUpdateEventSource.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2021 BankoBot Contributors 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | * 24 | */ 25 | 26 | package me.schlaubi.autohelp.kord 27 | 28 | import dev.kord.core.Kord 29 | import dev.kord.core.entity.Message 30 | import dev.kord.core.event.message.MessageUpdateEvent 31 | import dev.kord.x.emoji.DiscordEmoji 32 | import dev.kord.x.emoji.addReaction 33 | import dev.schlaubi.forp.fetch.input.FileInput 34 | import kotlinx.coroutines.flow.Flow 35 | import kotlinx.coroutines.flow.filter 36 | import kotlinx.coroutines.flow.filterIsInstance 37 | import kotlinx.coroutines.flow.map 38 | import me.schlaubi.autohelp.source.EventSource 39 | import me.schlaubi.autohelp.source.ReceivedMessage 40 | 41 | public class KordUpdateEventSource(kord: Kord) : EventSource { 42 | override val events: Flow = kord.events 43 | .filterIsInstance() 44 | .map { KordUpdateMessage(it.message.asMessage()) } 45 | } 46 | 47 | public class KordUpdateMessage(public val kordMessage: Message) : ReceivedMessage { 48 | override val guildId: Long 49 | get() = kordMessage.data.guildId.value!!.value.toLong() 50 | override val channelId: Long 51 | get() = kordMessage.data.channelId.value.toLong() 52 | override val authorId: Long? 53 | get() = kordMessage.author?.id?.value?.toLong() 54 | override val content: String? = null 55 | override val files: List 56 | get() = kordMessage.embeds.mapNotNull { 57 | it.url?.let { url -> 58 | KordReceivedMessage.KordReceivedFile(FileInput.FileType.IMAGE, 59 | url, 60 | kordMessage.kord.resources.httpClient) 61 | } 62 | } 63 | 64 | override suspend fun react(emoji: DiscordEmoji): Unit = kordMessage.addReaction(emoji) 65 | } 66 | -------------------------------------------------------------------------------- /src/main/kotlin/de/nycode/bankobot/command/Prefix.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the BankoBot Project. 3 | * Copyright (C) 2021 BankoBot Contributors 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero General Public License as published 7 | * by the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Affero General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Affero General Public License 16 | * along with this program. If not, see . 17 | * 18 | * Also add information on how to contact you by electronic and paper mail. 19 | * 20 | * If your software can interact with users remotely through a computer 21 | * network, you should also make sure that it provides a way for users to 22 | * get its source. For example, if your program is a web application, its 23 | * interface could display a "Source" link that leads users to an archive 24 | * of the code. There are many ways you could offer source, and different 25 | * solutions will be better for different programs; see section 13 for the 26 | * specific requirements. 27 | * 28 | * You should also get your employer (if you work as a programmer) or school, 29 | * if any, to sign a "copyright disclaimer" for the program, if necessary. 30 | * For more information on this, and how to apply and follow the GNU AGPL, see 31 | * . 32 | * 33 | */ 34 | 35 | package de.nycode.bankobot.command 36 | 37 | import dev.kord.core.event.message.MessageCreateEvent 38 | import dev.kord.x.commands.model.prefix.PrefixBuilder 39 | import dev.kord.x.commands.model.prefix.PrefixRule 40 | 41 | /** 42 | * [PrefixRule] which requires the literal string [prefix] to be present in front of the command. 43 | * This matches against the prefix being at the beginning of the line and ignores an unlimited amount 44 | * of spaces between the prefix and the command. (Regex "^$prefix\s*") 45 | */ 46 | @Suppress("unused") // it is supposed to be only invoked on PrefixBuilder even if PrefixBuilder is unused 47 | fun PrefixBuilder.literal(prefix: String): PrefixRule = 48 | LiteralPrefixRule(prefix) 49 | 50 | private class LiteralPrefixRule(prefix: String) : PrefixRule { 51 | private val regex = "^$prefix\\s*".toRegex(RegexOption.IGNORE_CASE) 52 | 53 | override suspend fun consume(message: String, context: Any?): PrefixRule.Result { 54 | val match = regex.find(message) ?: return PrefixRule.Result.Denied 55 | return PrefixRule.Result.Accepted(match.value) 56 | } 57 | } 58 | 59 | inline fun PrefixBuilder.bankoBot(supplier: () -> PrefixRule) = 60 | add(BankoBotContext, supplier()) 61 | -------------------------------------------------------------------------------- /src/main/kotlin/de/nycode/bankobot/docdex/DocDex.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the BankoBot Project. 3 | * Copyright (C) 2021 BankoBot Contributors 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero General Public License as published 7 | * by the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Affero General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Affero General Public License 16 | * along with this program. If not, see . 17 | * 18 | * Also add information on how to contact you by electronic and paper mail. 19 | * 20 | * If your software can interact with users remotely through a computer 21 | * network, you should also make sure that it provides a way for users to 22 | * get its source. For example, if your program is a web application, its 23 | * interface could display a "Source" link that leads users to an archive 24 | * of the code. There are many ways you could offer source, and different 25 | * solutions will be better for different programs; see section 13 for the 26 | * specific requirements. 27 | * 28 | * You should also get your employer (if you work as a programmer) or school, 29 | * if any, to sign a "copyright disclaimer" for the program, if necessary. 30 | * For more information on this, and how to apply and follow the GNU AGPL, see 31 | * . 32 | * 33 | */ 34 | 35 | package de.nycode.bankobot.docdex 36 | 37 | import de.nycode.bankobot.BankoBot 38 | import de.nycode.bankobot.config.Config 39 | import io.ktor.client.request.* 40 | import kotlinx.serialization.SerialName 41 | import kotlinx.serialization.Serializable 42 | import kotlin.time.ExperimentalTime 43 | 44 | object DocDex { 45 | 46 | /** 47 | * Retrieves a list of all available javadocs. 48 | */ 49 | @OptIn(ExperimentalTime::class) 50 | @Suppress("MagicNumber") 51 | suspend fun allJavadocs(): List = BankoBot.httpClient.get(Config.DOCDEX_URL) { 52 | url { 53 | path("javadocs") 54 | } 55 | } 56 | 57 | /** 58 | * Retrieves a list of [DocumentedElements][DocumentedElement] from the [javadoc]. 59 | */ 60 | suspend fun search(javadoc: String, query: String): List = 61 | BankoBot.httpClient.get(Config.DOCDEX_URL) { 62 | url { 63 | path("index") 64 | parameter("javadoc", javadoc) 65 | parameter("query", query) 66 | } 67 | } 68 | } 69 | 70 | @Serializable 71 | class JavaDoc( 72 | val names: List, 73 | val link: String, 74 | @SerialName("actual_link") 75 | val actualLink: String 76 | ) 77 | -------------------------------------------------------------------------------- /src/main/kotlin/de/nycode/bankobot/command/slashcommands/arguments/RoleArgument.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the BankoBot Project. 3 | * Copyright (C) 2021 BankoBot Contributors 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero General Public License as published 7 | * by the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Affero General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Affero General Public License 16 | * along with this program. If not, see . 17 | * 18 | * Also add information on how to contact you by electronic and paper mail. 19 | * 20 | * If your software can interact with users remotely through a computer 21 | * network, you should also make sure that it provides a way for users to 22 | * get its source. For example, if your program is a web application, its 23 | * interface could display a "Source" link that leads users to an archive 24 | * of the code. There are many ways you could offer source, and different 25 | * solutions will be better for different programs; see section 13 for the 26 | * specific requirements. 27 | * 28 | * You should also get your employer (if you work as a programmer) or school, 29 | * if any, to sign a "copyright disclaimer" for the program, if necessary. 30 | * For more information on this, and how to apply and follow the GNU AGPL, see 31 | * . 32 | * 33 | */ 34 | 35 | package de.nycode.bankobot.command.slashcommands.arguments 36 | 37 | import de.nycode.bankobot.command.slashcommands.SlashArgument 38 | import dev.kord.common.annotation.KordPreview 39 | import dev.kord.core.entity.Role 40 | import dev.kord.rest.builder.interaction.BaseApplicationBuilder 41 | import dev.kord.rest.builder.interaction.RoleBuilder 42 | import dev.kord.x.commands.argument.Argument 43 | import dev.kord.x.commands.kord.argument.RoleArgument 44 | 45 | /** 46 | * Turns this [Argument] into a [SlashArgument] with [description] 47 | * 48 | * @see RoleBuilder 49 | * @see RoleArgument 50 | */ 51 | @OptIn(KordPreview::class) 52 | fun Argument.asSlashArgument( 53 | description: String, 54 | builder: RoleBuilder.() -> Unit = {}, 55 | ): SlashArgument = RoleSlashArgument(description, this, builder) 56 | 57 | @OptIn(KordPreview::class) 58 | private class RoleSlashArgument( 59 | description: String, 60 | delegate: Argument, 61 | private val builder: RoleBuilder.() -> Unit, 62 | ) : AbstractSlashCommandArgument(description, delegate) { 63 | override fun BaseApplicationBuilder.applyArgument() { 64 | role(name, description, builder.applyRequired()) 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /src/main/kotlin/de/nycode/bankobot/command/slashcommands/arguments/BooleanArgument.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the BankoBot Project. 3 | * Copyright (C) 2021 BankoBot Contributors 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero General Public License as published 7 | * by the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Affero General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Affero General Public License 16 | * along with this program. If not, see . 17 | * 18 | * Also add information on how to contact you by electronic and paper mail. 19 | * 20 | * If your software can interact with users remotely through a computer 21 | * network, you should also make sure that it provides a way for users to 22 | * get its source. For example, if your program is a web application, its 23 | * interface could display a "Source" link that leads users to an archive 24 | * of the code. There are many ways you could offer source, and different 25 | * solutions will be better for different programs; see section 13 for the 26 | * specific requirements. 27 | * 28 | * You should also get your employer (if you work as a programmer) or school, 29 | * if any, to sign a "copyright disclaimer" for the program, if necessary. 30 | * For more information on this, and how to apply and follow the GNU AGPL, see 31 | * . 32 | * 33 | */ 34 | 35 | package de.nycode.bankobot.command.slashcommands.arguments 36 | 37 | import de.nycode.bankobot.command.slashcommands.SlashArgument 38 | import dev.kord.x.commands.argument.primitive.BooleanArgument 39 | import dev.kord.common.annotation.KordPreview 40 | import dev.kord.rest.builder.interaction.BaseApplicationBuilder 41 | import dev.kord.rest.builder.interaction.BooleanBuilder 42 | import dev.kord.x.commands.argument.Argument 43 | 44 | /** 45 | * Turns this [Argument] into a [SlashArgument] with [description] 46 | * 47 | * @see BooleanBuilder 48 | * @see BooleanArgument 49 | */ 50 | @OptIn(KordPreview::class) 51 | fun Argument.asSlashArgument( 52 | description: String, 53 | builder: BooleanBuilder.() -> Unit = {}, 54 | ): SlashArgument = BooleanSlashArgument(description, this, builder) 55 | 56 | @OptIn(KordPreview::class) 57 | private class BooleanSlashArgument( 58 | description: String, 59 | delegate: Argument, 60 | private val builder: BooleanBuilder.() -> Unit, 61 | ) : AbstractSlashCommandArgument(description, delegate) { 62 | override fun BaseApplicationBuilder.applyArgument() { 63 | boolean(name, description, builder.applyRequired()) 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /.idea/libraries-with-intellij-classes.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 64 | 65 | -------------------------------------------------------------------------------- /autohelp/publishing.gradle.kts: -------------------------------------------------------------------------------- 1 | import java.util.* 2 | 3 | apply(plugin = "org.gradle.maven-publish") 4 | apply(plugin = "org.gradle.signing") 5 | 6 | val cmp = components 7 | 8 | val configurePublishing: PublishingExtension.() -> Unit = { 9 | repositories { 10 | maven { 11 | setUrl("https://schlaubi.jfrog.io/artifactory/forp-artifacts") 12 | 13 | credentials { 14 | username = System.getenv("BINTRAY_USER") 15 | password = System.getenv("BINTRAY_KEY") 16 | } 17 | } 18 | } 19 | 20 | publications { 21 | create("maven") { 22 | from(cmp["java"]) 23 | 24 | groupId = group.toString() 25 | artifactId = project.name 26 | version = project.version.toString() 27 | 28 | pom { 29 | name.set(project.name) 30 | description.set( 31 | """ 32 | Autohelp is a Kotlin Library for Discord bots which want to automatically send dynamic help messages whenever someone 33 | sends something providing a JVM Stacktrace. 34 | """.trimIndent() 35 | ) 36 | url.set("https://github.com/DRSchlaubi/furry-okto-rotary-phone") 37 | 38 | licenses { 39 | license { 40 | name.set("Apache-2.0 License") 41 | url.set("https://github.com/DRSchlaubi/furry-okto-rotary-phone/blob/main/LICENSE") 42 | } 43 | } 44 | 45 | developers { 46 | developer { 47 | name.set("Michael Rittmeister") 48 | email.set("mail@schlaubi.me") 49 | organizationUrl.set("https://michael.rittmeister.in") 50 | } 51 | } 52 | 53 | scm { 54 | connection.set("scm:git:https://github.com/bankobotv14/bankbot.git") 55 | developerConnection.set("scm:git:https://github.com/bankobotv14/bankbot.git") 56 | url.set("https://github.com/bankobotv14/bankbot") 57 | } 58 | } 59 | 60 | artifact(tasks["kotlinSourcesJar"]) 61 | } 62 | } 63 | } 64 | 65 | val configureSigning: SigningExtension.() -> Unit = { 66 | val signingKey = findProperty("signingKey")?.toString() 67 | val signingPassword = findProperty("signingPassword")?.toString() 68 | if (signingKey != null && signingPassword != null) { 69 | useInMemoryPgpKeys( 70 | String(Base64.getDecoder().decode(signingKey.toByteArray())), 71 | signingPassword 72 | ) 73 | } 74 | 75 | publishing.publications.withType { 76 | sign(this) 77 | } 78 | } 79 | 80 | extensions.configure("signing", configureSigning) 81 | extensions.configure("publishing", configurePublishing) 82 | 83 | val Project.publishing: PublishingExtension 84 | get() = 85 | (this as ExtensionAware).extensions.getByName("publishing") as PublishingExtension 86 | -------------------------------------------------------------------------------- /src/main/kotlin/de/nycode/bankobot/command/slashcommands/arguments/IntArgument.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the BankoBot Project. 3 | * Copyright (C) 2021 BankoBot Contributors 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero General Public License as published 7 | * by the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Affero General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Affero General Public License 16 | * along with this program. If not, see . 17 | * 18 | * Also add information on how to contact you by electronic and paper mail. 19 | * 20 | * If your software can interact with users remotely through a computer 21 | * network, you should also make sure that it provides a way for users to 22 | * get its source. For example, if your program is a web application, its 23 | * interface could display a "Source" link that leads users to an archive 24 | * of the code. There are many ways you could offer source, and different 25 | * solutions will be better for different programs; see section 13 for the 26 | * specific requirements. 27 | * 28 | * You should also get your employer (if you work as a programmer) or school, 29 | * if any, to sign a "copyright disclaimer" for the program, if necessary. 30 | * For more information on this, and how to apply and follow the GNU AGPL, see 31 | * . 32 | * 33 | */ 34 | 35 | package de.nycode.bankobot.command.slashcommands.arguments 36 | 37 | import de.nycode.bankobot.command.slashcommands.SlashArgument 38 | import dev.kord.common.annotation.KordPreview 39 | import dev.kord.rest.builder.interaction.BaseApplicationBuilder 40 | import dev.kord.rest.builder.interaction.IntChoiceBuilder 41 | import dev.kord.x.commands.argument.Argument 42 | import dev.kord.x.commands.argument.primitive.IntArgument 43 | 44 | /** 45 | * Turns this [Argument] into a [SlashArgument] with [description] 46 | * 47 | * @see IntChoiceBuilder 48 | * @see IntArgument 49 | */ 50 | @OptIn(KordPreview::class) 51 | fun Argument.asSlashArgument( 52 | description: String, 53 | choiceBuilder: IntChoiceBuilder.() -> Unit = {}, 54 | ): SlashArgument { 55 | return IntSlashArgument(description, this, choiceBuilder) 56 | } 57 | 58 | @OptIn(KordPreview::class) 59 | private class IntSlashArgument( 60 | description: String, 61 | delegate: Argument, 62 | private val choiceBuilder: IntChoiceBuilder.() -> Unit, 63 | ) : AbstractSlashCommandArgument(description, delegate) { 64 | override fun BaseApplicationBuilder.applyArgument() { 65 | int(name, description, choiceBuilder.applyRequired()) 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /src/main/kotlin/de/nycode/bankobot/commands/tag/TagArgument.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the BankoBot Project. 3 | * Copyright (C) 2021 BankoBot Contributors 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero General Public License as published 7 | * by the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Affero General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Affero General Public License 16 | * along with this program. If not, see . 17 | * 18 | * Also add information on how to contact you by electronic and paper mail. 19 | * 20 | * If your software can interact with users remotely through a computer 21 | * network, you should also make sure that it provides a way for users to 22 | * get its source. For example, if your program is a web application, its 23 | * interface could display a "Source" link that leads users to an archive 24 | * of the code. There are many ways you could offer source, and different 25 | * solutions will be better for different programs; see section 13 for the 26 | * specific requirements. 27 | * 28 | * You should also get your employer (if you work as a programmer) or school, 29 | * if any, to sign a "copyright disclaimer" for the program, if necessary. 30 | * For more information on this, and how to apply and follow the GNU AGPL, see 31 | * . 32 | * 33 | */ 34 | 35 | package de.nycode.bankobot.commands.tag 36 | 37 | import de.nycode.bankobot.BankoBot 38 | import de.nycode.bankobot.command.slashcommands.arguments.AbstractSlashCommandArgument 39 | import dev.kord.common.annotation.KordPreview 40 | import dev.kord.rest.builder.interaction.BaseApplicationBuilder 41 | import dev.kord.x.commands.argument.Argument 42 | import dev.kord.x.commands.argument.extension.named 43 | import dev.kord.x.commands.argument.extension.tryMap 44 | import dev.kord.x.commands.argument.result.extension.MapResult 45 | import dev.kord.x.commands.argument.text.WordArgument 46 | import org.litote.kmongo.contains 47 | import org.litote.kmongo.eq 48 | import org.litote.kmongo.or 49 | 50 | val TagArgument: Argument = InternalTagArgument() 51 | 52 | @OptIn(KordPreview::class) 53 | internal class InternalTagArgument( 54 | description: String = "Der Tag" 55 | ) : AbstractSlashCommandArgument(description, WordArgument.named("tag").tagMap()) { 56 | override fun BaseApplicationBuilder.applyArgument() { 57 | string(name, description, required()) 58 | } 59 | } 60 | 61 | private fun Argument.tagMap() = tryMap { tagName -> 62 | val tag = BankoBot.repositories.tag.findOne(or(TagEntry::name eq tagName, TagEntry::aliases contains tagName)) 63 | MapResult.Pass(tag ?: EmptyTag) 64 | } 65 | -------------------------------------------------------------------------------- /src/main/kotlin/de/nycode/bankobot/command/slashcommands/arguments/ChannelArgument.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the BankoBot Project. 3 | * Copyright (C) 2021 BankoBot Contributors 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero General Public License as published 7 | * by the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Affero General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Affero General Public License 16 | * along with this program. If not, see . 17 | * 18 | * Also add information on how to contact you by electronic and paper mail. 19 | * 20 | * If your software can interact with users remotely through a computer 21 | * network, you should also make sure that it provides a way for users to 22 | * get its source. For example, if your program is a web application, its 23 | * interface could display a "Source" link that leads users to an archive 24 | * of the code. There are many ways you could offer source, and different 25 | * solutions will be better for different programs; see section 13 for the 26 | * specific requirements. 27 | * 28 | * You should also get your employer (if you work as a programmer) or school, 29 | * if any, to sign a "copyright disclaimer" for the program, if necessary. 30 | * For more information on this, and how to apply and follow the GNU AGPL, see 31 | * . 32 | * 33 | */ 34 | 35 | package de.nycode.bankobot.command.slashcommands.arguments 36 | 37 | import de.nycode.bankobot.command.slashcommands.SlashArgument 38 | import dev.kord.common.annotation.KordPreview 39 | import dev.kord.core.entity.channel.TextChannel 40 | import dev.kord.rest.builder.interaction.BaseApplicationBuilder 41 | import dev.kord.rest.builder.interaction.ChannelBuilder 42 | import dev.kord.x.commands.argument.Argument 43 | import dev.kord.x.commands.kord.argument.ChannelArgument 44 | 45 | /** 46 | * Turns this [Argument] into a [SlashArgument] with [description] 47 | * 48 | * @see ChannelBuilder 49 | * @see ChannelArgument 50 | */ 51 | @OptIn(KordPreview::class) 52 | fun Argument.asSlashArgument( 53 | description: String, 54 | builder: ChannelBuilder.() -> Unit = {}, 55 | ): SlashArgument = ChannelSlashArgument(description, this, builder) 56 | 57 | @OptIn(KordPreview::class) 58 | private class ChannelSlashArgument( 59 | description: String, 60 | delegate: Argument, 61 | private val builder: ChannelBuilder.() -> Unit, 62 | ) : AbstractSlashCommandArgument(description, delegate) { 63 | override fun BaseApplicationBuilder.applyArgument() { 64 | channel(name, description, builder.applyRequired()) 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /src/main/kotlin/de/nycode/bankobot/command/slashcommands/arguments/StringArgument.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the BankoBot Project. 3 | * Copyright (C) 2021 BankoBot Contributors 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero General Public License as published 7 | * by the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Affero General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Affero General Public License 16 | * along with this program. If not, see . 17 | * 18 | * Also add information on how to contact you by electronic and paper mail. 19 | * 20 | * If your software can interact with users remotely through a computer 21 | * network, you should also make sure that it provides a way for users to 22 | * get its source. For example, if your program is a web application, its 23 | * interface could display a "Source" link that leads users to an archive 24 | * of the code. There are many ways you could offer source, and different 25 | * solutions will be better for different programs; see section 13 for the 26 | * specific requirements. 27 | * 28 | * You should also get your employer (if you work as a programmer) or school, 29 | * if any, to sign a "copyright disclaimer" for the program, if necessary. 30 | * For more information on this, and how to apply and follow the GNU AGPL, see 31 | * . 32 | * 33 | */ 34 | 35 | package de.nycode.bankobot.command.slashcommands.arguments 36 | 37 | import de.nycode.bankobot.command.slashcommands.SlashArgument 38 | import dev.kord.common.annotation.KordPreview 39 | import dev.kord.rest.builder.interaction.BaseApplicationBuilder 40 | import dev.kord.rest.builder.interaction.StringChoiceBuilder 41 | import dev.kord.x.commands.argument.Argument 42 | import dev.kord.x.commands.argument.text.StringArgument 43 | import dev.kord.x.commands.argument.text.WordArgument 44 | 45 | /** 46 | * Turns this [Argument] into a [SlashArgument] with [description] 47 | * 48 | * @see StringChoiceBuilder 49 | * @see StringArgument 50 | * @see WordArgument 51 | */ 52 | @OptIn(KordPreview::class) 53 | fun Argument.asSlashArgument( 54 | description: String, 55 | choiceBuilder: StringChoiceBuilder.() -> Unit = {}, 56 | ): SlashArgument = StringSlashArgument(description, this, choiceBuilder) 57 | 58 | @OptIn(KordPreview::class) 59 | private class StringSlashArgument( 60 | description: String, 61 | delegate: Argument, 62 | private val choiceBuilder: StringChoiceBuilder.() -> Unit, 63 | ) : AbstractSlashCommandArgument(description, delegate) { 64 | override fun BaseApplicationBuilder.applyArgument() { 65 | string(name, description, choiceBuilder.applyRequired()) 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /src/main/kotlin/de/nycode/bankobot/command/slashcommands/arguments/AbstractSlashCommandArgument.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the BankoBot Project. 3 | * Copyright (C) 2021 BankoBot Contributors 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero General Public License as published 7 | * by the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Affero General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Affero General Public License 16 | * along with this program. If not, see . 17 | * 18 | * Also add information on how to contact you by electronic and paper mail. 19 | * 20 | * If your software can interact with users remotely through a computer 21 | * network, you should also make sure that it provides a way for users to 22 | * get its source. For example, if your program is a web application, its 23 | * interface could display a "Source" link that leads users to an archive 24 | * of the code. There are many ways you could offer source, and different 25 | * solutions will be better for different programs; see section 13 for the 26 | * specific requirements. 27 | * 28 | * You should also get your employer (if you work as a programmer) or school, 29 | * if any, to sign a "copyright disclaimer" for the program, if necessary. 30 | * For more information on this, and how to apply and follow the GNU AGPL, see 31 | * . 32 | * 33 | */ 34 | 35 | package de.nycode.bankobot.command.slashcommands.arguments 36 | 37 | import de.nycode.bankobot.command.slashcommands.SlashArgument 38 | import dev.kord.common.annotation.KordPreview 39 | import dev.kord.rest.builder.interaction.OptionsBuilder 40 | import dev.kord.x.commands.argument.Argument 41 | import dev.kord.x.commands.argument.extension.optional 42 | import java.util.* 43 | 44 | /** 45 | * Abstract implementation for [SlashArgument] which delegates [Argument] to [delegate] 46 | * and already implements [required] based on [optional] 47 | */ 48 | abstract class AbstractSlashCommandArgument( 49 | override val description: String, 50 | private val delegate: Argument, 51 | ) : Argument by delegate, SlashArgument { 52 | override val name: String 53 | get() = delegate.name.lowercase(Locale.getDefault()) 54 | 55 | override val required: Boolean 56 | get() = !delegate.toString().contains("optional|default".toRegex()) 57 | 58 | @OptIn(KordPreview::class) 59 | protected fun required(): OptionsBuilder.() -> Unit = { 60 | required = this@AbstractSlashCommandArgument.required 61 | } 62 | 63 | @OptIn(KordPreview::class) 64 | protected fun (T.() -> Unit).applyRequired(): T.() -> Unit { 65 | return { 66 | required()(this) 67 | invoke(this) 68 | } 69 | } 70 | } 71 | --------------------------------------------------------------------------------