Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 20 additions & 5 deletions src/main/kotlin/quoterbot/Main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,12 @@ suspend fun main(args: Array<String>) {
dp.dispatch {
messages {
handle(CommandFilter("start")) { msg ->
val markup = ReplyKeyboardMarkup() {
val markup = ReplyKeyboardMarkup() {
add(KeyboardButton("/quote"))
}
quoterbot.bot.replyTo(msg,"Can you hear me?", replyMarkup=markup)
quoterbot.bot.replyTo(msg, "Can you hear me?", replyMarkup = markup)
}
initCommands()

}
}
dp.poll()
Expand Down Expand Up @@ -87,6 +86,7 @@ fun CommandBuilder.command(name: String, parser: ArgParser? = null, block: suspe
fun CommandBuilder.initCommands() {
bindCommand()
quoteCommand()
helpCommand()
}

fun CommandBuilder.bindCommand() {
Expand Down Expand Up @@ -162,18 +162,33 @@ fun CommandBuilder.quoteCommand() {
.append(":\n")
.append(quote.content)
.append("\n\n")
if(reply.length + quoteRep.length > 4096) {
if (reply.length + quoteRep.length > 4096) {
bot.answerOn(msg, reply.toString())
reply = StringBuilder()
}
reply.append(quoteRep)
}
if(reply.isNotEmpty()) {
if (reply.isNotEmpty()) {
bot.answerOn(msg, reply.toString())
}
}
}

fun CommandBuilder.helpCommand() {
val parser = ArgParser()
command("help", parser) { msg ->
bot.answerOn(
msg,
"Привет ^^ \n " +
"Спасибо, что используете нашего бота! \n " +
"Он пока ещё маленький, и поэтому знает не так много команд. Но со временем (если оно появится у разработчиков..), бот будет расти и развиваться! \n" +
"Так вот, список команд: \n" +
"/quote [id] - Это команда, которая выдаст нам цитату. /id - это число, однозначно задающее цитату/ \n" +
"/bind *осторожно, только для админов!!* - команда для переключения репозитория."
)
}
}

fun extractCount(a: List<String>): Pair<Int, List<String>> {
val countPos = a.indexOf("*")
require(a.lastIndexOf("*") == countPos) { "'*' cannot be specified multiple times" }
Expand Down