Esempio n. 1
0
func (k *Mumble) Start(fl map[string]string, s *services.Services) {
	k.services = s

	//Config
	k.Config = gumble.NewConfig()
	k.Config.Username = fl["Flag_mumble_username"]
	k.Config.Password = fl["Flag_mumble_password"]
	k.Config.Address = fl["Flag_mumble_server"]

	k.Config.TLSConfig.InsecureSkipVerify = true

	k.conf_volume = 1.0

	//Client creation
	k.Client = gumble.NewClient(k.Config)

	//Attach listeners
	k.Client.Attach(gumbleutil.AutoBitrate)
	k.Client.Attach(k)

	//TLS
	if fl["Flag_mumble_cert_lock"] != "" {
		gumbleutil.CertificateLockFile(k.Client, fl["Flag_mumble_cert_lock"])
	}

	if _, err := os.Stat("./config/Kotik.pem"); err == nil && fl["Flag_dev"] == "false" {
		fl["Flag_mumble_cert"] = "./config/Kotik.pem"
	} else if _, err := os.Stat("./config/Kotik-dev.pem"); err == nil && fl["Flag_dev"] == "true" {
		fl["Flag_mumble_cert"] = "./config/Kotik-dev.pem"
	}

	if fl["Flag_mumble_cert"] != "" {
		if fl["Flag_mumble_cert_key"] == "" {
			fl["Flag_mumble_cert_key"] = fl["Flag_mumble_cert"]
		}
		if certificate, err := tls.LoadX509KeyPair(fl["Flag_mumble_cert"], fl["Flag_mumble_cert_key"]); err != nil {
			panic(err)
		} else {
			k.Config.TLSConfig.Certificates = append(k.Config.TLSConfig.Certificates, certificate)
		}
	}

	//Connect
	flag := false
	for flag == false {
		if err := k.Client.Connect(); err != nil {
			time.Sleep(time.Second * 5)
		} else {
			flag = true
		}
	}
}
Esempio n. 2
0
// main primarily performs startup tasks. Grabs and parses commandline
// args, sets up the gumble client and its listeners, and then connects to the server.
func main() {

	if currentUser, err := user.Current(); err == nil {
		dj.homeDir = currentUser.HomeDir
	}

	if err := loadConfiguration(); err == nil {
		fmt.Println("Configuration successfully loaded!")
	} else {
		panic(err)
	}

	var address, port, username, password, channel, pemCert, pemKey, accesstokens string
	var insecure bool
	var version bool

	flag.StringVar(&address, "server", "localhost", "address for Mumble server")
	flag.StringVar(&port, "port", "64738", "port for Mumble server")
	flag.StringVar(&username, "username", "MumbleDJ", "username of MumbleDJ on server")
	flag.StringVar(&password, "password", "", "password for Mumble server (if needed)")
	flag.StringVar(&channel, "channel", "root", "default channel for MumbleDJ")
	flag.StringVar(&pemCert, "cert", "", "path to user PEM certificate for MumbleDJ")
	flag.StringVar(&pemKey, "key", "", "path to user PEM key for MumbleDJ")
	flag.StringVar(&accesstokens, "accesstokens", "", "list of access tokens for channel auth")
	flag.BoolVar(&insecure, "insecure", false, "skip certificate checking")
	flag.BoolVar(&version, "version", false, "show version")
	flag.Parse()

	if version {
		fmt.Printf("MumbleDJ %s\n", VERSION)
		os.Exit(0)
	}
	dj.config = gumble.Config{
		Username: username,
		Password: password,
		Address:  address + ":" + port,
		Tokens:   strings.Split(accesstokens, " "),
	}
	dj.client = gumble.NewClient(&dj.config)

	dj.config.TLSConfig.InsecureSkipVerify = true
	if !insecure {
		gumbleutil.CertificateLockFile(dj.client, fmt.Sprintf("%s/.mumbledj/cert.lock", dj.homeDir))
	}
	if pemCert != "" {
		if pemKey == "" {
			pemKey = pemCert
		}
		if certificate, err := tls.LoadX509KeyPair(pemCert, pemKey); err != nil {
			panic(err)
		} else {
			dj.config.TLSConfig.Certificates = append(dj.config.TLSConfig.Certificates, certificate)
		}
	}

	dj.defaultChannel = strings.Split(channel, "/")

	services = append(services, Mixcloud{})
	CheckAPIKeys()

	dj.client.Attach(gumbleutil.Listener{
		Connect:     dj.OnConnect,
		Disconnect:  dj.OnDisconnect,
		TextMessage: dj.OnTextMessage,
		UserChange:  dj.OnUserChange,
	})
	dj.client.Attach(gumbleutil.AutoBitrate)

	if err := dj.client.Connect(); err != nil {
		fmt.Printf("Could not connect to Mumble server at %s:%s.\n", address, port)
		os.Exit(1)
	}

	<-dj.keepAlive
}
Esempio n. 3
0
//main parses command line argument and sets up the bot to connect
func main() {

	YouTubeAPICheck()

	if currentUser, err := user.Current(); err == nil {
		jew.homeDir = currentUser.HomeDir
	}

	if err := loadConfiguration(); err == nil {
		fmt.Println("Config loaded successfully!")
	} else {
		panic(err)
	}

	var address, port, username, password, pemCert, pemKey, accesstokens string
	var insecure bool

	flag.StringVar(&address, "server", "localhost", "addres of Mumble server")
	flag.StringVar(&port, "port", "64738", "port for Mumble server")
	flag.StringVar(&username, "username", "Jewvis", "username of bot")
	flag.StringVar(&password, "password", "", "password for Mumble server")
	flag.StringVar(&pemCert, "certificate", "", "path to PEM certificate")
	flag.StringVar(&pemKey, "key", "", "path to PEM key")
	flag.StringVar(&accesstokens, "accesstokens", "", "list of access tokens")
	flag.BoolVar(&insecure, "insecure", false, "skip certificate checking")
	flag.Parse()

	jew.config = gumble.Config{
		Username: username,
		Password: password,
		Address:  address + ":" + port,
		Tokens:   strings.Split(accesstokens, " "),
	}
	jew.client = gumble.NewClient(&jew.config)

	jew.config.TLSConfig.InsecureSkipVerify = true
	if !insecure {
		gumbleutil.CertificateLockFile(jew.client, fmt.Sprintf("%s/jewvis/cert.lock", jew.homeDir))
	}
	if pemCert != "" {
		if pemKey == "" {
			pemKey = pemCert
		}
		if certificate, err := tls.LoadX509KeyPair(pemCert, pemKey); err != nil {
			panic(err)
		} else {
			jew.config.TLSConfig.Certificates = append(jew.config.TLSConfig.Certificates, certificate)
		}
	}

	jew.client.Attach(gumbleutil.Listener{
		Connect:     jew.OnConnect,
		Disconnect:  jew.OnDisconnect,
		TextMessage: jew.OnTextMessage,
		UserChange:  jew.OnUserChange,
	})

	if err := jew.client.Connect(); err != nil {
		fmt.Print("Could not connect to server );", err)
		os.Exit(1)
	}

	<-jew.keepAlive
}
Esempio n. 4
0
func main() {
	// Flags
	username := flag.String("username", "piepan-bot", "username of the bot")
	password := flag.String("password", "", "user password")
	server := flag.String("server", "localhost:64738", "address of the server")
	certificateFile := flag.String("certificate", "", "user certificate file (PEM)")
	keyFile := flag.String("key", "", "user certificate key file (PEM)")
	insecure := flag.Bool("insecure", false, "skip certificate checking")
	lock := flag.String("lock", "", "server certificate lock file")
	ffmpeg := flag.String("ffmpeg", "ffmpeg", "ffmpeg-capable executable for media streaming")
	var accessTokens strFlagSlice
	flag.Var(&accessTokens, "access-token", "server access token (can be defined multiple times)")

	flag.Usage = func() {
		fmt.Fprintf(os.Stderr, "piepan v0.7.0\n")
		fmt.Fprintf(os.Stderr, "usage: %s [options] [script files]\n", os.Args[0])
		fmt.Fprintf(os.Stderr, "an easy to use framework for writing scriptable Mumble bots\n")
		flag.PrintDefaults()
		fmt.Fprintf(os.Stderr, "\nScript files are defined in the following way:\n")
		fmt.Fprintf(os.Stderr, "  [type%c[environment%c]]filename\n", os.PathListSeparator, os.PathListSeparator)
		fmt.Fprintf(os.Stderr, "    filename: path to script file\n")
		fmt.Fprintf(os.Stderr, "    type: type of script file (default: file extension)\n")
		fmt.Fprintf(os.Stderr, "    environment: name of environment where script will be executed (default: type)\n\n")
		fmt.Fprintf(os.Stderr, "Enabled script types:\n")
		fmt.Fprintf(os.Stderr, "  Type         Name\n")
		for _, ext := range piepan.PluginExtensions {
			fmt.Fprintf(os.Stderr, "  %-12s %s\n", ext, piepan.Plugins[ext].Name)
		}
	}

	flag.Parse()

	// Configuration
	config := gumble.NewConfig()
	config.Username = *username
	config.Password = *password
	config.Address = *server
	config.Tokens = gumble.AccessTokens(accessTokens)

	client := gumble.NewClient(config)
	instance := piepan.New(client)
	audio := gumble_ffmpeg.New(client)
	audio.Command = *ffmpeg
	instance.Audio = audio

	if *insecure {
		config.TLSConfig.InsecureSkipVerify = true
	}
	if *lock != "" {
		gumbleutil.CertificateLockFile(client, *lock)
	}
	if *certificateFile != "" {
		if *keyFile == "" {
			keyFile = certificateFile
		}
		if certificate, err := tls.LoadX509KeyPair(*certificateFile, *keyFile); err != nil {
			panic(err)
		} else {
			config.TLSConfig.Certificates = append(config.TLSConfig.Certificates, certificate)
		}
	}

	client.Attach(gumbleutil.AutoBitrate)

	// Load scripts
	for _, script := range flag.Args() {
		if err := instance.LoadScript(script); err != nil {
			fmt.Fprintf(os.Stderr, "%s: %s\n", script, err)
		}
	}

	keepAlive := make(chan bool)
	exitStatus := 0
	client.Attach(gumbleutil.Listener{
		Disconnect: func(e *gumble.DisconnectEvent) {
			if e.Type != gumble.DisconnectUser {
				exitStatus = int(e.Type) + 1
			}
			keepAlive <- true
		},
	})

	if err := client.Connect(); err != nil {
		fmt.Fprintf(os.Stderr, "%s\n", err)
		os.Exit(1)
	}

	<-keepAlive
	os.Exit(exitStatus)
}
Esempio n. 5
0
func main() {
	// Flags
	username := flag.String("username", "piepan-bot", "username of the bot")
	password := flag.String("password", "", "user password")
	server := flag.String("server", "localhost:64738", "address of the server")
	certificateFile := flag.String("certificate", "", "user certificate file (PEM)")
	keyFile := flag.String("key", "", "user certificate key file (PEM)")
	insecure := flag.Bool("insecure", false, "skip certificate checking")
	lock := flag.String("lock", "", "server certificate lock file")
	ffmpeg := flag.String("ffmpeg", "ffmpeg", "ffmpeg-capable executable for media streaming")
	var accessTokens strFlagSlice
	flag.Var(&accessTokens, "access-token", "server access token (can be defined multiple times)")

	flag.Usage = func() {
		fmt.Fprintf(os.Stderr, "piepan v0.9.0\n")
		fmt.Fprintf(os.Stderr, "usage: %s [options] [script files]\n", os.Args[0])
		fmt.Fprintf(os.Stderr, "an easy to use framework for writing Mumble bots using Lua\n")
		flag.PrintDefaults()
	}

	flag.Parse()

	// Configuration
	config := gumble.NewConfig()
	config.Username = *username
	config.Password = *password
	config.Address = *server
	config.Tokens = gumble.AccessTokens(accessTokens)

	client := gumble.NewClient(config)
	instance := piepan.New(client)
	instance.AudioCommand = *ffmpeg

	if *insecure {
		config.TLSConfig.InsecureSkipVerify = true
	}
	if *lock != "" {
		gumbleutil.CertificateLockFile(client, *lock)
	}
	if *certificateFile != "" {
		if *keyFile == "" {
			keyFile = certificateFile
		}
		certificate, err := tls.LoadX509KeyPair(*certificateFile, *keyFile)
		if err != nil {
			fmt.Fprintf(os.Stderr, "%s\n", err)
			os.Exit(1)
		}
		config.TLSConfig.Certificates = append(config.TLSConfig.Certificates, certificate)
	}

	client.Attach(gumbleutil.AutoBitrate)

	// Load scripts
	for _, script := range flag.Args() {
		if err := instance.LoadFile(script); err != nil {
			fmt.Fprintf(os.Stderr, "%s: %s\n", script, err)
		}
	}

	keepAlive := make(chan bool)
	exitStatus := 0
	client.Attach(gumbleutil.Listener{
		Disconnect: func(e *gumble.DisconnectEvent) {
			if e.Type != gumble.DisconnectUser {
				exitStatus = int(e.Type) + 1
			}
			keepAlive <- true
		},
	})

	if err := client.Connect(); err != nil {
		fmt.Fprintf(os.Stderr, "%s\n", err)
		os.Exit(1)
	}

	<-keepAlive
	os.Exit(exitStatus)
}