func ui(con *irc.Conn, in chan string) {
	curr_chan := ""

	for input := range in {
		if input[0] == '/' {
			// is a command
			var cmd string
			cmdend := strings.Index(input, " ")
			if cmdend > 0 {
				cmd = input[:cmdend]
			} else {
				cmd = input
			}

			switch cmd {
			case "/join":
				if len(input) > cmdend {
					channel := input[cmdend+1:]
					if channel[0] != '#' {
						channel = "#" + channel
					}
					curr_chan = channel
					con.Join(channel)
				} else {
					fmt.Println("Please specify the channel")
				}
			case "/quit":
				fmt.Println("Bye!")
				con.Quit()
			case "/goto":
				curr_chan = input[cmdend+1:]
			case "/list":
				break
			case "/nick":
				if cmdend > 0 {
					con.Nick(input[cmdend+1:])
				} else {
					fmt.Println("Too few arguments")
				}
			default:
				fmt.Println("Unknown command")
			}
			fmt.Printf("\n%s: ", curr_chan)
		} else {
			con.Privmsg(curr_chan, input)
			fmt.Printf("%s: ", curr_chan)
		}
	}
	fmt.Println("Closing connection. kthxbai!")
	con.Quit()
}
Exemple #2
0
func restart(conn *irc.Conn, nick *irc.Nick, args, channel string) {
	owner, _ := auth.String(conn.Network, "owner")
	if owner == user(nick) {
		cmd := exec.Command("./rbot")
		here, _ := os.Getwd()
		cmd.Dir = here
		cmd.Stdout = os.Stdout
		cmd.Stderr = os.Stderr
		err := cmd.Start()
		if err != nil {
			say(conn, channel, "Unable to start new process: %s", err)
			return
		}
		conn.Quit("Restarting.")
		time.Sleep(50)
		os.Exit(0)
	}
}