Exemplo n.º 1
0
func main() {
	var help bool
	var service string
	var put bool

	flag.BoolVar(&help, "h", false, "Show help message")
	flag.BoolVar(&help, "help", false, "Show help message")
	flag.StringVar(&service, "s", "sprunge", "Paste service")
	flag.StringVar(&service, "service", "sprunge", "Paste service")
	flag.BoolVar(&put, "p", false, "Send the paste")
	flag.BoolVar(&put, "put", false, "Send the paste")
	flag.Parse()

	if help {
		usage(os.Args[0])
	}

	if !put && flag.NArg() == 0 {
		usage(os.Args[0])
	}

	if put {
		for i := 0; i < flag.NArg(); i++ {
			file := flag.Arg(i)
			processFile(file)
		}
	} else {
		var sep bool = flag.NArg() > 1
		for i := 0; i < flag.NArg(); i++ {
			url := flag.Arg(i)
			if sep {
				fmt.Printf("%s:\n", url)
			}
			text, err := paste.Get(url)
			if err != nil {
				fmt.Fprintf(os.Stderr, "%s\n", err)
				continue
			}
			fmt.Println(text)
		}
	}
	return
}
Exemplo n.º 2
0
func (cp *CodePasteChecker) handleMessage(data interface{}) {
	req, ok := data.(*MessageRequest)
	if !ok {
		return
	}

	if req.neturl == nil {
		return
	}

	code, err := paste.Get(req.url)
	if err != nil {
		if err != paste.ErrNotSupported {
			cp.Logger.Println("Get paste error:", err)
		}
		return
	}

	lang := req.irc.config.ChannelLang(req.channel)
	if lang == "" {
		cp.Logger.Println("No language defined for channel", req.channel)
		return
	}
	cmplres, have_issues := cp.processCode(code, lang)
	if cmplres == "" {
		return
	}
	res := fmt.Sprintf("%s's paste: %s", req.nick, cmplres)
	if have_issues {
		res += fmt.Sprintf(" -- issues found, please address them first!")
		req.irc.sendReply(res, req)
	} else {
		// do not repaste from sprunge
		if req.neturl.Host == "sprunge.us" {
			return
		}
		if req.irc.config.ChannelRepaste(req.channel) {
			req.irc.sendReply(res, req)
		}
	}
	req.cleanURL()
}