Esempio n. 1
0
func (as *adminStruct) Action(msg *proto.Message, conn irc.ConnInterface) {
	switch msg.Code {
	case "PRIVMSG":
		if msg.Arguments[0] == conn.GetCurrentNick() { // private message
			if v, ok := as.adminVerified[msg.Nick]; ok {
				command := utils.SplitAndTrimN(msg.Content, " ", 2)
				if v {
					switch command[0] {
					case "privmsg":
						args := utils.SplitAndTrimN(command[1], " ", 2)
						channel := args[0]
						msg := args[1]
						conn.Privmsg(channel, msg)
					default:
					}
				} else {
					// only allow VERIFY message
					if command[0] == "verify" && command[1] == as.passwd {
						as.lock.Lock()
						as.adminVerified[msg.Nick] = true
						as.lock.Unlock()
						conn.Privmsg(msg.Nick, "VERIFIED")
					}
				}
			} else {
				// Do nothing if not an administrator
			}
		}
	case "QUIT":
		if _, ok := as.adminVerified[msg.Nick]; ok {
			as.lock.Lock()
			as.adminVerified[msg.Nick] = false
			as.lock.Lock()
		}
	default:
	}
}