zorael / kameloso

IRC bot with Twitch support
Boost Software License 1.0
9 stars 3 forks source link

New hostmasks mode #108

Closed zorael closed 3 years ago

zorael commented 3 years ago

This revamps hostmasks mode into something actually usable.

hostmasks.json is a file with a JSON string[string] associative array of account values and hostmask keys.

{
    "kameloso*!kameloso@123.123.*": "kameloso",
    "zorael*!~NaN@*": "zorael"
}

user.json remains a file with a string[][string][string] array with the top keys staff, operator, whitelist and blacklist.

{
    "staff":
    {
        "#channel1": [
            "ray",
            "steve"
        ]
    },
    "operator":
    {},
    "whitelist":
    {},
    "blacklist":
    {
        "<channel>": [
            "<nickname1>",
            "<nickname2>"
        ]
    }
}

Upon connection, hostmasks.json is read and cached in a runtime array. When a new user is spotted, this gets iterated and the hostmasks therein compared to the user (using dialect.common.matchesByMask). If they match, the user gets assigned the account listed as the value of the hostmask key. The pairing is then further cached in a separate runtime array, to speed up future lookups. (The cache entry is properly invalidated on NICK and such.)

It seems to work -- at least better than it did before, which was just broken.