create reminder route. formatting on frontend
This commit is contained in:
@ -2,6 +2,8 @@
|
||||
extern crate rocket;
|
||||
|
||||
mod consts;
|
||||
#[macro_use]
|
||||
mod macros;
|
||||
mod routes;
|
||||
|
||||
use std::{collections::HashMap, env};
|
||||
@ -9,13 +11,23 @@ use std::{collections::HashMap, env};
|
||||
use oauth2::{basic::BasicClient, AuthUrl, ClientId, ClientSecret, RedirectUrl, TokenUrl};
|
||||
use rocket::fs::FileServer;
|
||||
use rocket_dyn_templates::Template;
|
||||
use serenity::client::Context;
|
||||
use serenity::{
|
||||
client::Context,
|
||||
http::CacheHttp,
|
||||
model::id::{GuildId, UserId},
|
||||
};
|
||||
use sqlx::{MySql, Pool};
|
||||
|
||||
use crate::consts::{DISCORD_OAUTH_AUTHORIZE, DISCORD_OAUTH_TOKEN};
|
||||
use crate::consts::{CNC_GUILD, DISCORD_OAUTH_AUTHORIZE, DISCORD_OAUTH_TOKEN, SUBSCRIPTION_ROLES};
|
||||
|
||||
type Database = MySql;
|
||||
|
||||
#[derive(Debug)]
|
||||
enum Error {
|
||||
SQLx(sqlx::Error),
|
||||
serenity(serenity::Error),
|
||||
}
|
||||
|
||||
#[catch(401)]
|
||||
async fn not_authorized() -> Template {
|
||||
let map: HashMap<String, String> = HashMap::new();
|
||||
@ -98,3 +110,34 @@ pub async fn initialize(
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn check_subscription(cache_http: impl CacheHttp, user_id: impl Into<UserId>) -> bool {
|
||||
if let Some(subscription_guild) = *CNC_GUILD {
|
||||
let guild_member = GuildId(subscription_guild).member(cache_http, user_id).await;
|
||||
|
||||
if let Ok(member) = guild_member {
|
||||
for role in member.roles {
|
||||
if SUBSCRIPTION_ROLES.contains(role.as_u64()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
false
|
||||
} else {
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn check_guild_subscription(
|
||||
cache_http: impl CacheHttp,
|
||||
guild_id: impl Into<GuildId>,
|
||||
) -> bool {
|
||||
if let Some(guild) = cache_http.cache().unwrap().guild(guild_id) {
|
||||
let owner = guild.owner_id;
|
||||
|
||||
check_subscription(&cache_http, owner).await
|
||||
} else {
|
||||
false
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user