Exemplo n.º 1
0
func (ei *EndpointIRC) message(c *irc.Conn, l *irc.Line) {
	var messageTarget MessageTarget
	if l.Public() {
		messageTarget = ei.GetChannel(l.Target())
	} else {
		messageTarget = ei.GetUser(l.Target())
	}
	ei.handler(l.Text(), ei.GetUser(l.Nick), l.Target(), messageTarget)
}
Exemplo n.º 2
0
func handle_command(conn *irc.Conn, line *irc.Line, args []string) {
	command := args[0][len(RC.CmdPrefix):]
	args = args[1:]

	st := conn.StateTracker()
	authed := RC.Authed[line.Nick]

	if line.Nick == RC.Owner && authed {
		// Owner-only commands
		if command == "mock" {
			for _, n := range args {
				_, is_on := st.IsOn(RC.Channel, n)
				if is_on {
					RC.Mocking[n] = true
					conn.Privmsg(RC.Channel, "Now mocking "+n)
				}
			}
		} else if command == "unmock" {
			for _, n := range args {
				if RC.Mocking[n] {
					RC.Mocking[n] = false
					conn.Privmsg(RC.Channel, "No longer mocking "+n)
				}
			}
		} else if command == "shorten" {
			fmt.Println("unimplemented")
		} else if command == "snoop" {
			fmt.Println("unimplemented")
		}
	} else if (RC.Ops[line.Nick] || line.Nick == RC.Owner) && authed {
		// Ops-level commands
		if command == "poop" {
			conn.Privmsg(RC.Channel, "poop")
		}
	} else if command == "identify" && !line.Public() {
		fmt.Println("User " + line.Nick + " attempting to auth...")
		h := sha256.New()
		h.Write([]byte(args[0]))
		pwd_hash := hex.EncodeToString(h.Sum(nil))
		if (line.Nick == RC.Owner || RC.Ops[line.Nick]) && RC.Password == pwd_hash {
			fmt.Println("Auth succeeded for " + line.Nick)
			RC.Authed[line.Nick] = true
			conn.Privmsg(line.Nick, "You're authenticated now.")
		} else {
			fmt.Println("WARNING: Auth failed for " + line.Nick + "!")
			conn.Privmsg(line.Nick, "You f****d up.")
		}
	}
}