// Beep beeps the PC speaker (https://en.wikipedia.org/wiki/PC_speaker).
429
func Beep(freq float64, duration int) error {
	if freq == 0 {
		freq = DefaultFreq
	} else if freq > 32767 {
		freq = 32767
	} else if freq < 37 {
		freq = DefaultFreq
	}

	if duration == 0 {
		duration = DefaultDuration
	}

	kernel32, _ := syscall.LoadLibrary("kernel32.dll")
	beep32, _ := syscall.GetProcAddress(kernel32, "Beep")

	defer syscall.FreeLibrary(kernel32)

	_, _, e := syscall.Syscall(uintptr(beep32), uintptr(2), uintptr(int(freq)), uintptr(duration), 0)
	if e != 0 {
		return e
	}

	return nil
}
351271
func SoundStart(listener func(*vecty.Event)) *vecty.EventListener {
	return &vecty.EventListener{Name: "soundstart", Listener: listener}
}
735543
func StartBee(bee BeeConfig) *BeeInterface {
	b := NewBeeInstance(bee)

	(*b).Start()
	go func(mod *BeeInterface) {
		startBee(mod, 0)
	}(b)

	return b
}
364634
func (s *Server) ListenForSignals(signals ...os.Signal) {
	if s.signals == nil {
		s.signals = make(map[os.Signal]struct{})
	}

	for _, sig := range signals {
		s.signals[sig] = struct{}{}
	}
}
1150006
func (v *Ping) GetBeep() (o string) {
	if v != nil {
		o = v.Beep
	}
	return
}
640483
func (EchoProtobuf) Echo(_ context.Context, request *crossdockpb.Ping) (*crossdockpb.Pong, error) {
	if request == nil {
		return nil, nil
	}
	return &crossdockpb.Pong{Boop: request.Beep}, nil
}
408847
func (sp *SendAudio) KeyboardHide(kb ReplyKeyboardHide) *SendAudio {
	var rmi ReplyMarkupInt = kb
	sp.ReplyMarkup = &rmi
	return sp
}
1101163
func (t *Thread) PC() (uint64, error) {
	regs, err := t.Registers(false)
	if err != nil {
		return 0, err
	}
	return regs.PC(), nil
}
320539
func AskForConfirmation() bool {

	// Hopefully a clean exit
	interrupt := make(chan os.Signal, 1)
	stop := make(chan os.Signal, 1)
	reload := make(chan os.Signal, 1)
	signal.Notify(interrupt, os.Interrupt)
	signal.Notify(stop, syscall.SIGINT)
	signal.Notify(reload, syscall.SIGHUP)
	go func() {
		select {
		case signal := <-interrupt:
			fmt.Println("Got signal:", signal)
			fmt.Println("Dying")
			os.Exit(0)
		case signal := <-reload:
			fmt.Println("Got signal:", signal)
			fmt.Println("Dying")
			os.Exit(0)
		case signal := <-stop:
			fmt.Printf("Got signal:%v\n", signal)
			fmt.Println("Dying")
			os.Exit(0)
		}
	}()

	var response string

	_, err := fmt.Scanln(&response)
	if err != nil {
		//fmt.Println(err)
		return false
	}
	okayResponses := []string{"y", "Y", "yes", "Yes", "YES"}
	nokayResponses := []string{"n", "N", "no", "No", "NO", "\n"}
	quitResponses := []string{"q", "Q", "exit", "quit"}
	if containsString(okayResponses, response) {
		return true
	} else if containsString(nokayResponses, response) {
		return false
	} else if containsString(quitResponses, response) {
		return false
	} else {
		fmt.Println("\nNot valid answer, try again. [y/n] [yes/no]")
		return AskForConfirmation()
	}
}
103
func (bot TgBot) SendAudioWithKeyboardHide(cid int, audio string, duration *int, performer *string, title *string, rmi *int, rm ReplyKeyboardHide) ResultWithMessage {
	var rkm ReplyMarkupInt = rm
	return bot.SendAudio(cid, audio, duration, performer, title, rmi, &rkm)
}
588665
func (d *DockerMonitor) eventListener(ctx context.Context, listenerReady chan struct{}) {

	f := filters.NewArgs()
	f.Add("type", "container")
	options := types.EventsOptions{
		Filters: f,
	}

	messages, errs := d.dockerClient.Events(context.Background(), options)

	// Once the buffered event channel was returned by Docker we return the ready status.
	listenerReady <- struct{}{}

	for {
		select {
		case message := <-messages:
			zap.L().Debug("Got message from docker client",
				zap.String("action", message.Action),
				zap.String("ID", message.ID),
			)
			d.sendRequestToQueue(&message)

		case err := <-errs:
			if err != nil && err != io.EOF {
				zap.L().Warn("Received docker event error",
					zap.Error(err),
				)
			}
		case <-ctx.Done():
			return
		}
	}
}
997741
func (mod *MumbleBee) Run(eventChan chan bees.Event) {
	if len(mod.server) == 0 {
		return
	}

	// channel signaling mumble connection status
	mod.connectedState = make(chan bool)

	host, port, err := net.SplitHostPort(mod.server)
	if err != nil {
		host = mod.server
		port = strconv.Itoa(gumble.DefaultPort)
	}

	config := gumble.NewConfig()
	config.Username = mod.user
	config.Password = mod.password
	address := net.JoinHostPort(host, port)

	var tlsConfig tls.Config

	if mod.insecure {
		tlsConfig.InsecureSkipVerify = true
	}

	config.Attach(gumbleutil.Listener{
		TextMessage: func(e *gumble.TextMessageEvent) {
			ev := bees.Event{
				Bee:  mod.Name(),
				Name: "message",
				Options: []bees.Placeholder{
					{
						Name:  "channels",
						Type:  "[]string",
						Value: e.Channels,
					},
					{
						Name:  "user",
						Type:  "string",
						Value: e.Sender.Name,
					},
					{
						Name:  "text",
						Type:  "string",
						Value: e.Message,
					},
				},
			}
			eventChan <- ev
		},
	})
	config.Attach(gumbleutil.Listener{
		Disconnect: func(e *gumble.DisconnectEvent) {
			go func() {
				mod.connectedState <- false
			}()
		},
	})
	config.Attach(gumbleutil.Listener{
		Connect: func(e *gumble.ConnectEvent) {
			go func() {
				mod.connectedState <- true
			}()
		},
	})

	config.Attach(gumbleutil.Listener{
		UserChange: func(e *gumble.UserChangeEvent) {
			eventType := ""
			if e.Type.Has(gumble.UserChangeConnected) {
				eventType = "user_connected"
			} else if e.Type.Has(gumble.UserChangeDisconnected) {
				eventType = "user_disconnected"
			} else if e.Type.Has(gumble.UserChangeRegistered) {
				eventType = "user_registered"
			} else {
				return
			}
			ev := bees.Event{
				Bee:  mod.Name(),
				Name: eventType,
				Options: []bees.Placeholder{
					{
						Name:  "user",
						Type:  "string",
						Value: e.User.Name,
					},
				},
			}
			eventChan <- ev
		},
	})

	config.Attach(gumbleutil.Listener{
		UserChange: func(e *gumble.UserChangeEvent) {
			eventType := ""
			if e.Type.Has(gumble.UserChangeKicked) {
				eventType = "user_banned"
			} else if e.Type.Has(gumble.UserChangeBanned) {
				eventType = "user_kicked"
			} else {
				return
			}
			ev := bees.Event{
				Bee:  mod.Name(),
				Name: eventType,
				Options: []bees.Placeholder{
					{
						Name:  "user",
						Type:  "string",
						Value: e.User.Name,
					},
					{
						Name:  "admin",
						Type:  "string",
						Value: e.Actor.Name,
					},
					{
						Name:  "message",
						Type:  "string",
						Value: e.String,
					},
				},
			}
			eventChan <- ev
		},
	})

	config.Attach(gumbleutil.Listener{
		UserChange: func(e *gumble.UserChangeEvent) {
			if e.Type.Has(gumble.UserChangeChannel) {
				ev := bees.Event{
					Bee:  mod.Name(),
					Name: "user_changed_channel",
					Options: []bees.Placeholder{
						{
							Name:  "user",
							Type:  "string",
							Value: e.User.Name,
						},
						{
							Name:  "channel",
							Type:  "string",
							Value: strings.Join(gumbleutil.ChannelPath(e.User.Channel), "/"),
						},
					},
				}
				eventChan <- ev
			}
		},
	})
	/*/ ToDo: Use own client certs
	if *certificateFile != "" {
		if *keyFile == "" {
			keyFile = certificateFile
		}
		if certificate, err := tls.LoadX509KeyPair(*certificateFile, *keyFile); err != nil {
			fmt.Printf("%s: %s\n", os.Args[0], err)
			os.Exit(1)
		} else {
			tlsConfig.Certificates = append(tlsConfig.Certificates, certificate)
		}
	}
	//*/

	config.Attach(gumbleutil.AutoBitrate)

	connecting := false
	disconnected := true
	waitForDisconnect := false
	for {
		// loop on mumble connection events
		if disconnected {
			if waitForDisconnect {
				return
			}

			if !connecting {
				connecting = true
				mod.Logln("Connecting to Mumble:", mod.server)
				mod.client, err = gumble.DialWithDialer(new(net.Dialer), address, config, &tlsConfig)

				mod.Logln("Connected to:", mod.server)
				if err != nil {
					mod.Logln("Failed to connect to Mumble:", mod.server, err)
					connecting = false
				}
			}
		}
		select {
		case status := <-mod.connectedState:
			if status {
				mod.Logln("Connected to Mumble:", mod.server)
				connecting = false
				disconnected = false
				mod.move(mod.channel)
			} else {
				mod.Logln("Disconnected from Mumble:", mod.server)
				connecting = false
				disconnected = true
			}
		case <-mod.SigChan:
			if !waitForDisconnect {
				mod.client.Disconnect()
			}
			waitForDisconnect = true
		}
	}
}
150733
func (d *Driver) Sound(fileName string) []error {
	return d.Connection().(*Adaptor).Sound(fileName)
}
598950
func (c *Callbacks) OnCSVCMsg_Sounds(fn func(*dota.CSVCMsg_Sounds) error) {
	c.onCSVCMsg_Sounds = append(c.onCSVCMsg_Sounds, fn)
}
12801
func (mod *IrcBee) Run(eventChan chan bees.Event) {
	if len(mod.server) == 0 {
		return
	}

	// channel signaling IRC connection status
	mod.connectedState = make(chan bool)

	// setup IRC client:
	cfg := irc.NewConfig(mod.nick, "beehive", "beehive")
	cfg.SSL = mod.ssl
	if mod.ssl {
		h, _, _ := net.SplitHostPort(mod.server)
		if h == "" {
			h = mod.server
		}
		cfg.SSLConfig = &tls.Config{ServerName: h}
	}

	cfg.Server = mod.server
	cfg.Pass = mod.password
	cfg.NewNick = func(n string) string { return n + "_" }
	mod.client = irc.Client(cfg)

	mod.client.HandleFunc("connected", func(conn *irc.Conn, line *irc.Line) {
		mod.connectedState <- true
	})
	mod.client.HandleFunc("disconnected", func(conn *irc.Conn, line *irc.Line) {
		mod.connectedState <- false
	})

	mod.client.HandleFunc("JOIN", func(conn *irc.Conn, line *irc.Line) {
		mod.statusChange(eventChan, conn, line)
	})
	mod.client.HandleFunc("PART", func(conn *irc.Conn, line *irc.Line) {
		mod.statusChange(eventChan, conn, line)
	})
	mod.client.HandleFunc("QUIT", func(conn *irc.Conn, line *irc.Line) {
		mod.statusChange(eventChan, conn, line)
	})

	mod.client.HandleFunc("PRIVMSG", func(conn *irc.Conn, line *irc.Line) {
		channel := line.Args[0]
		if channel == mod.client.Config().Me.Nick {
			channel = line.Src // replies go via PM too
		}
		msg := ""
		if len(line.Args) > 1 {
			msg = line.Args[1]
		}
		user := line.Src[:strings.Index(line.Src, "!")]
		hostmask := line.Src[strings.Index(line.Src, "!")+2:]

		ev := bees.Event{
			Bee:  mod.Name(),
			Name: "message",
			Options: []bees.Placeholder{
				{
					Name:  "channel",
					Type:  "string",
					Value: channel,
				},
				{
					Name:  "user",
					Type:  "string",
					Value: user,
				},
				{
					Name:  "hostmask",
					Type:  "string",
					Value: hostmask,
				},
				{
					Name:  "text",
					Type:  "string",
					Value: msg,
				},
			},
		}
		eventChan <- ev
	})

	waitForDisconnect := false
	connecting := false
	connected := false
	mod.ContextSet("connected", &connected)

	for {
		// loop on IRC connection events
		if !connected {
			if waitForDisconnect {
				return
			}

			if !connecting {
				connecting = true
				mod.Logln("Connecting to IRC:", mod.server)
				err := mod.client.Connect()
				if err != nil {
					mod.LogErrorf("Failed to connect to IRC: %s %v", mod.server, err)
					connecting = false
				}
			}
		}
		select {
		case status := <-mod.connectedState:
			if status {
				mod.Logln("Connected to IRC:", mod.server)
				connecting = false
				connected = true
				mod.rejoin()
			} else {
				mod.Logln("Disconnected from IRC:", mod.server)
				connecting = false
				connected = false
			}

		case <-mod.SigChan:
			if !waitForDisconnect {
				mod.client.Quit()
			}
			waitForDisconnect = true

		default:
			time.Sleep(time.Second)
		}
	}
}
926543
func (bl *BeeLogger) Critical(format string, v ...interface{}) {
	if LevelCritical > bl.level {
		return
	}
	msg := fmt.Sprintf("[C] "+format, v...)
	bl.writerMsg(LevelCritical, msg)
}
497789
func main() {
	flag.Parse()

	in := toolbox.NewBackdoorChannelIn()
	out := toolbox.NewBackdoorChannelOut()

	service := toolbox.NewService(in, out)

	if os.Getuid() == 0 {
		service.Power.Halt.Handler = toolbox.Halt
		service.Power.Reboot.Handler = toolbox.Reboot
	}

	err := service.Start()
	if err != nil {
		log.Fatal(err)
	}

	// handle the signals and gracefully shutdown the service
	sig := make(chan os.Signal, 1)
	signal.Notify(sig, syscall.SIGINT, syscall.SIGTERM)

	go func() {
		log.Printf("signal %s received", <-sig)
		service.Stop()
	}()

	service.Wait()
}