Add a limit to the title length

Added a limit to how long the title can be when set from the /playing
command.  The default value is 50 if it is not in the settings file or
if the value in the settings is below zero.

Resolves #43
This commit is contained in:
Zorchenhimer 2019-03-16 21:04:11 -04:00
parent 7dff29b152
commit b30202441a
3 changed files with 11 additions and 1 deletions

View File

@ -127,6 +127,10 @@ var commands = &CommandControl{
title = strings.TrimSpace(title)
link = strings.TrimSpace(link)
if len(title) > settings.TitleLength {
return fmt.Sprintf("Title too long (%d/%d)", len(title), settings.TitleLength)
}
// Send a notice to the mods and admins
if len(link) == 0 {
cl.belongsTo.AddModNotice(cl.name + " set the playing title to '" + title + "' with no link")

View File

@ -18,6 +18,7 @@ type Settings struct {
filename string
cmdLineKey string // stream key from the command line
MaxMessageCount int
TitleLength int // maximum length of the title that can be set with the /playing
AdminPassword string
Bans []BanInfo
StreamKey string
@ -40,6 +41,10 @@ func init() {
panic("Missing stream key is settings.json")
}
if settings.TitleLength <= 0 {
settings.TitleLength = 50
}
// Save admin password to file
if err = settings.Save(); err != nil {
panic("Unable to save settings: " + err.Error())

View File

@ -1,7 +1,8 @@
{
"MaxMessageCount": 300,
"TitleLength": 50,
"AdminPassword": "",
"Bans": [],
"StreamKey": "ALongStreamKey",
"ListenAddress": ":8089"
}
}