Remove unused code and general cleanup

haste/handle-touch
Stein Ivar Berghei 2022-11-20 17:30:22 +01:00
parent 10e5400fd5
commit bba1bc5fa0
5 changed files with 10 additions and 61 deletions

10
bot.go
View File

@ -5,18 +5,15 @@ import (
"log"
"os"
"os/signal"
"sync"
"syscall"
"time"
"github.com/bwmarrin/discordgo"
"github.com/dpup/gohubbub"
"github.com/faiface/beep"
"github.com/gohugoio/hugo/cache/filecache"
"github.com/jackc/pgx/v5"
"github.com/julienschmidt/httprouter"
"github.com/kataras/go-events"
"github.com/r3labs/sse/v2"
"github.com/spf13/afero"
"github.com/spf13/viper"
"google.golang.org/api/youtube/v3"
@ -56,13 +53,9 @@ type App struct {
events events.EventEmmiter
next bool
db *pgx.Conn
sse *sse.Server
router *httprouter.Router
active []string
plidx int
playlist *Playlist
plm *sync.RWMutex
hubbub *gohubbub.Client
cache *filecache.Cache
}
@ -70,11 +63,10 @@ func main() {
bfs := afero.NewBasePathFs(afero.NewOsFs(), "cache")
app.cache = filecache.NewCache(bfs, 1*time.Hour, "")
app.plm = &sync.RWMutex{}
ticker := time.NewTicker(300 * time.Millisecond)
sc := make(chan os.Signal, 1)
signal.Notify(sc, syscall.SIGINT, syscall.SIGTERM, os.Interrupt, os.Kill)
signal.Notify(sc, syscall.SIGINT, syscall.SIGTERM, os.Interrupt)
for {
select {

View File

@ -1,7 +1,6 @@
package main
import (
"context"
"dndmusicbot/ffmpeg"
discordspeaker "dndmusicbot/speaker"
"encoding/json"
@ -195,29 +194,6 @@ func (app *App) songPosition(payload ...interface{}) {
}
func (app *App) checkQueue(payload ...interface{}) {
if !app.queue.IsPlaying() {
return
}
// This needs some tweaking.
if app.queue.playing && !app.next && app.queue.QLen() == 0 {
log.Println("Queue is 0. It should never be 0..")
ctx, cancel := context.WithTimeout(context.Background(), 4*time.Second)
defer cancel()
select {
case <-ctx.Done():
if app.queue.QLen() == 0 {
log.Println("Queue is still 0. Queueing a song.")
app.events.Emit("next")
}
log.Println("Seems queue is filled, doing nothing.")
}
}
}
func (app *App) checkTimeleft(payload ...interface{}) {
if !app.queue.IsPlaying() {
return
@ -389,6 +365,10 @@ func (app *App) loadPlaylist(payload ...interface{}) {
}
return uri, nil
})
if err != nil {
log.Println(err)
continue
}
ff, err := ffmpeg.NewPCM(string(yt), sampleRate, channels)
if err != nil {
@ -409,7 +389,3 @@ func (app *App) loadPlaylist(payload ...interface{}) {
}
}()
}
func (app *App) preloadSong(payload ...interface{}) {
app.queue.Preload()
}

View File

@ -47,7 +47,6 @@ func (s *Song) NewStream() (err error) {
type Queue struct {
Events events.EventEmmiter
playing bool
yt VideoInfo
list *list.List
current *list.Element
}
@ -106,7 +105,6 @@ func (q *Queue) Next() {
}
q.current = next
return
}
func (q *Queue) Prev() {
@ -123,9 +121,8 @@ func (q *Queue) Prev() {
if err != nil {
log.Println(err)
}
q.current = prev
return
q.current = prev
}
func (q *Queue) Preload() {

7
ws.go
View File

@ -18,11 +18,10 @@ func init() {
ws_msg = make(chan interface{})
go func() {
var msg interface{}
for {
select {
case msg := <-ws_msg:
ws_clients.Send(msg)
}
msg = <-ws_msg
ws_clients.Send(msg)
}
}()

View File

@ -14,16 +14,11 @@ import (
mrand "math/rand"
"github.com/faiface/beep"
"github.com/sosodev/duration"
"google.golang.org/api/option"
"google.golang.org/api/youtube/v3"
)
var (
yt_url = "https://www.youtube.com/watch?v=%s"
)
func init() {
log.Println("youtube.go loading..")
@ -38,14 +33,6 @@ func init() {
log.Println("youtube.go done.")
}
type YT struct {
dst io.WriteCloser
pcm io.ReadCloser
dur time.Duration
pos time.Duration
f beep.Format
}
func ShufflePlaylist(list []string) ([]string, error) {
seedb := make([]byte, 32)
_, err := rand.Read(seedb)
@ -110,7 +97,7 @@ func (app App) Video(vid string) (out VideoInfo, err error) {
}
if len(resp.Items) != 1 {
return nil, errors.New("Response contains not 1 item!")
return nil, errors.New("response contains not 1 item")
}
video := resp.Items[0]
@ -165,6 +152,4 @@ func (app App) Playlist(playlist string) ([]string, error) {
}
}
return list, nil
//return fmt.Sprintf(yt_url, list[rand.Intn(len(list))])
}