This commit is contained in:
Andreas Bielawski 2016-09-08 00:29:35 +02:00
commit 9e66527008
5 changed files with 29 additions and 22 deletions

View File

@ -23,7 +23,7 @@
local bindings = {} local bindings = {}
local https = require('ssl.https') local https = require('ssl.https')
https.timeout = 10 https.TIMEOUT = 10
local json = require('dkjson') local json = require('dkjson')
local ltn12 = require('ltn12') local ltn12 = require('ltn12')
local mp_encode = require('multipart-post').encode local mp_encode = require('multipart-post').encode

View File

@ -62,7 +62,6 @@ end
function bot:on_msg_receive(msg, config) -- The fn run whenever a message is received. function bot:on_msg_receive(msg, config) -- The fn run whenever a message is received.
-- remove comment to enable debugging -- remove comment to enable debugging
-- vardump(msg) -- vardump(msg)
-- Cache user info for those involved.
-- print messages -- print messages
msg_time = '\27[36m'..convert_timestamp(msg.date, '[%H:%M:%S]')..'\27[0m' msg_time = '\27[36m'..convert_timestamp(msg.date, '[%H:%M:%S]')..'\27[0m'

View File

@ -22,6 +22,8 @@ function banhammer:init(config)
"^/(block) (delete)$", "^/(block) (delete)$",
"^/(kick) (%d+)$", "^/(kick) (%d+)$",
"^/(kick)$", "^/(kick)$",
"^/(leave) (%-?%d+)",
"^/(leave) (@[A-Za-z0-9-_-]+)",
"^/(leave)$" "^/(leave)$"
} }
banhammer.doc = [[* banhammer.doc = [[*
@ -183,12 +185,20 @@ function banhammer:action(msg, config, matches)
end end
if matches[1] == 'leave' then if matches[1] == 'leave' then
if msg.chat.type == 'group' or msg.chat.type == 'supergroup' then if matches[2] then
bindings.request('leaveChat', { chat_id = matches[2]
chat_id = msg.chat.id else
} ) chat_id = msg.chat.id
return
end end
local result = bindings.request('leaveChat', {
chat_id = chat_id
} )
if matches[2] and result then
utilities.send_reply(msg, 'Chat verlassen!')
elseif matches[2] and not result then
utilities.send_reply(msg, 'Chat konnte nicht verlassen werden, ist die ID/der Name korrekt?')
end
return
end end
if matches[1] == 'ban' then if matches[1] == 'ban' then

View File

@ -23,9 +23,9 @@ end
function github:send_github_data(data) function github:send_github_data(data)
if not data.owner then return nil end if not data.owner then return nil end
local name = '*'..utilities.md_escape(data.name)..'*' local name = '<b>'..data.name..'</b>'
local description = '_'..utilities.md_escape(data.description)..'_' local description = '<i>'..data.description..'</i>'
local owner = utilities.md_escape(data.owner.login) local owner = data.owner.login
local clone_url = data.clone_url local clone_url = data.clone_url
if data.language == nil or data.language == "" then if data.language == nil or data.language == "" then
language = '' language = ''
@ -40,17 +40,17 @@ function github:send_github_data(data)
if data.homepage == nil or data.homepage == "" then if data.homepage == nil or data.homepage == "" then
homepage = '' homepage = ''
else else
homepage = '\n[Homepage besuchen]('..data.homepage..')' homepage = '\n<a href="'..data.homepage..'">Homepage besuchen</a>'
end end
local text = name..' von '..owner..'\n'..description..'\n`git clone '..clone_url..'`'..language..issues..homepage local text = name..' von '..owner..'\n'..description..'\n<pre>git clone '..clone_url..'</pre>'..language..issues..homepage
return text return text
end end
function github:send_gh_commit_data(gh_code, gh_commit_sha, data) function github:send_gh_commit_data(gh_code, gh_commit_sha, data)
if not data.committer then return nil end if not data.author then return nil end
local committer = data.committer.name local author = data.author.name
local message = utilities.md_escape(data.message) local message = utilities.md_escape(data.message)
local text = '`'..gh_code..'@'..gh_commit_sha..'` von *'..committer..'*:\n'..message local text = '<code>'..gh_code..'@'..gh_commit_sha..'</code> von <b>'..author..'</b>:\n'..message
return text return text
end end
@ -63,7 +63,7 @@ function github:action(msg, config, matches)
else else
output = github:send_gh_commit_data(gh_code, gh_commit_sha, data) output = github:send_gh_commit_data(gh_code, gh_commit_sha, data)
end end
utilities.send_reply(msg, output, true) utilities.send_reply(msg, output, 'HTML')
end end
return github return github

View File

@ -35,8 +35,8 @@ OAuth = require 'OAuth'
helpers = require 'OAuth.helpers' helpers = require 'OAuth.helpers'
require('/miku/encoding') require('/miku/encoding')
http.timeout = 5 http.TIMEOUT = 7
https.timeout = 5 https.TIMEOUT = 7
-- For the sake of ease to new contributors and familiarity to old contributors, -- For the sake of ease to new contributors and familiarity to old contributors,
-- we'll provide a couple of aliases to real bindings here. -- we'll provide a couple of aliases to real bindings here.
@ -388,10 +388,8 @@ function run_command(str)
return result return result
end end
function convert_timestamp(timestamp, format) function convert_timestamp(timestamp, date_format)
local converted_date = run_command('date -d @'..timestamp..' +"'..format..'"') return os.date(date_format, timestamp)
local converted_date = string.gsub(converted_date, '%\n', '')
return converted_date
end end
function string.starts(String, Start) function string.starts(String, Start)