ergochat / irc-go

Libraries to help with IRC development in Go.
ISC License
41 stars 6 forks source link

Read all hosts on event (help needed) #88

Closed kofany closed 9 months ago

kofany commented 2 years ago

Im looking for a way to read all hosts/nicks on channel and than look form a match on specific event (like command prvmsg channel: !match) but I have no clue how can I read all nick/hosts from channel using irc event?

slingamn commented 2 years ago

Sorry, I saw this earlier but lost track of it. The conventional way to do this is to handle 353 RPL_NAMREPLY, which is sent as part of the response to JOIN. Here's the format:

https://modern.ircdocs.horse/#rplnamreply-353

And here is some example output from irc.ergo.chat:

:irc.ergo.chat 353 testnick = #ergo :jkbrune100 knolle jd freakyy85 @aj teraspin mogad0n_ AJAr james1 [Pokey] MD87 mooff FiskFan1999 Mikaela tuxifreund @ErgoBridge ze0s pounce timdream y gerikson cranberry NiKaN darkowlzz jwheare berkay pirateoverboard flips hkmoritz10 mooff| petteri MasterSc- Polsaker toxic Noisytoot testnick mogad0n Ariadne matthias bookworm anon superkuh kylef secular Techcable kayos ziro km @slingamn anton vectr0n johncs Spydar007 ben @dan tnez tumble rcr JanC 9pfs mokou
:irc.ergo.chat 353 testnick = #ergo :tjr sbrivio_ lindsay @ErgoBot V Mikaela- Gokturk val

You can see that the nick list is split onto multiple 353 lines. In each line, the final parameter is a list of nicknames joined together with spaces. Some nicknames have a prefix character, e.g., with @ErgoBridge the actual nickname is just ErgoBridge and the @ indicates channel operator status. The possible prefixes are ~&@%+ (technically it can vary between ircds, but these are pretty standard).

So, you want to add a handler for RPL_NAMREPLY and then parse the responses accordingly. If you're having trouble, I can probably provide some example code.

slingamn commented 2 years ago

If you want hostnames the conventional way is to manually send WHO #channel and parse the response (RPL_WHOREPLY followed by RPL_ENDOFWHO):

https://modern.ircdocs.horse/#who-message
https://ircv3.net/specs/extensions/whox

kofany commented 2 years ago

thanks for Your time :), im starting to learn go on my irc bot project, till now I have made this: https://github.com/kofany/GoGolin - probably is primitive but its a beginning of my journey with go :).

Can You provide an example how to send who and get response as []slice?

slingamn commented 2 years ago

I created a branch called who_example for this:

https://github.com/ergochat/irc-go/commit/6a39acdaba6e03144c2f5e187f2c6a47ed1c64bb
https://github.com/ergochat/irc-go/blob/6a39acdaba6e03144c2f5e187f2c6a47ed1c64bb/ircevent/examples/simple.go

kofany commented 2 years ago

Thanks a lot for this, can You also say how I can bind specific ip address for irc connection (use a vhost)

slingamn commented 2 years ago

I'm not totally sure what you're referring to. "vhost" generally refers to a server-side feature that hides the user's IP/host information from other users.

If you have multiple source addresses on the client machine and want to bind to one of them for the outgoing connection, we don't support this yet, but it would be supported under #64, which lets you control the "dialer". See here:

https://github.com/ergochat/irc-go/commit/3b160198e96754d3707a7d549e0b5632fc4a1b7c

What's the underlying goal here?

kofany commented 2 years ago

I mean to bind ip for outgoing connection. I have this done for thoj/go-ircevent: (dialer := proxy.FromEnvironmentUsing(&net.Dialer{ LocalAddr: &net.TCPAddr{ IP: net.ParseIP(irc.myhost), Port: 0, },Timeout: irc.Timeout})

//where myhost is passed here: func IRC(nick, user string, myhost string) *Connection { // catch invalid values) but Yours is more complicated :)

My work for bind ip You can see under my fork of go-ircevent https://github.com/kofany/go-ircevent

Im writing a irc bot in go :) that's why I need to scan channel for hosts/users and bind ip function :)

slingamn commented 2 years ago

Thanks. This should be possible with the work in #64 --- could you test my branch (issue64_proxies) there for your use case?

kofany commented 2 years ago

I will rewrite my bot https://github.com/kofany/GoGolin using Your branch on weekend and I will post a feedback :)

slingamn commented 1 year ago

@kofany any update? :-)