mirror of
https://github.com/dyrkin/luxmed-bot.git
synced 2025-12-21 13:23:05 +01:00
Use scalafmt
This commit is contained in:
committed by
Yevhen Zadyra
parent
327bdfe6d7
commit
e870e404e1
@@ -1,11 +1,10 @@
|
||||
|
||||
package com.lbs.bot
|
||||
|
||||
import com.lbs.bot.model._
|
||||
import com.lbs.bot.telegram.TelegramBot
|
||||
import com.typesafe.scalalogging.LazyLogging
|
||||
|
||||
class Bot(telegram: TelegramBot /* other bots */) extends LazyLogging {
|
||||
class Bot(telegram: TelegramBot /* other bots */ ) extends LazyLogging {
|
||||
def sendMessage(source: MessageSource, text: String): Unit =
|
||||
resolveAdapter(source).sendMessage(source.chatId, text)
|
||||
|
||||
@@ -15,7 +14,12 @@ class Bot(telegram: TelegramBot /* other bots */) extends LazyLogging {
|
||||
def sendEditMessage(source: MessageSource, messageId: String, inlineKeyboard: Option[InlineKeyboard]): Unit =
|
||||
resolveAdapter(source).sendEditMessage(source.chatId, messageId, inlineKeyboard)
|
||||
|
||||
def sendEditMessage(source: MessageSource, messageId: String, text: String, inlineKeyboard: Option[InlineKeyboard] = None): Unit =
|
||||
def sendEditMessage(
|
||||
source: MessageSource,
|
||||
messageId: String,
|
||||
text: String,
|
||||
inlineKeyboard: Option[InlineKeyboard] = None
|
||||
): Unit =
|
||||
resolveAdapter(source).sendEditMessage(source.chatId, messageId, text, inlineKeyboard)
|
||||
|
||||
def sendFile(source: MessageSource, filename: String, contents: Array[Byte], caption: Option[String] = None): Unit =
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
package com.lbs.bot
|
||||
|
||||
import com.lbs.bot.model.{Event, InlineKeyboard}
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
package com.lbs.bot
|
||||
|
||||
import com.lbs.bot.model.Event
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
package com.lbs.bot.model
|
||||
|
||||
object Button {
|
||||
@@ -13,4 +12,4 @@ trait Button
|
||||
|
||||
class TaggedButton(val label: String, val tag: String) extends Button
|
||||
|
||||
class LabeledButton(val label: String) extends Button
|
||||
class LabeledButton(val label: String) extends Button
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
|
||||
package com.lbs.bot.model
|
||||
|
||||
case class Message(messageId: String, text: Option[String] = None)
|
||||
|
||||
case class Command(source: MessageSource, message: Message, callbackData: Option[String] = None)
|
||||
case class Command(source: MessageSource, message: Message, callbackData: Option[String] = None)
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
package com.lbs.bot.model
|
||||
|
||||
trait Event
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
package com.lbs.bot.model
|
||||
|
||||
case class InlineKeyboard(buttons: Seq[Seq[Button]])
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
package com.lbs.bot.model
|
||||
|
||||
case class MessageSource(sourceSystem: MessageSourceSystem, chatId: String)
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
package com.lbs.bot.model
|
||||
|
||||
trait MessageSourceSystem {
|
||||
@@ -10,10 +9,7 @@ trait MessageSourceSystem {
|
||||
}
|
||||
|
||||
object MessageSourceSystem {
|
||||
val MessageSourceSystems: Seq[MessageSourceSystem] = Seq(
|
||||
TelegramMessageSourceSystem,
|
||||
FacebookMessageSourceSystem
|
||||
)
|
||||
val MessageSourceSystems: Seq[MessageSourceSystem] = Seq(TelegramMessageSourceSystem, FacebookMessageSourceSystem)
|
||||
|
||||
private val MessageSourceSystemsMap = MessageSourceSystems.map(e => e.id -> e).toMap
|
||||
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
package com.lbs
|
||||
|
||||
import com.lbs.bot.model.{Button, InlineKeyboard}
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
package com.lbs.bot.telegram
|
||||
|
||||
import com.bot4s.telegram.models.InlineKeyboardMarkup
|
||||
@@ -18,10 +17,19 @@ class TelegramBot(onCommand: Command => Unit, botToken: String) extends PollBot[
|
||||
telegramBot.sendMessage(chatId.toLong, text, replyMarkup = buttons.map(_.mapTo[InlineKeyboardMarkup]))
|
||||
|
||||
def sendEditMessage(chatId: String, messageId: String, buttons: Option[InlineKeyboard]): Unit =
|
||||
telegramBot.sendEditMessage(chatId.toLong, messageId.toInt, replyMarkup = buttons.map(_.mapTo[InlineKeyboardMarkup]))
|
||||
telegramBot.sendEditMessage(
|
||||
chatId.toLong,
|
||||
messageId.toInt,
|
||||
replyMarkup = buttons.map(_.mapTo[InlineKeyboardMarkup])
|
||||
)
|
||||
|
||||
def sendEditMessage(chatId: String, messageId: String, text: String, buttons: Option[InlineKeyboard] = None): Unit =
|
||||
telegramBot.sendEditMessage(chatId.toLong, messageId.toInt, text, replyMarkup = buttons.map(_.mapTo[InlineKeyboardMarkup]))
|
||||
telegramBot.sendEditMessage(
|
||||
chatId.toLong,
|
||||
messageId.toInt,
|
||||
text,
|
||||
replyMarkup = buttons.map(_.mapTo[InlineKeyboardMarkup])
|
||||
)
|
||||
|
||||
def sendFile(chatId: String, filename: String, contents: Array[Byte], caption: Option[String] = None): Unit =
|
||||
telegramBot.sendFile(chatId.toLong, filename, contents, caption)
|
||||
@@ -29,4 +37,4 @@ class TelegramBot(onCommand: Command => Unit, botToken: String) extends PollBot[
|
||||
override protected def onReceive(command: TelegramEvent): Unit = {
|
||||
onCommand(command.mapTo[Command])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
package com.lbs.bot.telegram
|
||||
|
||||
import cats.implicits.toFunctorOps
|
||||
@@ -12,7 +11,13 @@ import com.typesafe.scalalogging.StrictLogging
|
||||
|
||||
import scala.concurrent.Future
|
||||
|
||||
class TelegramClient(onReceive: TelegramEvent => Unit, botToken: String) extends AkkaTelegramBot with TelegramBoT with Polling with Commands[Future] with Callbacks[Future] with StrictLogging {
|
||||
class TelegramClient(onReceive: TelegramEvent => Unit, botToken: String)
|
||||
extends AkkaTelegramBot
|
||||
with TelegramBoT
|
||||
with Polling
|
||||
with Commands[Future]
|
||||
with Callbacks[Future]
|
||||
with StrictLogging {
|
||||
|
||||
override val client: RequestHandler[Future] = new AkkaHttpClient(botToken)
|
||||
|
||||
@@ -22,11 +27,28 @@ class TelegramClient(onReceive: TelegramEvent => Unit, botToken: String) extends
|
||||
def sendMessage(chatId: Long, text: String, replyMarkup: Option[InlineKeyboardMarkup] = None): Future[Message] =
|
||||
loggingRequest(SendMessage(chatId, text, parseMode = Some(ParseMode.HTML), replyMarkup = replyMarkup))
|
||||
|
||||
def sendEditMessage(chatId: Long, messageId: Int, replyMarkup: Option[InlineKeyboardMarkup]): Future[Either[Boolean, Message]] =
|
||||
def sendEditMessage(
|
||||
chatId: Long,
|
||||
messageId: Int,
|
||||
replyMarkup: Option[InlineKeyboardMarkup]
|
||||
): Future[Either[Boolean, Message]] =
|
||||
loggingRequest(EditMessageReplyMarkup(Some(chatId), Some(messageId), replyMarkup = replyMarkup))
|
||||
|
||||
def sendEditMessage(chatId: Long, messageId: Int, text: String, replyMarkup: Option[InlineKeyboardMarkup] = None): Future[Either[Boolean, Message]] =
|
||||
loggingRequest(EditMessageText(Some(chatId), Some(messageId), text = text, parseMode = Some(ParseMode.HTML), replyMarkup = replyMarkup))
|
||||
def sendEditMessage(
|
||||
chatId: Long,
|
||||
messageId: Int,
|
||||
text: String,
|
||||
replyMarkup: Option[InlineKeyboardMarkup] = None
|
||||
): Future[Either[Boolean, Message]] =
|
||||
loggingRequest(
|
||||
EditMessageText(
|
||||
Some(chatId),
|
||||
Some(messageId),
|
||||
text = text,
|
||||
parseMode = Some(ParseMode.HTML),
|
||||
replyMarkup = replyMarkup
|
||||
)
|
||||
)
|
||||
|
||||
def sendFile(chatId: Long, filename: String, contents: Array[Byte], caption: Option[String] = None): Future[Message] =
|
||||
loggingRequest(SendDocument(chatId, InputFile(filename, contents), caption = caption))
|
||||
@@ -36,7 +58,6 @@ class TelegramClient(onReceive: TelegramEvent => Unit, botToken: String) extends
|
||||
request(req)
|
||||
}
|
||||
|
||||
|
||||
override def receiveMessage(msg: Message): Future[Unit] = {
|
||||
logger.debug(s"Received telegram message: $msg")
|
||||
Future.successful(onReceive(TelegramEvent(msg, None)))
|
||||
@@ -51,4 +72,4 @@ class TelegramClient(onReceive: TelegramEvent => Unit, botToken: String) extends
|
||||
} yield onReceive(TelegramEvent(msg, Some(data)))
|
||||
ack.zip(Future.successful(maybeOnReceive)).void
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
package com.lbs.bot.telegram
|
||||
|
||||
import com.bot4s.telegram.models.Message
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
package com.lbs.bot
|
||||
|
||||
import com.bot4s.telegram.models.{InlineKeyboardButton, InlineKeyboardMarkup, Message => BMessage}
|
||||
@@ -10,8 +9,7 @@ package object telegram {
|
||||
protected[bot] val TagPrefix = "callback"
|
||||
|
||||
object TelegramModelConverters extends ModelConverters {
|
||||
implicit val TelegramCommandToCommandConverter:
|
||||
ObjectConverter[TelegramEvent, Command] =
|
||||
implicit val TelegramCommandToCommandConverter: ObjectConverter[TelegramEvent, Command] =
|
||||
(data: TelegramEvent) => {
|
||||
Command(
|
||||
source = MessageSource(TelegramMessageSourceSystem, data.msg.chat.id.toString),
|
||||
@@ -20,14 +18,12 @@ package object telegram {
|
||||
)
|
||||
}
|
||||
|
||||
implicit val TelegramMessageToMessageConverter:
|
||||
ObjectConverter[BMessage, Message] =
|
||||
implicit val TelegramMessageToMessageConverter: ObjectConverter[BMessage, Message] =
|
||||
(data: BMessage) => {
|
||||
Message(data.messageId.toString, data.text)
|
||||
}
|
||||
|
||||
implicit val InlineKeyboardToInlineKeyboardMarkup:
|
||||
ObjectConverter[InlineKeyboard, InlineKeyboardMarkup] =
|
||||
implicit val InlineKeyboardToInlineKeyboardMarkup: ObjectConverter[InlineKeyboard, InlineKeyboardMarkup] =
|
||||
(inlineKeyboard: InlineKeyboard) => {
|
||||
val buttons = inlineKeyboard.buttons.map { row =>
|
||||
row.map(createInlineKeyboardButton)
|
||||
@@ -37,7 +33,7 @@ package object telegram {
|
||||
|
||||
private def createInlineKeyboardButton(button: Button) = {
|
||||
button match {
|
||||
case b: TaggedButton => InlineKeyboardButton.callbackData(b.label, tag(b.tag))
|
||||
case b: TaggedButton => InlineKeyboardButton.callbackData(b.label, tag(b.tag))
|
||||
case b: LabeledButton => InlineKeyboardButton.callbackData(b.label, b.label)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user