Example #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:
	}
}
Example #2
0
func Action(msg *proto.Message, conn irc.ConnInterface) {
	switch msg.Code {
	case "001":
		conn.SetServerHost(msg.Source)
	case "NICK":
		if msg.Nick == conn.GetCurrentNick() {
			conn.SetCurrentNick(msg.Content)
		}
	case "PING":
		conn.Pong(msg.Content)
		conn.SetLastAlive(time.Now())
	// case "PRIVMSG":
	// 	for _, v := range msg.Arguments {
	// 		if strings.HasPrefix(v, "#") {
	// 			conn.ChanMap.RLock()
	// 			if v, ok := conn.ChanMap.CM[v]; ok {
	// 				v.output.Printf("<%s> %s\n", msg.Nick, msg.Content)
	// 			}
	// 			conn.ChanMap.RUnlock()
	// 		} else {
	// 			conn.output.Printf("PRIVMSG <%s> %s\n", msg.Nick, msg.Content)
	// 		}
	// 	}
	case "PONG":
		conn.SetServerHost(msg.Arguments[0])
		conn.SetLastAlive(time.Now())
	case "NOTICE":
		fallthrough
	default:
	}
	fmt.Printf("%+v\n", msg)
}