blob: 6f8251307f9e39e30f1bc7e87cbe43498292fc79 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
object Main {
import org.slf4j._
import sx.blah.discord._
val logger = LoggerFactory getLogger Main.getClass
def main(args: Array[String]) = {
import api._
val client = (new ClientBuilder withLogin (Config \ "username", Config \ "password")).login
client.getDispatcher registerListener EventHandler
}
}
object Config {
import scala.io.Source
import org.yaml.snakeyaml._
import scala.collection._
import scala.collection.JavaConverters._
import java.util.{Map => JMap}
lazy val yaml: Map[String, Any] = ((new Yaml) load (Source fromFile "config.yml").mkString).asInstanceOf[JMap[String, Any]].asScala
import scala.reflect.runtime.universe._
def \[T: TypeTag](item: String): T = (yaml get item) match {
case Some(x: String) if typeOf[T] <:< typeOf[Int] => x.toInt.asInstanceOf[T]
case Some(x) => x.asInstanceOf[T]
case None => throw new IllegalStateException(s"Config had no value for '$item'.")
}
}
|