Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BanHammer #4

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ project/boot/
project/plugins/project/
.history
.cache
.idea
.lib/
build
.gradle
gradle/wrapper/gradle-wrapper.jar
last_podcast_number.txt
last_podcast_number.txt
10 changes: 10 additions & 0 deletions Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Telegram bot for ["Фронтенд Юность"](https://t.me/frontend_u) chat

## Building
```bash
gradle build
```

Authors:
- @immorte
- @likipiki
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ repositories {

dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
compile "io.github.kotlin-telegram-bot.kotlin-telegram-bot:telegram:5.0.0"
compile "io.github.kotlin-telegram-bot.kotlin-telegram-bot:telegram:6.0.6"
compile "io.ktor:ktor-client-cio:1.3.2"
compile "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.6"
compile "io.github.microutils:kotlin-logging:1.7.9"
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#Wed May 06 02:55:56 MSK 2020
distributionUrl=https\://services.gradle.org/distributions/gradle-6.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-6.9-all.zip
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStorePath=wrapper/dists
Expand Down
12 changes: 10 additions & 2 deletions src/main/kotlin/Commands.kt
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import com.github.kotlintelegrambot.Bot
import com.github.kotlintelegrambot.entities.InlineQuery
import com.github.kotlintelegrambot.entities.ChatId
import com.github.kotlintelegrambot.entities.inlinequeryresults.InlineQueryResult
import com.github.kotlintelegrambot.entities.inlinequeryresults.InputMessageContent
import com.github.kotlintelegrambot.entities.Message
import services.soundcloud.AllPodcasts
import services.telegram.Message
import services.telegram.Message as ServiceMessage
import services.telegram.Service

fun handleInlineQuery(bot: Bot, iq: InlineQuery, podcastsTitles: AllPodcasts?) {
Expand All @@ -17,7 +19,7 @@ fun handleInlineQuery(bot: Bot, iq: InlineQuery, podcastsTitles: AllPodcasts?) {
id = podcast.title,
title = podcast.title,
inputMessageContent = InputMessageContent.Text(
Message.podcastMessage(podcast, true),
ServiceMessage.podcastMessage(podcast, true),
parseMode = Service.PARSE_MODE
),
description = "Найдено"
Expand All @@ -26,3 +28,9 @@ fun handleInlineQuery(bot: Bot, iq: InlineQuery, podcastsTitles: AllPodcasts?) {

bot.answerInlineQuery(iq.id, list)
}

fun handleMemeQuery(bot: Bot, message: Message, text: String) {
when (text) {
"карман" -> bot.sendMessage(ChatId.fromId(message.chat.id), "Порвался!", disableNotification = true);
}
}
14 changes: 9 additions & 5 deletions src/main/kotlin/Main.kt
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import com.github.kotlintelegrambot.bot
import com.github.kotlintelegrambot.dispatch
import com.github.kotlintelegrambot.dispatcher.inlineQuery
import com.github.kotlintelegrambot.dispatcher.message
import com.github.kotlintelegrambot.dispatcher.text
import com.github.kotlintelegrambot.logging.LogLevel
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.channels.Channel
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
import okhttp3.logging.HttpLoggingInterceptor
import services.soundcloud.PodcastMessage
import services.soundcloud.SoundCloudWatcher
import services.telegram.MessageSendResponse
Expand All @@ -25,10 +25,14 @@ fun main() = runBlocking {
System.getenv("FU_TG_BOT_KEY")
?: throw IllegalStateException("env tg bot key FU_TG_BOT_KEY is not provided")
timeout = 5
logLevel = HttpLoggingInterceptor.Level.NONE
logLevel = LogLevel.Network.Body

dispatch {
inlineQuery { bot, iq ->
handleInlineQuery(bot, iq, soundCloudWatcher.allPodcastsTitles)
inlineQuery {
handleInlineQuery(bot, inlineQuery, soundCloudWatcher.allPodcastsTitles)
}
text { ->
handleMemeQuery(bot, message, text);
}
}
}
Expand Down
6 changes: 4 additions & 2 deletions src/main/kotlin/services/telegram/Message.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package services.telegram

import com.github.kotlintelegrambot.entities.InlineKeyboardButton
import com.github.kotlintelegrambot.entities.keyboard.InlineKeyboardButton
import com.github.kotlintelegrambot.entities.InlineKeyboardMarkup
import services.soundcloud.Podcast

Expand All @@ -25,7 +25,9 @@ ${if (withLink) "<a href='${message.link}'>$listenPodcastButton</a>" else ""}
}

fun buildListenButton(URL: String) =
InlineKeyboardMarkup.createSingleButton(InlineKeyboardButton(text = listenPodcastButton, url = URL))
InlineKeyboardMarkup.createSingleButton(
InlineKeyboardButton.Url(text = listenPodcastButton, url = URL)
)

private fun prettifyDescription(description: String, URL: String): String {
val split = description.split("\n\n")
Expand Down