reaction_roles.rs 1.08 KB
Newer Older
1 2 3 4 5 6
use serenity::{
    model::{channel::Message, channel::Reaction},
    client::Context
};
use crate::util::get_string_from_react;
use crate::config::CONFIG;
tec's avatar
tec committed
7

8 9 10 11 12 13 14
pub fn add_role_by_reaction(ctx: Context, msg: Message, added_reaction: Reaction) {
    CONFIG.react_role_messages.iter().find(|rrm| rrm.message == msg.id).and_then(|reaction_mapping| {
        let react_as_string = get_string_from_react(added_reaction.emoji);
        return reaction_mapping.mapping.get(&react_as_string);
    }).and_then(|role_id|{
        return ctx.http.add_member_role(CONFIG.server_id, *msg.author.id.as_u64(), *role_id.as_u64()).ok();
    });
tec's avatar
tec committed
15 16
}

17 18 19 20 21 22 23
pub fn remove_role_by_reaction(ctx: Context, msg: Message, removed_reaction: Reaction) {
    CONFIG.react_role_messages.iter().find(|rrm| rrm.message == msg.id).and_then(|reaction_mapping| {
        let react_as_string = get_string_from_react(removed_reaction.emoji);
        return reaction_mapping.mapping.get(&react_as_string);
    }).and_then(|role_id|{
        return ctx.http.remove_member_role(CONFIG.server_id, *msg.author.id.as_u64(), *role_id.as_u64()).ok();
    });
tec's avatar
tec committed
24
}