1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
use crate::env::global_config;
use crate::error::TelescopeError;
use serenity::http::Http;
use serenity::model::id::RoleId;
lazy_static! {
static ref DISCORD_API_CLIENT: Http =
Http::new_with_token(global_config().as_ref().discord_config.bot_token.as_str());
}
pub fn global_discord_client() -> &'static Http {
DISCORD_API_CLIENT.as_ref()
}
pub async fn rcos_discord_verified_role_id() -> Result<Option<RoleId>, TelescopeError> {
let rcos_discord: u64 = global_config().discord_config.rcos_guild_id();
Ok(global_discord_client()
.get_guild_roles(rcos_discord)
.await
.map_err(|err| {
error!("Could not get RCOS Discord Roles. Internal error: {}", err);
TelescopeError::serenity_error(err)
})?
.iter()
.find(|role| role.name.eq_ignore_ascii_case("Verified"))
.map(|role| role.id))
}