Skip to content
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

Merged
merged 12 commits into from
May 11, 2023
Merged

Conversation

baruchiro
Copy link
Contributor

@baruchiro baruchiro commented Apr 20, 2023

Resolves #31

Features

  • We expect the user to give us a Personal Access Token. This token can be retrieved from the browser Dev Tool, or by authenticating a Discord App. See plugin - scan a discord channel #31 (comment).
  • The user must give at least one --discord-server, we will not loop over all the user's servers.
  • The Server in Discord called Guild in the API.
  • If the user doesn't give --discord-channel, we will scan all the channels in a server.
  • We will scan all messages until --discord-duration or --discord-messages-count (the closest one).
  • Threads: Only bots can get all the threads from a channel. As we currently use Personal Access Token, we can get the thread from the message started it.
    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

  • It is a little confusing if you give multiple servers and multiple channels, because each channel relates to its server, and also if you will give channels only for one server, the other server will not be scanned at all.
    Compared to Confluence, which has servers and spaces, we are not scanning multiple servers in one scan.

Waits for #52

@github-actions
Copy link

kics-logo

KICS version: v1.6.13

Category Results
HIGH HIGH 0
MEDIUM MEDIUM 0
LOW LOW 1
INFO INFO 0
TRACE TRACE 0
TOTAL TOTAL 1
Metric Values
Files scanned placeholder 1
Files parsed placeholder 1
Files failed to scan placeholder 0
Total executed queries placeholder 49
Queries failed to execute placeholder 0
Execution time placeholder 2

lib/routines.go Outdated
Comment on lines 5 to 24
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
}
Copy link
Contributor Author

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)
Copy link
Contributor Author

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.

#20 (comment)

Comment on lines 99 to 116
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
}
Copy link
Contributor Author

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.

@jossef
Copy link
Member

jossef commented Apr 26, 2023

please merge with main branch, joao made some concurrency changes

@baruchiro baruchiro marked this pull request as ready for review May 1, 2023 11:17
@jossef jossef assigned jossef and unassigned baruchiro May 9, 2023
@jossef jossef merged commit 0a85890 into master May 11, 2023
@jossef jossef deleted the baruchiro/plugin---scan-a-discord-channel branch May 11, 2023 12:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

plugin - scan a discord channel
2 participants