From 31d0c65e91c6f40abab1416831f328ad1b9fc730 Mon Sep 17 00:00:00 2001 From: Brayden Banks Date: Fri, 26 Aug 2016 19:31:12 -0700 Subject: [PATCH 1/2] Record moderation reasoning to log when possible. --- otouto/plugins/administration.lua | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/otouto/plugins/administration.lua b/otouto/plugins/administration.lua index c5646d9..d190add 100644 --- a/otouto/plugins/administration.lua +++ b/otouto/plugins/administration.lua @@ -223,7 +223,7 @@ function administration:get_targets(msg, config) target.name = utilities.build_name(target.first_name, target.last_name) target.id_str = tostring(target.id) target.rank = administration.get_rank(self, target.id, msg.chat.id, config) - return { target } + return { target }, utilities.input(msg.text) else local input = utilities.input(msg.text) if input then @@ -809,8 +809,9 @@ function administration.init_command(self_, config_) doc = 'Removes a user from the group. The target may be specified via reply, username, or ID.', action = function(self, msg, group, config) - local targets = administration.get_targets(self, msg, config) + local targets, reason = administration.get_targets(self, msg, config) if targets then + reason = reason and ': ' .. utilities.trim(reason) or '' local output = '' local s = drua.sopen() for _, target in ipairs(targets) do @@ -820,7 +821,7 @@ function administration.init_command(self_, config_) output = output .. target.name .. ' is too privileged to be kicked.\n' else output = output .. target.name .. ' has been kicked.\n' - administration.kick_user(self, msg.chat.id, target.id, 'kicked by ' .. utilities.build_name(msg.from.first_name, msg.from.last_name) .. ' [' .. msg.from.id .. ']', config, s) + administration.kick_user(self, msg.chat.id, target.id, 'kicked by ' .. utilities.build_name(msg.from.first_name, msg.from.last_name) .. ' [' .. msg.from.id .. ']' .. reason, config, s) if msg.chat.type == 'supergroup' then bindings.unbanChatMember{ chat_id = msg.chat.id, user_id = target.id } end @@ -843,8 +844,9 @@ function administration.init_command(self_, config_) doc = 'Bans a user from the group. The target may be specified via reply, username, or ID.', action = function(self, msg, group, config) - local targets = administration.get_targets(self, msg, config) + local targets, reason = administration.get_targets(self, msg, config) if targets then + reason = reason and ': ' .. utilities.trim(reason) or '' local output = '' local s = drua.sopen() for _, target in ipairs(targets) do @@ -856,7 +858,7 @@ function administration.init_command(self_, config_) output = output .. target.name .. ' is too privileged to be banned.\n' else output = output .. target.name .. ' has been banned.\n' - administration.kick_user(self, msg.chat.id, target.id, 'banned by ' .. utilities.build_name(msg.from.first_name, msg.from.last_name) .. ' [' .. msg.from.id .. ']', config, s) + administration.kick_user(self, msg.chat.id, target.id, 'banned by ' .. utilities.build_name(msg.from.first_name, msg.from.last_name) .. ' [' .. msg.from.id .. ']' .. reason, config, s) group.mods[target.id_str] = nil group.bans[target.id_str] = true end @@ -1306,8 +1308,9 @@ Use this command to configure the point values for each message type. When a use doc = 'Bans a user from all groups. The target may be specified via reply, username, or ID.', action = function(self, msg, group, config) - local targets = administration.get_targets(self, msg, config) + local targets, reason = administration.get_targets(self, msg, config) if targets then + reason = reason and ': ' .. utilities.trim(reason) or '' local output = '' local s = drua.sopen() for _, target in ipairs(targets) do @@ -1319,8 +1322,8 @@ Use this command to configure the point values for each message type. When a use output = output .. target.name .. ' is too privileged to be globally banned.\n' else if group then - local reason = 'hammered by ' .. utilities.build_name(msg.from.first_name, msg.from.last_name) .. ' [' .. msg.from.id .. ']' - administration.kick_user(self, msg.chat.id, target.id, reason, config) + local reason_ = 'hammered by ' .. utilities.build_name(msg.from.first_name, msg.from.last_name) .. ' [' .. msg.from.id .. ']' .. reason + administration.kick_user(self, msg.chat.id, target.id, reason_, config) end for k,v in pairs(self.database.administration.groups) do if not v.flags[6] then From e92beeb58ac72b65c057f184b5a770239c11f7c4 Mon Sep 17 00:00:00 2001 From: topkecleon Date: Fri, 26 Aug 2016 23:25:55 -0400 Subject: [PATCH 2/2] trivial stuff --- README.md | 1 + otouto/bindings.lua | 12 ++++++------ 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index a2779d8..c9e4992 100644 --- a/README.md +++ b/README.md @@ -410,3 +410,4 @@ Contributions are appreciated in all forms. Monetary contributions will go towar | [n8 c00](http://telegram.me/n8_c00) | | [Alex](http://telegram.me/sandu) | | [Brayden](http://telegram.me/bb010g) | +| [Milad](http://telegram.me/thelad) | diff --git a/otouto/bindings.lua b/otouto/bindings.lua index b821722..5250422 100644 --- a/otouto/bindings.lua +++ b/otouto/bindings.lua @@ -22,10 +22,10 @@ local bindings = {} -local HTTPS = require('ssl.https') -local JSON = require('dkjson') +local https = require('ssl.https') +local json = require('dkjson') local ltn12 = require('ltn12') -local MP_ENCODE = require('multipart-post').encode +local mp_encode = require('multipart-post').encode function bindings.init(token) bindings.BASE_URL = 'https://api.telegram.org/bot' .. token .. '/' @@ -58,8 +58,8 @@ function bindings.request(method, parameters, file) parameters = {''} end local response = {} - local body, boundary = MP_ENCODE(parameters) - local success, code = HTTPS.request{ + local body, boundary = mp_encode(parameters) + local success, code = https.request{ url = bindings.BASE_URL .. method, method = 'POST', headers = { @@ -74,7 +74,7 @@ function bindings.request(method, parameters, file) print(method .. ': Connection error. [' .. code .. ']') return false, false else - local result = JSON.decode(data) + local result = json.decode(data) if not result then return false, false elseif result.ok then