This repository has been archived on 2021-04-24. You can view files and clone it, but cannot push or open issues or pull requests.
Mikubot-2/otouto/plugins/steam.lua

58 lines
1.6 KiB
Lua
Raw Normal View History

local steam = {}
steam.triggers = {
"store.steampowered.com/app/([0-9]+)",
"steamcommunity.com/app/([0-9]+)"
}
local BASE_URL = 'http://store.steampowered.com/api/appdetails/'
local DESC_LENTH = 400
function steam:get_steam_data(appid)
local url = BASE_URL
url = url..'?appids='..appid
url = url..'&l=german&cc=DE'
local res,code = http.request(url)
if code ~= 200 then return nil end
local data = json.decode(res)[appid].data
return data
end
function steam:price_info(data)
local price = '' -- If no data is empty
if data then
local initial = data.initial
local final = data.final or data.initial
local min = math.min(data.initial, data.final)
price = tostring(min/100)
if data.discount_percent and initial ~= final then
price = price..data.currency..' ('..data.discount_percent..'% OFF)'
end
price = price..''
end
return price
end
function steam:send_steam_data(data, msg)
local description = string.sub(unescape(data.about_the_game:gsub("%b<>", "")), 1, DESC_LENTH) .. '...'
local title = data.name
local price = steam:price_info(data.price_overview)
2016-10-04 16:00:25 +02:00
local text = '<b>'..title..'</b> <i>'..price..'</i>\n'..description
local image_url = data.header_image
return text, image_url
end
2016-08-25 18:21:37 +02:00
function steam:action(msg, config, matches)
local data = steam:get_steam_data(matches[1])
if not data then utilities.send_reply(msg, config.errors.connection) return end
local text, image_url = steam:send_steam_data(data, msg)
utilities.send_typing(msg.chat.id, 'upload_photo')
utilities.send_photo(msg.chat.id, image_url, nil, msg.message_id)
2016-10-04 16:00:25 +02:00
utilities.send_reply(msg, text, 'HTML')
end
return steam