mirror of
https://github.com/InsanusMokrassar/PlaguPoster.git
synced 2024-12-22 05:57:13 +00:00
almost fill readme and add samples
This commit is contained in:
parent
f411b757fd
commit
1446caaade
231
README.md
231
README.md
@ -1,224 +1,27 @@
|
|||||||
# How to use
|
# PlaguPoster
|
||||||
|
|
||||||
That is a template for Kotlin Multiplatform Projects. How to use it:
|
This is a posting system for the Telegram based on usage of three chats:
|
||||||
|
|
||||||
* Create your repository from this template
|
* Target chat where the posts will be published to
|
||||||
* Add `local.properties` file in case you plan to use `Android` target (you must set up location of SDK, it will not be tracked by `git` and it is correct behaviour). In the snippet below you may see approximate content of `local.properties` file:
|
* Source chat where the posts will be stored, available for management and ratings
|
||||||
```properties
|
* Cache chat where sometimes will appear your posts to be cached in memory of bot
|
||||||
## This file must *NOT* be checked into Version Control Systems,
|
|
||||||
# as it contains information specific to your local configuration.
|
|
||||||
#
|
|
||||||
# Location of the SDK. This is only used by Gradle.
|
|
||||||
# For customization when using a Version Control System, please read the
|
|
||||||
# header note.
|
|
||||||
sdk.dir=/your/path/to/android/sdk
|
|
||||||
```
|
|
||||||
* Replace in a whole project `project_group` by your group
|
|
||||||
* Replace in a whole project `project_name` by your **ROOT** project name
|
|
||||||
* Update your subproject packages. It is not critical, but recommended especially in case you plan to publish your
|
|
||||||
library
|
|
||||||
|
|
||||||
## Subprojects
|
And different plugins. Sample config is presented in the root of this repository.
|
||||||
|
Each plugin describes its own format of subconfig. Anyway, most of config parts will be stored in one
|
||||||
|
file `config.json` (you may name it anyhow).
|
||||||
|
|
||||||
In this template there is only one subproject with name `lib`. You are always able to rename it, but remember that in
|
## How does it work
|
||||||
this case you must rename it in `settings.gradle` file.
|
|
||||||
|
|
||||||
## JVM sources in Android target
|
1. You are sending post to __source__ chat
|
||||||
|
2. Bot register it
|
||||||
|
3. (Optionally) bot attaching ratings poll
|
||||||
|
|
||||||
By default JVM code is not included in Android target. In case you wish to include JVM sources in Android build, use
|
## How to launch the bot
|
||||||
next method in the end of your `build.gradle`:
|
|
||||||
|
|
||||||
```groovy
|
There are several ways to launch the bot:
|
||||||
enableIncludingJvmCodeInAndroidPart()
|
|
||||||
```
|
|
||||||
|
|
||||||
In case when you need to be sure that JVM sources are not included in Android part, use this snippet:
|
* With Docker (and `docker-compose`)
|
||||||
|
* With using of `gradle` and `run` command
|
||||||
|
* Using `zip`/`tar` after project building
|
||||||
|
|
||||||
```groovy
|
|
||||||
disableIncludingJvmCodeInAndroidPart()
|
|
||||||
```
|
|
||||||
|
|
||||||
## Types of projects
|
|
||||||
|
|
||||||
### `mppProjectWithSerialization`
|
|
||||||
|
|
||||||
This type of preset have `JVM`, `JS` and `Android` targets and available using
|
|
||||||
`apply from: "$mppProjectWithSerializationPresetPath"`. Template for project with this preset looks like next snippet:
|
|
||||||
|
|
||||||
```groovy
|
|
||||||
plugins {
|
|
||||||
id "org.jetbrains.kotlin.multiplatform"
|
|
||||||
id "org.jetbrains.kotlin.plugin.serialization"
|
|
||||||
id "com.android.library"
|
|
||||||
}
|
|
||||||
|
|
||||||
apply from: "$mppProjectWithSerializationPresetPath"
|
|
||||||
|
|
||||||
// The code below is optional
|
|
||||||
|
|
||||||
kotlin {
|
|
||||||
sourceSets {
|
|
||||||
commonMain {
|
|
||||||
dependencies {
|
|
||||||
// common dependencies
|
|
||||||
}
|
|
||||||
}
|
|
||||||
commonTest {
|
|
||||||
dependencies {
|
|
||||||
// common test dependencies
|
|
||||||
}
|
|
||||||
}
|
|
||||||
jvmMain {
|
|
||||||
dependencies {
|
|
||||||
// jvm dependencies
|
|
||||||
}
|
|
||||||
}
|
|
||||||
jvmTest {
|
|
||||||
dependencies {
|
|
||||||
// jvm test dependencies
|
|
||||||
}
|
|
||||||
}
|
|
||||||
jsMain {
|
|
||||||
dependencies {
|
|
||||||
// js dependencies
|
|
||||||
}
|
|
||||||
}
|
|
||||||
jsTest {
|
|
||||||
dependencies {
|
|
||||||
// js test dependencies
|
|
||||||
}
|
|
||||||
}
|
|
||||||
androidMain {
|
|
||||||
dependencies {
|
|
||||||
// android dependencies
|
|
||||||
}
|
|
||||||
}
|
|
||||||
androidTest {
|
|
||||||
dependencies {
|
|
||||||
// android test dependencies
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
### `mppJavaProject`
|
|
||||||
|
|
||||||
This type of preset have only `JVM` target and available using `apply from: "$mppJavaProjectPresetPath"`. Template for
|
|
||||||
project with this preset looks like next snippet:
|
|
||||||
|
|
||||||
```groovy
|
|
||||||
plugins {
|
|
||||||
id "org.jetbrains.kotlin.multiplatform"
|
|
||||||
}
|
|
||||||
|
|
||||||
apply from: "$mppJavaProjectPresetPath"
|
|
||||||
|
|
||||||
// The code below is optional
|
|
||||||
|
|
||||||
kotlin {
|
|
||||||
sourceSets {
|
|
||||||
commonMain {
|
|
||||||
dependencies {
|
|
||||||
// common dependencies
|
|
||||||
}
|
|
||||||
}
|
|
||||||
commonTest {
|
|
||||||
dependencies {
|
|
||||||
// common test dependencies
|
|
||||||
}
|
|
||||||
}
|
|
||||||
jvmMain {
|
|
||||||
dependencies {
|
|
||||||
// jvm dependencies
|
|
||||||
}
|
|
||||||
}
|
|
||||||
jvmTest {
|
|
||||||
dependencies {
|
|
||||||
// jvm test dependencies
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
### `mppJsProject`
|
|
||||||
|
|
||||||
This type of preset have only `JS` target and available using `apply from: "mppJsProjectPresetPath"`. Template for
|
|
||||||
project with this preset looks like next snippet:
|
|
||||||
|
|
||||||
```groovy
|
|
||||||
plugins {
|
|
||||||
id "org.jetbrains.kotlin.multiplatform"
|
|
||||||
}
|
|
||||||
|
|
||||||
apply from: "$mppJsProjectPresetPath"
|
|
||||||
|
|
||||||
// The code below is optional
|
|
||||||
|
|
||||||
kotlin {
|
|
||||||
sourceSets {
|
|
||||||
commonMain {
|
|
||||||
dependencies {
|
|
||||||
// common dependencies
|
|
||||||
}
|
|
||||||
}
|
|
||||||
commonTest {
|
|
||||||
dependencies {
|
|
||||||
// common test dependencies
|
|
||||||
}
|
|
||||||
}
|
|
||||||
jsMain {
|
|
||||||
dependencies {
|
|
||||||
// jvm dependencies
|
|
||||||
}
|
|
||||||
}
|
|
||||||
jsTest {
|
|
||||||
dependencies {
|
|
||||||
// jvm test dependencies
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
### `mppAndroidProject`
|
|
||||||
|
|
||||||
This type of preset have only `Android` target and available using `apply from: "$mppAndroidProjectPresetPath"`. Template for
|
|
||||||
project with this preset looks like next snippet:
|
|
||||||
|
|
||||||
```groovy
|
|
||||||
plugins {
|
|
||||||
id "org.jetbrains.kotlin.multiplatform"
|
|
||||||
id "com.android.library"
|
|
||||||
}
|
|
||||||
|
|
||||||
apply from: "$mppAndroidProjectPresetPath"
|
|
||||||
|
|
||||||
// The code below is optional
|
|
||||||
|
|
||||||
kotlin {
|
|
||||||
sourceSets {
|
|
||||||
commonMain {
|
|
||||||
dependencies {
|
|
||||||
// common dependencies
|
|
||||||
}
|
|
||||||
}
|
|
||||||
commonTest {
|
|
||||||
dependencies {
|
|
||||||
// common test dependencies
|
|
||||||
}
|
|
||||||
}
|
|
||||||
androidMain {
|
|
||||||
dependencies {
|
|
||||||
// android dependencies
|
|
||||||
}
|
|
||||||
}
|
|
||||||
androidTest {
|
|
||||||
dependencies {
|
|
||||||
// android test dependencies
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
@ -15,10 +15,9 @@ function assert_success() {
|
|||||||
|
|
||||||
app=plaguposter
|
app=plaguposter
|
||||||
version=0.0.1
|
version=0.0.1
|
||||||
server=docker.inmo.dev
|
server=docker.io/insanusmokrassar
|
||||||
|
|
||||||
assert_success ../gradlew build
|
assert_success ../gradlew build
|
||||||
# scp ./build/distributions/AutoPostTestTelegramBot-1.0.0.zip ./config.json developer@insanusmokrassar.dev:/tmp/
|
|
||||||
assert_success sudo docker build -t $app:"$version" .
|
assert_success sudo docker build -t $app:"$version" .
|
||||||
assert_success sudo docker tag $app:"$version" $server/$app:$version
|
assert_success sudo docker tag $app:"$version" $server/$app:$version
|
||||||
assert_success sudo docker tag $app:"$version" $server/$app:latest
|
assert_success sudo docker tag $app:"$version" $server/$app:latest
|
||||||
|
5
sample/.env
Normal file
5
sample/.env
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
DATA_PATH=.
|
||||||
|
|
||||||
|
PG_USER=test_user
|
||||||
|
PG_PASSWORD=test_password
|
||||||
|
PG_DB=test_db
|
138
sample/config.json
Normal file
138
sample/config.json
Normal file
@ -0,0 +1,138 @@
|
|||||||
|
{
|
||||||
|
"database": {
|
||||||
|
"url": "jdbc:postgresql://postgres/test_db",
|
||||||
|
"username": "test_user",
|
||||||
|
"password": "test_password",
|
||||||
|
"driver": "org.postgresql.Driver"
|
||||||
|
},
|
||||||
|
"botToken": "1234567890:ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghi",
|
||||||
|
"plugins": [
|
||||||
|
"dev.inmo.plaguposter.posts.Plugin",
|
||||||
|
"dev.inmo.plaguposter.posts.registrar.Plugin",
|
||||||
|
"dev.inmo.plaguposter.ratings.Plugin",
|
||||||
|
"dev.inmo.plaguposter.ratings.source.Plugin",
|
||||||
|
"dev.inmo.plaguposter.ratings.selector.Plugin",
|
||||||
|
"dev.inmo.plaguposter.triggers.selector_with_timer.Plugin",
|
||||||
|
"dev.inmo.plaguposter.ratings.gc.Plugin",
|
||||||
|
"dev.inmo.plaguposter.inlines.Plugin",
|
||||||
|
"dev.inmo.plaguposter.triggers.command.Plugin"
|
||||||
|
],
|
||||||
|
"posts": {
|
||||||
|
"chats": {
|
||||||
|
"targetChat": -1001234567890,
|
||||||
|
"cacheChat": -1001234567890,
|
||||||
|
"sourceChat": -1001234567890
|
||||||
|
},
|
||||||
|
"autoRemoveMessages": true
|
||||||
|
},
|
||||||
|
"ratingsPolls": {
|
||||||
|
"variants": {
|
||||||
|
"Круть": 2,
|
||||||
|
"Ок": 1,
|
||||||
|
"Не ок": -1,
|
||||||
|
"Совсем не ок": -2,
|
||||||
|
"Посмотреть результаты": 0
|
||||||
|
},
|
||||||
|
"autoAttach": true,
|
||||||
|
"ratingOfferText": "How do you like it?"
|
||||||
|
},
|
||||||
|
"selector": {
|
||||||
|
"items": [
|
||||||
|
{
|
||||||
|
"time": {
|
||||||
|
"from": "23:00",
|
||||||
|
"to": "23:59"
|
||||||
|
},
|
||||||
|
"rating": {
|
||||||
|
"min": -1.0,
|
||||||
|
"max": 2.0,
|
||||||
|
"prefer": "max",
|
||||||
|
"otherwise": {
|
||||||
|
"rating": {
|
||||||
|
"min": 2.0,
|
||||||
|
"prefer": "min",
|
||||||
|
"postAge": 86400
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"postAge": 86400
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"time": {
|
||||||
|
"from": "00:00",
|
||||||
|
"to": "06:59"
|
||||||
|
},
|
||||||
|
"rating": {
|
||||||
|
"min": -1.0,
|
||||||
|
"max": 2.0,
|
||||||
|
"prefer": "max",
|
||||||
|
"otherwise": {
|
||||||
|
"rating": {
|
||||||
|
"min": 2.0,
|
||||||
|
"prefer": "min",
|
||||||
|
"postAge": 86400
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"postAge": 86400
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"time": {
|
||||||
|
"from": "07:00",
|
||||||
|
"to": "12:00"
|
||||||
|
},
|
||||||
|
"rating": {
|
||||||
|
"min": 1.0,
|
||||||
|
"prefer": "min",
|
||||||
|
"otherwise": {
|
||||||
|
"rating": {
|
||||||
|
"max": 1.0,
|
||||||
|
"prefer": "max",
|
||||||
|
"postAge": 86400
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"postAge": 86400
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"time": {
|
||||||
|
"from": "12:00",
|
||||||
|
"to": "16:00"
|
||||||
|
},
|
||||||
|
"rating": {
|
||||||
|
"min": 2.0,
|
||||||
|
"prefer": "min",
|
||||||
|
"otherwise": {
|
||||||
|
"rating": {
|
||||||
|
"max": 2.0,
|
||||||
|
"prefer": "max",
|
||||||
|
"postAge": 86400
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"postAge": 86400
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"time": {
|
||||||
|
"from": "16:00",
|
||||||
|
"to": "23:00"
|
||||||
|
},
|
||||||
|
"rating": {
|
||||||
|
"prefer": "max",
|
||||||
|
"postAge": 86400
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"timer_trigger": {
|
||||||
|
"krontab": "0 30 */5 * *"
|
||||||
|
},
|
||||||
|
"gc": {
|
||||||
|
"autoclear": {
|
||||||
|
"rating": -1,
|
||||||
|
"autoClearKrontab": "0 0 0 * *",
|
||||||
|
"skipPostAge": 86400
|
||||||
|
},
|
||||||
|
"immediateDrop": -2
|
||||||
|
}
|
||||||
|
}
|
23
sample/docker-compose.yml
Normal file
23
sample/docker-compose.yml
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
version: "3.4"
|
||||||
|
|
||||||
|
services:
|
||||||
|
plaguposter_postgres:
|
||||||
|
image: postgres
|
||||||
|
container_name: "plaguposter_postgres"
|
||||||
|
restart: "unless-stopped"
|
||||||
|
environment:
|
||||||
|
POSTGRES_USER: "${PG_USER}"
|
||||||
|
POSTGRES_PASSWORD: "${PG_PASSWORD}"
|
||||||
|
POSTGRES_DB: "${PG_DB}"
|
||||||
|
volumes:
|
||||||
|
- "${DATA_PATH}/db/:/var/lib/postgresql/"
|
||||||
|
plaguposter:
|
||||||
|
image: insanusmokrassar/plaguposter
|
||||||
|
container_name: "plaguposter"
|
||||||
|
restart: "unless-stopped"
|
||||||
|
volumes:
|
||||||
|
- "${DATA_PATH}/config.json:/config.json"
|
||||||
|
links:
|
||||||
|
- "plaguposter_postgres:postgres"
|
||||||
|
depends_on:
|
||||||
|
- "plaguposter_postgres"
|
Loading…
Reference in New Issue
Block a user