Skip to content

Commit

Permalink
configurator: Release version 1.0
Browse files Browse the repository at this point in the history
tgbotter: Move project
  • Loading branch information
Com6235 committed May 21, 2024
1 parent adf8d9b commit e6bdc9b
Show file tree
Hide file tree
Showing 21 changed files with 552 additions and 228 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on:
- main

jobs:
publish:
publish-and-test:
runs-on: ubuntu-latest
permissions:
contents: write
Expand All @@ -26,6 +26,9 @@ jobs:
- name: Generate and submit dependency graph
uses: gradle/actions/dependency-submission@v3

- name: Test
run: ./gradlew test

- name: Publish package
run: ./gradlew publish
env:
Expand Down
160 changes: 15 additions & 145 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
# Tgbotter
# Maven-Libs

A Kotlin framework for creating telegram bots with ease. Made using [official Telegram Bots Java API](https://github.com/rubenlagus/TelegramBots).
A collection of my libraries for Java/Kotlin.
All packages will be published to [GitHub Packages](https://docs.github.com/ru/packages/working-with-a-github-packages-registry/working-with-the-apache-maven-registry#authenticating-with-a-personal-access-token),
so you can see all my libs in one place.

Latest version: https://github.com/Com6235/tgBotter/packages/2135012
## Using my libs

## Installation
### Maven
Since the packages are hosted on GitHub Packages, to download them,
you will need to add my GitHub Packages Maven repository to your repositories:

### In Maven
To add repositories in Maven, you need to edit your `~\.m2\settings.xml`

Since the packages are hosted on GitHub Packages, to download them, you will need to add my GitHub Packages Maven repository to your `~\.m2\settings.xml`
It should look something like this:
```xml
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
Expand All @@ -26,7 +30,7 @@ It should look something like this:
<!-- other repos -->
<repository>
<id>github tgbotter repository</id>
<url>https://maven.pkg.github.com/com6235/tgbotter</url>
<url>https://maven.pkg.github.com/com6235/maven-libs</url>
</repository>
<!-- other repos -->
</repositories>
Expand All @@ -43,28 +47,13 @@ It should look something like this:
</settings>
```

Your token MUST be a [classic token](https://github.com/settings/tokens), and it MUST have a `read:packages` permission

After you added the repository, you can start using my package by adding this to your `pom.xml`
```xml
<dependency>
<groupId>io.github.com6235</groupId>
<artifactId>tgbotter</artifactId>
<version>${your desired version}</version>
</dependency>
```

More information on GitHub Packages Maven Registry is [here](https://docs.github.com/ru/packages/working-with-a-github-packages-registry/working-with-the-apache-maven-registry#authenticating-with-a-personal-access-token)

### Gradle

Since the packages are hosted on GitHub Packages, to download them, you will need to add my GitHub Packages Maven repository to your `repositories`:
### In Gradle

In `build.gradle.kts`:
```kotlin
repositories {
maven {
url = uri("https://maven.pkg.github.com/com6235/tgbotter")
url = uri("https://maven.pkg.github.com/com6235/maven-libs")
credentials {
// this is just example code, you can change it to just strings if you are not going to publish your code
username = project.findProperty("gpr.user") as String? ?: System.getenv("USERNAME") // your GitHub username
Expand All @@ -78,7 +67,7 @@ In `build.gradle`:
```groovy
repositories {
maven {
url = uri("https://maven.pkg.github.com/com6235/tgbotter")
url = uri("https://maven.pkg.github.com/com6235/maven-libs")
credentials {
// this is just example code, you can change it to just strings if you are not going to publish your code
username = project.findProperty("gpr.user") ?: System.getenv("USERNAME") // your GitHub username
Expand All @@ -87,123 +76,4 @@ repositories {
}
}
```
Your token MUST be a [classic token](https://github.com/settings/tokens), and it MUST have a `read:packages` permission

After you added the repository, you can start using my package by adding this to `dependencies`:

In `build.gradle.kts`:
```kotlin
dependencies {
implementation("io.github.com6235:tgbotter:${your desired version}")
}
```

In `build.gradle`:
```groovy
dependencies {
implementation 'io.github.com6235:tgbotter:${your desired version}'
}
```

## Examples

### Echo bot

```kotlin
import io.github.com6235.tgbotter.*
import org.telegram.telegrambots.meta.api.methods.send.SendMessage
import org.telegram.telegrambots.meta.api.objects.message.Message
import org.telegram.telegrambots.meta.generics.TelegramClient

fun main() {
// Create a LongPollingBot
val bot = LongPollingBot(BotCreationOptions("your token"))

// Add a listener
bot.addListener(Handler())

// Start the bot
bot.start()
}

// Define a listener
class Handler : Listener {
// Make an event handler
override fun onMessage(message: Message, telegramClient: TelegramClient) {
// Send a message using telegramClient
telegramClient.execute(
SendMessage.builder().text(message.text).chatId(message.chatId).replyToMessageId(message.messageId).build()
)
}
}
```

### Using the command handler

```kotlin
import io.github.com6235.tgbotter.*
import org.telegram.telegrambots.meta.api.methods.send.SendMessage

fun main() {
// Create a LongPollingBot
val bot = LongPollingBot(BotCreationOptions("your token"))

// Add commands
bot.commandManager.addCommand(
Command("start") { handleStart(this) }
)
bot.commandManager.addCommand(
Command("help") { handleInfo(this) }
)

// Start the bot
bot.start()
}

fun handleStart(commandHandler: CommandHandler) {
commandHandler.telegramClient.execute(
SendMessage.builder()
.chatId(commandHandler.message.chatId)
.text("Hello! Send /help to view the help page.")
.build()
)
}

fun handleInfo(commandHandler: CommandHandler) {
commandHandler.telegramClient.execute(
SendMessage.builder()
.chatId(commandHandler.message.chatId)
.text("A very useful help page!")
.build()
)
}
```

## Building from sources

### Requirements

- JDK 17
- [GnuPG](https://www.gnupg.org/) (for signing publications)

### Building the project

Use commands
```bash
.\gradlew build
.\gradlew sourcesJar
.\gradlew dokkaJavadocJar
```
to build all the needed jar-files, or you can do:
```bash
.\gradlew signKotlinPublication
```
to automatically build and sign everything

### Publishing to local Maven repository

Use command
```bash
.\gradlew publishToMavenLocal
```
to publish all the [artifacts](#building-the-project) to your local Maven repository _(~/.m2/repository)_
Your token MUST be a [classic token](https://github.com/settings/tokens), and it MUST have `read:packages` scope
131 changes: 53 additions & 78 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,12 @@ plugins {
}

group = "io.github.com6235"
version = "1.0.3"
version = "root"

repositories {
mavenCentral()
}

dependencies {
testImplementation(kotlin("test"))

implementation("org.telegram:telegrambots-longpolling:7.2.1")
implementation("org.telegram:telegrambots-webhook:7.2.1")
implementation("org.telegram:telegrambots-client:7.2.1")
api("org.telegram:telegrambots-meta:7.2.1")

implementation("org.slf4j:slf4j-api:2.0.13")
}

tasks.test {
useJUnitPlatform()
}
Expand All @@ -41,84 +30,70 @@ idea {
}
}

tasks.register<Jar>("dokkaJavadocJar") {
dependsOn(tasks.dokkaJavadoc)
from(tasks.dokkaJavadoc.flatMap { it.outputDirectory })
archiveClassifier.set("javadoc")
}
subprojects {
apply(plugin = "org.jetbrains.kotlin.jvm")
apply(plugin = "org.jetbrains.dokka")
apply(plugin = "idea")
apply(plugin = "maven-publish")
apply(plugin = "signing")

tasks.register<Jar>("sourcesJar") {
from(sourceSets.main.get().allSource)
archiveClassifier.set("sources")
}
repositories {
mavenCentral()
}

configurations {
create("javadoc")
create("sources")
}
tasks.test {
useJUnitPlatform()
}

val jdFile = layout.buildDirectory.file("libs/$name-$version-javadoc.jar")
val jdArtifact = artifacts.add("javadoc", jdFile.get().asFile) {
type = "jar"
builtBy("dokkaJavadocJar")
}
kotlin {
jvmToolchain(17)
}

val srcFile = layout.buildDirectory.file("libs/$name-$version-sources.jar")
val srcArtifact = artifacts.add("sources", srcFile.get().asFile) {
type = "jar"
builtBy("sourcesJar")
}
idea {
module {
isDownloadJavadoc = true
isDownloadSources = true
}
}

publishing {
publications {
create<MavenPublication>("kotlin") {
from(components["kotlin"])
artifact(jdArtifact)
artifact(srcArtifact)
pom {
packaging = "jar"
groupId = group.toString()
artifactId = project.name
version = project.version.toString()
name = "${group}:${project.name}"
description = "A framework for creating Telegram bots with ease. Made using official Telegram API"
url = "https://github.com/Com6235/tgBotter"
licenses {
license {
name = "MIT License"
url = "https://opensource.org/license/mit"
}
}
developers {
developer {
id = "com6235"
name = "Com6235"
}
}
scm {
connection = "scm:git:git://github.com/Com6235/tgBotter.git"
developerConnection = "scm:git:ssh://github.com:Com6235/tgBotter.git"
url = "https://github.com/Com6235/tgBotter"
tasks.register<Jar>("dokkaJavadocJar") {
group = "jar"
dependsOn(tasks.dokkaJavadoc)
from(tasks.dokkaJavadoc.flatMap { it.outputDirectory })
archiveClassifier.set("javadoc")
}

tasks.register<Jar>("sourcesJar") {
group = "jar"
from(sourceSets.main.get().allSource)
archiveClassifier.set("sources")
}

configurations {
create("javadoc")
create("sources")
}

publishing {
repositories {
maven {
name = "GitHubPackages"
url = URI("https://maven.pkg.github.com/com6235/maven-libs")
credentials {
username = System.getenv("GITHUB_ACTOR")
password = System.getenv("GITHUB_TOKEN")
}
}
}
}

repositories {
maven {
name = "GitHubPackages"
url = URI("https://maven.pkg.github.com/com6235/tgbotter")
credentials {
username = System.getenv("GITHUB_ACTOR")
password = System.getenv("GITHUB_TOKEN")
}
tasks.withType<PublishToMavenRepository> {
onlyIf {
!project.version.toString().endsWith("-SNAPSHOT")
}
}
}

signing {
if (System.getenv("IS_CI") == null) {
useGpgCmd()
sign(publishing.publications["kotlin"])
}
tasks.jar {
enabled = false
}
18 changes: 18 additions & 0 deletions configurator/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
group = "io.github.com6235"
version = "1.0"

plugins {
kotlin("plugin.serialization") version "2.0.0-RC3"
}

val serializationVersion = "1.6.3"

dependencies {
testImplementation(kotlin("test"))

implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:$serializationVersion")
implementation("org.jetbrains.kotlinx:kotlinx-serialization-hocon:$serializationVersion")
implementation("org.jetbrains.kotlinx:kotlinx-serialization-properties:$serializationVersion")
implementation("com.charleskorn.kaml:kaml:0.59.0")
implementation("net.peanuuutz.tomlkt:tomlkt:0.3.7")
}
Loading

0 comments on commit e6bdc9b

Please sign in to comment.