Git Product home page Git Product logo

icq-bot-core's Introduction

ICQ Bot Core

Maven Central Build Status Codecov Codebeat

Easy interface to ICQ Bot API powered by Kotlin.

Getting started

  • Create your own bot by sending the /newbot command to MegaBot 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:
<dependency>
  <groupId>su.nlq</groupId>
  <artifactId>icq-bot-core</artifactId>
  <version>1.2.1</version>
</dependency>
  • Gradle:
compile("su.nlq:icq-bot-core:1.2.1")

How-To

The only thing you should know to create a new bot is token:

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):

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:

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:

val chat = bot.chat("[email protected]")
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.:

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:

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()) })
    }
}

icq-bot-core's People

Contributors

nolequen avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

realeu

icq-bot-core's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.