Skip to content

Instantly share code, notes, and snippets.

@denysvitali
Created June 13, 2015 17:42
Show Gist options
  • Save denysvitali/2a8f3b4d210ed9833459 to your computer and use it in GitHub Desktop.
Save denysvitali/2a8f3b4d210ed9833459 to your computer and use it in GitHub Desktop.
service_enter.lua
local remove_user_cfg = load_from_file('data/add_user_cfg.lua')
local function urlencode(str)
if (str) then
str = string.gsub (str, "\n", "\r\n")
str = string.gsub (str, "([^%w ])",
function (c) return string.format ("%%%02X", string.byte(c)) end)
str = string.gsub (str, " ", "+")
end
return str
end
local function template_add_user(to_username, from_username, chat_name, chat_id)
text = text or ''
to_username_noat = (to_username or '')
to_username = '@' .. (to_username or '')
from_username = '@' .. (from_username or '')
chat_name = chat_name or ''
chat_id = "chat#id" .. (chat_id or '')
if to_username == "@" then
to_username = ''
end
if from_username == "@" then
from_username = ''
end
local text_top = remove_user_cfg.text_top
local text_bottom = remove_user_cfg.text_bottom
text_top = string.gsub(text_top, "{to_username}", to_username)
text_top = string.gsub(text_top, "{to_username_noat}", to_username_noat)
text_top = string.gsub(text_top, "{from_username}", from_username)
text_top = string.gsub(text_top, "{chat_name}", chat_name)
text_top = string.gsub(text_top, "{chat_id}", chat_id)
text_bottom = string.gsub(text_bottom, "{to_username}", to_username)
text_bottom = string.gsub(text_bottom, "{to_username_noat}", to_username_noat)
text_bottom = string.gsub(text_bottom, "{from_username}", from_username)
text_bottom = string.gsub(text_bottom, "{chat_name}", chat_name)
text_bottom = string.gsub(text_bottom, "{chat_id}", chat_id)
local imageurl = "http://i.huffpost.com/gen/1487651/images/o-DEPRESSION-facebook.jpg"
local base = "http://memecaptain.com/i"
local final = base .. "?u="..urlencode(imageurl).."&t1="..urlencode(text_top).."&t2="..urlencode(text_bottom)
return final
end
function chat_add_user(msg)
local to_username = msg.action.user.username
local from_username = msg.from.username
local chat_name = msg.to.print_name
local chat_id = msg.to.id
pattern = template_add_user(to_username, from_nome, chat_name, chat_id)
if pattern ~= '' then
local receiver = get_receiver(msg)
send_photo_from_url(receiver, pattern)
end
end
local function run(msg, matches)
if not msg.service then
return "Are you trying to troll me?"
end
chat_add_user(msg)
end
return {
description = "Service Enter.",
usage = "",
patterns = {
"^!!tgservice (chat_add_user)$",
"^!!tgservice (chat_add_user_link)$"
},
run = run
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment