Skip to content

Commit

Permalink
Add Taskobot URL button to task messages
Browse files Browse the repository at this point in the history
  • Loading branch information
johnspade committed Jul 21, 2024
1 parent ad6eb17 commit c0b129a
Show file tree
Hide file tree
Showing 29 changed files with 391 additions and 363 deletions.
2 changes: 1 addition & 1 deletion project/Dependencies.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import sbt.librarymanagement.syntax._

object Dependencies {
object V {
val telegramium = "9.74.0"
val telegramium = "9.77.0"
val tgbotUtils = "0.8.1"
val zio = "2.1.4"
val zioCats = "23.1.0.2"
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/reference.conf
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@ bot {
port = ${?PORT}
token = ${?BOT_TOKEN}
url = ${BOT_EXTERNAL_URL}
username = "tasko_bot"
username = ${?BOT_USERNAME}
}
2 changes: 1 addition & 1 deletion src/main/scala/ru/johnspade/taskobot/BotService.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import zio.interop.catz.*
import telegramium.bots
import telegramium.bots.high.messageentities.MessageEntities
import telegramium.bots.high.messageentities.MessageEntityFormat
import telegramium.bots.high.messageentities.MessageEntityFormat.Plain.lineBreak
import telegramium.bots.high.messageentities.MessageEntityFormat.*
import telegramium.bots.high.messageentities.MessageEntityFormat.Plain.lineBreak

import ru.johnspade.taskobot.core.Page
import ru.johnspade.taskobot.core.TelegramOps.toUser
Expand Down
18 changes: 12 additions & 6 deletions src/main/scala/ru/johnspade/taskobot/KeyboardService.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package ru.johnspade.taskobot
import zio.*

import cats.syntax.option.*
import telegramium.bots.InlineKeyboardButton
import telegramium.bots.InlineKeyboardMarkup
import telegramium.bots.KeyboardButton
import telegramium.bots.ReplyKeyboardMarkup
Expand All @@ -11,8 +12,8 @@ import telegramium.bots.high.keyboards.InlineKeyboardButtons
import telegramium.bots.high.keyboards.InlineKeyboardMarkups
import telegramium.bots.high.keyboards.KeyboardButtons

import ru.johnspade.taskobot.core.TelegramOps.inlineKeyboardButton
import ru.johnspade.taskobot.core.*
import ru.johnspade.taskobot.core.TelegramOps.inlineKeyboardButton
import ru.johnspade.taskobot.messages.Language
import ru.johnspade.taskobot.messages.MessageService
import ru.johnspade.taskobot.messages.MsgId
Expand All @@ -38,7 +39,9 @@ trait KeyboardService:

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

final class KeyboardServiceLive(msgService: MessageService) extends KeyboardService:
def taskobotUrlButton: InlineKeyboardButton

final class KeyboardServiceLive(msgService: MessageService, botConfig: BotConfig) extends KeyboardService:
def chats(page: Page[User], `for`: User): InlineKeyboardMarkup = {
lazy val prevButton = inlineKeyboardButton(msgService.previousPage(`for`.language), Chats(page.number - 1))
lazy val nextButton = inlineKeyboardButton(msgService.nextPage(`for`.language), Chats(page.number + 1))
Expand All @@ -53,7 +56,7 @@ final class KeyboardServiceLive(msgService: MessageService) extends KeyboardServ
List(
InlineKeyboardButtons.url(
msgService.getMessage(`buy-coffee`, `for`.language) + "",
"https://buymeacoff.ee/johnspade"
DonateUrl
)
)
)
Expand Down Expand Up @@ -105,7 +108,7 @@ final class KeyboardServiceLive(msgService: MessageService) extends KeyboardServ
KeyboardButtons.text("⚙️ " + msgService.getMessage(`settings`, language)),
KeyboardButton(
text = "🌍 " + msgService.getMessage(`timezone`, language),
webApp = Some(WebAppInfo("https://timezones.johnspade.ru"))
webApp = Some(WebAppInfo(TimezonesAppUrl))
)
)
),
Expand Down Expand Up @@ -154,8 +157,11 @@ final class KeyboardServiceLive(msgService: MessageService) extends KeyboardServ
inlineKeyboardButton(msgService.remindersDaysBefore(3, language), CreateReminder(taskId, 60 * 24 * 3)),
inlineKeyboardButton("🔙", Reminders(taskId, pageNumber))
)

override val taskobotUrlButton: InlineKeyboardButton =
InlineKeyboardButtons.url("\uD83D\uDE80 Taskobot", s"https://t.me/${botConfig.username}")
end KeyboardServiceLive

object KeyboardServiceLive:
val layer: URLayer[MessageService, KeyboardService] =
ZLayer(ZIO.service[MessageService].map(new KeyboardServiceLive(_)))
val layer: URLayer[MessageService & BotConfig, KeyboardService] =
ZLayer.fromFunction(new KeyboardServiceLive(_, _))
17 changes: 7 additions & 10 deletions src/main/scala/ru/johnspade/taskobot/Taskobot.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package ru.johnspade.taskobot

import java.time.ZoneId

import zio.Task
import zio.*
import zio.Task
import zio.interop.catz.*
import zio.json.*

Expand Down Expand Up @@ -32,11 +32,6 @@ import ru.johnspade.taskobot.task.TaskController
import ru.johnspade.taskobot.task.TaskRepository
import ru.johnspade.taskobot.user.User

val DefaultPageSize: Int = 5
val MessageLimit = 4096

val UTC = ZoneId.of("UTC")

type CbDataRoutes[F[_]] = CallbackQueryRoutes[CbData, Option[Method[_]], F]

type CbDataUserRoutes[F[_]] = CallbackQueryContextRoutes[CbData, User, Option[Method[_]], F]
Expand Down Expand Up @@ -74,8 +69,9 @@ final class Taskobot(
entities = messageEntities.toTelegramEntities().map(OpenEnum(_))
),
replyMarkup = InlineKeyboardMarkups
.singleButton(
inlineKeyboardButton("Confirm task", ConfirmTask(id = None, senderId = query.from.id.some))
.singleColumn(
inlineKeyboardButton("Confirm task", ConfirmTask(id = None, senderId = query.from.id.some)),
kbService.taskobotUrlButton
)
.some,
description = text.some
Expand All @@ -93,8 +89,9 @@ final class Taskobot(
method = editMessageReplyMarkup(
inlineMessageId = inlineResult.inlineMessageId,
replyMarkup = InlineKeyboardMarkups
.singleButton(
inlineKeyboardButton("Confirm task", ConfirmTask(task.id.some, user.id.some))
.singleColumn(
inlineKeyboardButton("Confirm task", ConfirmTask(task.id.some, user.id.some)),
kbService.taskobotUrlButton
)
.some
)
Expand Down
4 changes: 2 additions & 2 deletions src/main/scala/ru/johnspade/taskobot/UserMiddleware.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package ru.johnspade.taskobot

import zio._
import zio.interop.catz._
import zio.*
import zio.interop.catz.*

import cats.data.Kleisli
import cats.data.OptionT
Expand Down
7 changes: 4 additions & 3 deletions src/main/scala/ru/johnspade/taskobot/configuration.scala
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,12 @@ object DbConfig:
}.orDie
)

final case class BotConfig(port: Int, url: String, token: String)
final case class BotConfig(port: Int, url: String, token: String, username: String)
object BotConfig:
implicit val botConfigReader: ConfigReader[BotConfig] =
ConfigReader.forProduct3[BotConfig, Int, String, String]("port", "url", "token") { case (port, url, token) =>
BotConfig(port, url, token)
ConfigReader.forProduct4[BotConfig, Int, String, String, String]("port", "url", "token", "username") {
case (port, url, token, username) =>
BotConfig(port, url, token, username)
}
val live: ULayer[BotConfig] = ZLayer(
ZIO.attempt {
Expand Down
12 changes: 12 additions & 0 deletions src/main/scala/ru/johnspade/taskobot/constants.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package ru.johnspade.taskobot

import java.time.ZoneId

val DefaultPageSize: Int = 5
val MessageLimit = 4096

val UTC = ZoneId.of("UTC")

val DonateUrl = "https://buymeacoff.ee/johnspade"

val TimezonesAppUrl = "https://timezones.johnspade.ru"
2 changes: 1 addition & 1 deletion src/main/scala/ru/johnspade/taskobot/core/Page.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package ru.johnspade.taskobot.core

import cats.Functor
import cats.syntax.functor._
import cats.syntax.functor.*

final case class Page[T](
items: List[T],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import zio.URLayer
import zio.ZIO
import zio.ZLayer

import ru.johnspade.taskobot.DonateUrl

import MsgId.*

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

def taskCreated(task: String, language: Language): String =
getMessage(`tasks-personal-created`, language, task)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import zio.*

import cats.data.NonEmptyList
import telegramium.bots.*
import telegramium.bots.high.Api
import telegramium.bots.high.*
import telegramium.bots.high.Api
import telegramium.bots.high.implicits.*

import ru.johnspade.taskobot.BotService
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ final class SettingsControllerLive(
execDiscardWithHandling(
editMessageText(
msgService.currentLanguage(language),
ChatIntId(msg.chat.id).some,
msg.messageId.some,
chatId = ChatIntId(msg.chat.id).some,
messageId = msg.messageId.some,
replyMarkup = kbService.languages(language).some
)
)
Expand Down
Loading

0 comments on commit c0b129a

Please sign in to comment.