hexchat / hexchat

GTK+ IRC client
https://hexchat.github.io
GNU General Public License v2.0
3.09k stars 537 forks source link

Add some convenience functions to plugin API #715

Open TingPing opened 11 years ago

TingPing commented 11 years ago

Currently you must loop through lists (which is very slow to create in Python) of all users and all channels to find out basic information like a single users account. Perl already has these (userinfo, contextinfo) and it would be useful to add them to the API itself for Python and JavaScript to use.

Another common thing to do is get the calculated color of a nick in a script so adding a function to call _text_colorof() for us could be useful.

nitori commented 11 years ago

hexchat.nicklower or hexchat.nickupper, to convert nicknames and channel names to upper/lower case (according to the rfc just like hexchat.nickcmp does), so you can use nicknames and/or channel names as keys for e.g. python/javascript dictionaries. That way you don't have to iterate over the whole dictionary to find the entry or it's existence.

bendem commented 9 years ago

+1 for the ability to get the color of a nickname

FichteFoll commented 9 years ago

Apparently, the algorithm for nick color is as follows (pasted in IRC by TingPing):

colors = (19, 20, 22, 24, 25, 26, 27, 28, 29)

def color_of (nick):
    total = sum(ord(char) for char in nick)
    total %= len(colors)
    return colors[total]

color_of('TingPing')
29