From b30202441a4438b823df873fb7d6a78dc5931d91 Mon Sep 17 00:00:00 2001 From: Zorchenhimer Date: Sat, 16 Mar 2019 21:04:11 -0400 Subject: [PATCH] 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 --- chatcommands.go | 4 ++++ settings.go | 5 +++++ settings_example.json | 3 ++- 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/chatcommands.go b/chatcommands.go index 0353cc6..56fe31e 100644 --- a/chatcommands.go +++ b/chatcommands.go @@ -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") diff --git a/settings.go b/settings.go index baaa098..fceda84 100644 --- a/settings.go +++ b/settings.go @@ -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()) diff --git a/settings_example.json b/settings_example.json index a2fbba8..3153988 100644 --- a/settings_example.json +++ b/settings_example.json @@ -1,7 +1,8 @@ { "MaxMessageCount": 300, + "TitleLength": 50, "AdminPassword": "", "Bans": [], "StreamKey": "ALongStreamKey", "ListenAddress": ":8089" -} \ No newline at end of file +}