-
Notifications
You must be signed in to change notification settings - Fork 108
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Nick tracker #79
base: master
Are you sure you want to change the base?
Add Nick tracker #79
Conversation
irc.SetupNickTrack() Adds nessesarry callbacks irc.Channels map Populated by said callbacks irc.Channels["#chan"].Users[nickname]
Nice! Definitely a great start. There are a few subtleties with this:
I have an implementation of some of the ISUPPORT stuff here: https://github.com/belak/python-seabird/blob/master/seabird/modules/isupport.py There's also an implementation of nick tracking here: https://github.com/belak/python-seabird/blob/master/seabird/modules/track.py And I have some more notes here: https://gist.github.com/belak/09edcc4f5e51056bf5bc728647659d81 |
Thanks a ton! I keep on efnet where stuff is simple and nice. hehe. I'll look into this. I'm not to worried about getting the mode stuff right. Maybe just keep an array of modes instead of just a string is cleaner.
|
Yeah, writing this sort of thing properly without multi-prefix is a pain, but it can be done. |
Is there any update on this? Seems like the PR just got forgotten :( |
I ended up writing my own earlier this year which does its best to cover all the bases without needing any special IRCv3 features... unfortunately it's pretty integrated into my irc bot, but the code might be helpful. https://github.com/belak/go-seabird/blob/master/plugins/channel_track.go It's technically licensed under MIT, but I'm the sole person who worked on it, and as far as I'm concerned, it's totally find to use as a reference. |
Mode string | ||
} | ||
|
||
var mode_split = regexp.MustCompile("([%@+]{0,1})(.+)") //Half-Op, //Op, //Voice |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is fairly limited and will break on any servers that support other modes (I've seen & used for admin). This should be pulled from the PREFIX
isupport value which comes in the format like this: (qaohv)~&@%+
if _, ok := irc.Channels[channelName]; ok != true { | ||
irc.Channels[channelName] = Channel{Users: make(map[string]User)} | ||
} | ||
if _, ok := irc.Channels[channelName].Users[e.Arguments[2]]; ok != true { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This only seems to handle setting all modes, however MODE
responses don't always contain all modes of a user. Because this code seems to set mode directly, it looks like the Mode won't be accurate if MODE
is called more than once for a user or if a user has a mode set and MODE
is called.
Additionally, this will probably end up being the most complicated portion. Either IRCv3 multi-prefix needs to be enabled (and handled) or you will need to query for the user's modes in a channel using NAMES
or WHO
(rather, WHOX
) when a mode is removed. As an example, a user can have +v+o
in a channel, but in most cases, only the highest mode will be returned (in this case +o
). When +o
is removed, they still have +v
, so there should be a way to determine that.
}) | ||
|
||
irc.AddCallback("PART", func(e *Event) { | ||
channelName := e.Arguments[0] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the bot leaves a channel, the whole channel should be removed as it won't be tracked any more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll try and work on this, it's something that will probably break things for me.
nickandmode := mode_split.FindStringSubmatch(modenick) | ||
u := User{} | ||
if len(nickandmode) == 3 { | ||
if nickandmode[1] == "@" { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As mentioned above, these should probably be pulled from isupport, if possible, rather than hard coded.
It's fairly buggy, but should handle the basic cases relatively well.
This might sound like overkill, but I actually wrote my own IRC library a while back, so using this branch wouldn't really be an option. Anyway, this code needs a bit of love before it would be production ready. I left a few comments about bugs I noticed off the top of my head (EDIT: I actually noticed I left similar comments above - this may make it easier to see where there may be trouble though). It doesn't use IRCv3. This sort of tracking can be done without IRCv3 but it takes a bit of extra code. Essentially, IRCv3 would let you handle some of the edge cases when |
Thanks for the info @belak. Does storing modes in a slice sound good to you? Might be worth calling it "TrackState", creating a |
Yep, storing modes in a slice would probably be good enough. I ended up using a https://github.com/belak/go-seabird/blob/master/plugins/channel_track.go#L31 The other main difference in my implementation is that it assigns a unique identifier to each user and allows you to track nick changes using the user struct and/or that ID. |
Please test
Usage (Prints Nick list every 30 seconds):