package main

import (
	"crypto/tls"
	"layeh.com/gumble/gumble"
	"layeh.com/gumble/gumbleopenal"
	"layeh.com/gumble/gumbleutil"
	"log"
	"net"
	"os"
	"time"
)

type MHeadless struct {
	Config *gumble.Config
	Client *gumble.Client

	Address   string
	TLSConfig tls.Config

	Stream *gumbleopenal.Stream

	ChannelName string
}

func (p *MHeadless) Init() {
	p.Config.Username = "radiobotv5"
	p.Config.Attach(gumbleutil.AutoBitrate)
	p.Config.Attach(p)

	p.Connect()

	keepAlive := make(chan bool)

	exitStatus := 0

	<-keepAlive

	os.Exit(exitStatus)
}

func (p *MHeadless) Connect() {
	_, err := gumble.DialWithDialer(new(net.Dialer), p.Address, p.Config, &p.TLSConfig)

	if err != nil {
		log.Println("Failed to connect", err)
		p.Reconnect()
	} else {
		p.OpenStream()
		/*
			if stream, err := gumbleopenal.New(p.Client); err != nil {

			} else {
				p.Stream = stream
			}
		*/
	}
}

func (p *MHeadless) Reconnect() {
	if p.Client != nil {
		p.Client.Disconnect()
	}

	go func() {
		time.Sleep(3 * time.Second)
		p.Connect()
	}()
}

func (p *MHeadless) OpenStream() {
	if stream, err := gumbleopenal.New(p.Client); err != nil {
		log.Printf("Stream open error (%s)\n", err)
		os.Exit(1)
	} else {
		log.Println(stream)
		//		p.Stream = stream
	}
}

func (b *MHeadless) OnUserList(e *gumble.UserListEvent) {
}

func (b *MHeadless) OnACL(e *gumble.ACLEvent) {
}

func (b *MHeadless) OnBanList(e *gumble.BanListEvent) {
}

func (b *MHeadless) OnContextActionChange(e *gumble.ContextActionChangeEvent) {
}

func (b *MHeadless) OnServerConfig(e *gumble.ServerConfigEvent) {
}

func (b *MHeadless) OnTextMessage(e *gumble.TextMessageEvent) {
}

func (b *MHeadless) OnUserChange(e *gumble.UserChangeEvent) {

}

func (b *MHeadless) OnChannelChange(e *gumble.ChannelChangeEvent) {
}

func (b *MHeadless) OnPermissionDenied(e *gumble.PermissionDeniedEvent) {
	var info string
	switch e.Type {
	case gumble.PermissionDeniedOther:
		info = e.String
	case gumble.PermissionDeniedPermission:
		info = "insufficient permissions"
	case gumble.PermissionDeniedSuperUser:
		info = "cannot modify SuperUser"
	case gumble.PermissionDeniedInvalidChannelName:
		info = "invalid channel name"
	case gumble.PermissionDeniedTextTooLong:
		info = "text too long"
	case gumble.PermissionDeniedTemporaryChannel:
		info = "temporary channel"
	case gumble.PermissionDeniedMissingCertificate:
		info = "missing certificate"
	case gumble.PermissionDeniedInvalidUserName:
		info = "invalid user name"
	case gumble.PermissionDeniedChannelFull:
		info = "channel full"
	case gumble.PermissionDeniedNestingLimit:
		info = "nesting limit"
	}
	log.Println("Info: ", info)
}

func (b *MHeadless) OnConnect(e *gumble.ConnectEvent) {
	b.Client = e.Client
}

func (b *MHeadless) OnDisconnect(e *gumble.DisconnectEvent) {

}

func main() {
	mh := MHeadless{
		Config:      gumble.NewConfig(),
		Address:     "jugregator.org:64738",
		ChannelName: "dj",
	}

	mh.Init()
}

Изменить пасту