option to specify minimum length for upstream nicks

This commit is contained in:
mappu 2018-06-04 16:46:49 +12:00
parent b470b9a5b3
commit f4025ad513
2 changed files with 12 additions and 5 deletions

View File

@ -11,6 +11,7 @@ type NTFConfig struct {
HubAddr string
HubDescription string
HubSecNick string // Nickname of Hub-Security to exclude (e.g. "PtokaX")
HubNickMinChars int
BotAPIKey string
GroupChatID int64

View File

@ -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())