Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
InsanusMokrassar committed May 8, 2023
0 parents commit 9c12c92
Show file tree
Hide file tree
Showing 19 changed files with 656 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#
# https://help.github.com/articles/dealing-with-line-endings/
#
# These are explicitly windows files and should use crlf
*.bat text eol=crlf

19 changes: 19 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: Build

on: [push]

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Set up JDK 11
uses: actions/setup-java@v1
with:
java-version: 11
- name: Build with Gradle
run: ./gradlew build
env:
GITHUB_USER: ${{ github.actor }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
28 changes: 28 additions & 0 deletions .github/workflows/docker-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Docker

on: [push]

jobs:
publishing:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Rewrite version
run: |
branch="`echo "${{ github.ref }}" | grep -o "[^/]*$"`"
if [[ "$branch" != "master" ]]; then
cat gradle.properties | sed -e "s/^version=\([0-9\.]*\)/version=\1-branch_$branch-build${{ github.run_number }}/" > gradle.properties.tmp
rm gradle.properties
mv gradle.properties.tmp gradle.properties
fi
- name: Log into registry
uses: docker/login-action@28218f9b04b4f3f62068d7b6ce6ca5b26e35336c
with:
username: ${{ secrets.DOCKER_LOGIN }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Deploy
run: ./gradlew build && ./nonsudo_deploy
17 changes: 17 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
.idea
out/*
*.iml
target

settings.xml

.gradle/
build/
out/

local.properties
secret.gradle

config.json
local.*
local/
10 changes: 10 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
FROM bellsoft/liberica-openjdk-alpine:19

ENTRYPOINT /bot/bin/bot /config.json

RUN mkdir /data/ && chown -R 1000:1000 /data/
VOLUME /data/

ADD --chown=1000:1000 build/distributions/bot.tar /

USER 1000
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2020 InsanusMokrassar

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
30 changes: 30 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# PlaguBot Bot Template

1. Update your dependencies [here](https://github.com/InsanusMokrassar/PlaguBotBotTemplate/blob/master/build.gradle#L27-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](https://github.com/InsanusMokrassar/PlaguBotBotTemplate/blob/master/config.json#L2-L4) section
* Change [bot token](https://github.com/InsanusMokrassar/PlaguBotBotTemplate/blob/master/config.json#L5)
* Change [list of plugins](https://github.com/InsanusMokrassar/PlaguBotBotTemplate/blob/master/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](https://github.com/InsanusMokrassar/PlaguBotBotTemplate/blob/master/config.json#L6-L11): here `Hello` is name of plugin and
`parameter` is its configuration parameter
* Change [params](https://github.com/InsanusMokrassar/PlaguBotBotTemplate/blob/master/config.json#L12-L17):
* Any key here will be available in plugins as name of param
* Any value must contains:
* `type` to detect which one object to instantiate
* Other type parameters
* You may look into example related to database in
[config](https://github.com/InsanusMokrassar/PlaguBotBotTemplate/blob/master/config.json#13): `defaultDatabase`
is easily available in plugins as `params.database` extension

## How to launch

There are two main ways to launch it:

* 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
1 change: 1 addition & 0 deletions _config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
theme: jekyll-theme-cayman
50 changes: 50 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
buildscript {
repositories {
mavenCentral()
}

dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "org.jetbrains.kotlin:kotlin-serialization:$kotlin_version"
}
}

plugins {
id 'org.jetbrains.kotlin.jvm' version "$kotlin_version"
id "org.jetbrains.kotlin.plugin.serialization" version "$kotlin_version"
id 'application'
}

project.version = null

Object GithubPackagesCredsClosure = {
username = project.findProperty("GITHUB_USER") ?: System.getenv("GITHUB_USER")
password = project.findProperty("GITHUB_TOKEN") ?: System.getenv("GITHUB_TOKEN")
}

repositories {
mavenCentral()
maven { url 'https://jitpack.io' }
mavenLocal()
maven { url "https://git.inmo.dev/api/packages/InsanusMokrassar/maven" }
}

dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation "dev.inmo:plagubot.bot:$plagubot_version"
implementation "org.jetbrains.kotlinx:kotlinx-serialization-cbor:$serialization_version"

implementation "dev.inmo:plagubot.plugins.captcha:$plugins_version"
implementation "dev.inmo:plagubot.plugins.commands:$plugins_version"
implementation "dev.inmo:plagubot.plugins.bans:$plugins_version"
implementation "dev.inmo:plagubot.plugins.welcome:$plugins_version"
implementation "dev.inmo:plagubot.plugins.inline.buttons:$plugins_version"
implementation "dev.inmo:micro_utils.repos.exposed:$micro_utils_version"
implementation "dev.inmo:micro_utils.koin:$micro_utils_version"

implementation "dev.inmo:tgbotapi:$tgbotapi_version"
}

application {
mainClassName = 'dev.inmo.plagubot.AppKt'
}
17 changes: 17 additions & 0 deletions config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"botToken": "1234567890:ABCDEFGHIJKLMNOP_qrstuvwxyz12345678",
"plugins": [
"dev.inmo.tgbotapi.libraries.cache.admins.AdminsPlugin",
"dev.inmo.plagubot.example.CustomPlugin",
"dev.inmo.plagubot.plugins.inline.buttons.InlineButtonsPlugin",
"dev.inmo.plagubot.plugins.commands.CommandsPlugin",
"dev.inmo.plagubot.plugins.bans.BanPlugin",
"dev.inmo.plagubot.plugins.captcha.CaptchaBotPlugin",
"dev.inmo.plagubot.plugins.welcome.WelcomePlugin"
],
"flushUpdates": true,
"clearCommands": true,
"database": {
"url": "jdbc:sqlite:local.db"
}
}
26 changes: 26 additions & 0 deletions deploy
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/bash

function send_notification() {
echo "$1"
}

function assert_success() {
"${@}"
local status=${?}
if [ ${status} -ne 0 ]; then
send_notification "### Error ${status} at: ${BASH_LINENO[*]} ###"
exit ${status}
fi
}

app=adminbot
version="`grep ./gradle.properties -e "^version=" | sed -e "s/version=\(.*\)/\1/"`"
server=docker.inmo.dev

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 tag $app:"$version" $server/$app:$version
assert_success sudo docker tag $app:"$version" $server/$app:latest
assert_success sudo docker push $server/$app:$version
assert_success sudo docker push $server/$app:latest
14 changes: 14 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
kotlin.code.style=official
org.gradle.parallel=true
kotlin.js.generate.externals=true
kotlin.incremental=true

kotlin_version=1.8.21
plagubot_version=5.1.2
plugins_version=0.11.2

micro_utils_version=0.18.1
tgbotapi_version=7.1.2
serialization_version=1.5.0

version=0.1.1
Binary file added gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
5 changes: 5 additions & 0 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.1-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Loading

0 comments on commit 9c12c92

Please sign in to comment.