Skip to content

Commit

Permalink
!id members name <text>
Browse files Browse the repository at this point in the history
  • Loading branch information
yagop committed Oct 31, 2015
1 parent 788039b commit 53b4bc2
Showing 1 changed file with 44 additions and 3 deletions.
47 changes: 44 additions & 3 deletions plugins/id.lua
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ local function run(msg, matches)
chat_info(chat, function (extra, success, result)
local receiver = extra.receiver
local nick = extra.nick
print("Searching: "..nick)
local found
for k,user in pairs(result.members) do
if user.username == nick then
Expand All @@ -70,6 +69,46 @@ local function run(msg, matches)
send_msg(receiver, text, ok_cb, false)
end
end, {receiver=chat, nick=nick})
elseif matches[1] == "members" and matches[2] == "name" then
local text = matches[3]
local chat = get_receiver(msg)
if not is_chat_msg(msg) then
return "You are not in a group."
end
chat_info(chat, function (extra, success, result)
local members = result.members
local receiver = extra.receiver
local text = extra.text

local founds = {}
for k,member in pairs(members) do
local fields = {'first_name', 'print_name', 'username'}
for k,field in pairs(fields) do
if member[field] and type(member[field]) == "string" then
if member[field]:match(text) then
local id = tostring(member.id)
founds[id] = member
end
end
end
end
if next(founds) == nil then -- Empty table
send_msg(receiver, "User not found on this chat.", ok_cb, false)
else
local text = ""
for k,user in pairs(founds) do
local first_name = user.first_name or ""
local print_name = user.print_name or ""
local user_name = user.user_name or ""
local id = user.id or "" -- This would be funny
text = text.."First name: "..first_name.."\n"
.."Print name: "..print_name.."\n"
.."User name: "..user_name.."\n"
.."ID: "..id
end
send_msg(receiver, text, ok_cb, false)
end
end, {receiver=chat, text=text})
end
end

Expand All @@ -79,13 +118,15 @@ return {
"!id: Return your ID and the chat id if you are in one.",
"!ids chat: Return the IDs of the current chat members.",
"!ids chat <chat_id>: Return the IDs of the <chat_id> members.",
"!id member @<user_name>: Return the member @<user_name> ID from the current chat"
"!id member @<user_name>: Return the member @<user_name> ID from the current chat",
"!id members name <text>: Search for users with <text> on first_name, print_name or username on current chat"
},
patterns = {
"^!id$",
"^!ids? (chat) (%d+)$",
"^!ids? (chat)$",
"^!id (member) (@)(.+)"
"^!id (member) (@)(.+)",
"^!id (members) (name) (.+)"
},
run = run
}

0 comments on commit 53b4bc2

Please sign in to comment.