diff --git a/commands.go b/commands.go index bcf2917..a14baee 100644 --- a/commands.go +++ b/commands.go @@ -147,6 +147,7 @@ func goToSleep(s *discordgo.Session, m *discordgo.Message, ctx *mux.Context) { s.ChannelMessageSendEmbed(m.ChannelID, embed) } +//Set now playing status func setNowPlaying(s *discordgo.Session, m *discordgo.Message, ctx *mux.Context) { if !checkRole(s, m, ctx, bot_admin_role) { resp := "OwO you aren't my daddy..." @@ -158,6 +159,23 @@ func setNowPlaying(s *discordgo.Session, m *discordgo.Message, ctx *mux.Context) arg := strings.Join(ctx.Fields[1:], " ") s.UpdateStatus(0, arg) resp = "Now playing: " + arg + f, err := os.Create("userdata/nowplaying.txt") + if err != nil { + log.Println(err) + return + } + _, err = f.WriteString(arg) + if err != nil { + log.Println(err) + f.Close() + return + } + log.Println("Updated Now Playing to", arg, "at the request of", m.Author.String()) + err = f.Close() + if err != nil { + log.Println(err) + return + } } else { resp = "Please tell me what to play!" } diff --git a/pocketbot.go b/pocketbot.go index 3c6e632..196a9ad 100644 --- a/pocketbot.go +++ b/pocketbot.go @@ -5,6 +5,7 @@ import ( "fmt" "github.com/bwmarrin/discordgo" "github.com/bwmarrin/disgord/x/mux" + "io/ioutil" "log" "math/rand" "os" @@ -89,7 +90,16 @@ func main() { } func ready(s *discordgo.Session, event *discordgo.Ready) { - s.UpdateStatus(0, "with droids!") + playingstatus := "with droids!" + _, err := os.Stat("userdata/nowplaying.txt") + if !os.IsNotExist(err) { + content, err := ioutil.ReadFile("userdata/nowplaying.txt") + if err != nil { + log.Fatal(err) + } + playingstatus = string(content) + } + s.UpdateStatus(0, playingstatus) if os.Getenv("POCKETBOT_STARTUP_MESSAGE") == "TRUE" { s.ChannelMessageSend(bot_channel, "This isn't Tatooine...") }