Changed interface to lenovo.

This commit is contained in:
Pavel Kachalouski
2018-05-25 20:44:09 +02:00
parent 9e845d29c6
commit 7bfd8ae49f
4 changed files with 11 additions and 53 deletions

5
.idea/codeStyles/codeStyleConfig.xml generated Normal file
View File

@@ -0,0 +1,5 @@
<component name="ProjectCodeStyleConfiguration">
<state>
<option name="PREFERRED_PROJECT_CODE_STYLE" value="Leveris-scala" />
</state>
</component>

View File

@@ -40,9 +40,9 @@ class TelegramBotServer(botId: String, port: Int, httpsContext: Option[HttpsConn
private val http: HttpExt = Http()
private val hookId = UUID.randomUUID().toString
private val webhookUri = Uri(s"https://xeppaka.eu:$port/$hookId")
private val webhookUri = Uri(s"https://xeppaka.eu:88/$hookId")
private val bindingFuture = http.bindAndHandle(botRoutes(hookId),
"pkcloud",
"lenovo",
port,
connectionContext = httpsContext.getOrElse(http.defaultClientHttpsContext))
@@ -65,7 +65,7 @@ class TelegramBotServer(botId: String, port: Int, httpsContext: Option[HttpsConn
def botRoutes(hookId: String): Route = {
path(hookId) {
post {
entity(as[Update]) { update =>
entity(as[Update]) { _ =>
handleWith(receivedUpdate)
}
}
@@ -146,7 +146,7 @@ object TelegramBotServer {
def main(args: Array[String]): Unit = {
val httpsContext = createHttpsConnectionContext
val tbs = TelegramBotServer(88, Some(createHttpsConnectionContext))
val tbs = TelegramBotServer(8443, Some(createHttpsConnectionContext))
StdIn.readLine()
tbs.stop()

View File

@@ -4,19 +4,14 @@ import akka.actor.typed.scaladsl.Behaviors
import akka.actor.typed.{ActorRef, Behavior}
object ChatActor {
sealed trait ChatCommand {
def replyTo: ActorRef[Response]
}
case class Response(text: String)
case class Help(replyTo: ActorRef[Response]) extends ChatCommand
case class Start(replyTo: ActorRef[Response]) extends ChatCommand
case class MessageReceived(text: String, replyTo: ActorRef[Response]) extends ChatCommand
case class Stop(replyTo: ActorRef[Response]) extends ChatCommand
private val started: Behavior[ChatCommand] = Behaviors.receive { (ctx, msg) =>
@@ -33,7 +28,7 @@ object ChatActor {
case _ =>
Behaviors.unhandled
}
}
}
private val initial: Behavior[ChatCommand] = Behaviors.receive { (ctx, msg) =>
msg match {
@@ -44,7 +39,7 @@ object ChatActor {
c.replyTo ! Response("Only /start command is supported. Try it...")
Behaviors.same
}
}
}
private def replyHelp(replyTo: ActorRef[Response]): Unit = {
replyTo ! Response("No help is provided for such motherfuckers like you! But... ok, send /stop and we are free.")

View File

@@ -1,42 +0,0 @@
package eu.xeppaka.bot1.actors
import akka.actor.{Actor, ActorLogging, Props}
import akka.http.scaladsl.HttpExt
import akka.http.scaladsl.model.{ContentTypes, HttpEntity, HttpMethods, HttpRequest}
import akka.util.ByteString
import eu.xeppaka.bot1.TelegramEntities.SendMessage
import eu.xeppaka.bot1.{BotUri, TelegramEntities}
class UpdateActor2 extends Actor with ActorLogging {
import UpdateActor2.ReceivedUpdate
override def receive: Receive = {
case ReceivedUpdate(update) => processUpdate(update)
}
private def processUpdate(update: TelegramEntities.Update) = {
log.info(s"Received update: $update")
if (update.message.isDefined) {
processMessage(update.message.get)
}
}
private def processMessage(message: TelegramEntities.Message) = {
import io.circe._, io.circe.generic.auto._, io.circe.syntax._
// log.info("Received message from: {}", message.from)
// val sendMessage = SendMessage(message.chat.id, s"Привет, ${message.from.get.first_name}")
// val printer = Printer.noSpaces.copy(dropNullValues = true)
// val json = printer.pretty(sendMessage.asJson)
// val request = HttpRequest(HttpMethods.POST, uri = botUri.sendMessage, entity = HttpEntity.Strict(ContentTypes.`application/json`, ByteString(json)))
// http.singleRequest(request)
}
}
object UpdateActor2 {
case class ReceivedUpdate(update: TelegramEntities.Update)
def props(): Props = Props(new UpdateActor2())
}