Skip to content

Commit c0b129a

Browse files
committed
Add Taskobot URL button to task messages
1 parent ad6eb17 commit c0b129a

29 files changed

+391
-363
lines changed

project/Dependencies.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import sbt.librarymanagement.syntax._
22

33
object Dependencies {
44
object V {
5-
val telegramium = "9.74.0"
5+
val telegramium = "9.77.0"
66
val tgbotUtils = "0.8.1"
77
val zio = "2.1.4"
88
val zioCats = "23.1.0.2"

src/main/resources/reference.conf

+2
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,6 @@ bot {
1010
port = ${?PORT}
1111
token = ${?BOT_TOKEN}
1212
url = ${BOT_EXTERNAL_URL}
13+
username = "tasko_bot"
14+
username = ${?BOT_USERNAME}
1315
}

src/main/scala/ru/johnspade/taskobot/BotService.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ import zio.interop.catz.*
99
import telegramium.bots
1010
import telegramium.bots.high.messageentities.MessageEntities
1111
import telegramium.bots.high.messageentities.MessageEntityFormat
12-
import telegramium.bots.high.messageentities.MessageEntityFormat.Plain.lineBreak
1312
import telegramium.bots.high.messageentities.MessageEntityFormat.*
13+
import telegramium.bots.high.messageentities.MessageEntityFormat.Plain.lineBreak
1414

1515
import ru.johnspade.taskobot.core.Page
1616
import ru.johnspade.taskobot.core.TelegramOps.toUser

src/main/scala/ru/johnspade/taskobot/KeyboardService.scala

+12-6
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package ru.johnspade.taskobot
33
import zio.*
44

55
import cats.syntax.option.*
6+
import telegramium.bots.InlineKeyboardButton
67
import telegramium.bots.InlineKeyboardMarkup
78
import telegramium.bots.KeyboardButton
89
import telegramium.bots.ReplyKeyboardMarkup
@@ -11,8 +12,8 @@ import telegramium.bots.high.keyboards.InlineKeyboardButtons
1112
import telegramium.bots.high.keyboards.InlineKeyboardMarkups
1213
import telegramium.bots.high.keyboards.KeyboardButtons
1314

14-
import ru.johnspade.taskobot.core.TelegramOps.inlineKeyboardButton
1515
import ru.johnspade.taskobot.core.*
16+
import ru.johnspade.taskobot.core.TelegramOps.inlineKeyboardButton
1617
import ru.johnspade.taskobot.messages.Language
1718
import ru.johnspade.taskobot.messages.MessageService
1819
import ru.johnspade.taskobot.messages.MsgId
@@ -38,7 +39,9 @@ trait KeyboardService:
3839

3940
def standardReminders(taskId: Long, pageNumber: Int, language: Language): InlineKeyboardMarkup
4041

41-
final class KeyboardServiceLive(msgService: MessageService) extends KeyboardService:
42+
def taskobotUrlButton: InlineKeyboardButton
43+
44+
final class KeyboardServiceLive(msgService: MessageService, botConfig: BotConfig) extends KeyboardService:
4245
def chats(page: Page[User], `for`: User): InlineKeyboardMarkup = {
4346
lazy val prevButton = inlineKeyboardButton(msgService.previousPage(`for`.language), Chats(page.number - 1))
4447
lazy val nextButton = inlineKeyboardButton(msgService.nextPage(`for`.language), Chats(page.number + 1))
@@ -53,7 +56,7 @@ final class KeyboardServiceLive(msgService: MessageService) extends KeyboardServ
5356
List(
5457
InlineKeyboardButtons.url(
5558
msgService.getMessage(`buy-coffee`, `for`.language) + "",
56-
"https://buymeacoff.ee/johnspade"
59+
DonateUrl
5760
)
5861
)
5962
)
@@ -105,7 +108,7 @@ final class KeyboardServiceLive(msgService: MessageService) extends KeyboardServ
105108
KeyboardButtons.text("⚙️ " + msgService.getMessage(`settings`, language)),
106109
KeyboardButton(
107110
text = "🌍 " + msgService.getMessage(`timezone`, language),
108-
webApp = Some(WebAppInfo("https://timezones.johnspade.ru"))
111+
webApp = Some(WebAppInfo(TimezonesAppUrl))
109112
)
110113
)
111114
),
@@ -154,8 +157,11 @@ final class KeyboardServiceLive(msgService: MessageService) extends KeyboardServ
154157
inlineKeyboardButton(msgService.remindersDaysBefore(3, language), CreateReminder(taskId, 60 * 24 * 3)),
155158
inlineKeyboardButton("🔙", Reminders(taskId, pageNumber))
156159
)
160+
161+
override val taskobotUrlButton: InlineKeyboardButton =
162+
InlineKeyboardButtons.url("\uD83D\uDE80 Taskobot", s"https://t.me/${botConfig.username}")
157163
end KeyboardServiceLive
158164

159165
object KeyboardServiceLive:
160-
val layer: URLayer[MessageService, KeyboardService] =
161-
ZLayer(ZIO.service[MessageService].map(new KeyboardServiceLive(_)))
166+
val layer: URLayer[MessageService & BotConfig, KeyboardService] =
167+
ZLayer.fromFunction(new KeyboardServiceLive(_, _))

src/main/scala/ru/johnspade/taskobot/Taskobot.scala

+7-10
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ package ru.johnspade.taskobot
22

33
import java.time.ZoneId
44

5-
import zio.Task
65
import zio.*
6+
import zio.Task
77
import zio.interop.catz.*
88
import zio.json.*
99

@@ -32,11 +32,6 @@ import ru.johnspade.taskobot.task.TaskController
3232
import ru.johnspade.taskobot.task.TaskRepository
3333
import ru.johnspade.taskobot.user.User
3434

35-
val DefaultPageSize: Int = 5
36-
val MessageLimit = 4096
37-
38-
val UTC = ZoneId.of("UTC")
39-
4035
type CbDataRoutes[F[_]] = CallbackQueryRoutes[CbData, Option[Method[_]], F]
4136

4237
type CbDataUserRoutes[F[_]] = CallbackQueryContextRoutes[CbData, User, Option[Method[_]], F]
@@ -74,8 +69,9 @@ final class Taskobot(
7469
entities = messageEntities.toTelegramEntities().map(OpenEnum(_))
7570
),
7671
replyMarkup = InlineKeyboardMarkups
77-
.singleButton(
78-
inlineKeyboardButton("Confirm task", ConfirmTask(id = None, senderId = query.from.id.some))
72+
.singleColumn(
73+
inlineKeyboardButton("Confirm task", ConfirmTask(id = None, senderId = query.from.id.some)),
74+
kbService.taskobotUrlButton
7975
)
8076
.some,
8177
description = text.some
@@ -93,8 +89,9 @@ final class Taskobot(
9389
method = editMessageReplyMarkup(
9490
inlineMessageId = inlineResult.inlineMessageId,
9591
replyMarkup = InlineKeyboardMarkups
96-
.singleButton(
97-
inlineKeyboardButton("Confirm task", ConfirmTask(task.id.some, user.id.some))
92+
.singleColumn(
93+
inlineKeyboardButton("Confirm task", ConfirmTask(task.id.some, user.id.some)),
94+
kbService.taskobotUrlButton
9895
)
9996
.some
10097
)

src/main/scala/ru/johnspade/taskobot/UserMiddleware.scala

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package ru.johnspade.taskobot
22

3-
import zio._
4-
import zio.interop.catz._
3+
import zio.*
4+
import zio.interop.catz.*
55

66
import cats.data.Kleisli
77
import cats.data.OptionT

src/main/scala/ru/johnspade/taskobot/configuration.scala

+4-3
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,12 @@ object DbConfig:
3131
}.orDie
3232
)
3333

34-
final case class BotConfig(port: Int, url: String, token: String)
34+
final case class BotConfig(port: Int, url: String, token: String, username: String)
3535
object BotConfig:
3636
implicit val botConfigReader: ConfigReader[BotConfig] =
37-
ConfigReader.forProduct3[BotConfig, Int, String, String]("port", "url", "token") { case (port, url, token) =>
38-
BotConfig(port, url, token)
37+
ConfigReader.forProduct4[BotConfig, Int, String, String, String]("port", "url", "token", "username") {
38+
case (port, url, token, username) =>
39+
BotConfig(port, url, token, username)
3940
}
4041
val live: ULayer[BotConfig] = ZLayer(
4142
ZIO.attempt {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package ru.johnspade.taskobot
2+
3+
import java.time.ZoneId
4+
5+
val DefaultPageSize: Int = 5
6+
val MessageLimit = 4096
7+
8+
val UTC = ZoneId.of("UTC")
9+
10+
val DonateUrl = "https://buymeacoff.ee/johnspade"
11+
12+
val TimezonesAppUrl = "https://timezones.johnspade.ru"

src/main/scala/ru/johnspade/taskobot/core/Page.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package ru.johnspade.taskobot.core
22

33
import cats.Functor
4-
import cats.syntax.functor._
4+
import cats.syntax.functor.*
55

66
final case class Page[T](
77
items: List[T],

src/main/scala/ru/johnspade/taskobot/messages/MessageService.scala

+3-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import zio.URLayer
66
import zio.ZIO
77
import zio.ZLayer
88

9+
import ru.johnspade.taskobot.DonateUrl
10+
911
import MsgId.*
1012

1113
trait MessageService:
@@ -45,7 +47,7 @@ final class MessageServiceLive(msgConfig: MsgConfig) extends MessageService:
4547
getMessage(`help-due-date`, lang) + "\n\n" +
4648
getMessage(`help-task-complete`, lang) + "\n\n" +
4749
switchLanguage(lang) + ": /settings" + "\n" +
48-
getMessage(`support-creator`, lang) + ": https://buymeacoff.ee/johnspade"
50+
getMessage(`support-creator`, lang) + s": $DonateUrl"
4951

5052
def taskCreated(task: String, language: Language): String =
5153
getMessage(`tasks-personal-created`, language, task)

src/main/scala/ru/johnspade/taskobot/scheduled/ReminderService.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ import zio.*
66

77
import cats.data.NonEmptyList
88
import telegramium.bots.*
9-
import telegramium.bots.high.Api
109
import telegramium.bots.high.*
10+
import telegramium.bots.high.Api
1111
import telegramium.bots.high.implicits.*
1212

1313
import ru.johnspade.taskobot.BotService

src/main/scala/ru/johnspade/taskobot/settings/SettingsController.scala

+2-2
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ final class SettingsControllerLive(
6161
execDiscardWithHandling(
6262
editMessageText(
6363
msgService.currentLanguage(language),
64-
ChatIntId(msg.chat.id).some,
65-
msg.messageId.some,
64+
chatId = ChatIntId(msg.chat.id).some,
65+
messageId = msg.messageId.some,
6666
replyMarkup = kbService.languages(language).some
6767
)
6868
)

0 commit comments

Comments
 (0)