Skip to content

Instantly share code, notes, and snippets.

@Earu
Last active September 4, 2020 22:31
Show Gist options
  • Save Earu/1c0825e0e8c419945539475c3931dac1 to your computer and use it in GitHub Desktop.
Save Earu/1c0825e0e8c419945539475c3931dac1 to your computer and use it in GitHub Desktop.
EasyChat mentions sent directly to you via your os notifications.
require("win_toast") -- you need https://github.com/Earu/gm_win_toast
local base_dir = "windows_mentions"
local function get_avatar(id64, success_callback, err_callback)
http.Fetch("http://steamcommunity.com/profiles/" .. id64 .. "?xml=1", function(content, size)
local ret = content:match("<avatarIcon><!%[CDATA%[(.-)%]%]></avatarIcon>")
success_callback(ret)
end, err_callback)
end
hook.Add("ECPlayerMention", "windows_mentions", function(ply, msg)
if not IsValid(ply) then
WinToast.Show("Console / Invalid Player", msg)
return
end
if ply:IsBot() then
WinToast.Show(EasyChat.GetProperNick(ply), msg)
return
end
local id64 = ply:SteamID64()
local avatar_path = ("%s/%s.jpg"):format(base_dir, id64)
if file.Exists(avatar_path, "DATA") then
WinToast.Show(EasyChat.GetProperNick(ply), msg, avatar_path)
else
local function fallback()
WinToast.Show(EasyChat.GetProperNick(ply), msg)
end
get_avatar(id64, function(avatar_url)
http.Fetch(avatar_url, function(body)
if not file.Exists(base_dir, "DATA") then
file.CreateDir(base_dir)
end
file.Write(avatar_path, body)
WinToast.Show(EasyChat.GetProperNick(ply), msg, avatar_path)
end, fallback)
end, fallback)
end
end)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment