You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

auth.go 1.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. package main
  2. import (
  3. "github.com/thoj/go-ircevent"
  4. "strings"
  5. )
  6. func (i *IRCCat) inChannel(channel string) bool {
  7. return i.channels.Contains(channel)
  8. }
  9. func (i *IRCCat) authorisedUser(nick string) bool {
  10. _, exists := i.auth_users[nick]
  11. return exists
  12. }
  13. func (i *IRCCat) handleJoin(e *irc.Event) {
  14. if e.Arguments[0] == i.auth_channel {
  15. i.auth_users[e.Nick] = true
  16. }
  17. }
  18. func (i *IRCCat) handlePart(e *irc.Event) {
  19. if e.Arguments[0] == i.auth_channel {
  20. delete(i.auth_users, e.Nick)
  21. }
  22. }
  23. func (i *IRCCat) handleQuit(e *irc.Event) {
  24. delete(i.auth_users, e.Nick)
  25. }
  26. func (i *IRCCat) handleNames(e *irc.Event) {
  27. if e.Arguments[2] == i.auth_channel {
  28. nicks := strings.Split(e.Arguments[3], " ")
  29. for _, nick := range nicks {
  30. // TODO: this is probably not an optimal way of trimming the mode characters.
  31. nick = strings.TrimLeft(nick, "@%+")
  32. i.auth_users[nick] = true
  33. }
  34. }
  35. }
  36. func (i *IRCCat) handleNick(e *irc.Event) {
  37. if i.auth_users[e.Nick] {
  38. delete(i.auth_users, e.Nick)
  39. i.auth_users[e.Arguments[0]] = true
  40. }
  41. }