mirror of
https://github.com/InsanusMokrassar/CaptchaPlaguBotPlugin.git
synced 2024-11-26 03:58:52 +00:00
commit
8f25f8233e
16
.github/workflows/build.yml
vendored
16
.github/workflows/build.yml
vendored
@ -1,16 +0,0 @@
|
|||||||
name: Build
|
|
||||||
|
|
||||||
on: [push]
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
build:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v2
|
|
||||||
- name: Set up JDK 1.8
|
|
||||||
uses: actions/setup-java@v1
|
|
||||||
with:
|
|
||||||
java-version: 1.8
|
|
||||||
- name: Build with Gradle
|
|
||||||
run: ./gradlew build
|
|
27
.github/workflows/publish_package.yml
vendored
Normal file
27
.github/workflows/publish_package.yml
vendored
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
|
||||||
|
name: Publish package to GitHub Packages
|
||||||
|
on: [push]
|
||||||
|
jobs:
|
||||||
|
publishing:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
- uses: actions/setup-java@v1
|
||||||
|
with:
|
||||||
|
java-version: 1.8
|
||||||
|
- name: Update version
|
||||||
|
run: |
|
||||||
|
branch="`echo "${{ github.ref }}" | grep -o "[^/]*$"`"
|
||||||
|
sed -i -e "s/^project_version=\([0-9\.]*\)/project_version=\1-branch_$branch-build${{ github.run_number }}/" gradle.properties
|
||||||
|
- name: prebuild
|
||||||
|
run: ./gradlew clean build
|
||||||
|
env:
|
||||||
|
GITHUB_USER: ${{ github.actor }}
|
||||||
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
- name: Publish package
|
||||||
|
run: ./gradlew publishAllPublicationsToGithubPackagesRepository --no-parallel -x signMavenPublication
|
||||||
|
env:
|
||||||
|
GITHUBPACKAGES_USER: ${{ github.actor }}
|
||||||
|
GITHUBPACKAGES_PASSWORD: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
GITHUB_USER: ${{ github.actor }}
|
||||||
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
13
build.gradle
13
build.gradle
@ -17,12 +17,22 @@ plugins {
|
|||||||
apply from: "./publish.gradle"
|
apply from: "./publish.gradle"
|
||||||
|
|
||||||
project.group = "$project_group"
|
project.group = "$project_group"
|
||||||
project.version = "$plagubot_version"
|
project.version = "$project_version"
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
mavenLocal()
|
mavenLocal()
|
||||||
mavenCentral()
|
mavenCentral()
|
||||||
jcenter()
|
jcenter()
|
||||||
|
if ((project.hasProperty("GITHUB_USER") || System.getenv("GITHUB_USER") != null) && (project.hasProperty("GITHUB_TOKEN") || System.getenv("GITHUB_TOKEN") != null)) {
|
||||||
|
maven {
|
||||||
|
name = "GitHubPackages"
|
||||||
|
url = uri("https://maven.pkg.github.com/InsanusMokrassar/TelegramBotApiLibraries")
|
||||||
|
credentials {
|
||||||
|
username = project.hasProperty("GITHUB_USER") ? project.getProperty("GITHUB_USER") : System.getenv("GITHUB_USER")
|
||||||
|
password = project.hasProperty("GITHUB_TOKEN") ? project.getProperty("GITHUB_TOKEN") : System.getenv("GITHUB_TOKEN")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
@ -32,4 +42,5 @@ dependencies {
|
|||||||
|
|
||||||
api "dev.inmo:plagubot.plugin:$plagubot_version"
|
api "dev.inmo:plagubot.plugin:$plagubot_version"
|
||||||
api "dev.inmo:micro_utils.repos.exposed:$micro_utils_version"
|
api "dev.inmo:micro_utils.repos.exposed:$micro_utils_version"
|
||||||
|
api "dev.inmo:tgbotapi.libraries.cache.admins.plagubot:$tgbotapi_libraries_version"
|
||||||
}
|
}
|
||||||
|
@ -4,11 +4,13 @@ org.gradle.parallel=true
|
|||||||
kotlin.js.generate.externals=true
|
kotlin.js.generate.externals=true
|
||||||
kotlin.incremental=true
|
kotlin.incremental=true
|
||||||
|
|
||||||
kotlin_version=1.4.30
|
kotlin_version=1.4.31
|
||||||
kotlin_coroutines_version=1.4.2
|
kotlin_coroutines_version=1.4.3
|
||||||
kotlin_serialisation_runtime_version=1.1.0-RC
|
kotlin_serialisation_runtime_version=1.1.0
|
||||||
plagubot_version=0.1.3
|
plagubot_version=0.1.5
|
||||||
|
|
||||||
micro_utils_version=0.4.25
|
micro_utils_version=0.4.30
|
||||||
|
tgbotapi_libraries_version=0.0.2-branch_master-build11
|
||||||
|
|
||||||
project_group=dev.inmo
|
project_group=dev.inmo
|
||||||
|
project_version=0.1.4
|
||||||
|
@ -51,12 +51,24 @@ publishing {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
repositories {
|
repositories {
|
||||||
maven {
|
if ((project.hasProperty('GITHUBPACKAGES_USER') || System.getenv('GITHUBPACKAGES_USER') != null) && (project.hasProperty('GITHUBPACKAGES_PASSWORD') || System.getenv('GITHUBPACKAGES_PASSWORD') != null)) {
|
||||||
name = "sonatype"
|
maven {
|
||||||
url = uri("https://oss.sonatype.org/service/local/staging/deploy/maven2/")
|
name = "GithubPackages"
|
||||||
credentials {
|
url = uri("https://maven.pkg.github.com/InsanusMokrassar/CaptchaPlaguBotPlugin")
|
||||||
username = project.hasProperty('SONATYPE_USER') ? project.property('SONATYPE_USER') : System.getenv('SONATYPE_USER')
|
credentials {
|
||||||
password = project.hasProperty('SONATYPE_PASSWORD') ? project.property('SONATYPE_PASSWORD') : System.getenv('SONATYPE_PASSWORD')
|
username = project.hasProperty('GITHUBPACKAGES_USER') ? project.property('GITHUBPACKAGES_USER') : System.getenv('GITHUBPACKAGES_USER')
|
||||||
|
password = project.hasProperty('GITHUBPACKAGES_PASSWORD') ? project.property('GITHUBPACKAGES_PASSWORD') : System.getenv('GITHUBPACKAGES_PASSWORD')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ((project.hasProperty('SONATYPE_USER') || System.getenv('SONATYPE_USER') != null) && (project.hasProperty('SONATYPE_PASSWORD') || System.getenv('SONATYPE_PASSWORD') != null)) {
|
||||||
|
maven {
|
||||||
|
name = "sonatype"
|
||||||
|
url = uri("https://oss.sonatype.org/service/local/staging/deploy/maven2/")
|
||||||
|
credentials {
|
||||||
|
username = project.hasProperty('SONATYPE_USER') ? project.property('SONATYPE_USER') : System.getenv('SONATYPE_USER')
|
||||||
|
password = project.hasProperty('SONATYPE_PASSWORD') ? project.property('SONATYPE_PASSWORD') : System.getenv('SONATYPE_PASSWORD')
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1 +1 @@
|
|||||||
{"licenses":[{"id":"Apache-2.0","title":"Apache Software License 2.0","url":"https://github.com/InsanusMokrassar/CaptchaPlaguBotPlugin/blob/master/LICENSE"}],"mavenConfig":{"name":"${project.name}","description":"${project.name}","url":"https://github.com/InsanusMokrassar/CaptchaPlaguBotPlugin","vcsUrl":"https://github.com/InsanusMokrassar/CaptchaPlaguBotPlugin.git","includeGpgSigning":true,"publishToMavenCentral":true,"developers":[{"id":"InsanusMokrassar","name":"Ovsiannikov Aleksei","eMail":"ovsyannikov.alexey95@gmail.com"}]},"type":"JVM"}
|
{"licenses":[{"id":"Apache-2.0","title":"Apache Software License 2.0","url":"https://github.com/InsanusMokrassar/CaptchaPlaguBotPlugin/blob/master/LICENSE"}],"mavenConfig":{"name":"${project.name}","description":"${project.name}","url":"https://github.com/InsanusMokrassar/CaptchaPlaguBotPlugin","vcsUrl":"https://github.com/InsanusMokrassar/CaptchaPlaguBotPlugin.git","includeGpgSigning":true,"developers":[{"id":"InsanusMokrassar","name":"Ovsiannikov Aleksei","eMail":"ovsyannikov.alexey95@gmail.com"}],"repositories":[{"name":"GithubPackages","url":"https://maven.pkg.github.com/InsanusMokrassar/CaptchaPlaguBotPlugin"},{"name":"sonatype","url":"https://oss.sonatype.org/service/local/staging/deploy/maven2/"}]},"type":"JVM"}
|
@ -16,32 +16,55 @@ import dev.inmo.tgbotapi.extensions.api.send.sendTextMessage
|
|||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.*
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.*
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.waitBaseInlineQuery
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.waitBaseInlineQuery
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.waitDataCallbackQuery
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.waitDataCallbackQuery
|
||||||
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onCommand
|
||||||
import dev.inmo.tgbotapi.updateshandlers.FlowsUpdatesFilter
|
import dev.inmo.tgbotapi.updateshandlers.FlowsUpdatesFilter
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onNewChatMembers
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onNewChatMembers
|
||||||
import dev.inmo.tgbotapi.extensions.utils.*
|
import dev.inmo.tgbotapi.extensions.utils.*
|
||||||
import dev.inmo.tgbotapi.extensions.utils.formatting.buildEntities
|
import dev.inmo.tgbotapi.extensions.utils.formatting.buildEntities
|
||||||
import dev.inmo.tgbotapi.extensions.utils.formatting.regular
|
import dev.inmo.tgbotapi.extensions.utils.formatting.regular
|
||||||
import dev.inmo.tgbotapi.extensions.utils.shortcuts.executeUnsafe
|
import dev.inmo.tgbotapi.extensions.utils.shortcuts.executeUnsafe
|
||||||
|
import dev.inmo.tgbotapi.libraries.cache.admins.*
|
||||||
import dev.inmo.tgbotapi.requests.DeleteMessage
|
import dev.inmo.tgbotapi.requests.DeleteMessage
|
||||||
|
import dev.inmo.tgbotapi.types.BotCommand
|
||||||
import dev.inmo.tgbotapi.types.MessageEntity.textsources.mention
|
import dev.inmo.tgbotapi.types.MessageEntity.textsources.mention
|
||||||
import dev.inmo.tgbotapi.types.User
|
import dev.inmo.tgbotapi.types.User
|
||||||
import dev.inmo.tgbotapi.types.chat.ChatPermissions
|
import dev.inmo.tgbotapi.types.chat.ChatPermissions
|
||||||
import dev.inmo.tgbotapi.types.chat.LeftRestrictionsChatPermissions
|
import dev.inmo.tgbotapi.types.chat.LeftRestrictionsChatPermissions
|
||||||
|
import dev.inmo.tgbotapi.types.chat.abstracts.Chat
|
||||||
|
import dev.inmo.tgbotapi.types.chat.abstracts.PublicChat
|
||||||
import dev.inmo.tgbotapi.types.dice.SlotMachineDiceAnimationType
|
import dev.inmo.tgbotapi.types.dice.SlotMachineDiceAnimationType
|
||||||
import dev.inmo.tgbotapi.types.message.abstracts.Message
|
import dev.inmo.tgbotapi.types.message.abstracts.*
|
||||||
|
import dev.inmo.tgbotapi.types.message.content.abstracts.MessageContent
|
||||||
import kotlinx.coroutines.*
|
import kotlinx.coroutines.*
|
||||||
import kotlinx.coroutines.channels.Channel
|
import kotlinx.coroutines.channels.Channel
|
||||||
import kotlinx.coroutines.channels.toList
|
import kotlinx.coroutines.channels.toList
|
||||||
import kotlinx.serialization.Serializable
|
import kotlinx.serialization.Serializable
|
||||||
import org.jetbrains.exposed.sql.Database
|
import org.jetbrains.exposed.sql.Database
|
||||||
|
|
||||||
|
private const val enableAutoDeleteCommands = "captcha_auto_delete_commands_on"
|
||||||
|
private const val disableAutoDeleteCommands = "captcha_auto_delete_commands_off"
|
||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
class CaptchaBotPlugin : Plugin {
|
class CaptchaBotPlugin : Plugin {
|
||||||
|
override suspend fun getCommands(): List<BotCommand> = listOf(
|
||||||
|
BotCommand(
|
||||||
|
enableAutoDeleteCommands,
|
||||||
|
"Enable auto removing of commands addressed to captcha plugin"
|
||||||
|
),
|
||||||
|
BotCommand(
|
||||||
|
disableAutoDeleteCommands,
|
||||||
|
"Disable auto removing of commands addressed to captcha plugin"
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
override suspend fun BehaviourContext.invoke(
|
override suspend fun BehaviourContext.invoke(
|
||||||
database: Database,
|
database: Database,
|
||||||
params: Map<String, Any>
|
params: Map<String, Any>
|
||||||
) {
|
) {
|
||||||
val repo = CaptchaChatsSettingsRepo(database)
|
val repo = CaptchaChatsSettingsRepo(database)
|
||||||
|
val adminsAPI = params.adminsPlugin ?.adminsAPI(database)
|
||||||
|
suspend fun Chat.settings() = repo.getById(id) ?: repo.create(ChatSettings(id)).first()
|
||||||
|
|
||||||
onNewChatMembers(
|
onNewChatMembers(
|
||||||
additionalFilter = {
|
additionalFilter = {
|
||||||
it.chat.asPublicChat() != null
|
it.chat.asPublicChat() != null
|
||||||
@ -59,7 +82,7 @@ class CaptchaBotPlugin : Plugin {
|
|||||||
permissions = ChatPermissions()
|
permissions = ChatPermissions()
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
val settings = repo.getById(it.chat.id) ?: repo.create(ChatSettings(it.chat.id)).firstOrNull() ?: return@onNewChatMembers
|
val settings = it.chat.settings() ?: return@onNewChatMembers
|
||||||
val userBanDateTime = eventDateTime + settings.checkTimeSpan
|
val userBanDateTime = eventDateTime + settings.checkTimeSpan
|
||||||
val authorized = Channel<User>(newUsers.size)
|
val authorized = Channel<User>(newUsers.size)
|
||||||
val messagesToDelete = Channel<Message>(Channel.UNLIMITED)
|
val messagesToDelete = Channel<Message>(Channel.UNLIMITED)
|
||||||
@ -128,5 +151,36 @@ class CaptchaBotPlugin : Plugin {
|
|||||||
executeUnsafe(DeleteMessage(message.chat.id, message.messageId), retries = 0)
|
executeUnsafe(DeleteMessage(message.chat.id, message.messageId), retries = 0)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (adminsAPI != null) {
|
||||||
|
onCommand(
|
||||||
|
enableAutoDeleteCommands,
|
||||||
|
requireOnlyCommandInMessage = false
|
||||||
|
) { message ->
|
||||||
|
message.doAfterVerification(adminsAPI) {
|
||||||
|
val settings = message.chat.settings()
|
||||||
|
|
||||||
|
repo.update(
|
||||||
|
message.chat.id,
|
||||||
|
settings.copy(autoRemoveCommands = true)
|
||||||
|
)
|
||||||
|
|
||||||
|
deleteMessage(message)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
onCommand(
|
||||||
|
disableAutoDeleteCommands,
|
||||||
|
requireOnlyCommandInMessage = false
|
||||||
|
) { message ->
|
||||||
|
message.doAfterVerification(adminsAPI) {
|
||||||
|
val settings = message.chat.settings()
|
||||||
|
|
||||||
|
repo.update(
|
||||||
|
message.chat.id,
|
||||||
|
settings.copy(autoRemoveCommands = false)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,6 +17,7 @@ class CaptchaChatsSettingsRepo(
|
|||||||
private val chatIdColumn = long("chatId")
|
private val chatIdColumn = long("chatId")
|
||||||
private val checkTimeSecondsColumn = integer("checkTime")
|
private val checkTimeSecondsColumn = integer("checkTime")
|
||||||
private val solveCaptchaTextColumn = text("solveCaptchaText")
|
private val solveCaptchaTextColumn = text("solveCaptchaText")
|
||||||
|
private val autoRemoveCommandsColumn = bool("autoRemoveCommands")
|
||||||
|
|
||||||
override val primaryKey = PrimaryKey(chatIdColumn)
|
override val primaryKey = PrimaryKey(chatIdColumn)
|
||||||
|
|
||||||
@ -30,19 +31,22 @@ class CaptchaChatsSettingsRepo(
|
|||||||
it[chatIdColumn] = value.chatId.chatId
|
it[chatIdColumn] = value.chatId.chatId
|
||||||
it[checkTimeSecondsColumn] = value.checkTime
|
it[checkTimeSecondsColumn] = value.checkTime
|
||||||
it[solveCaptchaTextColumn] = value.captchaText
|
it[solveCaptchaTextColumn] = value.captchaText
|
||||||
|
it[autoRemoveCommandsColumn] = value.autoRemoveCommands
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun update(id: ChatId, value: ChatSettings, it: UpdateStatement) {
|
override fun update(id: ChatId, value: ChatSettings, it: UpdateStatement) {
|
||||||
if (id.chatId == value.chatId.chatId) {
|
if (id.chatId == value.chatId.chatId) {
|
||||||
it[checkTimeSecondsColumn] = value.checkTime
|
it[checkTimeSecondsColumn] = value.checkTime
|
||||||
it[solveCaptchaTextColumn] = value.captchaText
|
it[solveCaptchaTextColumn] = value.captchaText
|
||||||
|
it[autoRemoveCommandsColumn] = value.autoRemoveCommands
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun InsertStatement<Number>.asObject(value: ChatSettings): ChatSettings = ChatSettings(
|
override fun InsertStatement<Number>.asObject(value: ChatSettings): ChatSettings = ChatSettings(
|
||||||
get(chatIdColumn).toChatId(),
|
get(chatIdColumn).toChatId(),
|
||||||
get(checkTimeSecondsColumn),
|
get(checkTimeSecondsColumn),
|
||||||
get(solveCaptchaTextColumn)
|
get(solveCaptchaTextColumn),
|
||||||
|
get(autoRemoveCommandsColumn)
|
||||||
)
|
)
|
||||||
|
|
||||||
override val selectById: SqlExpressionBuilder.(ChatId) -> Op<Boolean> = { chatIdColumn.eq(it.chatId) }
|
override val selectById: SqlExpressionBuilder.(ChatId) -> Op<Boolean> = { chatIdColumn.eq(it.chatId) }
|
||||||
@ -50,7 +54,8 @@ class CaptchaChatsSettingsRepo(
|
|||||||
get() = ChatSettings(
|
get() = ChatSettings(
|
||||||
get(chatIdColumn).toChatId(),
|
get(chatIdColumn).toChatId(),
|
||||||
get(checkTimeSecondsColumn),
|
get(checkTimeSecondsColumn),
|
||||||
get(solveCaptchaTextColumn)
|
get(solveCaptchaTextColumn),
|
||||||
|
get(autoRemoveCommandsColumn)
|
||||||
)
|
)
|
||||||
|
|
||||||
init {
|
init {
|
||||||
|
@ -10,7 +10,8 @@ import kotlinx.serialization.Transient
|
|||||||
data class ChatSettings(
|
data class ChatSettings(
|
||||||
val chatId: ChatId,
|
val chatId: ChatId,
|
||||||
val checkTime: Seconds = 60,
|
val checkTime: Seconds = 60,
|
||||||
val captchaText: String = "solve next captcha:"
|
val captchaText: String = "solve next captcha:",
|
||||||
|
val autoRemoveCommands: Boolean = false
|
||||||
) {
|
) {
|
||||||
@Transient
|
@Transient
|
||||||
val checkTimeSpan = TimeSpan(checkTime * 1000.0)
|
val checkTimeSpan = TimeSpan(checkTime * 1000.0)
|
||||||
|
Loading…
Reference in New Issue
Block a user