Skip to content

Pure functional library for interacting with League of Legends chat servers.

License

Notifications You must be signed in to change notification settings

Thangiee/LoL-chat-lib

Repository files navigation

LoL Chat Lib

Codacy Badge Dependency Status

Pure functional library for interacting with League of Legends chat servers.

Setup

  • Import with SBT

    Projects that target a JVM supporting Java7+:

    resolvers += "jcenter" at "https://jcenter.bintray.com/"
    
    libraryDependencies ++= Seq(
      "org.igniterealtime.smack" % "smack-java7" % "4.1.7",
      "com.github.thangiee" %% "lol-chat-lib" % "0.3.0"
    ) 

    Projects that target android:

    resolvers += "jcenter" at "https://jcenter.bintray.com/"
    
    libraryDependencies ++= Seq(
      "org.igniterealtime.smack" % "smack-android" % "4.1.7",
      "com.github.thangiee" %% "lol-chat-lib" % "0.3.0"
    )

    For other build tools look here: https://github.com/igniterealtime/Smack/wiki/Smack-4.1-Readme-and-Upgrade-Guide

Usage

Import library

import lolchat._
import lolchat.model._

Create a session and login.

val sess = Session("username", "passwd", Region.NA)
LoLChat.run(login(sess))

You can combine multiple operations with for-comprehension.

val getFriends =
  for {
    _ <- login
    f <- friends
  } yield f

val result: ChatResult[Vector[Friend]] = LoLChat.run(getFriends(sess))

Notice resulting type. LoLChat.run(...) will return ChatResult[...] which is an asynchronous computation that can either be a ChatError type or some successful type determined by the operation (in this case Vector[Friend]).

With that said, you can handle errors that may occur like invalid credentials, connection issues, etc...

LoLChat.run(getFriends(sess)).fold(
  error   => println(error.msg),
  friends => friends.foreach(println)
)

See all operations for LoLChat HERE


Each Session also contains the following event streams:

  • Incoming message stream
sess.msgStream.foreach(msg => println(s"From summId:${msg.fromId} message:${msg.txt}"))
  • Friend list event stream
sess.friendListStream.foreach {
  case FriendAdded(summId)   =>
  case FriendRemoved(summId) =>
  case FriendRequest(summId) =>
  case FriendUpdated(friend) =>
}
  • Connection event Stream
sess.connectionEventStream.foreach {
  case ConnectionLost   =>
  case Reconnected      =>
  case ReconnectFailed  =>
  case ReconnectIn(sec) =>
}

About

Pure functional library for interacting with League of Legends chat servers.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages