Exemplo n.º 1
0
func main() {
	var msg, country string
	flag.Parse()
	if *token_file == "" {
		flag.PrintDefaults()
		os.Exit(1)
	}
	token, err := ioutil.ReadFile(*token_file)
	if err != nil {
		log.Fatal(err)
	}
	bot, err := telebot.NewBot(string(token))
	if err != nil {
		return
	}

	messages := make(chan telebot.Message)
	bot.Listen(messages, 1*time.Second)

	for message := range messages {
		// pretty.Println(message.Sender)
		msg = message.Text
		if msg == "/hi" {
			count := 1
			for {
				pretty.Println(count)
				count++
				bot.SendMessage(message.Chat,
					"Hello, "+message.Sender.FirstName+"!", nil)
				time.Sleep(1000 * time.Millisecond)
			}
		} else if strings.HasPrefix(msg, "/flag") {
			//check if flag is empty
			country = "ASEAN" //msg[6:]
			pretty.Print(country)
			photo := "./resources/flags/" + country + ".png"
			boom, err := telebot.NewFile(photo)
			if err != nil {
				pretty.Print(err)
			}
			pretty.Print(&bot)
			pretty.Print(&boom)

			// SendPhoto
			// telebot.File{}ASEAN&telebot.File{FileID:"", FileSize:0, filename:"./resources/flags/ASEAN.png"}
			// pretty.Print(reflect.TypeOf((*bot).SendMessage))
			// // get from directory
			// err = bot.SendAudio(message.Chat, &boom, nil)
			// err = bot.SendMessage(message.Chat, &boom, nil)
			if err != nil {
				pretty.Print(err)
			}
		}
	}
}
Exemplo n.º 2
0
func main() {
	flag.Parse()
	if *inputFile == "" {
		log.Fatal("No input file specified")
	}
	if *outputFile == "" {
		*outputFile = *inputFile + ".gen.go"
	}

	f, err := os.Open(*inputFile)
	if err != nil {
		log.Fatal(err)
	}
	defer f.Close()

	s, err := schema.Parse(f)
	if err != nil {
		log.Fatal(err)
	}

	if *debug {
		pretty.Print(s)
	}

	output, _ := os.Create(*outputFile)
	s.(schema.Schema).Generate(output, *packageFile)
}
Exemplo n.º 3
0
func main() {
	if len(os.Args) == 1 {
		os.Exit(1)
	}
	backend, ok := schema.Backends[os.Args[1]]
	if !ok {
		fmt.Fprintln(os.Stderr, "No such backend, available backends are:")
		for name := range schema.Backends {
			fmt.Fprintln(os.Stderr, name)
		}
		os.Exit(1)
	}

	flags := backend.Flags()

	SchemaFile := ""
	Debug := false

	flags.StringVar(&SchemaFile, "schema", "", "Schema file to process")
	flags.BoolVar(&Debug, "debug", false, "Pretty print the resulting schema defs")

	flags.Parse(os.Args[2:])

	if SchemaFile == "" {
		log.Fatal("No file specified")
	}

	file, err := os.Open(SchemaFile)

	if err != nil {
		log.Fatalf("Error opening schema file: %s", err)
	}

	if file == nil {
		log.Fatalf("error opening file %s", file)
	}

	s, err := schema.ParseSchema(file)

	if Debug {
		pretty.Print(s)
	}

	if err != nil {
		log.Fatalf("Error parsing schema: %s", err)
	}

	code, err := backend.Generate(s)

	if err != nil {
		log.Fatalf("Error generating output: %s", err)
	}

	err = ioutil.WriteFile(backend.GeneratedFilename(SchemaFile), []byte(code), 0666)

	if err != nil {
		log.Fatalf("Error writing output file: %s", err)
	}

}
Exemplo n.º 4
0
func TestParseHeader(t *testing.T) {
	input := `
2|afrinic|20150612|7236|00000000|20150612|00000
afrinic|*|asn|*|2302|summary
afrinic|*|ipv4|*|2935|summary
afrinic|*|ipv6|*|1999|summary
afrinic|ZA|asn|1228|1|19910301|allocated|F36B9F4B
afrinic|ZA|asn|1229|1|19910301|allocated|F36B9F4B
afrinic|ZA|asn|1230|1|19910301|allocated|F36B9F4B
afrinic|ZA|asn|1231|1|19910301|allocated|F36B9F4B
`
	hdr, recs, err := Parse(strings.NewReader(input))
	if err != nil {
		t.Fatal(err)
	}

	pretty.Print(hdr)
	pretty.Print(recs)
}
Exemplo n.º 5
0
Arquivo: uparse.go Projeto: mewmew/uc
// parseFile parses the given file and pretty-prints its abstract syntax tree to
// standard output, optionally using the Gocc generated lexer.
func parseFile(path string, goccLexer bool) error {
	// Create lexer for the input.
	buf, err := ioutilx.ReadFile(path)
	if err != nil {
		return errutil.Err(err)
	}
	if path == "-" {
		fmt.Fprintln(os.Stderr, "Parsing from standard input")
	} else {
		fmt.Fprintf(os.Stderr, "Parsing %q\n", path)
	}
	var s parser.Scanner
	if goccLexer {
		s = goccscanner.NewFromBytes(buf)
	} else {
		s = handscanner.NewFromBytes(buf)
	}

	// Parse input.
	p := parser.NewParser()
	file, err := p.Parse(s)
	if err != nil {
		if err, ok := err.(*errors.Error); ok {
			// Unwrap Gocc error.
			return parser.NewError(err)
		}
		return errutil.Err(err)
	}
	f := file.(*ast.File)
	for _, decl := range f.Decls {
		fmt.Println("=== [ Top-level declaration ] ===")
		fmt.Println()
		fmt.Printf("decl type: %T\n", decl)
		fmt.Println()
		fmt.Println("decl:", decl)
		fmt.Println()
		pretty.Print(decl)
		fmt.Println()
		spew.Print(decl)
		fmt.Println()
		fmt.Println()
	}

	return nil
}
Exemplo n.º 6
0
func main() {
	flag.Parse()
	p := MakeParser()
	data, err := ioutil.ReadFile(*inputFile)
	if err != nil {
		log.Fatal(err)
	}
	s, err := p.ParseString(string(data))
	if err != nil {
		log.Fatal(err)
	}

	if *debug {
		pretty.Print(s)
	}

	output, _ := os.Create(*outputFile)
	s.(schema.Schema).Generate(output, *packageFile)
}
Exemplo n.º 7
0
func print(c *cli.Context, model Model) {
	var err error
	var value []byte
	key := c.String("encryptionKey")
	label := c.String("activeKeyLabel")

	if len(c.Args()) > 0 {
		value = []byte(c.Args()[0])
	} else {
		bio := bufio.NewReader(os.Stdin)
		value, err = bio.ReadBytes(0)
		if err != io.EOF {
			panic(err)
			os.Exit(1)
		}
	}
	err = model.Unmarshal(decrypt([]byte(value), key, label))
	if err != nil {
		fmt.Println(err)
	} else {
		pretty.Print(model)
	}
}
Exemplo n.º 8
0
func pp(a ...interface{}) (int, error) {
	if debug {
		return pretty.Print(a...)
	}
	return 0, nil
}
Exemplo n.º 9
0
func gdebug(g Graph, args ...interface{}) {
	fmt.Println("DEBUG: graph type", reflect.New(reflect.Indirect(reflect.ValueOf(g)).Type()))
	pretty.Print(args...)
}