-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: discord plugin #53
Conversation
lib/routines.go
Outdated
func ParallelApply[T comparable, K comparable](items []T, f func(item T) (*[]K, error)) *[]K { | ||
var wg sync.WaitGroup | ||
results := []K{} | ||
for _, item := range items { | ||
wg.Add(1) | ||
go func(item T) { | ||
defer wg.Done() | ||
result, err := f(item) | ||
if err != nil { | ||
return | ||
} | ||
if result != nil { | ||
results = append(results, *result...) | ||
} | ||
}(item) | ||
} | ||
wg.Wait() | ||
|
||
return &results | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am using a generic method to run a function on each item in a slice, in parallel, and collect the results.
flags.Duration(discordFromDateFlag, defaultDateFrom, "discord from date") | ||
flags.Int(discordMessagesCountFlag, 0, "discord messages count") | ||
|
||
cmd.MarkFlagsRequiredTogether(discordTokenFlag, discordServersFlag) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note to force required flags, when they are required only if one of the DiscordPlugin flags is used.
plugins/discord.go
Outdated
func (p *DiscordPlugin) getDiscordReady() (err error) { | ||
p.Session, err = discordgo.New(p.Token) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
p.Session.StateEnabled = true | ||
ready := make(chan int) | ||
p.Session.AddHandler(func(s *discordgo.Session, r *discordgo.Ready) { | ||
ready <- 1 | ||
}) | ||
err = p.Session.Open() | ||
if err != nil { | ||
return err | ||
} | ||
<-ready | ||
return nil | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
discordgo.Session
loads its State
. The State
is required for State.User.ID
, but as it loaded, we are using it also for retrieving the guilds
.
please merge with main branch, joao made some concurrency changes |
…scan-a-discord-channel
Resolves #31
Features
--discord-server
, we will not loop over all the user's servers.--discord-channel
, we will scan all the channels in a server.--discord-duration
or--discord-messages-count
(the closest one).So we will scan the threads that started in the time/limit arguments (as they are messages that scanned), and for each thread we will scan the messages in the time/limit requirements.
Questions
Compared to Confluence, which has servers and spaces, we are not scanning multiple servers in one scan.
Waits for #52