Rewrite build.gradle to kotlin DSL

Remove bot username from config
Fix lateinit property not initialized in `Plugin::onDisable()`
This commit is contained in:
kraftwerk28 2021-06-26 17:52:25 +03:00
parent b99748f96b
commit 555478599c
25 changed files with 256 additions and 402 deletions

2
.idea/.gitignore vendored
View File

@ -1,2 +0,0 @@
# Default ignored files
/workspace.xml

View File

@ -1,69 +0,0 @@
<component name="ArtifactManager">
<artifact type="jar" name="rzcraft-bridge:jar">
<output-path>$USER_HOME$/MinecraftServers/spigot_1.15.2/plugins/</output-path>
<root id="archive" name="rzcraft-bridge.jar">
<element id="module-output" name="rzcraft-bridge.main" />
<element id="extracted-dir" path="$USER_HOME$/.gradle/caches/modules-2/files-2.1/com.google.guava/failureaccess/1.0.1/1dcf1de382a0bf95a3d8b0849546c88bac1292c9/failureaccess-1.0.1.jar" path-in-jar="/" />
<element id="extracted-dir" path="$USER_HOME$/.gradle/caches/modules-2/files-2.1/org.telegram/telegrambots-meta/4.6/959a0ea151af21113accf17b3843a43826c76726/telegrambots-meta-4.6.jar" path-in-jar="/" />
<element id="extracted-dir" path="$USER_HOME$/.gradle/caches/modules-2/files-2.1/org.javassist/javassist/3.22.0-CR2/44eaf0990dea92f4bca4b9931b2239c0e8756ee7/javassist-3.22.0-CR2.jar" path-in-jar="/" />
<element id="extracted-dir" path="$USER_HOME$/.gradle/caches/modules-2/files-2.1/org.glassfish.jersey.core/jersey-common/2.29.1/ea60b9ace56f1ae758c2eebbb48e8387d959102f/jersey-common-2.29.1.jar" path-in-jar="/" />
<element id="extracted-dir" path="$USER_HOME$/.gradle/caches/modules-2/files-2.1/jakarta.ws.rs/jakarta.ws.rs-api/2.1.6/1dcb770bce80a490dff49729b99c7a60e9ecb122/jakarta.ws.rs-api-2.1.6.jar" path-in-jar="/" />
<element id="extracted-dir" path="$USER_HOME$/.gradle/caches/modules-2/files-2.1/org.codehaus.mojo/animal-sniffer-annotations/1.18/f7aa683ea79dc6681ee9fb95756c999acbb62f5d/animal-sniffer-annotations-1.18.jar" path-in-jar="/" />
<element id="extracted-dir" path="$USER_HOME$/.gradle/caches/modules-2/files-2.1/commons-io/commons-io/2.6/815893df5f31da2ece4040fe0a12fd44b577afaf/commons-io-2.6.jar" path-in-jar="/" />
<element id="extracted-dir" path="$USER_HOME$/.gradle/caches/modules-2/files-2.1/junit/junit/4.12/2973d150c0dc1fefe998f834810d68f278ea58ec/junit-4.12.jar" path-in-jar="/" />
<element id="extracted-dir" path="$USER_HOME$/.gradle/caches/modules-2/files-2.1/org.apache.httpcomponents/httpclient/4.5.10/7ca2e4276f4ef95e4db725a8cd4a1d1e7585b9e5/httpclient-4.5.10.jar" path-in-jar="/" />
<element id="extracted-dir" path="$USER_HOME$/.gradle/caches/modules-2/files-2.1/com.google.j2objc/j2objc-annotations/1.3/ba035118bc8bac37d7eff77700720999acd9986d/j2objc-annotations-1.3.jar" path-in-jar="/" />
<element id="extracted-dir" path="$USER_HOME$/.gradle/caches/modules-2/files-2.1/javax.inject/javax.inject/1/6975da39a7040257bd51d21a231b76c915872d38/javax.inject-1.jar" path-in-jar="/" />
<element id="extracted-dir" path="$USER_HOME$/.gradle/caches/modules-2/files-2.1/jakarta.annotation/jakarta.annotation-api/1.3.5/59eb84ee0d616332ff44aba065f3888cf002cd2d/jakarta.annotation-api-1.3.5.jar" path-in-jar="/" />
<element id="extracted-dir" path="$USER_HOME$/.gradle/caches/modules-2/files-2.1/org.slf4j/slf4j-api/1.7.29/e56bf4473a4c6b71c7dd397a833dce86d1993d9d/slf4j-api-1.7.29.jar" path-in-jar="/" />
<element id="extracted-dir" path="$USER_HOME$/.gradle/caches/modules-2/files-2.1/org.glassfish.grizzly/grizzly-http/2.4.4/c789d449906458d4174126f6a4fefdd7a6008777/grizzly-http-2.4.4.jar" path-in-jar="/" />
<element id="extracted-dir" path="$USER_HOME$/.gradle/caches/modules-2/files-2.1/com.fasterxml.jackson.jaxrs/jackson-jaxrs-json-provider/2.10.1/69ee6b94fa8e0653bf62c718c7a2fe533a6558d4/jackson-jaxrs-json-provider-2.10.1.jar" path-in-jar="/" />
<element id="extracted-dir" path="$USER_HOME$/.gradle/caches/modules-2/files-2.1/commons-codec/commons-codec/1.11/3acb4705652e16236558f0f4f2192cc33c3bd189/commons-codec-1.11.jar" path-in-jar="/" />
<element id="extracted-dir" path="$USER_HOME$/.gradle/caches/modules-2/files-2.1/org.glassfish.jersey.inject/jersey-hk2/2.29.1/54b316e9f91ac9de1e6900aeb63457505862a296/jersey-hk2-2.29.1.jar" path-in-jar="/" />
<element id="extracted-dir" path="$USER_HOME$/.gradle/caches/modules-2/files-2.1/org.glassfish.jersey.media/jersey-media-json-jackson/2.29.1/e16c6b8d486604ac55a2b5f49b20e75564e7979b/jersey-media-json-jackson-2.29.1.jar" path-in-jar="/" />
<element id="extracted-dir" path="$USER_HOME$/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib-jdk7/1.3.60/a42a01c0338795930e0a7d8f9d19acafdd1c50ee/kotlin-stdlib-jdk7-1.3.60.jar" path-in-jar="/" />
<element id="extracted-dir" path="$USER_HOME$/.gradle/caches/modules-2/files-2.1/org.glassfish.hk2.external/jakarta.inject/2.6.1/8096ebf722902e75fbd4f532a751e514f02e1eb7/jakarta.inject-2.6.1.jar" path-in-jar="/" />
<element id="extracted-dir" path="$USER_HOME$/.gradle/caches/modules-2/files-2.1/jakarta.xml.bind/jakarta.xml.bind-api/2.3.2/8d49996a4338670764d7ca4b85a1c4ccf7fe665d/jakarta.xml.bind-api-2.3.2.jar" path-in-jar="/" />
<element id="extracted-dir" path="$USER_HOME$/.gradle/caches/modules-2/files-2.1/org.telegram/telegrambots/4.6/9f88658948bcd41557390610f7ca1af85aed0261/telegrambots-4.6.jar" path-in-jar="/" />
<element id="extracted-dir" path="$USER_HOME$/.gradle/caches/modules-2/files-2.1/org.glassfish.grizzly/grizzly-framework/2.4.4/85ff29df39616972a074737948f116ef25addfee/grizzly-framework-2.4.4.jar" path-in-jar="/" />
<element id="extracted-dir" path="$USER_HOME$/.gradle/caches/modules-2/files-2.1/org.glassfish.grizzly/grizzly-http-server/2.4.4/f9a62c711eb51f351cc5ba48faf44d5a49faa0a7/grizzly-http-server-2.4.4.jar" path-in-jar="/" />
<element id="extracted-dir" path="$USER_HOME$/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib-common/1.3.60/538bd29b2d5a7d278a7188f89c3b84183fa37f75/kotlin-stdlib-common-1.3.60.jar" path-in-jar="/" />
<element id="extracted-dir" path="$USER_HOME$/.gradle/caches/modules-2/files-2.1/aopalliance/aopalliance/1.0/235ba8b489512805ac13a8f9ea77a1ca5ebe3e8/aopalliance-1.0.jar" path-in-jar="/" />
<element id="extracted-dir" path="$USER_HOME$/.gradle/caches/modules-2/files-2.1/org.apache.httpcomponents/httpmime/4.5.10/3513ca10d24d7aa962741c90e914fec650f0848c/httpmime-4.5.10.jar" path-in-jar="/" />
<element id="extracted-dir" path="$USER_HOME$/.gradle/caches/modules-2/files-2.1/com.google.code.findbugs/jsr305/3.0.2/25ea2e8b0c338a877313bd4672d3fe056ea78f0d/jsr305-3.0.2.jar" path-in-jar="/" />
<element id="extracted-dir" path="$USER_HOME$/.gradle/caches/modules-2/files-2.1/org.glassfish.hk2/hk2-api/2.6.1/114bd7afb4a1bd9993527f52a08a252b5d2acac5/hk2-api-2.6.1.jar" path-in-jar="/" />
<element id="extracted-dir" path="$USER_HOME$/.gradle/caches/modules-2/files-2.1/org.yaml/snakeyaml/1.25/8b6e01ef661d8378ae6dd7b511a7f2a33fae1421/snakeyaml-1.25.jar" path-in-jar="/" />
<element id="extracted-dir" path="$USER_HOME$/.gradle/caches/modules-2/files-2.1/com.fasterxml.jackson.core/jackson-annotations/2.10.1/54d72475c0d6819f2d0e9a09d25c3ed876a4972f/jackson-annotations-2.10.1.jar" path-in-jar="/" />
<element id="extracted-dir" path="$USER_HOME$/.gradle/caches/modules-2/files-2.1/org.glassfish.hk2/hk2-utils/2.6.1/396513aa96c1d5a10aa4f75c4dcbf259a698d62d/hk2-utils-2.6.1.jar" path-in-jar="/" />
<element id="extracted-dir" path="$USER_HOME$/.gradle/caches/modules-2/files-2.1/com.fasterxml.jackson.core/jackson-databind/2.10.1/18eee15ffc662d27538d5b6ee84e4c92c0a9d03e/jackson-databind-2.10.1.jar" path-in-jar="/" />
<element id="extracted-dir" path="$USER_HOME$/.gradle/caches/modules-2/files-2.1/org.apache.httpcomponents/httpcore/4.4.12/21ebaf6d532bc350ba95bd81938fa5f0e511c132/httpcore-4.4.12.jar" path-in-jar="/" />
<element id="extracted-dir" path="$USER_HOME$/.gradle/caches/modules-2/files-2.1/com.vdurmont/emoji-java/5.1.1/5b5896190e12110584f1e9e09eff376565a92626/emoji-java-5.1.1.jar" path-in-jar="/" />
<element id="extracted-dir" path="$USER_HOME$/.gradle/caches/modules-2/files-2.1/org.jetbrains/annotations/13.0/919f0dfe192fb4e063e7dacadee7f8bb9a2672a9/annotations-13.0.jar" path-in-jar="/" />
<element id="extracted-dir" path="$USER_HOME$/.gradle/caches/modules-2/files-2.1/jakarta.validation/jakarta.validation-api/2.0.2/5eacc6522521f7eacb081f95cee1e231648461e7/jakarta.validation-api-2.0.2.jar" path-in-jar="/" />
<element id="extracted-dir" path="$USER_HOME$/.gradle/caches/modules-2/files-2.1/com.google.guava/guava/28.1-jre/b0e91dcb6a44ffb6221b5027e12a5cb34b841145/guava-28.1-jre.jar" path-in-jar="/" />
<element id="extracted-dir" path="$USER_HOME$/.gradle/caches/modules-2/files-2.1/org.glassfish.hk2.external/aopalliance-repackaged/2.6.1/b2eb0a83bcbb44cc5d25f8b18f23be116313a638/aopalliance-repackaged-2.6.1.jar" path-in-jar="/" />
<element id="extracted-dir" path="$USER_HOME$/.gradle/caches/modules-2/files-2.1/com.google.errorprone/error_prone_annotations/2.3.2/d1a0c5032570e0f64be6b4d9c90cdeb103129029/error_prone_annotations-2.3.2.jar" path-in-jar="/" />
<element id="extracted-dir" path="$USER_HOME$/.gradle/caches/modules-2/files-2.1/com.google.guava/listenablefuture/9999.0-empty-to-avoid-conflict-with-guava/b421526c5f297295adef1c886e5246c39d4ac629/listenablefuture-9999.0-empty-to-avoid-conflict-with-guava.jar" path-in-jar="/" />
<element id="extracted-dir" path="$USER_HOME$/.gradle/caches/modules-2/files-2.1/org.glassfish.jersey.ext/jersey-entity-filtering/2.29.1/e68a310e03fcd97f245854e7f59b2e9668c5c146/jersey-entity-filtering-2.29.1.jar" path-in-jar="/" />
<element id="extracted-dir" path="$USER_HOME$/.gradle/caches/modules-2/files-2.1/org.glassfish.hk2/hk2-locator/2.6.1/9dedf9d2022e38ec0743ed44c1ac94ad6149acdd/hk2-locator-2.6.1.jar" path-in-jar="/" />
<element id="extracted-dir" path="$USER_HOME$/.gradle/caches/modules-2/files-2.1/commons-logging/commons-logging/1.2/4bfc12adfe4842bf07b657f0369c4cb522955686/commons-logging-1.2.jar" path-in-jar="/" />
<element id="extracted-dir" path="$USER_HOME$/.gradle/caches/modules-2/files-2.1/com.fasterxml.jackson.core/jackson-core/2.10.1/2c8b5e26ba40e5f91eb37a24075a2028b402c5f9/jackson-core-2.10.1.jar" path-in-jar="/" />
<element id="extracted-dir" path="$USER_HOME$/.gradle/caches/modules-2/files-2.1/org.json/json/20180813/8566b2b0391d9d4479ea225645c6ed47ef17fe41/json-20180813.jar" path-in-jar="/" />
<element id="extracted-dir" path="$USER_HOME$/.gradle/caches/modules-2/files-2.1/org.glassfish.jersey.core/jersey-client/2.29.1/1635f245b7e9eecf8d3d753fba87f3b79aef1b34/jersey-client-2.29.1.jar" path-in-jar="/" />
<element id="extracted-dir" path="$USER_HOME$/.gradle/caches/modules-2/files-2.1/com.google.inject/guice/4.2.2/6dacbe18e5eaa7f6c9c36db33b42e7985e94ce77/guice-4.2.2.jar" path-in-jar="/" />
<element id="extracted-dir" path="$USER_HOME$/.gradle/caches/modules-2/files-2.1/org.hamcrest/hamcrest-core/1.3/42a25dc3219429f0e5d060061f71acb49bf010a0/hamcrest-core-1.3.jar" path-in-jar="/" />
<element id="extracted-dir" path="$USER_HOME$/.gradle/caches/modules-2/files-2.1/org.glassfish.jersey.media/jersey-media-jaxb/2.29.1/53f22b94254ff781667b3313acbb3afebfd091b5/jersey-media-jaxb-2.29.1.jar" path-in-jar="/" />
<element id="extracted-dir" path="$USER_HOME$/.gradle/caches/modules-2/files-2.1/com.fasterxml.jackson.jaxrs/jackson-jaxrs-base/2.10.1/76b76bab5f077c877e8c40290aec2b1c24085df5/jackson-jaxrs-base-2.10.1.jar" path-in-jar="/" />
<element id="extracted-dir" path="$USER_HOME$/.gradle/caches/modules-2/files-2.1/com.fasterxml.jackson.module/jackson-module-jaxb-annotations/2.10.1/7a733550bf39eed5f9d0db25adca72781de959bf/jackson-module-jaxb-annotations-2.10.1.jar" path-in-jar="/" />
<element id="extracted-dir" path="$USER_HOME$/.gradle/caches/modules-2/files-2.1/org.glassfish.hk2/osgi-resource-locator/1.0.3/de3b21279df7e755e38275137539be5e2c80dd58/osgi-resource-locator-1.0.3.jar" path-in-jar="/" />
<element id="extracted-dir" path="$USER_HOME$/.gradle/caches/modules-2/files-2.1/org.checkerframework/checker-qual/2.8.1/eb2e8ab75598548cc8acf9a1ca227e480e01881e/checker-qual-2.8.1.jar" path-in-jar="/" />
<element id="extracted-dir" path="$USER_HOME$/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib/1.3.60/984644b61450add3bcef8cf20f948fec458b420d/kotlin-stdlib-1.3.60.jar" path-in-jar="/" />
<element id="extracted-dir" path="$USER_HOME$/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib-jdk8/1.3.60/5cb6bf19bab36ab9d10b216356e869250c686a09/kotlin-stdlib-jdk8-1.3.60.jar" path-in-jar="/" />
<element id="extracted-dir" path="$USER_HOME$/.gradle/caches/modules-2/files-2.1/org.glassfish.jersey.core/jersey-server/2.29.1/edeaa59abad953156a4ed83199780d66ce7998c0/jersey-server-2.29.1.jar" path-in-jar="/" />
<element id="extracted-dir" path="$USER_HOME$/.gradle/caches/modules-2/files-2.1/org.glassfish.jersey.containers/jersey-container-grizzly2-http/2.29.1/5b70b50891d48f6ee3dcf77d15f729ec900ab035/jersey-container-grizzly2-http-2.29.1.jar" path-in-jar="/" />
<element id="extracted-dir" path="$USER_HOME$/.gradle/caches/modules-2/files-2.1/jakarta.activation/jakarta.activation-api/1.2.1/562a587face36ec7eff2db7f2fc95425c6602bc1/jakarta.activation-api-1.2.1.jar" path-in-jar="/" />
<element id="file-copy" path="$PROJECT_DIR$/src/config.yml" />
<element id="file-copy" path="$PROJECT_DIR$/src/main/resources/plugin.yml" />
</root>
</artifact>
</component>

View File

@ -1,11 +0,0 @@
<component name="ProjectCodeStyleConfiguration">
<code_scheme name="Project" version="173">
<option name="SOFT_MARGINS" value="80" />
<JetCodeStyleSettings>
<option name="CODE_STYLE_DEFAULTS" value="KOTLIN_OFFICIAL" />
</JetCodeStyleSettings>
<codeStyleSettings language="kotlin">
<option name="CODE_STYLE_DEFAULTS" value="KOTLIN_OFFICIAL" />
</codeStyleSettings>
</code_scheme>
</component>

View File

@ -1,5 +0,0 @@
<component name="ProjectCodeStyleConfiguration">
<state>
<option name="USE_PER_PROJECT_SETTINGS" value="true" />
</state>
</component>

View File

@ -1,6 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CompilerConfiguration">
<bytecodeTargetLevel target="14" />
</component>
</project>

View File

@ -1,21 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="GradleMigrationSettings" migrationVersion="1" />
<component name="GradleSettings">
<option name="linkedExternalProjectsSettings">
<GradleProjectSettings>
<option name="delegatedBuild" value="true" />
<option name="testRunner" value="GRADLE" />
<option name="distributionType" value="DEFAULT_WRAPPED" />
<option name="externalProjectPath" value="$PROJECT_DIR$" />
<option name="gradleHome" value="$PROJECT_DIR$/../../../../Program Files/Gradle/gradle-6.5.1" />
<option name="modules">
<set>
<option value="$PROJECT_DIR$" />
</set>
</option>
<option name="useQualifiedModuleNames" value="true" />
</GradleProjectSettings>
</option>
</component>
</project>

View File

@ -1,40 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="RemoteRepositoriesConfiguration">
<remote-repository>
<option name="id" value="central" />
<option name="name" value="Maven Central repository" />
<option name="url" value="https://repo1.maven.org/maven2" />
</remote-repository>
<remote-repository>
<option name="id" value="jboss.community" />
<option name="name" value="JBoss Community repository" />
<option name="url" value="https://repository.jboss.org/nexus/content/repositories/public/" />
</remote-repository>
<remote-repository>
<option name="id" value="MavenRepo" />
<option name="name" value="MavenRepo" />
<option name="url" value="https://repo.maven.apache.org/maven2/" />
</remote-repository>
<remote-repository>
<option name="id" value="maven" />
<option name="name" value="maven" />
<option name="url" value="https://hub.spigotmc.org/nexus/content/repositories/snapshots" />
</remote-repository>
<remote-repository>
<option name="id" value="maven" />
<option name="name" value="maven" />
<option name="url" value="https://oss.sonatype.org/content/repositories/snapshots/" />
</remote-repository>
<remote-repository>
<option name="id" value="maven2" />
<option name="name" value="maven2" />
<option name="url" value="https://jitpack.io" />
</remote-repository>
<remote-repository>
<option name="id" value="BintrayJCenter" />
<option name="name" value="BintrayJCenter" />
<option name="url" value="https://jcenter.bintray.com/" />
</remote-repository>
</component>
</project>

View File

@ -1,18 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="EntryPointsManager">
<list size="1">
<item index="0" class="java.lang.String" itemvalue="org.bukkit.event.EventHandler" />
</list>
</component>
<component name="ExternalStorageConfigurationManager" enabled="true" />
<component name="FrameworkDetectionExcludesConfiguration">
<file type="web" url="file://$PROJECT_DIR$" />
</component>
<component name="JavaScriptSettings">
<option name="languageLevel" value="ES6" />
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_14" default="true" project-jdk-name="14" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>

View File

@ -1,2 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4" />

View File

@ -1,6 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

View File

@ -13,10 +13,9 @@
- Copy [config.yml](https://raw.githubusercontent.com/kraftwerk28/spigot-tg-bridge/master/src/main/resources/config.yml) to `plugins/SpigotTGBridge/` in your server directory.
4. A `config.yml` is just a [valid YAML](https://en.wikipedia.org/wiki/YAML) file, alternative for JSON, but more human-readable.
Now, take bot's __username__ and __token__ which you got in 2nd step and paste them into `config.yml`, so it looks like this:
Now, take bot's __token__ which you got in 2nd step and paste them into `config.yml`, so it looks like this:
```yaml
botToken: abcdefghijklmnopq123123123
botUsername: my_awesome_spigot_bot
# other configuration values...
```
@ -25,7 +24,6 @@
6. Add you bot to chats, where you plan to use it. In each of them, run `/chat_id` command. The bot should respond and give special value - __chat id__. Now, open `config.yml` and paste this ID under `chats` section, so it will look like this:
```yaml
botToken: abcdefghijklmnopq123123123
botUsername: my_awesome_spigot_bot
chats:
# Note about doubling minus sign. This is not a mistake, first one means list element, the second one - actual minus
- -123456789
@ -47,7 +45,6 @@ P. S. You can always update plugin configuration without restarting the server.
|:-----:|:------------|:----:|:--------:|:-------:|
| enable | If plugin should be enabled | `boolean` | :x: | `true` |
| botToken | Telegram bot token ([How to create bot](https://core.telegram.org/bots#3-how-do-i-create-a-bot)) | `string` | :heavy_check_mark: | - |
| botUsername | Telegram bot username | `string` | :heavy_check_mark: | - |
| chats | Chats, where bot will work (to prevent using bot by unknown chats) | `number[] or string[]` | :heavy_check_mark: | `[]` |
| serverStartMessage | What will be sent to chats when server starts | `string` | :x: | `'Server started.'` |
| serverStopMessage | What will be sent to chats when server stops | `string` | :x: | `'Server stopped.'` |

View File

@ -1,67 +0,0 @@
import org.yaml.snakeyaml.Yaml
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath group: 'org.yaml', name: 'snakeyaml', version: '1.26'
}
}
plugins {
id 'java'
id 'org.jetbrains.kotlin.jvm' version '1.3.60'
id 'com.github.johnrengelman.shadow' version '5.2.0'
}
group 'org.kraftwerk28'
def pluginConfigFile = new File("src/main/resources/plugin.yml").newInputStream()
def cfg = (Map<String, Object>)new Yaml().load(pluginConfigFile)
version cfg.get("version")
repositories {
maven {
url "https://hub.spigotmc.org/nexus/content/repositories/snapshots"
}
maven {
url "https://jitpack.io"
}
maven {
url "https://oss.sonatype.org/content/repositories/snapshots/"
}
mavenCentral()
jcenter()
}
def plugDir = "MinecraftServers/spigot_1.15.2/plugins/"
def homeDir = System.properties['user.home']
task cpArtifacts(type: Copy) {
from shadowJar
into "$homeDir/$plugDir"
}
shadowJar {
archiveClassifier = null
}
shadowJar.finalizedBy cpArtifacts
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
testImplementation group: 'junit', name: 'junit', version: '4.12'
compileOnly "org.spigotmc:spigot-api:1.15.2-R0.1-SNAPSHOT"
implementation 'com.vdurmont:emoji-java:5.1.1'
def tgBotVer = '5.0.0'
implementation "io.github.kotlin-telegram-bot.kotlin-telegram-bot:telegram:$tgBotVer"
// def ktorVersion = '1.3.2'
// implementation "io.ktor:ktor-server-core:$ktorVersion"
}
compileKotlin {
kotlinOptions.jvmTarget = "1.8"
}
compileTestKotlin {
kotlinOptions.jvmTarget = "1.8"
}

74
build.gradle.kts Normal file
View File

@ -0,0 +1,74 @@
import org.yaml.snakeyaml.Yaml
import java.io.*
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath(group = "org.yaml", name = "snakeyaml", version = "1.26")
}
}
plugins {
id("org.jetbrains.kotlin.jvm") version "1.4.31"
id("com.github.johnrengelman.shadow") version "5.2.0"
}
group = "org.kraftwerk28"
val cfg: Map<String, String> = Yaml().load(
FileInputStream("src/main/resources/plugin.yml")
)
val pluginVersion = cfg.get("version")
val spigotApiVersion = cfg.get("api-version")
version = pluginVersion as Any
repositories {
mavenCentral()
maven(
url = "https://hub.spigotmc.org/nexus/content/repositories/snapshots/"
)
maven(url = "https://jitpack.io")
maven(url = "https://oss.sonatype.org/content/repositories/snapshots/")
}
val tgBotVersion = "6.0.4"
val plugDir = "MinecraftServers/spigot_1.16.5/plugins/"
val homeDir = System.getProperty("user.home")
tasks {
named<ShadowJar>("shadowJar") {
archiveBaseName.set(
"spigot-tg-bridge-${spigotApiVersion}-v${pluginVersion}.jar"
)
}
}
tasks.register<Copy>("copyArtifacts") {
from(tasks.shadowJar)
into(File(homeDir, plugDir))
}
tasks.register("pack") {
dependsOn("shadowJar")
finalizedBy("copyArtifacts")
}
defaultTasks("pack")
dependencies {
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
compileOnly("org.spigotmc:spigot-api:$spigotApiVersion-R0.1-SNAPSHOT")
implementation(
"io.github.kotlin-telegram-bot.kotlin-telegram-bot" +
":telegram:$tgBotVersion"
)
implementation("com.vdurmont:emoji-java:5.1.1")
}
tasks.withType<KotlinCompile> {
kotlinOptions.jvmTarget = "1.8"
}

View File

@ -1,6 +1,5 @@
#Sat Feb 08 20:44:49 EET 2020
distributionUrl=https\://services.gradle.org/distributions/gradle-6.3-all.zip
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

53
gradlew vendored
View File

@ -1,5 +1,21 @@
#!/usr/bin/env sh
#
# Copyright 2015 the original author or authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
##############################################################################
##
## Gradle start up script for UN*X
@ -28,7 +44,7 @@ APP_NAME="Gradle"
APP_BASE_NAME=`basename "$0"`
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m"'
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD="maximum"
@ -66,6 +82,7 @@ esac
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
# Determine the Java command to use to start the JVM.
if [ -n "$JAVA_HOME" ] ; then
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
@ -109,10 +126,11 @@ if $darwin; then
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
fi
# For Cygwin, switch paths to Windows format before running java
if $cygwin ; then
# For Cygwin or MSYS, switch paths to Windows format before running java
if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
JAVACMD=`cygpath --unix "$JAVACMD"`
# We build the pattern for arguments to be converted via cygpath
@ -138,19 +156,19 @@ if $cygwin ; then
else
eval `echo args$i`="\"$arg\""
fi
i=$((i+1))
i=`expr $i + 1`
done
case $i in
(0) set -- ;;
(1) set -- "$args0" ;;
(2) set -- "$args0" "$args1" ;;
(3) set -- "$args0" "$args1" "$args2" ;;
(4) set -- "$args0" "$args1" "$args2" "$args3" ;;
(5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
(6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
(7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
(8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
(9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
0) set -- ;;
1) set -- "$args0" ;;
2) set -- "$args0" "$args1" ;;
3) set -- "$args0" "$args1" "$args2" ;;
4) set -- "$args0" "$args1" "$args2" "$args3" ;;
5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
esac
fi
@ -159,14 +177,9 @@ save () {
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
echo " "
}
APP_ARGS=$(save "$@")
APP_ARGS=`save "$@"`
# Collect all arguments for the java command, following the shell quoting and substitution rules
eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
cd "$(dirname "$0")"
fi
exec "$JAVACMD" "$@"

43
gradlew.bat vendored
View File

@ -1,3 +1,19 @@
@rem
@rem Copyright 2015 the original author or authors.
@rem
@rem Licensed under the Apache License, Version 2.0 (the "License");
@rem you may not use this file except in compliance with the License.
@rem You may obtain a copy of the License at
@rem
@rem https://www.apache.org/licenses/LICENSE-2.0
@rem
@rem Unless required by applicable law or agreed to in writing, software
@rem distributed under the License is distributed on an "AS IS" BASIS,
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@rem See the License for the specific language governing permissions and
@rem limitations under the License.
@rem
@if "%DEBUG%" == "" @echo off
@rem ##########################################################################
@rem
@ -13,15 +29,18 @@ if "%DIRNAME%" == "" set DIRNAME=.
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%
@rem Resolve any "." and ".." in APP_HOME to make it shorter.
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS="-Xmx64m"
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
@rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome
set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if "%ERRORLEVEL%" == "0" goto init
if "%ERRORLEVEL%" == "0" goto execute
echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
@ -35,7 +54,7 @@ goto fail
set JAVA_HOME=%JAVA_HOME:"=%
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
if exist "%JAVA_EXE%" goto init
if exist "%JAVA_EXE%" goto execute
echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
@ -45,28 +64,14 @@ echo location of your Java installation.
goto fail
:init
@rem Get command-line arguments, handling Windows variants
if not "%OS%" == "Windows_NT" goto win9xME_args
:win9xME_args
@rem Slurp the command line arguments.
set CMD_LINE_ARGS=
set _SKIP=2
:win9xME_args_slurp
if "x%~1" == "x" goto execute
set CMD_LINE_ARGS=%*
:execute
@rem Setup the command line
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
@rem Execute Gradle
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
:end
@rem End local scope for the variables with windows NT shell

View File

@ -14,4 +14,4 @@ class Commands(yamlCfg: YamlConfiguration) {
chatID = getString("commands.chat_id")
}
}
}
}

View File

@ -4,7 +4,7 @@ import org.bukkit.configuration.file.YamlConfiguration
import java.io.File
import org.kraftwerk28.spigot_tg_bridge.Constants as C
class Configuration(plugin: Plugin) {
class Configuration {
private lateinit var yamlCfg: YamlConfiguration
var isEnabled: Boolean = false
@ -16,7 +16,6 @@ class Configuration(plugin: Plugin) {
// Telegram bot stuff
var botToken: String = ""
var botUsername: String = ""
var allowedChats: List<Long> = listOf()
var logFromTGtoMC: Boolean = false
var allowWebhook: Boolean = false
@ -32,16 +31,12 @@ class Configuration(plugin: Plugin) {
lateinit var commands: Commands
init {
reload(plugin)
}
fun reload(plugin: Plugin) {
val cfgFile = File(plugin.dataFolder, C.configFilename);
if (!cfgFile.exists()) {
cfgFile.parentFile.mkdirs()
plugin.saveResource(C.configFilename, false);
throw Exception()
throw Exception(C.WARN.noConfigWarning)
}
yamlCfg = YamlConfiguration()
@ -56,10 +51,7 @@ class Configuration(plugin: Plugin) {
allowedChats = getLongList("chats")
serverStartMessage = getString("serverStartMessage")
serverStopMessage = getString("serverStopMessage")
botToken = getString("botToken") ?: throw Exception(C.WARN.noToken)
botUsername = getString("botUsername") ?: throw Exception(C.WARN.noUsername)
allowWebhook = getBoolean("useWebhook", false)
val whCfg = get("webhookConfig")
if (whCfg is Map<*, *>) {
@ -79,4 +71,6 @@ class Configuration(plugin: Plugin) {
commands = Commands(yamlCfg)
}
}
fun load(plugin: Plugin) = reload(plugin)
}

View File

@ -9,42 +9,43 @@ import org.bukkit.event.player.PlayerJoinEvent
import org.bukkit.event.player.PlayerQuitEvent
class EventHandler(
private val plugin: Plugin,
private val tgBot: TgBot,
private val config: Configuration
) : Listener {
@EventHandler
fun onPlayerChat(event: AsyncPlayerChatEvent) {
if (config.logFromMCtoTG) {
plugin.tgBot.sendMessageToTGFrom(
event.player.displayName, event.message
if (!config.logFromMCtoTG) return
event.run {
tgBot.sendMessageToTelegram(
message, player.displayName
)
}
}
@EventHandler
fun onPlayerJoin(event: PlayerJoinEvent) {
if (!config.logJoinLeave || config.joinString == null) return
val username = TgBot.fullEscape(event.player.displayName)
if (!config.logJoinLeave || config.joinString == null) return
val username = fullEscape(event.player.displayName)
val text = config.joinString!!.replace("%username%", username)
plugin.tgBot.broadcastToTG(text)
tgBot.sendMessageToTelegram(text)
}
@EventHandler
fun onPlayerLeave(event: PlayerQuitEvent) {
if (!config.logJoinLeave || config.leaveString == null) return
val username = TgBot.fullEscape(event.player.displayName)
val username = fullEscape(event.player.displayName)
val text = config.leaveString!!.replace("%username%", username)
plugin.tgBot.broadcastToTG(text)
tgBot.sendMessageToTelegram(text)
}
@EventHandler
fun onPlayerDied(event: PlayerDeathEvent) {
if (!config.logDeath) return
event.deathMessage?.let {
val username = TgBot.fullEscape(event.entity.displayName)
val username = fullEscape(event.entity.displayName)
val text = it.replace(username, "<i>$username</i>")
plugin.tgBot.broadcastToTG(text)
tgBot.sendMessageToTelegram(text)
}
}
@ -53,6 +54,6 @@ class EventHandler(
if (!config.logPlayerAsleep) return
if (event.bedEnterResult != PlayerBedEnterEvent.BedEnterResult.OK) return
val text = "<i>${event.player.displayName}</i> fell asleep."
plugin.tgBot.broadcastToTG(text)
tgBot.sendMessageToTelegram(text)
}
}
}

View File

@ -7,60 +7,56 @@ import org.kraftwerk28.spigot_tg_bridge.Constants as C
class Plugin : JavaPlugin() {
lateinit var tgBot: TgBot
lateinit var config: Configuration
var tgBot: TgBot? = null
val config: Configuration = Configuration()
override fun onEnable() {
try {
config = Configuration(this)
config.load(this)
} catch (e: Exception) {
logger.warning(C.WARN.noConfigWarning)
logger.warning(e.message)
return
}
if (!config.isEnabled) return
if (!config.isEnabled)
return
val cmdHandler = CommandHandler(this)
val eventHandler = EventHandler(this, config)
tgBot = TgBot(this, config)
getCommand(C.COMMANDS.PLUGIN_RELOAD)?.setExecutor(cmdHandler)
val eventHandler = EventHandler(tgBot!!, config)
server.pluginManager.registerEvents(eventHandler, this)
// Notify Telegram groups about server start
config.serverStartMessage?.let {
tgBot.broadcastToTG(it)
config.serverStartMessage?.let { message ->
tgBot?.sendMessageToTelegram(message)
}
logger.info("Plugin started.")
}
override fun onDisable() {
if (!config?.isEnabled) return
config.serverStopMessage?.let {
tgBot.broadcastToTG(it)
if (!config.isEnabled) return
config.serverStopMessage?.let { message ->
tgBot?.sendMessageToTelegram(message)
}
logger.info("Plugin stopped.")
}
fun sendMessageToMC(text: String) {
val prep = EmojiParser.parseToAliases(text)
server.broadcastMessage(prep)
}
fun sendMessageToMCFrom(username: String, text: String) {
val prepared = config.telegramMessageFormat
.replace(C.USERNAME_PLACEHOLDER, emojiEsc(username))
.replace(C.MESSAGE_TEXT_PLACEHOLDER, emojiEsc(text))
fun sendMessageToMinecraft(text: String, username: String? = null) {
var prepared = config.telegramMessageFormat
.replace(C.MESSAGE_TEXT_PLACEHOLDER, escapeEmoji(text))
username?.let {
prepared = prepared
.replace(C.USERNAME_PLACEHOLDER, escapeEmoji(it))
}
server.broadcastMessage(prepared)
}
fun emojiEsc(text: String) = EmojiParser.parseToAliases(text)
fun reload() {
logger.info(C.INFO.reloading)
config.reload(this)
tgBot.stop()
tgBot.start(this, config)
tgBot?.stop()
tgBot?.start(this, config)
logger.info(C.INFO.reloadComplete)
}
}

View File

@ -6,20 +6,11 @@ import com.github.kotlintelegrambot.dispatcher.text
import com.github.kotlintelegrambot.entities.BotCommand
import com.github.kotlintelegrambot.entities.ParseMode
import com.github.kotlintelegrambot.entities.Update
import com.github.kotlintelegrambot.entities.User
import com.github.kotlintelegrambot.logging.LogLevel
import com.github.kotlintelegrambot.entities.ChatId
import okhttp3.logging.HttpLoggingInterceptor
import org.kraftwerk28.spigot_tg_bridge.Constants as C
fun Bot.skipUpdates(lastUpdateID: Long = 0) {
val newUpdates = getUpdates(lastUpdateID)
if (newUpdates.isNotEmpty()) {
val lastUpd = newUpdates.last()
if (lastUpd !is Update) return
return skipUpdates(lastUpd.updateId + 1)
}
}
class TgBot(private val plugin: Plugin, private val config: Configuration) {
private lateinit var bot: Bot
@ -35,9 +26,9 @@ class TgBot(private val plugin: Plugin, private val config: Configuration) {
skipUpdates()
bot = bot {
token = config.botToken
logLevel = HttpLoggingInterceptor.Level.NONE
logLevel = LogLevel.None
val cmdBinding = commands.let {
val commandBindings = commands.let {
mapOf(
it.time to ::time,
it.online to ::online,
@ -46,10 +37,12 @@ class TgBot(private val plugin: Plugin, private val config: Configuration) {
}.filterKeys { it != null }
dispatch {
cmdBinding.forEach { (text, handler) ->
command(text!!.replace(slashRegex, ""), handler)
commandBindings.forEach { (text, handler) ->
command(text!!.replace(slashRegex, "")) {
handler(update)
}
}
text(null, ::onText)
text { onText(update) }
}
}
bot.setMyCommands(getBotCommands())
@ -65,7 +58,7 @@ class TgBot(private val plugin: Plugin, private val config: Configuration) {
bot.stopPolling()
}
private fun time(bot: Bot, update: Update) {
private fun time(update: Update) {
val msg = update.message!!
if (!config.allowedChats.contains(msg.chat.id)) {
return
@ -73,7 +66,7 @@ class TgBot(private val plugin: Plugin, private val config: Configuration) {
if (plugin.server.worlds.isEmpty()) {
bot.sendMessage(
msg.chat.id,
ChatId.fromId(msg.chat.id),
"No worlds available",
replyToMessageId = msg.messageId
)
@ -90,13 +83,14 @@ class TgBot(private val plugin: Plugin, private val config: Configuration) {
} + " ($t)"
bot.sendMessage(
msg.chat.id, text,
ChatId.fromId(msg.chat.id),
text,
replyToMessageId = msg.messageId,
parseMode = ParseMode.HTML
)
}
private fun online(bot: Bot, update: Update) {
private fun online(update: Update) {
val msg = update.message!!
if (!config.allowedChats.contains(msg.chat.id)) {
return
@ -111,13 +105,14 @@ class TgBot(private val plugin: Plugin, private val config: Configuration) {
if (playerList.isNotEmpty()) "${config.onlineString}:\n$playerStr"
else config.nobodyOnlineString
bot.sendMessage(
msg.chat.id, text,
ChatId.fromId(msg.chat.id),
text,
replyToMessageId = msg.messageId,
parseMode = ParseMode.HTML
)
}
private fun chatID(bot: Bot, update: Update) {
private fun chatID(update: Update) {
val msg = update.message!!
val chatID = msg.chat.id
val text = """
@ -127,46 +122,49 @@ class TgBot(private val plugin: Plugin, private val config: Configuration) {
""".trimIndent() +
"\n\n<code>chats:\n # other ids...\n - ${chatID}</code>"
bot.sendMessage(
chatID,
ChatId.fromId(chatID),
text,
parseMode = ParseMode.HTML,
replyToMessageId = msg.messageId
)
}
fun broadcastToTG(text: String) {
fun sendMessageToTelegram(text: String, username: String? = null) {
config.allowedChats.forEach { chatID ->
bot.sendMessage(chatID, text, parseMode = ParseMode.HTML)
username?.let {
bot.sendMessage(
ChatId.fromId(chatID),
formatMsgFromMinecraft(username, text),
parseMode = ParseMode.HTML,
)
} ?: run {
bot.sendMessage(
ChatId.fromId(chatID),
text,
parseMode = ParseMode.HTML,
)
}
}
}
fun sendMessageToTGFrom(username: String, text: String) {
config.allowedChats.forEach { chatID ->
bot.sendMessage(
chatID,
messageFromMinecraft(username, text),
parseMode = ParseMode.HTML
)
}
}
private fun onText(bot: Bot, update: Update) {
private fun onText(update: Update) {
if (!config.logFromTGtoMC) return
val msg = update.message!!
if (msg.text!!.startsWith("/")) return // Suppress command forwarding
plugin.sendMessageToMCFrom(rawUserMention(msg.from!!), msg.text!!)
// Suppress commands to be sent to Minecraft
if (msg.text!!.startsWith("/")) return
plugin.sendMessageToMinecraft(msg.text!!, rawUserMention(msg.from!!))
}
private fun messageFromMinecraft(username: String, text: String): String =
private fun formatMsgFromMinecraft(
username: String,
text: String
): String =
config.minecraftMessageFormat
.replace("%username%", fullEscape(username))
.replace("%message%", escapeHTML(text))
private fun rawUserMention(user: User): String =
(if (user.firstName.length < 2) null else user.firstName)
?: user.username
?: user.lastName!!
private fun getBotCommands(): List<BotCommand> {
val cmdList = config.commands.run { listOfNotNull(time, online, chatID) }
val descList = C.COMMAND_DESC.run { listOf(timeDesc, onlineDesc, chatIDDesc) }
@ -174,21 +172,11 @@ class TgBot(private val plugin: Plugin, private val config: Configuration) {
}
private fun skipUpdates() {
// Creates a temporary bot w/ 0 timeout to skip updates
bot {
token = config.botToken
timeout = 0
logLevel = HttpLoggingInterceptor.Level.NONE
logLevel = LogLevel.None
}.skipUpdates()
}
companion object {
fun escapeHTML(s: String) = s
.replace("&", "&amp;")
.replace(">", "&gt;")
.replace("<", "&lt;")
fun escapeColorCodes(s: String) = s.replace("\u00A7.".toRegex(), "")
fun fullEscape(s: String) = escapeColorCodes(escapeHTML(s))
}
}
}

View File

@ -0,0 +1,35 @@
package org.kraftwerk28.spigot_tg_bridge
import com.github.kotlintelegrambot.Bot
import com.github.kotlintelegrambot.entities.Update
import com.github.kotlintelegrambot.entities.User
import com.vdurmont.emoji.EmojiParser
fun Bot.skipUpdates(lastUpdateID: Long = 0) {
val newUpdates = getUpdates(lastUpdateID)
if (newUpdates.isNotEmpty()) {
val lastUpd = newUpdates.last()
if (lastUpd !is Update) return
return skipUpdates(lastUpd.updateId + 1)
}
}
fun String.escapeHtml() =
this.replace("&", "&amp;").replace(">", "&gt;").replace("<", "&lt;")
fun escapeHTML(s: String) = s
.replace("&", "&amp;")
.replace(">", "&gt;")
.replace("<", "&lt;")
fun escapeColorCodes(s: String) = s.replace("\u00A7.".toRegex(), "")
fun fullEscape(s: String) = escapeColorCodes(escapeHTML(s))
fun escapeEmoji(text: String) = EmojiParser.parseToAliases(text)
fun rawUserMention(user: User): String =
(if (user.firstName.length < 2) null else user.firstName)
?: user.username
?: user.lastName!!

View File

@ -1,6 +1,5 @@
enable: true
botToken: abcdef123456789
botUsername: sample_username
chats:
- -1234567890123
serverStartMessage: 'Server started.'

View File

@ -1,5 +1,5 @@
name: SpigotTGBridge
version: 0.0.14
version: 0.0.16
api-version: '1.15'
main: org.kraftwerk28.spigot_tg_bridge.Plugin
description: Telegram <-> Minecraft communication plugin for Spigot.