Skip to content
Snippets Groups Projects
Unverified Commit 689b1d15 authored by tec's avatar tec
Browse files

Revert my refactor. Squimmy did it better.

This reverts commit 9cd8e23a.
parent 9cd8e23a
No related merge requests found
Pipeline #158 canceled with stages
use crate::config::{ReactRoleMap, CONFIG}; use crate::config::{CONFIG, ReactRoleMap};
use crate::util::{get_react_from_string, get_string_from_react}; use crate::util::{get_react_from_string, get_string_from_react};
use serenity::{ use serenity::{
client::Context, client::Context,
...@@ -174,28 +174,28 @@ pub fn sync_all_role_reactions(ctx: Context) { ...@@ -174,28 +174,28 @@ pub fn sync_all_role_reactions(ctx: Context) {
info!("Role reaction sync complete"); 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(); let guild = ctx.http.get_guild(CONFIG.server_id).unwrap();
info!(" Find role-react message: guild determined"); info!(" Find role-react message: guild determined");
let channels = ctx.http.get_channels(*guild.id.as_u64()).unwrap(); let channels = ctx.http.get_channels(*guild.id.as_u64()).unwrap();
info!(" Find role-react message: channels determined"); info!(" Find role-react message: channels determined");
channels
let mut channel_search_indices: Vec<_> = (0..channels.len()).collect(); .iter()
let mut results: Vec<(Message, &'static ReactRoleMap)> = Vec::new(); .flat_map(|channel| {
for react_role in CONFIG.react_role_messages.iter() { let ctxx = ctx.clone();
for channel_index in &channel_search_indices { // since we don't know which channels the messages are in, we check every combination of message and
if let Ok(msg) = ctx.http.get_message( // channel and ignore the bad matches using .ok() and .filter_map()
*channels[*channel_index].id.as_u64(), CONFIG.react_role_messages.iter().filter_map(move |rrm| {
*react_role.message.as_u64(), ctxx.http
) { .get_message(*channel.id.as_u64(), *rrm.message.as_u64())
results.push((msg, &react_role.mapping)); .ok()
// move channel with message to front of index vector .map(|m| (m, &rrm.mapping))
let channel_index_clone = channel_index.to_owned(); })
channel_search_indices.retain(|&i| i != channel_index_clone); })
channel_search_indices.insert(0, channel_index_clone); .collect()
break;
}
}
}
results
} }
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment