From f4025ad513f9138ce3892963a68a97b974dbf829 Mon Sep 17 00:00:00 2001 From: mappu Date: Mon, 4 Jun 2018 16:46:49 +1200 Subject: [PATCH] option to specify minimum length for upstream nicks --- NTFConfig.go | 11 ++++++----- NTFServer.go | 6 ++++++ 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/NTFConfig.go b/NTFConfig.go index c0237eb..7524bc8 100644 --- a/NTFConfig.go +++ b/NTFConfig.go @@ -8,11 +8,12 @@ import ( // NTFConfig keeps track of setup properties as well as runtime state. // FIXME separate compile-time and run-time properties into separate files type NTFConfig struct { - HubAddr string - HubDescription string - HubSecNick string // Nickname of Hub-Security to exclude (e.g. "PtokaX") - BotAPIKey string - GroupChatID int64 + HubAddr string + HubDescription string + HubSecNick string // Nickname of Hub-Security to exclude (e.g. "PtokaX") + HubNickMinChars int + BotAPIKey string + GroupChatID int64 // Map of telegram user IDs to NMDC nicks KnownUsers map[int64]string diff --git a/NTFServer.go b/NTFServer.go index ea06029..3d4e74c 100644 --- a/NTFServer.go +++ b/NTFServer.go @@ -544,6 +544,12 @@ func (this *NTFServer) HandleDirectMessage(update telegram.Update) error { } else if strings.HasPrefix(msg, "/join ") { requestedHubNick := msg[6:] + + // Minimum nick lengths + if len(requestedHubNick) < this.config.HubNickMinChars { + return respond(fmt.Sprintf("Upstream nickname '%s' should be at least %d characters long", requestedHubNick, this.config.HubNickMinChars)) + } + err := this.registerUser(userID, requestedHubNick) if err != nil { log.Printf("Failed to register user: %s", err.Error())