Add the /addemotes command

This command launches a goroutine that does the actual downloading of
the emotes so the client doesn't hang until the process is finished.

subscribers.json needs to be manually downloaded and added next to the
main executable for now.  Eventually, it will download and cache this
file (for 24 hours, at a minimum).

Issue #10 should not be considered finished yet.  This needs to be
tested a bit more with multiple channels.  Ideally, some that exist and
some that don't to verify that it fails gracefully (ie, adds the emotes
it was able to download).
This commit is contained in:
Zorchenhimer 2019-03-28 16:47:58 -04:00
parent 6f865b7a53
commit fb2c25dc99
4 changed files with 36 additions and 1 deletions

3
.gitignore vendored
View File

@ -35,3 +35,6 @@ static/main.wasm
# tags for vim # tags for vim
tags tags
# channel and emote list from twitch
subscribers.json

View File

@ -318,6 +318,37 @@ var commands = &CommandControl{
return "see console for output" return "see console for output"
}, },
}, },
common.CNAddEmotes.String(): Command{
HelpText: "Add emotes from a given twitch channel.",
Function: func(cl *Client, args []string) string {
// Fire this off in it's own goroutine so the client doesn't
// block waiting for the emote download to finish.
go func() {
// Pretty sure this breaks on partial downloads (eg, one good channel and one non-existant)
_, err := GetEmotes(args)
if err != nil {
cl.SendChatData(common.NewChatMessage("", "",
err.Error(),
common.CmdlUser, common.MsgCommandResponse))
return
}
// reload emotes now that new ones were added
_, err = common.LoadEmotes()
if err != nil {
cl.SendChatData(common.NewChatMessage("", "",
err.Error(),
common.CmdlUser, common.MsgCommandResponse))
return
}
cl.belongsTo.AddModNotice(cl.name + " has added emotes from the following channels: " + strings.Join(args, ", "))
}()
return "Emote download initiated for the following channels: " + strings.Join(args, ", ")
},
},
}, },
} }

View File

@ -64,6 +64,7 @@ var ChatCommands = []ChatCommandNames{
CNReloadEmotes, CNReloadEmotes,
CNModpass, CNModpass,
CNIP, CNIP,
CNAddEmotes,
} }
func GetFullChatCommand(c string) string { func GetFullChatCommand(c string) string {

View File

@ -17,7 +17,7 @@ type twitchChannel struct {
Plans map[string]string `json:"plans"` Plans map[string]string `json:"plans"`
Emotes []struct { Emotes []struct {
Code string `json:"code"` Code string `json:"code"`
Set string `json:"emoticon_set"` Set int `json:"emoticon_set"`
Id int `json:"id"` Id int `json:"id"`
} `json:"emotes"` } `json:"emotes"`
BaseSetId string `json:"base_set_id"` BaseSetId string `json:"base_set_id"`