Skip to content

Commit

Permalink
/gdpr and /privacy command handlers stubs
Browse files Browse the repository at this point in the history
  • Loading branch information
madhead committed Jul 5, 2024
1 parent 113af12 commit 06c48c6
Show file tree
Hide file tree
Showing 7 changed files with 130 additions and 4 deletions.
6 changes: 3 additions & 3 deletions .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions .idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package me.madhead.tyzenhaus.core.telegram.updates.policy

import dev.inmo.tgbotapi.bot.RequestsExecutor
import dev.inmo.tgbotapi.extensions.api.send.sendMessage
import dev.inmo.tgbotapi.types.buttons.InlineKeyboardButtons.CallbackDataInlineKeyboardButton
import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup
import dev.inmo.tgbotapi.types.message.MarkdownV2
import dev.inmo.tgbotapi.types.message.abstracts.CommonMessage
import dev.inmo.tgbotapi.types.message.content.TextContent
import dev.inmo.tgbotapi.types.message.textsources.BotCommandTextSource
import dev.inmo.tgbotapi.types.update.MessageUpdate
import dev.inmo.tgbotapi.types.update.abstracts.Update
import me.madhead.tyzenhaus.core.telegram.updates.UpdateProcessor
import me.madhead.tyzenhaus.core.telegram.updates.UpdateReaction
import me.madhead.tyzenhaus.core.telegram.updates.groupId
import me.madhead.tyzenhaus.core.telegram.updates.lang.LangCallbackQueryUpdateProcessor.Companion.CALLBACK_PREFIX
import me.madhead.tyzenhaus.core.telegram.updates.policy.PrivacyCommandUpdateProcessor.Companion
import me.madhead.tyzenhaus.core.telegram.updates.userId
import me.madhead.tyzenhaus.entity.dialog.state.DialogState
import me.madhead.tyzenhaus.entity.group.config.GroupConfig
import me.madhead.tyzenhaus.i18.I18N
import org.apache.logging.log4j.LogManager

/**
* /GDPR command handler.
*/
class GDPRCommandUpdateProcessor(
private val requestsExecutor: RequestsExecutor,
) : UpdateProcessor {
companion object {
private val logger = LogManager.getLogger(GDPRCommandUpdateProcessor::class.java)!!
}

@Suppress("DuplicatedCode")
override suspend fun process(update: Update, groupConfig: GroupConfig?, dialogState: DialogState?): UpdateReaction? {
@Suppress("NAME_SHADOWING")
val update = update as? MessageUpdate ?: return null
val message = update.data as? CommonMessage<*> ?: return null
val content = (message as? CommonMessage<*>)?.content as? TextContent ?: return null

return if (content.textSources.any { "gdpr" == (it as? BotCommandTextSource)?.command }) {
{
logger.debug("{} asked for GDPR in {}", update.userId, update.groupId)

requestsExecutor.sendMessage(
chatId = update.data.chat.id,
text = I18N(groupConfig?.language)["gdpr"],
parseMode = MarkdownV2,
disableWebPagePreview = true,
)
}
} else null
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package me.madhead.tyzenhaus.core.telegram.updates.policy

import dev.inmo.tgbotapi.bot.RequestsExecutor
import dev.inmo.tgbotapi.extensions.api.send.sendMessage
import dev.inmo.tgbotapi.types.buttons.InlineKeyboardButtons.CallbackDataInlineKeyboardButton
import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup
import dev.inmo.tgbotapi.types.message.MarkdownV2
import dev.inmo.tgbotapi.types.message.abstracts.CommonMessage
import dev.inmo.tgbotapi.types.message.content.TextContent
import dev.inmo.tgbotapi.types.message.textsources.BotCommandTextSource
import dev.inmo.tgbotapi.types.update.MessageUpdate
import dev.inmo.tgbotapi.types.update.abstracts.Update
import me.madhead.tyzenhaus.core.telegram.updates.UpdateProcessor
import me.madhead.tyzenhaus.core.telegram.updates.UpdateReaction
import me.madhead.tyzenhaus.core.telegram.updates.groupId
import me.madhead.tyzenhaus.core.telegram.updates.help.HelpCommandUpdateProcessor
import me.madhead.tyzenhaus.core.telegram.updates.help.HelpCommandUpdateProcessor.Companion
import me.madhead.tyzenhaus.core.telegram.updates.lang.LangCallbackQueryUpdateProcessor.Companion.CALLBACK_PREFIX
import me.madhead.tyzenhaus.core.telegram.updates.userId
import me.madhead.tyzenhaus.entity.dialog.state.DialogState
import me.madhead.tyzenhaus.entity.group.config.GroupConfig
import me.madhead.tyzenhaus.i18.I18N
import org.apache.logging.log4j.LogManager

/**
* /privacy command handler.
*/
class PrivacyCommandUpdateProcessor(
private val requestsExecutor: RequestsExecutor,
) : UpdateProcessor {
companion object {
private val logger = LogManager.getLogger(PrivacyCommandUpdateProcessor::class.java)!!
}

@Suppress("DuplicatedCode")
override suspend fun process(update: Update, groupConfig: GroupConfig?, dialogState: DialogState?): UpdateReaction? {
@Suppress("NAME_SHADOWING")
val update = update as? MessageUpdate ?: return null
val message = update.data as? CommonMessage<*> ?: return null
val content = (message as? CommonMessage<*>)?.content as? TextContent ?: return null

return if (content.textSources.any { "privacy" == (it as? BotCommandTextSource)?.command }) {
{
logger.debug("{} asked for privacy in {}", update.userId, update.groupId)

requestsExecutor.sendMessage(
chatId = update.data.chat.id,
text = I18N(groupConfig?.language)["privacy"],
parseMode = MarkdownV2,
disableWebPagePreview = true,
)
}
} else null
}
}
3 changes: 3 additions & 0 deletions i18n/src/main/resources/i18n.properties
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,6 @@ debts.response.title=*💸 Debts in this group:*\n\n
debts.response.owes={0} → {1}: {2}

history.response=Click [👉 here 📜](https://t\\.me/{0}/history?startapp\\={1}) to view the transaction history\\.

privacy=PRIVACY
gdpr=GDPR
1 change: 0 additions & 1 deletion launcher/fly/requests.http
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ Content-Type: application/json
POST https://{{ngrok}}/app/api/auth/validation
Authorization: Bearer {{api_token}}


### Get group members
GET https://{{ngrok}}/app/api/group/members
Authorization: Bearer {{api_token}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import me.madhead.tyzenhaus.core.telegram.updates.help.WelcomeMessageUpdateProce
import me.madhead.tyzenhaus.core.telegram.updates.history.HistoryCommandUpdateProcessor
import me.madhead.tyzenhaus.core.telegram.updates.lang.LangCallbackQueryUpdateProcessor
import me.madhead.tyzenhaus.core.telegram.updates.lang.LangCommandUpdateProcessor
import me.madhead.tyzenhaus.core.telegram.updates.policy.GDPRCommandUpdateProcessor
import me.madhead.tyzenhaus.core.telegram.updates.policy.PrivacyCommandUpdateProcessor
import me.madhead.tyzenhaus.core.telegram.updates.supergroup.SupergroupChatCreatedUpdateProcessor
import me.madhead.tyzenhaus.core.telegram.updates.support.IDCommandUpdateProcessor
import org.koin.dsl.module
Expand Down Expand Up @@ -138,6 +140,16 @@ val pipelineModule = module {
apiTokenRepository = get(),
)
}
single {
PrivacyCommandUpdateProcessor(
requestsExecutor = get(),
)
}
single {
GDPRCommandUpdateProcessor(
requestsExecutor = get(),
)
}
single {
UpdateProcessingPipeline(
listOf(
Expand All @@ -159,6 +171,8 @@ val pipelineModule = module {
get<ParticipateCommandUpdateProcessor>(),
get<SupergroupChatCreatedUpdateProcessor>(),
get<HistoryCommandUpdateProcessor>(),
get<PrivacyCommandUpdateProcessor>(),
get<GDPRCommandUpdateProcessor>(),
),
get(),
get(),
Expand Down

0 comments on commit 06c48c6

Please sign in to comment.