From 0f4f32fc0d1c9dab14487f08c4c007f71323b5ad Mon Sep 17 00:00:00 2001 From: Timothy du Heaume <timothy.duheaume@gmail.com> Date: Wed, 5 Feb 2020 10:28:12 +0900 Subject: [PATCH] prserve insertion order of react/role mappings --- Cargo.toml | 1 + src/config.rs | 7 +++++-- src/reaction_roles.rs | 4 ++-- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 41b4994..77946de 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,3 +16,4 @@ serde_yaml = "^0.8" serenity = "0.8.0" simplelog = "^0.7.4" guard = "0.5.0" +indexmap = "1.3.1" diff --git a/src/config.rs b/src/config.rs index 452553c..376b9fa 100644 --- a/src/config.rs +++ b/src/config.rs @@ -1,7 +1,8 @@ +extern crate indexmap; use serde::Deserialize; use serde_yaml; use serenity::model::id; -use std::collections::HashMap; +use indexmap::IndexMap; use std::fs; lazy_static! { @@ -44,8 +45,10 @@ impl UccbotConfig { } } +pub type ReactRoleMap = IndexMap<String, id::RoleId>; + #[derive(Debug, Deserialize, Clone)] pub struct ReactionMapping { pub message: serenity::model::id::MessageId, - pub mapping: HashMap<String, id::RoleId>, + pub mapping: ReactRoleMap, } diff --git a/src/reaction_roles.rs b/src/reaction_roles.rs index 35861b9..faa2a23 100644 --- a/src/reaction_roles.rs +++ b/src/reaction_roles.rs @@ -1,4 +1,4 @@ -use crate::config::CONFIG; +use crate::config::{CONFIG, ReactRoleMap}; use crate::util::{get_react_from_string, get_string_from_react}; use serenity::{ client::Context, @@ -178,7 +178,7 @@ fn get_all_role_reaction_message( ctx: &Context, ) -> Vec<( Message, - &'static HashMap<String, serenity::model::id::RoleId>, + &'static ReactRoleMap, )> { let guild = ctx.http.get_guild(CONFIG.server_id).unwrap(); info!(" Find role-react message: guild determined"); -- GitLab