Skip to content

Commit 376818c

Browse files
authored
Merge pull request #1 from ivalukyan/dev
Dev
2 parents 09c53b5 + d2e363f commit 376818c

File tree

16 files changed

+394
-2
lines changed

16 files changed

+394
-2
lines changed

.gitignore

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,8 @@ bin/
4242
.vscode/
4343

4444
### Mac OS ###
45-
.DS_Store
45+
.DS_Store
46+
47+
*.env
48+
49+
cred.json

.idea/codeStyles/Project.xml

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/codeStyles/codeStyleConfig.xml

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/gradle.xml

Lines changed: 17 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/inspectionProfiles/Project_Default.xml

Lines changed: 19 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/kotlinc.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/misc.xml

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/vcs.xml

Lines changed: 3 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build.gradle.kts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,32 @@
11
plugins {
22
kotlin("jvm") version "2.0.21"
3+
id("com.google.devtools.ksp") version "2.1.10-1.0.29"
34
}
45

56
group = "org.example"
67
version = "1.0-SNAPSHOT"
78

89
repositories {
910
mavenCentral()
11+
maven("https://jitpack.io")
1012
}
1113

1214
dependencies {
1315
testImplementation(kotlin("test"))
16+
17+
implementation("org.jetbrains.kotlin:kotlin-stdlib")
18+
19+
// Telegram Bot
20+
implementation("io.github.kotlin-telegram-bot.kotlin-telegram-bot:telegram:6.3.0")
21+
22+
// Env
23+
implementation("io.github.cdimascio:dotenv-kotlin:6.4.1")
24+
25+
// Google Api
26+
implementation("com.google.api-client:google-api-client:2.3.0")
27+
implementation("com.google.oauth-client:google-oauth-client-jetty:1.34.1")
28+
implementation("com.google.apis:google-api-services-calendar:v3-rev20250115-2.0.0")
29+
1430
}
1531

1632
tasks.test {

src/main/kotlin/Main.kt

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,58 @@
11
package org.example
22

3+
import com.github.kotlintelegrambot.bot
4+
import com.github.kotlintelegrambot.dispatch
5+
import com.github.kotlintelegrambot.dispatcher.callbackQuery
6+
import com.github.kotlintelegrambot.dispatcher.command
7+
import com.github.kotlintelegrambot.entities.ChatId
8+
import com.github.kotlintelegrambot.entities.ParseMode
9+
import com.github.kotlintelegrambot.logging.LogLevel
10+
import org.example.config.ConfigVar
11+
import java.time.LocalDate
12+
import java.util.logging.Logger
13+
import org.example.handlers.handleCalendarNavigation
14+
import org.example.handlers.handleDateSelection
15+
import org.example.keyboards.generateCalendar
16+
317

418
fun main() {
19+
val service = GoogleCalendarService.getCalendarService()
20+
val bot = bot {
21+
token = ConfigVar().BOT_TOKEN
22+
timeout = 30
23+
logLevel = LogLevel.Network.Basic
24+
val logger = Logger.getLogger("MainKt")
25+
26+
dispatch {
27+
command("start") {
28+
val today = LocalDate.now()
29+
val year = today.year
30+
val month = today.monthValue
31+
32+
logger.info("Генерация календаря...")
33+
val calendarInlineKeyboard = generateCalendar(year, month)
34+
logger.info("Календарь получен - $calendarInlineKeyboard")
35+
36+
bot.sendMessage(
37+
chatId = ChatId.fromId(message.chat.id),
38+
text = "Здравствуйте, ${message.from?.firstName}!\nВыберите дату на календаре:",
39+
replyMarkup = calendarInlineKeyboard,
40+
parseMode = ParseMode.MARKDOWN
41+
)
42+
}
43+
44+
callbackQuery {
45+
val data = callbackQuery.data
46+
val params = data.split("_")
47+
println(params)
548

49+
when (params[0]) {
50+
"date" -> handleDateSelection(params, service, callbackQuery, bot)
51+
"calendar", "next", "back" -> handleCalendarNavigation(params, callbackQuery, bot)
52+
else -> println("⚠️ Ошибка: неизвестный callback-запрос: $data")
53+
}
54+
}
55+
}
56+
}
57+
bot.startPolling()
658
}

0 commit comments

Comments
 (0)