Skip to content

Commit 3b867ff

Browse files
committed
upgrade gradle and dependencies
1 parent b6579ca commit 3b867ff

17 files changed

+121
-307
lines changed

.idea/codeStyles/Project.xml

+10
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/codeStyles/codeStyleConfig.xml

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/compiler.xml

+1-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/jarRepositories.xml

+25
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/misc.xml

+2-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/modules.xml

-10
This file was deleted.

.idea/modules/moztw-space-bot.iml

-13
This file was deleted.

.idea/modules/moztw-space-bot.main.iml

-101
This file was deleted.

.idea/modules/moztw-space-bot.test.iml

-111
This file was deleted.

build.gradle.kts

+6-6
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
22

33
buildscript {
44
var kotlin_version: String by extra
5-
kotlin_version = "1.3.50"
5+
kotlin_version = "1.6.0"
66

77
repositories {
88
mavenCentral()
@@ -32,11 +32,11 @@ repositories {
3232

3333
dependencies {
3434
implementation(kotlin("stdlib-jdk8", kotlin_version))
35-
implementation("commons-cli", "commons-cli", "1.4")
36-
implementation("org.telegram", "telegrambots", "3.6")
37-
implementation("com.squareup.okhttp3", "okhttp", "4.2.1")
38-
implementation("com.beust", "klaxon", "5.0.13")
39-
testImplementation("org.junit.jupiter", "junit-jupiter-api", "5.1.0")
35+
implementation("commons-cli", "commons-cli", "1.5.0")
36+
implementation("org.telegram", "telegrambots", "5.5.0")
37+
implementation("com.squareup.okhttp3", "okhttp", "4.9.3")
38+
implementation("com.beust", "klaxon", "5.5")
39+
testImplementation("org.junit.jupiter", "junit-jupiter-api", "5.8.2")
4040
}
4141

4242
configure<JavaPluginConvention> {

gradle/wrapper/gradle-wrapper.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.1-all.zip

src/main/kotlin/org/moztw/bot/telegram/space/Bot.kt

+15-18
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,14 @@ package org.moztw.bot.telegram.space
33
import okhttp3.OkHttpClient
44
import okhttp3.Request
55
import org.moztw.bot.telegram.space.co2.SpaceCo2
6-
import org.telegram.telegrambots.api.methods.ActionType
7-
import org.telegram.telegrambots.api.methods.groupadministration.SetChatTitle
8-
import org.telegram.telegrambots.api.methods.send.SendChatAction
9-
import org.telegram.telegrambots.api.methods.send.SendMessage
10-
import org.telegram.telegrambots.api.methods.send.SendPhoto
11-
import org.telegram.telegrambots.api.objects.CallbackQuery
12-
import org.telegram.telegrambots.api.objects.Chat
13-
import org.telegram.telegrambots.api.objects.Message
14-
import org.telegram.telegrambots.api.objects.Update
6+
import org.telegram.telegrambots.meta.api.methods.ActionType
7+
import org.telegram.telegrambots.meta.api.methods.groupadministration.SetChatTitle
8+
import org.telegram.telegrambots.meta.api.methods.send.SendChatAction
9+
import org.telegram.telegrambots.meta.api.methods.send.SendMessage
10+
import org.telegram.telegrambots.meta.api.methods.send.SendPhoto
1511
import org.telegram.telegrambots.bots.TelegramLongPollingBot
16-
import org.telegram.telegrambots.exceptions.TelegramApiException
12+
import org.telegram.telegrambots.meta.api.objects.*
13+
import org.telegram.telegrambots.meta.exceptions.TelegramApiException
1714
import java.text.SimpleDateFormat
1815
import java.time.ZoneId
1916
import java.time.ZonedDateTime
@@ -31,7 +28,7 @@ internal class Bot(val username: String, val token: String) : TelegramLongPollin
3128

3229
private fun onCallbackQueryReceived(callbackQuery: CallbackQuery): Boolean {
3330
try {
34-
Reply().getCheckList(callbackQuery)?.run { execute(this) }
31+
Reply().getCheckList(callbackQuery).run { execute(this) }
3532
return true
3633
} catch (e: TelegramApiException) {
3734
e.printStackTrace()
@@ -46,7 +43,7 @@ internal class Bot(val username: String, val token: String) : TelegramLongPollin
4643
try {
4744
execute(SendChatAction().apply {
4845
chatId = message.chat.id.toString()
49-
action = ActionType.TYPING
46+
setAction(ActionType.TYPING)
5047
})
5148
} catch (e: TelegramApiException) {
5249
e.printStackTrace()
@@ -77,19 +74,19 @@ internal class Bot(val username: String, val token: String) : TelegramLongPollin
7774
try {
7875
execute(SendChatAction().apply {
7976
chatId = message.chat.id.toString()
80-
action = ActionType.UPLOADPHOTO
77+
setAction(ActionType.UPLOADPHOTO)
8178
})
8279

83-
sendPhoto(SendPhoto().apply {
80+
execute(SendPhoto().apply {
8481
caption = messageText
8582
chatId = message.chat.id.toString()
8683
parseMode = "HTML"
8784
replyToMessageId = message.messageId
88-
setNewPhoto("moztw-space-co2.png", imageUrl.let {
85+
photo = InputFile(imageUrl.let {
8986
OkHttpClient()
90-
.newCall(Request.Builder().url(it).build())
91-
.execute().body?.byteStream()
92-
})
87+
.newCall(Request.Builder().url(it).build())
88+
.execute().body?.byteStream()
89+
}, "moztw-space-co2.png")
9390
})
9491
} catch (e: TelegramApiException) {
9592
e.printStackTrace()
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
package org.moztw.bot.telegram.space
22

3-
import org.telegram.telegrambots.api.methods.groupadministration.SetChatTitle
3+
import org.telegram.telegrambots.meta.api.methods.groupadministration.SetChatTitle
44

55
internal class Caption {
6-
private fun getCaption(chatId: Long) = SetChatTitle().setChatId(chatId)!!
7-
fun getCaptionOpened(chatId: Long) = getCaption(chatId).setTitle("Moz://TW(工寮開放中)")!!
8-
fun getCaptionClosed(chatId: Long) = getCaption(chatId).setTitle("Moz://TW")!!
6+
private fun getCaption(chatId: Long) = SetChatTitle().apply { setChatId(chatId.toString()) }
7+
fun getCaptionOpened(chatId: Long) = getCaption(chatId).apply { title = "Moz://TW(工寮開放中)" }
8+
fun getCaptionClosed(chatId: Long) = getCaption(chatId).apply { title = "Moz://TW" }
99
}

src/main/kotlin/org/moztw/bot/telegram/space/Keyboard.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package org.moztw.bot.telegram.space
22

3-
import org.telegram.telegrambots.api.objects.replykeyboard.InlineKeyboardMarkup
4-
import org.telegram.telegrambots.api.objects.replykeyboard.buttons.InlineKeyboardButton
3+
import org.telegram.telegrambots.meta.api.objects.replykeyboard.InlineKeyboardMarkup
4+
import org.telegram.telegrambots.meta.api.objects.replykeyboard.buttons.InlineKeyboardButton
55
import java.util.*
66

77
internal class Keyboard {

src/main/kotlin/org/moztw/bot/telegram/space/Main.kt

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
package org.moztw.bot.telegram.space
22

33
import org.apache.commons.cli.*
4-
import org.telegram.telegrambots.ApiContextInitializer
5-
import org.telegram.telegrambots.TelegramBotsApi
6-
import org.telegram.telegrambots.exceptions.TelegramApiRequestException
4+
import org.telegram.telegrambots.meta.TelegramBotsApi
5+
import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException
6+
import org.telegram.telegrambots.updatesreceivers.DefaultBotSession
77
import kotlin.system.exitProcess
88

99
fun main(args: Array<String>) {
@@ -24,9 +24,8 @@ fun main(args: Array<String>) {
2424
val botUsername = cmd.getOptionValue("username")
2525
val botToken = cmd.getOptionValue("token")
2626

27-
ApiContextInitializer.init()
2827
try {
29-
TelegramBotsApi().registerBot(Bot(username = botUsername, token = botToken))
28+
TelegramBotsApi(DefaultBotSession::class.java).registerBot(Bot(username = botUsername, token = botToken))
3029
} catch (e: TelegramApiRequestException) {
3130
e.printStackTrace()
3231
}

src/main/kotlin/org/moztw/bot/telegram/space/Reply.kt

+48-30
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,71 @@
11
package org.moztw.bot.telegram.space
22

3-
import org.telegram.telegrambots.api.methods.send.SendMessage
4-
import org.telegram.telegrambots.api.methods.updatingmessages.EditMessageReplyMarkup
5-
import org.telegram.telegrambots.api.objects.CallbackQuery
6-
import org.telegram.telegrambots.api.objects.Message
7-
import org.telegram.telegrambots.api.objects.User
3+
import org.telegram.telegrambots.meta.api.methods.send.SendMessage
4+
import org.telegram.telegrambots.meta.api.methods.updatingmessages.EditMessageReplyMarkup
5+
import org.telegram.telegrambots.meta.api.objects.CallbackQuery
6+
import org.telegram.telegrambots.meta.api.objects.Message
7+
import org.telegram.telegrambots.meta.api.objects.User
88

99
internal class Reply {
10-
private fun getGeneralMessage(chatId: Long) = SendMessage().setChatId(chatId).setParseMode("Markdown")
10+
private fun getGeneralMessage(chatId: Long) = SendMessage().apply {
11+
setChatId(chatId.toString())
12+
parseMode = "Markdown"
13+
}
1114

1215
fun getGeneralMessageOpen(chatId: Long, operator: User) =
13-
getGeneralMessage(chatId).setText("#工寮開門 ${Bot.dateTime}(by [${operator.firstName}](tg://user?id=${operator.id}))")!!
16+
getGeneralMessage(chatId).apply {
17+
text = "#工寮開門 ${Bot.dateTime}(by [${operator.firstName}](tg://user?id=${operator.id}))"
18+
}
1419

1520
fun getGeneralMessageClose(chatId: Long, operator: User) =
16-
getGeneralMessage(chatId).setText("#工寮關門 ${Bot.dateTime}(by [${operator.firstName}](tg://user?id=${operator.id}))")!!
21+
getGeneralMessage(chatId).apply {
22+
text = "#工寮關門 ${Bot.dateTime}(by [${operator.firstName}](tg://user?id=${operator.id}))"
23+
}
1724

18-
private fun getMessage(message: Message) = SendMessage().setChatId(message.chatId!!).setReplyToMessageId(message.messageId)
25+
private fun getMessage(message: Message) = SendMessage().apply {
26+
chatId = message.chatId.toString()
27+
replyToMessageId = message.messageId
28+
}
1929

20-
fun getMessageOpen(message: Message) = getMessage(message).setText(
21-
"#工寮開門 已於 ${Bot.dateTime} 送出開門資訊。\n\n" +
22-
"您可以先擦拭白板並書寫 Keyholder 名稱、活動名稱以及開關門預定時間。\n" +
23-
"招呼訪客時,請提醒他們於白板簽到(暱稱或 Mozillians ID e.g. moz:irvin)"
24-
)!!
30+
fun getMessageOpen(message: Message) = getMessage(message).apply {
31+
text = "#工寮開門 已於 ${Bot.dateTime} 送出開門資訊。\n\n" +
32+
"您可以先擦拭白板並書寫 Keyholder 名稱、活動名稱以及開關門預定時間。\n" +
33+
"招呼訪客時,請提醒他們於白板簽到(暱稱或 Mozillians ID e.g. moz:irvin)"
34+
}
2535

26-
fun getMessageClose(message: Message) = getMessage(message).setText(
27-
"#工寮關門 已於 " + Bot.dateTime + " 送出關門資訊。\n\n" +
28-
"請檢視以下項目是否完成,完成後可點選來標記:"
29-
).setReplyMarkup(Keyboard().showButton)!!
36+
fun getMessageClose(message: Message) = getMessage(message).apply {
37+
text = "#工寮關門 已於 " + Bot.dateTime + " 送出關門資訊。\n\n" +
38+
"請檢視以下項目是否完成,完成後可點選來標記:"
39+
replyMarkup = Keyboard().showButton
40+
}
3041

31-
private fun getOtherMessage(chatId: Long) = SendMessage().setChatId(chatId).setParseMode("Markdown")
42+
private fun getOtherMessage(chatId: Long) = SendMessage().apply {
43+
setChatId(chatId.toString())
44+
parseMode = "Markdown"
45+
}
3246

3347
fun getOtherMessageOpen(message: Message, chatId: Long, operator: User) =
34-
getOtherMessage(chatId).setText("#工寮開門 [${operator.firstName}](tg://user?id=${operator.id}) 已從「${message.chat.title}」群組於 ${Bot.dateTime} 送出開門資訊。")!!
48+
getOtherMessage(chatId).apply {
49+
text = "#工寮開門 [${operator.firstName}](tg://user?id=${operator.id}) 已從「${message.chat.title}」群組於 ${Bot.dateTime} 送出開門資訊。"
50+
}
3551

3652
fun getOtherMessageClose(message: Message, chatId: Long, operator: User) =
37-
getOtherMessage(chatId).setText("#工寮關門 [${operator.firstName}](tg://user?id=${operator.id}) 已從「${message.chat.title}」群組於 ${Bot.dateTime} 送出關門資訊。")!!
53+
getOtherMessage(chatId).apply {
54+
text = "#工寮關門 [${operator.firstName}](tg://user?id=${operator.id}) 已從「${message.chat.title}」群組於 ${Bot.dateTime} 送出關門資訊。"
55+
}
3856

3957
fun getCheckList(query: CallbackQuery): EditMessageReplyMarkup? {
4058
val data = query.data.split(":".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()
4159
when (data[0]) {
42-
"hide" -> return EditMessageReplyMarkup()
43-
.setChatId(query.message.chatId!!)
44-
.setMessageId(query.message.messageId)
45-
.setReplyMarkup(Keyboard().showButton)
46-
"list" -> {
47-
return if (data.size < 2) null else EditMessageReplyMarkup()
48-
.setChatId(query.message.chatId!!)
49-
.setMessageId(query.message.messageId)
50-
.setReplyMarkup(Keyboard().getCheckList(Integer.parseInt(data[1], 16)))
60+
"hide" -> return EditMessageReplyMarkup().apply {
61+
chatId = query.message.chatId.toString()
62+
messageId = query.message.messageId
63+
replyMarkup = Keyboard().showButton
64+
}
65+
"list" -> return if (data.size < 2) null else EditMessageReplyMarkup().apply {
66+
chatId = query.message.chatId.toString()
67+
messageId = query.message.messageId
68+
replyMarkup = Keyboard().getCheckList(Integer.parseInt(data[1], 16))
5169
}
5270
}
5371
return null

src/main/kotlin/org/moztw/bot/telegram/space/co2/model/Chart.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ data class Chart(
1010
private val dataX = data.map { it.first.format(DateTimeFormatter.ofPattern("HH:mm")) }
1111
private val dataY = data.map { it.second.toInt() }
1212

13-
private val dataMin = dataY.minBy { it } ?: 0
14-
private val dataMax = dataY.maxBy { it } ?: 0
13+
private val dataMin = dataY.minByOrNull { it } ?: 0
14+
private val dataMax = dataY.minByOrNull { it } ?: 0
1515
private val dataMid = (dataMin + dataMax) / 2
1616
private val dataQuad = arrayOf(dataMin, (dataMin + dataMid) / 2, dataMid, (dataMid + dataMax) / 2, dataMax)
1717

0 commit comments

Comments
 (0)