Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
grahame
Discord Bot
Commits
2070ef78
Commit
2070ef78
authored
Feb 05, 2020
by
Timothy du Heaume
Browse files
find messages in parallel
parent
b0048da2
Changes
2
Hide whitespace changes
Inline
Side-by-side
Cargo.toml
View file @
2070ef78
...
...
@@ -17,3 +17,4 @@ serenity = "0.8.0"
simplelog
=
"^0.7.4"
guard
=
"0.5.0"
indexmap
=
{
version
=
"1.3.1"
,
features
=
["serde-1"]
}
rayon
=
"1.3.0"
src/reaction_roles.rs
View file @
2070ef78
use
crate
::
config
::{
CONFIG
,
ReactRoleMap
};
use
crate
::
util
::{
get_react_from_string
,
get_string_from_react
};
use
rayon
::
prelude
::
*
;
use
serenity
::{
client
::
Context
,
model
::{
channel
::
Message
,
channel
::
Reaction
,
id
::
RoleId
,
id
::
UserId
},
...
...
@@ -174,25 +175,20 @@ pub fn sync_all_role_reactions(ctx: Context) {
info!
(
"Role reaction sync complete"
);
}
fn
get_all_role_reaction_message
(
ctx
:
&
Context
,
)
->
Vec
<
(
Message
,
&
'static
ReactRoleMap
,
)
>
{
fn
get_all_role_reaction_message
(
ctx
:
&
Context
)
->
Vec
<
(
Message
,
&
'static
ReactRoleMap
)
>
{
let
guild
=
ctx
.http
.get_guild
(
CONFIG
.server_id
)
.unwrap
();
info!
(
" Find role-react message: guild determined"
);
let
channels
=
ctx
.http
.get_channels
(
*
guild
.id
.as_u64
())
.unwrap
();
info!
(
" Find role-react message: channels determined"
);
let
http
=
ctx
.http
.clone
();
channels
.iter
()
.
par_
iter
()
.flat_map
(|
channel
|
{
let
ctxx
=
ctx
.clone
();
// since we don't know which channels the messages are in, we check every combination of message and
// channel and ignore the bad matches using .ok() and .filter_map()
CONFIG
.react_role_messages
.iter
()
.filter_map
(
move
|
rrm
|
{
ctxx
.http
.get_message
(
*
channel
.id
.as_u64
(),
*
rrm
.message
.as_u64
())
// since we don't know which channels the messages are in, we check every combination
// of message and channel and ignore the bad matches using .ok() and .filter_map()
let
h
=
http
.clone
();
// thread-local copy
CONFIG
.react_role_messages
.par_iter
()
.filter_map
(
move
|
rrm
|
{
h
.get_message
(
*
channel
.id
.as_u64
(),
*
rrm
.message
.as_u64
())
.ok
()
.map
(|
m
|
(
m
,
&
rrm
.mapping
))
})
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment