https://github.com/nolequen/icq-bot-core
Kotlin core interface to ICQ Bot API
https://github.com/nolequen/icq-bot-core
api bot icq instant-messaging kotlin
Last synced: 6 months ago
JSON representation
Kotlin core interface to ICQ Bot API
- Host: GitHub
- URL: https://github.com/nolequen/icq-bot-core
- Owner: nolequen
- License: mit
- Created: 2018-12-17T19:29:30.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2019-06-09T10:20:16.000Z (about 7 years ago)
- Last Synced: 2023-07-07T14:40:46.504Z (almost 3 years ago)
- Topics: api, bot, icq, instant-messaging, kotlin
- Language: Kotlin
- Homepage:
- Size: 85.9 KB
- Stars: 0
- Watchers: 4
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# ICQ Bot Core
[](https://maven-badges.herokuapp.com/maven-central/su.nlq/icq-bot-core)
[](https://travis-ci.org/nolequen/icq-bot-core)
[](https://codecov.io/gh/nolequen/icq-bot-core)
[](https://codebeat.co/a/nolequen/projects/github-com-nolequen-icq-bot-core-master)
Easy interface to ICQ Bot API powered by Kotlin.
## Getting started
* Create your own bot by sending the `/newbot` command to [MegaBot](https://icq.com/people/70001) and follow the instructions
* Note a bot can only reply after the user has added it contact list, or if the user was the first to start a conversation
## Usage
You can find latest release on Maven Central:
* Maven:
```xml
su.nlq
icq-bot-core
1.2.1
```
* Gradle:
```kotlin
compile("su.nlq:icq-bot-core:1.2.1")
```
## How-To
The only thing you should know to create a new bot is token:
```kotlin
val bot = Bot("001.1234567890.1234567890:123456789")
```
### Contacts and messages
To be able to send a message you should create a conversation (no matter is it chat or dialogue):
```kotlin
val penpal = PenPal("42")
val conversation = bot.conversation(penpal)
// not neccessary but looks nice to set typing status
conversation.typing()
conversation.message("Hi, how are you?")
```
It is possible to operate the contact list, for example:
```kotlin
bot.contacts().all().onSuccess { buddies ->
buddies.find { it.name == "Adolf" }?.apply { remove() }
}
```
### Chats
To get any chat information you want is neccessary to create a chat instance:
```kotlin
val chat = bot.chat("123456789@chat.agent")
chat.description().onSuccess {
println("Chat \"${it.name}\" was created ${it.created} by ${it.creator}")
}
```
There are various actions you can do with chat members or history, e.g.:
```kotlin
chat.invite(listOf(PenPal("42")))
chat.members().onSuccess { members -> members.forEach { it.block() } }
chat.history(0, 10).onSuccess { history ->
history.messages.forEach { println("${it.id}: $it") }
val message = history.messages[0]
if (message is Chat.Text) {
message.pin()
}
}
```
### Files
It is possible to get the file info, upload or download the file:
```kotlin
val files = bot.files()
files.upload(File("myfile.txt")).map { URL(it) }.onSuccess { url ->
files.download(url)
.map { it.toInputStream() }
.onSuccess { stream ->
println(stream.use { String(it.readAllBytes()) })
}
}
```