diff options
| author | ilotterytea <iltsu@alright.party> | 2025-07-23 10:43:56 +0500 |
|---|---|---|
| committer | ilotterytea <iltsu@alright.party> | 2025-07-23 10:43:56 +0500 |
| commit | bdf5110655da586e05da0c5dff3512b4d83bd207 (patch) | |
| tree | 5a353e07e7e858dc7b80f8373f736964c2b6ac66 | |
| parent | d63df159a389d5b2e071d5c116fda75e73c40e99 (diff) | |
feat: !telegram command
| -rw-r--r-- | luamods/telegram.lua | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/luamods/telegram.lua b/luamods/telegram.lua new file mode 100644 index 0000000..975740a --- /dev/null +++ b/luamods/telegram.lua @@ -0,0 +1,68 @@ +local lines = { + english = { + ["not_configured"] = "{sender.alias_name}: This command is not set up properly. Try again later.", + ["not_found"] = "{sender.alias_name}: Channel %s not found.", + ["no_value"] = "{sender.alias_name}: Public Telegram channel must be specified.", + ["message"] = "{sender.alias_name}: %s's last post: %s (posted %s ago)", + ["no_messages"] = "{sender.alias_name}: This Telegram channel does not have any posts." + }, + russian = { + ["not_configured"] = "{sender.alias_name}: Команда не настроена. Попробуйте позже.", + ["not_found"] = "{sender.alias_name}: Канал %s не найден.", + ["no_value"] = "{sender.alias_name}: Нужно указать публичный Telegram канал.", + ["message"] = "{sender.alias_name}: Последний пост %s: %s (опубликовано %s назад)", + ["no_messages"] = "{sender.alias_name}: Этот Telegram канал не содержит каких-либо постов." + }, +} + +return { + name = "telegram", + description = [[ +Get the latest post from the specified public Telegram channel. + +## Syntax + +`!telegram [username]` + ++ `[username]` - Valid public Telegram channel. + +## Usage + ++ `!telegram durov` +]], + delay_sec = 5, + options = {}, + subcommands = {}, + aliases = { "tg", "tgc", "тгк" }, + minimal_rights = "user", + handle = function(request) + local cfg = bot_config() + if cfg.url.rssbridge == nil then + return l10n_custom_formatted_line_request(request, lines, "not_configured", {}) + end + + if request.message == nil then + return l10n_custom_formatted_line_request(request, lines, "no_value", {}) + end + + local url = str_format(cfg.url.rssbridge, { "TelegramBridge", request.message }) + local channel = rss_get(url) + if channel == nil then + return l10n_custom_formatted_line_request(request, lines, "not_found", { request.message }) + end + + local posts = channel.messages + if #posts == 0 then + return l10n_custom_formatted_line_request(request, lines, "no_messages", {}) + end + + local latest_post = posts[1] + local post_time = "N/A" + if latest_post.timestamp ~= 0 then + post_time = time_humanize(time_current() - latest_post.timestamp) + end + + return l10n_custom_formatted_line_request(request, lines, "message", + { request.message, latest_post.title, post_time }) + end, +} |
