- RSS für Kanäle! Fix #6
- ID kennzeichnet Chat-Admins und -Gründer - table.contains() in utilites.lua verschoben - Mehr Bindings: getChatInfo, getChatAdministrators
This commit is contained in:
parent
14215f52dd
commit
4eb46422b5
@ -95,6 +95,17 @@ function id:action(msg)
|
|||||||
local user_info = id:get_user(user_id, chat_id)
|
local user_info = id:get_user(user_id, chat_id)
|
||||||
table.insert(users_info, user_info)
|
table.insert(users_info, user_info)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- get all administrators and the creator
|
||||||
|
local administrators = utilities.get_chat_administrators(self, chat_id)
|
||||||
|
local admins = {}
|
||||||
|
for num in pairs(administrators.result) do
|
||||||
|
if administrators.result[num].status ~= 'creator' then
|
||||||
|
table.insert(admins, tostring(administrators.result[num].user.id))
|
||||||
|
else
|
||||||
|
creator_id = administrators.result[num].user.id
|
||||||
|
end
|
||||||
|
end
|
||||||
local result = id:get_member_count(self, msg, chat_id)
|
local result = id:get_member_count(self, msg, chat_id)
|
||||||
local member_count = result.result - 1 -- minus the bot
|
local member_count = result.result - 1 -- minus the bot
|
||||||
if member_count == 1 then
|
if member_count == 1 then
|
||||||
@ -104,8 +115,13 @@ function id:action(msg)
|
|||||||
end
|
end
|
||||||
local text = 'IDs für *'..chat_name..'* `['..chat_id..']`\nHier '..member_count..':*\n---------\n'
|
local text = 'IDs für *'..chat_name..'* `['..chat_id..']`\nHier '..member_count..':*\n---------\n'
|
||||||
for k,user in pairs(users_info) do
|
for k,user in pairs(users_info) do
|
||||||
|
if table.contains(admins, tostring(user.id)) then
|
||||||
|
text = text..'*'..user.name..'* `['..user.id..']` _Administrator_\n'
|
||||||
|
elseif tostring(creator_id) == user.id then
|
||||||
|
text = text..'*'..user.name..'* `['..user.id..']` _Gruppenersteller_\n'
|
||||||
|
else
|
||||||
text = text..'*'..user.name..'* `['..user.id..']`\n'
|
text = text..'*'..user.name..'* `['..user.id..']`\n'
|
||||||
text = string.gsub(text, "%_", " ")
|
end
|
||||||
end
|
end
|
||||||
utilities.send_reply(self, msg, text, true)
|
utilities.send_reply(self, msg, text, true)
|
||||||
end
|
end
|
||||||
|
@ -3,6 +3,7 @@ local rss = {}
|
|||||||
local http = require('socket.http')
|
local http = require('socket.http')
|
||||||
local https = require('ssl.https')
|
local https = require('ssl.https')
|
||||||
local url = require('socket.url')
|
local url = require('socket.url')
|
||||||
|
local bindings = require('otouto.bindings')
|
||||||
local utilities = require('otouto.utilities')
|
local utilities = require('otouto.utilities')
|
||||||
local redis = (loadfile "./otouto/redis.lua")()
|
local redis = (loadfile "./otouto/redis.lua")()
|
||||||
local feedparser = require("feedparser")
|
local feedparser = require("feedparser")
|
||||||
@ -10,12 +11,22 @@ local feedparser = require("feedparser")
|
|||||||
rss.command = 'rss <sub/del>'
|
rss.command = 'rss <sub/del>'
|
||||||
|
|
||||||
function rss:init(config)
|
function rss:init(config)
|
||||||
rss.triggers = utilities.triggers(self.info.username, config.cmd_pat):t('rss', true).table
|
rss.triggers = {
|
||||||
|
"^/(rss) @(.*)$",
|
||||||
|
"^/rss$",
|
||||||
|
"^/rss (sub) (https?://[%w-_%.%?%.:/%+=&%~]+) @(.*)$",
|
||||||
|
"^/rss (sub) (https?://[%w-_%.%?%.:/%+=&%~]+)$",
|
||||||
|
"^/rss (del) (%d+) @(.*)$",
|
||||||
|
"^/rss (del) (%d+)$",
|
||||||
|
"^/rss (del)",
|
||||||
|
"^/rss (sync)$"
|
||||||
|
}
|
||||||
rss.doc = [[*
|
rss.doc = [[*
|
||||||
]]..config.cmd_pat..[[rss*: Feed-Abonnements anzeigen
|
]]..config.cmd_pat..[[rss* _@[Kanalname]_: Feed-Abonnements anzeigen
|
||||||
*]]..config.cmd_pat..[[rss* _sub_ _<URL>_: Diesen Feed abonnieren
|
*]]..config.cmd_pat..[[rss* _sub_ _<URL>_ _@[Kanalname]_: Diesen Feed abonnieren
|
||||||
*]]..config.cmd_pat..[[rss* _del_ _<#>_: Diesen Feed deabonnieren
|
*]]..config.cmd_pat..[[rss* _del_ _<#>_ _@[Kanalname]_: Diesen Feed deabonnieren
|
||||||
*]]..config.cmd_pat..[[rss* _sync_: Feeds syncen (nur Superuser)]]
|
*]]..config.cmd_pat..[[rss* _sync_: Feeds syncen (nur Superuser)
|
||||||
|
Der Kanalname ist optional]]
|
||||||
end
|
end
|
||||||
|
|
||||||
function tail(n, k)
|
function tail(n, k)
|
||||||
@ -208,60 +219,91 @@ function rss:print_subs(id, chat_name)
|
|||||||
return text, keyboard
|
return text, keyboard
|
||||||
end
|
end
|
||||||
|
|
||||||
function rss:action(msg, config)
|
function rss:action(msg, config, matches)
|
||||||
local input = utilities.input(msg.text)
|
|
||||||
local id = "user#id" .. msg.from.id
|
local id = "user#id" .. msg.from.id
|
||||||
if msg.chat.type == 'channel' then
|
|
||||||
print('Kanäle werden momentan nicht unterstützt')
|
|
||||||
end
|
|
||||||
if msg.chat.type == 'group' or msg.chat.type == 'supergroup' then
|
if msg.chat.type == 'group' or msg.chat.type == 'supergroup' then
|
||||||
id = 'chat#id'..msg.chat.id
|
id = 'chat#id'..msg.chat.id
|
||||||
end
|
end
|
||||||
|
|
||||||
if not input then
|
-- For channels
|
||||||
if msg.chat.type == 'group' or msg.chat.type == 'supergroup' then
|
if matches[1] == 'sub' and matches[2] and matches[3] then
|
||||||
chat_name = msg.chat.title
|
if msg.from.id ~= config.admin then
|
||||||
else
|
utilities.send_reply(self, msg, config.errors.sudo)
|
||||||
chat_name = msg.chat.first_name
|
return
|
||||||
end
|
end
|
||||||
|
local id = '@'..matches[3]
|
||||||
|
local result = utilities.get_chat_info(self, id)
|
||||||
|
if not result then
|
||||||
|
utilities.send_reply(self, msg, 'Diesen Kanal gibt es nicht!')
|
||||||
|
return
|
||||||
|
end
|
||||||
|
local output = rss:subscribe(id, matches[2])
|
||||||
|
utilities.send_reply(self, msg, output, true)
|
||||||
|
return
|
||||||
|
elseif matches[1] == 'del' and matches[2] and matches[3] then
|
||||||
|
if msg.from.id ~= config.admin then
|
||||||
|
utilities.send_reply(self, msg, config.errors.sudo)
|
||||||
|
return
|
||||||
|
end
|
||||||
|
local id = '@'..matches[3]
|
||||||
|
local result = utilities.get_chat_info(self, id)
|
||||||
|
if not result then
|
||||||
|
utilities.send_reply(self, msg, 'Diesen Kanal gibt es nicht!')
|
||||||
|
return
|
||||||
|
end
|
||||||
|
local output = rss:unsubscribe(id, matches[2])
|
||||||
|
utilities.send_reply(self, msg, output, true)
|
||||||
|
return
|
||||||
|
elseif matches[1] == 'rss' and matches[2] then
|
||||||
|
local id = '@'..matches[2]
|
||||||
|
local result = utilities.get_chat_info(self, id)
|
||||||
|
if not result then
|
||||||
|
utilities.send_reply(self, msg, 'Diesen Kanal gibt es nicht!')
|
||||||
|
return
|
||||||
|
end
|
||||||
|
local chat_name = result.result.title
|
||||||
local output = rss:print_subs(id, chat_name)
|
local output = rss:print_subs(id, chat_name)
|
||||||
utilities.send_reply(self, msg, output, true)
|
utilities.send_reply(self, msg, output, true)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
if input:match('(sub) (https?://[%w-_%.%?%.:/%+=&%~]+)$') then
|
|
||||||
if msg.from.id ~= config.admin then
|
|
||||||
utilities.send_reply(self, msg, config.errors.sudo)
|
|
||||||
return
|
|
||||||
end
|
|
||||||
local rss_url = input:match('(https?://[%w-_%.%?%.:/%+=&%~]+)$')
|
|
||||||
local output = rss:subscribe(id, rss_url)
|
|
||||||
utilities.send_reply(self, msg, output, true)
|
|
||||||
elseif input:match('(del) (%d+)$') then
|
|
||||||
if msg.from.id ~= config.admin then
|
|
||||||
utilities.send_reply(self, msg, config.errors.sudo)
|
|
||||||
return
|
|
||||||
end
|
|
||||||
local rss_url = input:match('(%d+)$')
|
|
||||||
local output = rss:unsubscribe(id, rss_url)
|
|
||||||
utilities.send_reply(self, msg, output, true, '{"hide_keyboard":true}')
|
|
||||||
elseif input:match('(del)$') then
|
|
||||||
if msg.chat.type == 'group' or msg.chat.type == 'supergroup' then
|
if msg.chat.type == 'group' or msg.chat.type == 'supergroup' then
|
||||||
chat_name = msg.chat.title
|
chat_name = msg.chat.title
|
||||||
else
|
else
|
||||||
chat_name = msg.chat.first_name
|
chat_name = msg.chat.first_name
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if matches[1] == 'sub' and matches[2] then
|
||||||
|
if msg.from.id ~= config.admin then
|
||||||
|
utilities.send_reply(self, msg, config.errors.sudo)
|
||||||
|
return
|
||||||
|
end
|
||||||
|
local output = rss:subscribe(id, matches[2])
|
||||||
|
utilities.send_reply(self, msg, output, true)
|
||||||
|
return
|
||||||
|
elseif matches[1] == 'del' and matches[2] then
|
||||||
|
if msg.from.id ~= config.admin then
|
||||||
|
utilities.send_reply(self, msg, config.errors.sudo)
|
||||||
|
return
|
||||||
|
end
|
||||||
|
local output = rss:unsubscribe(id, matches[2])
|
||||||
|
utilities.send_reply(self, msg, output, true, '{"hide_keyboard":true}')
|
||||||
|
return
|
||||||
|
elseif matches[1] == 'del' and not matches[2] then
|
||||||
local list_subs, keyboard = rss:print_subs(id, chat_name)
|
local list_subs, keyboard = rss:print_subs(id, chat_name)
|
||||||
utilities.send_reply(self, msg, list_subs, true, keyboard)
|
utilities.send_reply(self, msg, list_subs, true, keyboard)
|
||||||
return
|
return
|
||||||
elseif input:match('(sync)$') then
|
elseif matches[1] == 'sync' then
|
||||||
if msg.from.id ~= config.admin then
|
if msg.from.id ~= config.admin then
|
||||||
utilities.send_reply(self, msg, config.errors.sudo)
|
utilities.send_reply(self, msg, config.errors.sudo)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
rss:cron(self)
|
rss:cron(self)
|
||||||
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local output = rss:print_subs(id, chat_name)
|
||||||
|
utilities.send_reply(self, msg, output, true)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -24,15 +24,6 @@ local apikey = cred_data.google_apikey
|
|||||||
|
|
||||||
local BASE_URL = 'https://www.googleapis.com/youtube/v3'
|
local BASE_URL = 'https://www.googleapis.com/youtube/v3'
|
||||||
|
|
||||||
function table.contains(table, element)
|
|
||||||
for _, value in pairs(table) do
|
|
||||||
if value == element then
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
end
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
|
|
||||||
local makeOurDate = function(dateString)
|
local makeOurDate = function(dateString)
|
||||||
local pattern = "(%d+)%-(%d+)%-(%d+)T"
|
local pattern = "(%d+)%-(%d+)%-(%d+)T"
|
||||||
local year, month, day = dateString:match(pattern)
|
local year, month, day = dateString:match(pattern)
|
||||||
|
@ -175,6 +175,20 @@ function utilities:answer_callback_query(callback, text, show_alert)
|
|||||||
} )
|
} )
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- https://core.telegram.org/bots/api#getchat
|
||||||
|
function utilities:get_chat_info(chat_id)
|
||||||
|
return bindings.request(self, 'getChat', {
|
||||||
|
chat_id = chat_id
|
||||||
|
} )
|
||||||
|
end
|
||||||
|
|
||||||
|
-- https://core.telegram.org/bots/api#getchatadministrators
|
||||||
|
function utilities:get_chat_administrators(chat_id)
|
||||||
|
return bindings.request(self, 'getChatAdministrators', {
|
||||||
|
chat_id = chat_id
|
||||||
|
} )
|
||||||
|
end
|
||||||
|
|
||||||
-- get the indexed word in a string
|
-- get the indexed word in a string
|
||||||
function utilities.get_word(s, i)
|
function utilities.get_word(s, i)
|
||||||
s = s or ''
|
s = s or ''
|
||||||
@ -865,4 +879,13 @@ function url_encode(str)
|
|||||||
return str
|
return str
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function table.contains(table, element)
|
||||||
|
for _, value in pairs(table) do
|
||||||
|
if value == element then
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
return utilities
|
return utilities
|
||||||
|
Reference in New Issue
Block a user