From 8c7e527468eb98115466388b119ebc9c2de67171 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Thu, 12 Nov 2020 13:28:59 +0600 Subject: [PATCH] fill --- README.md | 42 +++++++++++++---------------- build.gradle | 17 ++++++++---- config.json | 12 +++++++++ gradle.properties | 5 +--- settings.gradle | 2 +- src/main/kotlin/telegram_bot/App.kt | 13 --------- 6 files changed, 44 insertions(+), 47 deletions(-) create mode 100644 config.json delete mode 100644 src/main/kotlin/telegram_bot/App.kt diff --git a/README.md b/README.md index 5c95f86..5b6dd54 100644 --- a/README.md +++ b/README.md @@ -1,28 +1,22 @@ -# Telegram Bot Template +# PlaguBot Bot Template -That is template for telegram bots based on next stack of technologies: +1. Update your dependencies [here](./build.gradle#L30). Usually in gradle projects/readmes developers define names of +their dependencies +2. Edit [config](config.json). The main points +([full list of parameters with explanation](https://github.com/InsanusMokrassar/PlaguBot/blob/master/template.config.json): + * Change [database](./config.json#L3) section + * Change [bot token](./config.json#L5)) + * Change [list of plugins](./config.json#L6-L11): + * Field `type` - it is name of the plugin provided by developer/dependency + * Other fields are parameters of plugin and must be provided directly + * Example is available in the [example section](./config.json#L6-L11): here `Hello` is name of plugin and + `parameter` is its configuration parameter -* [Kotlin Coroutines](https://github.com/Kotlin/kotlinx.coroutines) -* [Kotlin Serialization](https://github.com/Kotlin/kotlinx.serialization) -* [Telegram Bot API Library](https://github.com/InsanusMokrassar/TelegramBotAPI) (by default everything is included like -it was described [here](https://github.com/InsanusMokrassar/TelegramBotAPI#ok-where-should-i-start)) +## How to launch -## Default +There are two main ways to launch it: -Since you have used this repo as a template you can simply run command `./gradlew run --args="BOT_TOKEN"` (of course, -replace here `BOT_TOKEN` with your telegram bot token like `1234567890:ABCDEFGHIJKLM_OPqrstuvwxyz012345678`). As an -output you will get your bot information like: - -```bash -ExtendedBot(id=ChatId(chatId=1234567890), username=Username(username=@username_of_your_bot), firstName=Name of bot, lastName=, canJoinGroups=(some boolean), canReadAllGroupMessages=(some boolean), supportsInlineQueries=(some boolean)) -``` - -## What next? - -There are several ways to continue: - -* [Tutorials](https://bookstack.inmo.dev/books/telegrambotapi) -* [Github readme](https://github.com/InsanusMokrassar/TelegramBotAPI) - -In other words, this template (and [TelegramBotAPI library](https://github.com/InsanusMokrassar/TelegramBotAPI)) does -not limit you on choosing of way to continue 😊 +* Run `./gradlew build && ./gradlew run --args="PATH_TO_YOUR_CONFIG"` with replacing of `PATH_TO_YOUR_CONFIG` +* Run `./gradlew build` and get [zip of bot](build/distributions/bot.zip) and unarchive it somewhere you need. In this +archive there is an executable files `bot.bat` (for windows) and `bot` (for linux) by the path inside of archive +`/bot/bin`. After unarchiving you can just launch executable file with one argument: path to the config diff --git a/build.gradle b/build.gradle index 170836c..7217367 100644 --- a/build.gradle +++ b/build.gradle @@ -12,22 +12,29 @@ buildscript { plugins { id 'org.jetbrains.kotlin.jvm' version "$kotlin_version" id "org.jetbrains.kotlin.plugin.serialization" version "$kotlin_version" + id "org.jetbrains.kotlin.kapt" version "$kotlin_version" id 'application' } repositories { jcenter() mavenCentral() + mavenLocal() + maven { url 'https://jitpack.io' } + maven { url "https://dl.bintray.com/insanusmokrassar/PlaguBot/" } } dependencies { implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" - implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$kotlin_coroutines_version" - implementation "org.jetbrains.kotlinx:kotlinx-serialization-json:$kotlin_serialisation_runtime_version" - - implementation "dev.inmo:tgbotapi:$tgbotapi_version" + api "dev.inmo:plagubot.bot:$plagubot_version" } application { - mainClassName = 'telegram_bot.AppKt' + mainClassName = 'dev.inmo.plagubot.AppKt' +} + +kapt { + arguments { + arg("com.github.matfax.klassindex.IndexSubclasses", "dev.inmo.plagubot.Plugin") + } } diff --git a/config.json b/config.json new file mode 100644 index 0000000..3b998f1 --- /dev/null +++ b/config.json @@ -0,0 +1,12 @@ +{ + "database": { + "url": "jdbc:sqlite:file:test?mode=memory&cache=shared" + }, + "botToken": "1234567890:ABCDEFGHIJKLMNOP_qrstuvwxyz12345678", + "plugins": [ + { + "type": "Hello", + "parameter": "Example" + } + ] +} \ No newline at end of file diff --git a/gradle.properties b/gradle.properties index f34b94b..16eae00 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,10 +1,7 @@ -org.gradle.jvmargs=-Xmx2048m kotlin.code.style=official org.gradle.parallel=true kotlin.js.generate.externals=true kotlin.incremental=true kotlin_version=1.4.10 -kotlin_coroutines_version=1.4.1 -kotlin_serialisation_runtime_version=1.0.1 -tgbotapi_version=0.30.0 +plagubot_version=0.0.1 diff --git a/settings.gradle b/settings.gradle index d3c1e54..c9dee36 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1 +1 @@ -rootProject.name = 'telegram_bot' +rootProject.name = "bot" diff --git a/src/main/kotlin/telegram_bot/App.kt b/src/main/kotlin/telegram_bot/App.kt deleted file mode 100644 index dfd5989..0000000 --- a/src/main/kotlin/telegram_bot/App.kt +++ /dev/null @@ -1,13 +0,0 @@ -package telegram_bot - -import dev.inmo.tgbotapi.extensions.api.bot.getMe -import dev.inmo.tgbotapi.extensions.api.telegramBot - -/** - * This method by default expects one argument in [args] field: telegram bot token - */ -suspend fun main(args: Array) { - val bot = telegramBot(args.first()) - - println(bot.getMe()) -}