forked from kotlin-telegram-bot/kotlin-telegram-bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Main.kt
68 lines (52 loc) 路 2.28 KB
/
Main.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package me.ivmg.filters
import me.ivmg.telegram.bot
import me.ivmg.telegram.dispatch
import me.ivmg.telegram.dispatcher.filter
import me.ivmg.telegram.dispatcher.filters.Filter
import me.ivmg.telegram.dispatcher.filters.and
import me.ivmg.telegram.dispatcher.filters.not
import me.ivmg.telegram.dispatcher.filters.or
import me.ivmg.telegram.dispatcher.text
fun main(args: Array<String>) {
val one: Filter = { it.message?.text?.contains('1') ?: false }
val two: Filter = { it.message?.text?.contains('2') ?: false }
val three: Filter = { it.message?.text?.contains('3') ?: false }
val bot = bot {
token = "YOUR_API_KEY"
dispatch {
text(filter = one) { bot, update ->
bot.sendMessage(chatId = update.message!!.chat.id, text = "1")
}
text(filter = !one) { bot, update ->
bot.sendMessage(chatId = update.message!!.chat.id, text = "not 1")
}
text(filter = two) { bot, update ->
bot.sendMessage(chatId = update.message!!.chat.id, text = "2")
}
text(filter = one and two) { bot, update ->
bot.sendMessage(chatId = update.message!!.chat.id, text = "1 and 2")
}
text(filter = one or two) { bot, update ->
bot.sendMessage(chatId = update.message!!.chat.id, text = "1 or 2")
}
// important: use parenthesis because `and` doesn't take precedence over `or`
text(filter = one or (two and three)) { bot, update ->
bot.sendMessage(chatId = update.message!!.chat.id, text = "1 or 2 and 3")
}
filter(two) {
text { bot, update ->
bot.sendMessage(chatId = update.message!!.chat.id, text = "2 [filter block]")
}
text(filter = three) { bot, update ->
bot.sendMessage(chatId = update.message!!.chat.id, text = "2 and 3 [filter block + custom filter]")
}
filter(one) {
text { bot, update ->
bot.sendMessage(chatId = update.message!!.chat.id, text = "2 and 1 [nested filter blocks]")
}
}
}
}
}
bot.startPolling()
}