Пример #1
0
func (p *Plugin) apiAudioSetVolume(call otto.FunctionCall) otto.Value {
	volume, err := call.Argument(0).ToFloat()
	if err != nil {
		return otto.UndefinedValue()
	}
	p.instance.Audio.Volume = float32(volume)
	return otto.UndefinedValue()
}
Пример #2
0
func (p *Plugin) apiAudioSetBitrate(call otto.FunctionCall) otto.Value {
	bitrate, err := call.Argument(0).ToInteger()
	if err != nil {
		return otto.UndefinedValue()
	}
	if enc, ok := p.instance.Client.AudioEncoder.(*opus.Encoder); ok {
		enc.SetBitrate(int(bitrate))
	}
	return otto.UndefinedValue()
}
Пример #3
0
func (p *Plugin) apiAudioBitrate(call otto.FunctionCall) otto.Value {
	if enc, ok := p.instance.Client.AudioEncoder.(*opus.Encoder); ok {
		value, _ := p.state.ToValue(enc.Bitrate())
		return value
	}
	return otto.UndefinedValue()
}
Пример #4
0
func (p *Plugin) apiFileOpen(call otto.FunctionCall) otto.Value {
	var filename, mode string
	switch len(call.ArgumentList) {
	case 1:
		filename = call.Argument(0).String()
		mode = "r"
	case 2:
		filename = call.Argument(0).String()
		mode = call.Argument(1).String()
	default:
		return otto.UndefinedValue()
	}

	var iMode int

	switch mode {
	case "r":
		iMode = os.O_RDONLY
	case "r+":
		iMode = os.O_RDWR
	case "w":
		iMode = os.O_WRONLY | os.O_CREATE
	case "w+":
		iMode = os.O_RDWR | os.O_CREATE | os.O_TRUNC
	case "a":
		iMode = os.O_WRONLY | os.O_CREATE | os.O_APPEND
	case "a+":
		iMode = os.O_RDWR | os.O_CREATE | os.O_APPEND
	default:
		return otto.UndefinedValue()
	}

	osFile, err := os.OpenFile(filename, iMode, 0644)
	if err != nil {
		return otto.UndefinedValue()
	}

	f := &file{
		f: osFile,
	}

	ret, _ := p.state.ToValue(f)
	return ret
}
Пример #5
0
func (p *Plugin) apiAudioNewTarget(call otto.FunctionCall) otto.Value {
	id, err := call.Argument(0).ToInteger()
	if err != nil {
		return otto.UndefinedValue()
	}

	target := &gumble.VoiceTarget{}
	target.ID = uint32(id)
	value, _ := p.state.ToValue(target)
	return value
}
Пример #6
0
func (f *file) Read(call otto.FunctionCall) otto.Value {
	bytes, err := call.Argument(0).ToInteger()
	var data []byte
	if bytes <= 0 {
		data, err = ioutil.ReadAll(f.f)
		if err != nil {
			return otto.UndefinedValue()
		}
	} else {
		data = make([]byte, bytes)
		_, err = io.ReadFull(f.f, data)
		if err != nil {
			panic(err)
			return otto.UndefinedValue()
		}
	}

	ret, _ := call.Otto.ToValue(string(data))
	return ret
}
Пример #7
0
func (p *Plugin) apiAudioSetTarget(call otto.FunctionCall) otto.Value {
	if len(call.ArgumentList) == 0 {
		p.instance.Client.VoiceTarget = nil
		return otto.TrueValue()
	}
	target, err := call.Argument(0).Export()
	if err != nil {
		return otto.UndefinedValue()
	}
	voiceTarget := target.(*gumble.VoiceTarget)
	p.instance.Client.Send(voiceTarget)
	p.instance.Client.VoiceTarget = voiceTarget
	return otto.TrueValue()
}
Пример #8
0
func (f *file) Seek(call otto.FunctionCall) otto.Value {
	offset, _ := call.Argument(0).ToInteger()
	whence := call.Argument(1).String()

	if whence == "" {
		whence = "cur"
	}
	var iWhence int
	switch whence {
	case "set":
		iWhence = 0
	case "cur":
		iWhence = 1
	case "end":
		iWhence = 2
	default:
		return otto.UndefinedValue()
	}

	val, _ := f.f.Seek(offset, iWhence)
	ret, _ := call.Otto.ToValue(val)
	return ret
}
Пример #9
0
func (p *Plugin) apiAudioStop(call otto.FunctionCall) otto.Value {
	p.instance.Audio.Stop()
	return otto.UndefinedValue()
}
Пример #10
0
func (p *Plugin) apiOn(call otto.FunctionCall) otto.Value {
	event := strings.ToLower(call.Argument(0).String())
	function := call.Argument(1)
	p.listeners[event] = append(p.listeners[event], function)
	return otto.UndefinedValue()
}