summaryrefslogtreecommitdiff
path: root/luamods/followlist.lua
diff options
context:
space:
mode:
authorilotterytea <iltsu@alright.party>2025-04-11 00:33:22 +0500
committerilotterytea <iltsu@alright.party>2025-04-11 00:33:22 +0500
commit87889f2efcdce62f680a5286ae0ecf86a9e09ca9 (patch)
tree45e3e95d3df110d05b365b16d837337c7a39fae4 /luamods/followlist.lua
parent02c5bd1a82aecf348ca97cdcfaaab30e1c31c4da (diff)
feat: !followlist command
Diffstat (limited to 'luamods/followlist.lua')
-rw-r--r--luamods/followlist.lua96
1 files changed, 96 insertions, 0 deletions
diff --git a/luamods/followlist.lua b/luamods/followlist.lua
new file mode 100644
index 0000000..5a3f6bd
--- /dev/null
+++ b/luamods/followlist.lua
@@ -0,0 +1,96 @@
+local lines = {
+ english = {
+ ["command_unavailable"] = "{sender.alias_name}: This command is not available.",
+ ["external_api_error"] = "{sender.alias_name}: Failed to get followlist for %s. Try again later. (%s)",
+ ["success"] = "{sender.alias_name}: %s",
+ },
+ russian = {
+ ["command_unavailable"] = "{sender.alias_name}: Эта команда недоступна.",
+ ["external_api_error"] = "{sender.alias_name}: Не удалось получить фолловлист %s. Попробуйте позже. (%s)",
+ ["success"] = "{sender.alias_name}: %s",
+ },
+}
+
+return {
+ name = "followlist",
+ description = [[
+Read the user's follows as plain text.
+After collecting the list of chatters, the bot returns a link to the paste from
+[the Pastebin-like service](https://paste.alright.party).
+
+## Syntax
+
+`!followlist <username>`
+
++ `<username>` - Twitch username *(optional)*.
+
+## Responses
++ `https://paste.alright.party/XXXXX.txt`
+]],
+ delay_sec = 5,
+ options = {},
+ subcommands = {},
+ aliases = { "flist", "follows" },
+ minimal_rights = "user",
+ handle = function(request)
+ cfg = bot_config()
+ if cfg == nil then
+ return l10n_custom_formatted_line_request(request, lines, "command_unavailable", {})
+ end
+
+ if
+ cfg.url.paste_service == nil
+ or cfg.commands.paste_path == nil
+ or cfg.commands.paste_body_name == nil
+ or cfg.commands.paste_title_name == nil
+ then
+ return l10n_custom_formatted_line_request(request, lines, "command_unavailable", {})
+ end
+
+ username = request.sender.alias_name
+
+ if request.message ~= nil then
+ username = request.message
+ end
+
+ response =
+ net_get_with_headers("https://tools.2807.eu/api/getfollows/" .. username, { Accept = "application/json" })
+
+ if response.code ~= 200 then
+ return l10n_custom_formatted_line_request(request, lines, "external_api_error", { username, response.code })
+ end
+
+ follows = json_parse(response.text)
+
+ body = #follows .. " channels\r\n---------------------\r\n\r\n"
+
+ for i = 1, #follows, 1 do
+ follow = follows[i]
+ follow_timestamp = time_parse(follow.followedAt, "%Y-%m-%dT%H:%M:%SZ")
+ follow_diff = time_humanize(time_current() - follow_timestamp)
+ body = body .. follow.login .. " (" .. follow_diff .. " ago)" .. "\r\n"
+ end
+
+ time = time_format(time_current(), "%d.%m.%Y %H:%M:%S %z")
+
+ response = net_post_multipart_with_headers(cfg.url.paste_service, {
+ [cfg.commands.paste_body_name] = body,
+ [cfg.commands.paste_title_name] = username .. "'s followlist on " .. time,
+ }, {
+ Accept = "application/json",
+ })
+
+ if response.code ~= 201 and response.code ~= 200 then
+ return l10n_custom_formatted_line_request(request, lines, "external_api_error", { response.code })
+ end
+
+ body = json_parse(response.text)
+
+ link = json_get_value(body, cfg.commands.paste_path)
+ if link == nil then
+ return l10n_custom_formatted_line_request(request, lines, "command_unavailable", {})
+ end
+
+ return l10n_custom_formatted_line_request(request, lines, "success", { link })
+ end,
+}