Skip to content

Commit

Permalink
Update Telegramium and other dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
johnspade committed Jun 20, 2024
1 parent 4ca7d97 commit 9fe8f49
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 52 deletions.
4 changes: 3 additions & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Dependencies._

name := "tasko_bot"

scalaVersion := "3.3.0"
scalaVersion := "3.3.3"

scalacOptions ++= Seq(
"-language:higherKinds",
Expand All @@ -27,3 +27,5 @@ dockerLabels := Map("org.opencontainers.image.source" -> "https://github.com

ThisBuild / semanticdbEnabled := true
ThisBuild / semanticdbVersion := scalafixSemanticdb.revision

Global / onChangedBuildSource := ReloadOnSourceChanges
14 changes: 7 additions & 7 deletions project/Dependencies.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ import sbt.librarymanagement.syntax._

object Dependencies {
object V {
val telegramium = "8.71.0"
val tgbotUtils = "0.7.1"
val zio = "2.0.15"
val zioCats = "23.0.0.7"
val zioLogging = "2.1.13"
val zioJson = "0.5.0"
val telegramium = "9.74.0"
val tgbotUtils = "0.8.1"
val zio = "2.1.4"
val zioCats = "23.1.0.2"
val zioLogging = "2.3.0"
val zioJson = "0.7.0"
val logback = "1.4.8"
val cats = "2.9.0"
val cats = "2.12.0"
val pureconfig = "0.17.4"
val doobie = "1.0.0-RC4"
val flyway = "9.20.0"
Expand Down
4 changes: 2 additions & 2 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
addSbtPlugin("com.github.sbt" % "sbt-native-packager" % "1.9.16")
addSbtPlugin("com.github.sbt" % "sbt-native-packager" % "1.10.0")
addSbtPlugin("com.github.sbt" % "sbt-dynver" % "5.0.1")
addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "0.11.0")
addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "0.12.1")
5 changes: 3 additions & 2 deletions src/main/scala/ru/johnspade/taskobot/Errors.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package ru.johnspade.taskobot

object Errors:
final val Default: String = "Something went wrong..."
final val NotFound: String = "Not found."
final val Default: String = "Something went wrong..."
final val NotFound: String = "Not found."
final val NotSupported: String = "This message is not supported."

final case class MaxRemindersExceeded(taskId: Long) extends Throwable
71 changes: 36 additions & 35 deletions src/main/scala/ru/johnspade/taskobot/Taskobot.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import zio.interop.catz.*
import zio.json.*

import cats.implicits.*
import iozhik.OpenEnum
import ru.johnspade.tgbot.callbackqueries.*
import telegramium.bots.*
import telegramium.bots.client.Method
Expand Down Expand Up @@ -70,7 +71,7 @@ final class Taskobot(
title = msgService.getMessage(MsgId.`tasks-create`, language),
inputMessageContent = InputTextMessageContent(
messageEntities.toPlainText(),
entities = messageEntities.toTelegramEntities()
entities = messageEntities.toTelegramEntities().map(OpenEnum(_))
),
replyMarkup = InlineKeyboardMarkups
.singleButton(
Expand Down Expand Up @@ -133,40 +134,40 @@ final class Taskobot(
}

def handleForward() =
for
forwardOrigin <- msg.forwardOrigin
(senderName, forwardFromId) = forwardOrigin match {
case MessageOriginUser(_, senderUser) =>
Some(senderUser.firstName + senderUser.lastName.map(" " + _).getOrElse("")) -> Some(senderUser.id)
case MessageOriginChannel(_, chat, _, _) => chat.title.orElse(chat.username) -> Some(chat.id)
case MessageOriginHiddenUser(_, senderUserName) => Some(senderUserName) -> None
case MessageOriginChat(_, senderChat, _) =>
senderChat.title.orElse(senderChat.username) -> Some(senderChat.id)
}
text <- msg.text
from <- msg.from
yield {
for
user <- botService.updateUser(from, msg.chat.id.some)
now <- Clock.instant
newTask = NewTask(
user.id,
text,
now,
user.timezoneOrDefault,
user.id.some,
forwardFromId = forwardFromId,
forwardFromSenderName = senderName
)
_ <- taskRepo.create(newTask)
_ <- sendMessage(
ChatIntId(msg.chat.id),
msgService.taskCreated(text, user.language),
replyMarkup = kbService.menu(user.language).some
).exec
method <- listPersonalTasks(user)
yield method.some
}
msg.forwardOrigin.fold(None): originOpen =>
originOpen match
case OpenEnum.Unknown(_) => Some(ZIO.some(sendMessage(ChatIntId(msg.chat.id), Errors.NotSupported)))
case OpenEnum.Known(origin) =>
val (senderName, forwardFromId) = origin match
case MessageOriginUser(_, senderUser) =>
Some(senderUser.firstName + senderUser.lastName.map(" " + _).getOrElse("")) -> Some(senderUser.id)
case MessageOriginChannel(_, chat, _, _) => chat.title.orElse(chat.username) -> Some(chat.id)
case MessageOriginHiddenUser(_, senderUserName) => Some(senderUserName) -> None
case MessageOriginChat(_, senderChat, _) =>
senderChat.title.orElse(senderChat.username) -> Some(senderChat.id)
for
text <- msg.text
from <- msg.from
yield for
user <- botService.updateUser(from, msg.chat.id.some)
now <- Clock.instant
newTask = NewTask(
user.id,
text,
now,
user.timezoneOrDefault,
user.id.some,
forwardFromId = forwardFromId,
forwardFromSenderName = senderName
)
_ <- taskRepo.create(newTask)
_ <- sendMessage(
ChatIntId(msg.chat.id),
msgService.taskCreated(text, user.language),
replyMarkup = kbService.menu(user.language).some
).exec
method <- listPersonalTasks(user)
yield method.some

def handleText() =
msg.text
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ object TelegramOps {

def execDiscardWithHandling[Res](method: Method[Res])(using api: Api[Task]) =
method.exec.catchSome {
case err: FailedRequest[Res]
case err: FailedRequest[_]
if err.errorCode.contains(400) && err.description.exists(
_.contains(
"Bad Request: message is not modified: specified new message content and reply markup are exactly the same as a current content and reply markup of the message"
Expand Down
5 changes: 3 additions & 2 deletions src/test/scala/ru/johnspade/taskobot/TaskobotISpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import zio.test.TestAspect.sequential
import zio.test.*

import cats.syntax.option.*
import iozhik.OpenEnum
import org.mockserver.client.MockServerClient
import telegramium.bots.*
import telegramium.bots.client.Method
Expand Down Expand Up @@ -50,7 +51,7 @@ object TaskobotISpec extends ZIOSpecDefault:
"Create task",
InputTextMessageContent(
"Buy some milk",
entities = MessageEntities().bold("Buy some milk").toTelegramEntities()
entities = MessageEntities().bold("Buy some milk").toTelegramEntities().map(OpenEnum(_))
),
InlineKeyboardMarkups
.singleButton(
Expand Down Expand Up @@ -320,7 +321,7 @@ object TaskobotISpec extends ZIOSpecDefault:
from = johnTg.some,
text = "Watch Firefly".some,
entities = List.empty,
forwardOrigin = MessageOriginUser(0, johnTg).some
forwardOrigin = OpenEnum(MessageOriginUser(0, johnTg)).some
)
withTaskobotService(_.onMessageReply(forwardedMessage))
.map { forwardReply =>
Expand Down
6 changes: 4 additions & 2 deletions src/test/scala/ru/johnspade/taskobot/TestHelpers.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package ru.johnspade.taskobot

import cats.syntax.option._
import cats.syntax.option.*
import iozhik.OpenEnum
import telegramium.bots.BotCommandMessageEntity
import telegramium.bots.CallbackQuery
import telegramium.bots.Chat
Expand Down Expand Up @@ -28,7 +29,8 @@ object TestHelpers:
chat = Chat(id = chatId, `type` = "private"),
from = johnTg.some,
text = text.some,
entities = if (isCommand) List(BotCommandMessageEntity(offset = 0, length = text.length)) else List.empty,
entities =
if (isCommand) List(OpenEnum(BotCommandMessageEntity(offset = 0, length = text.length))) else List.empty,
replyToMessage = replyToMessage
)

Expand Down

0 comments on commit 9fe8f49

Please sign in to comment.