<commit_before>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)

  local text = '*'..title..'* _'..price..'_\n'..description
  local image_url = data.header_image
  return text, image_url
end

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)
  utilities.send_reply(msg, text, true)
end

return steam<commit_msg>Steam: Fix<commit_after>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)

  local text = '<b>'..title..'</b> <i>'..price..'</i>\n'..description
  local image_url = data.header_image
  return text, image_url
end

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)
  print(text)
  utilities.send_reply(msg, text, 'HTML')
end

return steam
{'fraction_non_alphanumeric': 0.1434414256500146, 'fraction_numerical': 0.008764241893076249, 'mean_word_length': 3.884450784593438, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2609843', 'n_tokens_mistral': 1251, 'n_tokens_neox': 1226, 'n_words': 275}