From bf161d212ea5c54801d2102093de2a9807297f2f Mon Sep 17 00:00:00 2001 From: Michael Kochell <6913320+mickmister@users.noreply.github.com> Date: Fri, 23 Feb 2024 13:29:15 -0500 Subject: [PATCH 1/4] add sleep betwene calls to add user to channels --- server/welcomebot.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/server/welcomebot.go b/server/welcomebot.go index 7f65ad45f..a83be0cfd 100644 --- a/server/welcomebot.go +++ b/server/welcomebot.go @@ -113,6 +113,7 @@ func (p *Plugin) renderWelcomeMessage(messageTemplate MessageTemplate, configMes for _, channelName := range configAction.ChannelsAddedTo { p.joinChannel(action, channelName) + time.Sleep(time.Second) } } @@ -200,6 +201,7 @@ func (p *Plugin) processWelcomeMessage(messageTemplate MessageTemplate, configMe func (p *Plugin) processActionMessage(messageTemplate MessageTemplate, action *Action, configMessageAction ConfigMessageAction) { for _, channelName := range configMessageAction.ChannelsAddedTo { p.joinChannel(action, channelName) + time.Sleep(time.Second) } tmpMsg, _ := template.New("Response").Parse(strings.Join(configMessageAction.ActionSuccessfulMessage, "\n")) From af24fe5025fbb9358d1383a677f2d854ef59e410 Mon Sep 17 00:00:00 2001 From: mickmister <6913320+mickmister@users.noreply.github.com> Date: Fri, 23 Feb 2024 17:35:34 -0500 Subject: [PATCH 2/4] make delay configurable --- server/configuration.go | 5 ++++- server/plugin.go | 2 ++ server/welcomebot.go | 4 ++-- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/server/configuration.go b/server/configuration.go index 2b8123323..b4689b550 100644 --- a/server/configuration.go +++ b/server/configuration.go @@ -46,7 +46,8 @@ type ConfigMessage struct { // Configuration from config.json type Configuration struct { - WelcomeMessages []*ConfigMessage + WelcomeMessages []*ConfigMessage + AddToChannelDelayInMilliseconds int } // List of the welcome messages from the configuration @@ -63,6 +64,8 @@ func (p *Plugin) OnConfigurationChange() error { return err } + p.conf = c + p.welcomeMessages.Store(c.WelcomeMessages) return nil diff --git a/server/plugin.go b/server/plugin.go index c13354ae7..af83ea886 100644 --- a/server/plugin.go +++ b/server/plugin.go @@ -25,6 +25,8 @@ type Plugin struct { welcomeMessages atomic.Value + conf Configuration + // botUserID of the created bot account. botUserID string } diff --git a/server/welcomebot.go b/server/welcomebot.go index a83be0cfd..68767a517 100644 --- a/server/welcomebot.go +++ b/server/welcomebot.go @@ -113,7 +113,6 @@ func (p *Plugin) renderWelcomeMessage(messageTemplate MessageTemplate, configMes for _, channelName := range configAction.ChannelsAddedTo { p.joinChannel(action, channelName) - time.Sleep(time.Second) } } @@ -201,7 +200,6 @@ func (p *Plugin) processWelcomeMessage(messageTemplate MessageTemplate, configMe func (p *Plugin) processActionMessage(messageTemplate MessageTemplate, action *Action, configMessageAction ConfigMessageAction) { for _, channelName := range configMessageAction.ChannelsAddedTo { p.joinChannel(action, channelName) - time.Sleep(time.Second) } tmpMsg, _ := template.New("Response").Parse(strings.Join(configMessageAction.ActionSuccessfulMessage, "\n")) @@ -235,6 +233,8 @@ func (p *Plugin) joinChannel(action *Action, channelName string) { p.API.LogError("Couldn't add user to the channel, continuing to next channel", "user_id", action.Context.UserID, "channel_id", channel.Id) return } + + time.Sleep(time.Millisecond * time.Duration(p.conf.AddToChannelDelayInMilliseconds)) } else { p.API.LogError("failed to get channel, continuing to the next channel", "channel_name", channelName, "user_id", action.Context.UserID) } From b11fd9ebf253b380739e81bd987d0f24db8e1b9d Mon Sep 17 00:00:00 2001 From: mickmister <6913320+mickmister@users.noreply.github.com> Date: Tue, 27 Feb 2024 21:36:44 -0500 Subject: [PATCH 3/4] Revert "make delay configurable" This reverts commit af24fe5025fbb9358d1383a677f2d854ef59e410. --- server/configuration.go | 5 +---- server/plugin.go | 2 -- server/welcomebot.go | 4 ++-- 3 files changed, 3 insertions(+), 8 deletions(-) diff --git a/server/configuration.go b/server/configuration.go index b4689b550..2b8123323 100644 --- a/server/configuration.go +++ b/server/configuration.go @@ -46,8 +46,7 @@ type ConfigMessage struct { // Configuration from config.json type Configuration struct { - WelcomeMessages []*ConfigMessage - AddToChannelDelayInMilliseconds int + WelcomeMessages []*ConfigMessage } // List of the welcome messages from the configuration @@ -64,8 +63,6 @@ func (p *Plugin) OnConfigurationChange() error { return err } - p.conf = c - p.welcomeMessages.Store(c.WelcomeMessages) return nil diff --git a/server/plugin.go b/server/plugin.go index af83ea886..c13354ae7 100644 --- a/server/plugin.go +++ b/server/plugin.go @@ -25,8 +25,6 @@ type Plugin struct { welcomeMessages atomic.Value - conf Configuration - // botUserID of the created bot account. botUserID string } diff --git a/server/welcomebot.go b/server/welcomebot.go index 68767a517..a83be0cfd 100644 --- a/server/welcomebot.go +++ b/server/welcomebot.go @@ -113,6 +113,7 @@ func (p *Plugin) renderWelcomeMessage(messageTemplate MessageTemplate, configMes for _, channelName := range configAction.ChannelsAddedTo { p.joinChannel(action, channelName) + time.Sleep(time.Second) } } @@ -200,6 +201,7 @@ func (p *Plugin) processWelcomeMessage(messageTemplate MessageTemplate, configMe func (p *Plugin) processActionMessage(messageTemplate MessageTemplate, action *Action, configMessageAction ConfigMessageAction) { for _, channelName := range configMessageAction.ChannelsAddedTo { p.joinChannel(action, channelName) + time.Sleep(time.Second) } tmpMsg, _ := template.New("Response").Parse(strings.Join(configMessageAction.ActionSuccessfulMessage, "\n")) @@ -233,8 +235,6 @@ func (p *Plugin) joinChannel(action *Action, channelName string) { p.API.LogError("Couldn't add user to the channel, continuing to next channel", "user_id", action.Context.UserID, "channel_id", channel.Id) return } - - time.Sleep(time.Millisecond * time.Duration(p.conf.AddToChannelDelayInMilliseconds)) } else { p.API.LogError("failed to get channel, continuing to the next channel", "channel_name", channelName, "user_id", action.Context.UserID) } From e99fa66220e4d4e39c0d946ffb3d389b2a850f1e Mon Sep 17 00:00:00 2001 From: mickmister <6913320+mickmister@users.noreply.github.com> Date: Tue, 27 Feb 2024 21:37:35 -0500 Subject: [PATCH 4/4] de-duplicate wait in `joinChannel` --- server/welcomebot.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/server/welcomebot.go b/server/welcomebot.go index a83be0cfd..4fdc4c0bd 100644 --- a/server/welcomebot.go +++ b/server/welcomebot.go @@ -113,7 +113,6 @@ func (p *Plugin) renderWelcomeMessage(messageTemplate MessageTemplate, configMes for _, channelName := range configAction.ChannelsAddedTo { p.joinChannel(action, channelName) - time.Sleep(time.Second) } } @@ -201,7 +200,6 @@ func (p *Plugin) processWelcomeMessage(messageTemplate MessageTemplate, configMe func (p *Plugin) processActionMessage(messageTemplate MessageTemplate, action *Action, configMessageAction ConfigMessageAction) { for _, channelName := range configMessageAction.ChannelsAddedTo { p.joinChannel(action, channelName) - time.Sleep(time.Second) } tmpMsg, _ := template.New("Response").Parse(strings.Join(configMessageAction.ActionSuccessfulMessage, "\n")) @@ -235,6 +233,8 @@ func (p *Plugin) joinChannel(action *Action, channelName string) { p.API.LogError("Couldn't add user to the channel, continuing to next channel", "user_id", action.Context.UserID, "channel_id", channel.Id) return } + + time.Sleep(time.Second) } else { p.API.LogError("failed to get channel, continuing to the next channel", "channel_name", channelName, "user_id", action.Context.UserID) }