Skip to content
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

Getting user perms? #120

Open
Dontmindmes opened this issue Apr 23, 2019 · 4 comments
Open

Getting user perms? #120

Dontmindmes opened this issue Apr 23, 2019 · 4 comments
Labels

Comments

@Dontmindmes
Copy link

How can i get the senders perms?

ex: sender uses !test -> checks if sender has op perms

@belak
Copy link
Contributor

belak commented Apr 23, 2019

This is actually fairly complicated and involves setting up a number of callbacks and tracking a bunch of stuff.

I've got a relatively detailed write up of the callbacks you'll need here: https://gist.github.com/belak/09edcc4f5e51056bf5bc728647659d81

@Dontmindmes
Copy link
Author

ugh its to confusing :/

if wish there was somthing like
e.Perm("Username") that returns true or false

@belak
Copy link
Contributor

belak commented Apr 24, 2019

Unfortunately because of how IRC is designed (there's not consistency between daemons) this is hard. There are some IRCv3 CAPs you could use (which I think are mentioned in the gist) but they don't work everywhere.

@thoj thoj added feature request needhelp Need pull request labels Apr 29, 2019
@adamhassel
Copy link

adamhassel commented Apr 7, 2020

I;ve been messing a bit with this, and I have come up with a helper function that illustrates how to do it. I use this to check if the bot has +o:

// RequestReply abstracts sending a command to the IRC server and listening for a reply. Eventcodes must match the
// commands. See https://www.alien.net.au/irc/irc2numerics.html
func RequestReply(c *irc.Connection, eventcode, command string) (string, error) {
	reply := make(chan string, 1)
	id := c.AddCallback(eventcode, func(e *irc.Event) {
		reply <- e.Message()
		defer close(reply)
	})
	defer c.RemoveCallback(eventcode, id)
	c.SendRaw(command)
	var r string
	select {
	case r = <-reply:
	case <-time.NewTicker(5 * time.Second).C:
		return "", errors.New("timeout getting command response")
	}
	return r, nil
}

Then I can use it to send a "NAMES -ops " command to the IRC server, and record the response:

o, err := RequestReply(c, "366", "NAMES -ops "+channel)
if err != nil {
	SendReply(c, channel, fmt.Sprintf("Error getting ops list: %s", err), false)
	return
}

o is then a space-separated string of all channel operators on channel. Then you just need to make sure your bot's name's in there. However, see also #130

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants