Module:FormatSocials: Difference between revisions

From The TF2 Sourcemod Wiki
Jump to navigation Jump to search
m Added afew missing domains
m Added moddb and gambanana
 
Line 7: Line 7:
     ["https://github.com/"] = "GitHub",
     ["https://github.com/"] = "GitHub",
     ["https://bsky.app/"] = "BlueSky",
     ["https://bsky.app/"] = "BlueSky",
     ["https://www.youtube.com/"] = "YouTube",
     ["https://youtube.com/"] = "YouTube",
     ["https://steamcommunity.com/"] = "Steam",
     ["https://steamcommunity.com/"] = "Steam",
     ["https://discord.com/"] = "Discord",
     ["https://discord.com/"] = "Discord",
     ["https://discord.gg/"] = "Discord",
     ["https://discord.gg/"] = "Discord",
     ["https://discord.gg/"] = "Discord",
     ["https://discord.gg/"] = "Discord",
    ["https://www.moddb.com/"] = "ModDB",
    ["https://gamebanana.com/"] = "ModDB",
     ["https://community.lambdageneration.com"] = "Lambda Generation",
     ["https://community.lambdageneration.com"] = "Lambda Generation",
}
}

Latest revision as of 15:10, 2 February 2025

Documentation for this module may be created at Module:FormatSocials/doc

local FormatSocials= {}

local SiteNames = {
    ["https://x.com/"] = "Twitter/X",
    ["https://twitter.com/"] = "Twitter/X",
    ["https://www.youtube.com/"] = "YouTube",
    ["https://github.com/"] = "GitHub",
    ["https://bsky.app/"] = "BlueSky",
    ["https://youtube.com/"] = "YouTube",
    ["https://steamcommunity.com/"] = "Steam",
    ["https://discord.com/"] = "Discord",
    ["https://discord.gg/"] = "Discord",
    ["https://discord.gg/"] = "Discord",
    ["https://www.moddb.com/"] = "ModDB",
    ["https://gamebanana.com/"] = "ModDB",
    ["https://community.lambdageneration.com"] = "Lambda Generation",
}

function FormatSocials.Format(frame)
    local Input = frame.args[1] or ""
    local Parts = {}
    for Word in string.gmatch(Input, '([^,]+)') do
        table.insert(Parts, Word)
    end
    
    local Result = {}
    for i, Part in ipairs(Parts) do
        local DisplayTitle = nil
        for url, name in pairs(SiteNames) do
            if string.find(Part, url) then
                DisplayTitle = name
                break
            end
        end
        
        if DisplayTitle then
            table.insert(Result, string.format("[%s %s]", Part, DisplayTitle))
        else -- HEY MIXER, this is the bad case when nothing is found so it just displays the url
            table.insert(Result, string.format("[%s Website]", Part, Part))
        end
    end
    
    return table.concat(Result, "<br>")
end

return FormatSocials