steam.help = '/steam [username] - Displays information about the given Steam user. If no username is specified then information about your Steam account (if applicable) is sent.'
end
function steam.search(input, key)
local jstr, res = https.request('https://steamcommunity.com/id/' .. url.escape(input))
if res ~= 200
then
return false, true
end
jstr = jstr:match('g%_rgProfileData %= (.-)%;')
if not jstr or not jstr:match('^%{.-%}$')
then
return true, false
end
local jdat = json.decode(jstr)
if not jdat
or not jdat.steamid
then
return true, false
end
return steam.get_info(
jdat.steamid,
key
), true
end
function steam.get_info(id, key)
local jstr, res = http.request('http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=' .. key .. '&steamids=' .. id)
if res ~= 200
then
return false
end
return jstr
end
function steam.get_username(id)
return redis:hget(
'steam:' .. id,
'username'
)
end
function steam.set_username(message, language)
local input = mattata.input(message.text)
if not input
then
return mattata.send_reply(
message,
steam.help
)
end
redis:hset(
'steam:' .. message.from.id,
'username',
input
)
return mattata.send_reply(
message,
string.format(
language['steam']['1'],
input
)
)
end
function steam.format_output(jdat, language)
if not jdat.response
or not jdat.response.players
or not jdat.response.players[1]
then
return false
end
local name = mattata.escape_html(jdat.response.players[1].personaname)
if jdat.response.players[1].realname
then
name = mattata.escape_html(jdat.response.players[1].realname)
end
name = string.format(
'<a href="%s">%s</a>',
jdat.response.players[1].avatarfull,
name
)
if jdat.response.players[1].realname
and jdat.response.players[1].realname ~= jdat.response.players[1].personaname