From 2779329b1a91970ada309532bffe57bf1c0790ab Mon Sep 17 00:00:00 2001 From: topkecleon Date: Fri, 15 Apr 2016 01:44:24 -0400 Subject: [PATCH 1/3] needless bindings fussing --- bindings.lua | 2 ++ 1 file changed, 2 insertions(+) diff --git a/bindings.lua b/bindings.lua index 2de684a..7de9beb 100755 --- a/bindings.lua +++ b/bindings.lua @@ -16,6 +16,8 @@ sendRequest = function(url) local dat, res = HTTPS.request(url) + if not dat then return false, res end + local tab = JSON.decode(dat) if not tab.ok then From effe34cb32b7d68fc9419e54a8b119480b075838 Mon Sep 17 00:00:00 2001 From: topkecleon Date: Sun, 17 Apr 2016 23:28:55 -0400 Subject: [PATCH 2/3] about.lua: Less redundant if-else. administration.lua: Will now attempt to unban kicked users in supergrounds. remind.lua: New plugin! Set a reminder. control.lua: No more lost control messages. --- plugins/about.lua | 10 ++-- plugins/administration.lua | 15 ++++++ plugins/control.lua | 2 +- plugins/remind.lua | 102 +++++++++++++++++++++++++++++++++++++ 4 files changed, 121 insertions(+), 8 deletions(-) create mode 100644 plugins/remind.lua diff --git a/plugins/about.lua b/plugins/about.lua index f57dc28..030abf1 100755 --- a/plugins/about.lua +++ b/plugins/about.lua @@ -13,13 +13,9 @@ local action = function(msg) local message = config.about_text .. '\nBased on @otouto v'..version..' by topkecleon.' - if msg.new_chat_participant and msg.new_chat_participant.id == bot.id then - sendMessage(msg.chat.id, message, true) - return - elseif msg.text_lower:match('^/about[@'..bot.username..']*') then - sendMessage(msg.chat.id, message, true) - return - elseif msg.text_lower:match('^/start') then + if (msg.new_chat_participant and msg.new_chat_participant.id == bot.id) + or msg.text_lower:match('^/about[@'..bot.username..']*') + or msg.text_lower:match('^/start') then sendMessage(msg.chat.id, message, true) return end diff --git a/plugins/administration.lua b/plugins/administration.lua index 81713bf..c974ccd 100644 --- a/plugins/administration.lua +++ b/plugins/administration.lua @@ -254,6 +254,9 @@ local commands = { return true end drua.kick_user(msg.chat.id, msg.from.id) + if msg.chat.type == 'supergroup' then + unbanChatMember(msg.chat.id, msg.from.id) + end local output = flags[2].kicked:gsub('GROUPNAME', msg.chat.title) sendMessage(msg.from.id, output) end @@ -282,6 +285,9 @@ local commands = { if group.flags[3] == true then if msg.from.name:match('[\216-\219][\128-\191]') or msg.from.name:match('‮') or msg.from.name:match('‏') then drua.kick_user(msg.chat.id, msg.from.id) + if msg.chat.type == 'supergroup' then + unbanChatMember(msg.chat.id, msg.from.id) + end local output = flags[3].kicked:gsub('GROUPNAME', msg.chat.title) sendMessage(msg.from.id, output) return @@ -320,6 +326,9 @@ local commands = { end if admin_temp.flood[msg.chat.id_str][msg.from.id_str] > 99 then drua.kick_user(msg.chat.id, msg.from.id) + if msg.chat.type == 'supergroup' then + unbanChatMember(msg.chat.id, msg.from.id) + end local output = flags[5].kicked:gsub('GROUPNAME', msg.chat.title) sendMessage(msg.from.id, output) admin_temp.flood[msg.chat.id_str][msg.from.id_str] = nil @@ -344,6 +353,9 @@ local commands = { if group.flags[3] == true then if msg.new_chat_participant.name:match('[\216-\219][\128-\191]') or msg.new_chat_participant.name:match('‮') or msg.new_chat_participant.name:match('‏') then drua.kick_user(msg.chat.id, msg.new_chat_participant.id) + if msg.chat.type == 'supergroup' then + unbanChatMember(msg.chat.id, msg.from.id) + end local output = flags[3].kicked:gsub('GROUPNAME', msg.chat.title) sendMessage(msg.new_chat_participant.id, output) return @@ -617,6 +629,9 @@ local commands = { return end drua.kick_user(msg.chat.id, target.id) + if msg.chat.type == 'supergroup' then + unbanChatMember(msg.chat.id, target.id) + end sendMessage(msg.chat.id, target.name .. ' has been kicked.') end }, diff --git a/plugins/control.lua b/plugins/control.lua index 663cc1e..e0a0a0f 100644 --- a/plugins/control.lua +++ b/plugins/control.lua @@ -9,7 +9,7 @@ local action = function(msg) return end - if msg.date < os.time() then return end + if msg.date < os.time() - 1 then return end if msg.text:match('^/reload') then bot_init() diff --git a/plugins/remind.lua b/plugins/remind.lua new file mode 100644 index 0000000..9618dfb --- /dev/null +++ b/plugins/remind.lua @@ -0,0 +1,102 @@ +database.reminders = database.reminders or {} + +local command = 'remind ' +local doc = [[``` +/remind +Repeats a message after a duration of time, in minutes. +```]] + +local triggers = { + '^/remind' +} + +local action = function(msg) + -- Ensure there are arguments. If not, send doc. + local input = msg.text:input() + if not input then + sendMessage(msg.chat.id, doc, true, msg.message_id, true) + return + end + -- Ensure first arg is a number. If not, send doc. + local duration = get_word(input, 1) + if not tonumber(duration) then + sendMessage(msg.chat.id, doc, true, msg.message_id, true) + return + end + -- Duration must be between one minute and one year (approximately). + duration = tonumber(duration) + if duration < 1 then + duration = 1 + elseif duration > 526000 then + duration = 526000 + end + -- Ensure there is a second arg. + local message = input:input() + if not message then + sendMessage(msg.chat.id, doc, true, msg.message_id, true) + return + end + -- Make a database entry for the group/user if one does not exist. + database.reminders[msg.chat.id_str] = database.reminders[msg.chat.id_str] or {} + -- Limit group reminders to 10 and private reminders to 50. + if msg.chat.type ~= 'private' and table_size(database.reminders[msg.chat.id_str]) > 9 then + sendReply(msg, 'Sorry, this group already has ten reminders.') + return + elseif msg.chat.type == 'private' and table_size(database.reminders[msg.chat.id_str]) > 49 then + sendReply(msg, 'Sorry, you already have fifty reminders.') + return + end + -- Put together the reminder with the expiration, message, and message to reply to. + local reminder = { + time = os.time() + duration * 60, + message = message + } + table.insert(database.reminders[msg.chat.id_str], reminder) + local output = 'I will remind you in ' .. duration + if duration == 1 then + output = output .. ' minute!' + else + output = output .. ' minutes!' + end + sendReply(msg, output) +end + +local cron = function() + local time = os.time() + -- Iterate over the group entries in the reminders database. + for chat_id, group in pairs(database.reminders) do + local new_group = {} + -- Iterate over each reminder. + for i, reminder in ipairs(group) do + -- If the reminder is past-due, send it and nullify it. + -- Otherwise, add it to the replacement table. + if time > reminder.time then + local output = 'Reminder:\n"' .. reminder.message .. '"' + local res = sendMessage(chat_id, output, true) + -- If the message fails to send, save it for later. + if res then + reminder = nil + else + table.insert(new_group, reminder) + end + else + table.insert(new_group, reminder) + end + end + -- Nullify the original table and replace it with the new one. + group = nil + database.reminders[chat_id] = new_group + -- Nullify the table if it is empty. + if #new_group == 0 then + database.reminders[chat_id] = nil + end + end +end + +return { + action = action, + triggers = triggers, + cron = cron, + command = command, + doc = doc +} From 73f4863bc3359c3491d6b216746efe45deb1f743 Mon Sep 17 00:00:00 2001 From: topkecleon Date: Wed, 20 Apr 2016 16:43:08 -0400 Subject: [PATCH 3/3] Small improvements to administration.lua. --- .gitignore | 1 + plugins/administration.lua | 30 +++++++++++++++++++++--------- utilities.lua | 2 ++ 3 files changed, 24 insertions(+), 9 deletions(-) diff --git a/.gitignore b/.gitignore index 4fd526d..86b10b3 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ plugins/mokubot* plugins/qtbot* plugins/mjolnir* plugins/antisquigbot* +profile-pictures *.db lua-tg drua-tg diff --git a/plugins/administration.lua b/plugins/administration.lua index c974ccd..eb1e0e1 100644 --- a/plugins/administration.lua +++ b/plugins/administration.lua @@ -1,6 +1,6 @@ --[[ administration.lua - Version 1.8.1 + Version 1.8.2 Part of the otouto project. © 2016 topkecleon GNU General Public License, version 2 @@ -23,6 +23,9 @@ 1.8.1 - /rule will return that numbered rule, if it exists. + 1.8.2 - Will now attempt to unban users kicked from supergroups. Other small + changes. + ]]-- -- Build the administration db if nonexistent. @@ -415,10 +418,12 @@ local commands = { end -- Last active time for group listing. - for i,v in pairs(database.administration.activity) do - if v == msg.chat.id_str then - table.remove(database.administration.activity, i) - table.insert(database.administration.activity, 1, msg.chat.id_str) + if msg.text:len() > 0 then + for i,v in pairs(database.administration.activity) do + if v == msg.chat.id_str then + table.remove(database.administration.activity, i) + table.insert(database.administration.activity, 1, msg.chat.id_str) + end end end @@ -443,7 +448,7 @@ local commands = { local group = database.administration.groups[v] if not group.flags[1] then -- no unlisted groups if group.link then - output = output .. '• [' .. group.name .. '](' .. group.link .. ')\n' + output = output .. '• [' .. group.name:md_escape() .. '](' .. group.link .. ')\n' else output = output .. '• ' .. group.name .. '\n' end @@ -1091,21 +1096,28 @@ local commands = { command = 'gremove \\[chat]', privilege = 5, - interior = true, + interior = false, action = function(msg) local input = msg.text:input() or msg.chat.id_str + local output if database.administration.groups[input] then + local chat_name = database.administration.groups[input].name database.administration.groups[input] = nil for i,v in ipairs(database.administration.activity) do if v == input then table.remove(database.administration.activity, i) end end - sendReply(msg, 'I am no longer administrating that group.') + output = 'I am no longer administrating _' .. chat_name:md_escape() .. '_.' else - sendReply(msg, 'I do not administrate that group.') + if input == msg.chat.id_str then + output = 'I do not administrate this group.' + else + output = 'I do not administrate that group.' + end end + sendMessage(msg.chat.id, output, true, nil, true) end }, diff --git a/utilities.lua b/utilities.lua index 8f1db19..62bcfc9 100755 --- a/utilities.lua +++ b/utilities.lua @@ -255,6 +255,7 @@ markdown_escape = function(text) text = text:gsub('_', '\\_') text = text:gsub('%[', '\\[') + text = text:gsub('%]', '\\]') text = text:gsub('%*', '\\*') text = text:gsub('`', '\\`') return text @@ -265,6 +266,7 @@ function string:md_escape() local text = self text = text:gsub('_', '\\_') text = text:gsub('%[', '\\[') + text = text:gsub('%]', '\\]') text = text:gsub('%*', '\\*') text = text:gsub('`', '\\`') return text