fmt: formatting and clippy
This commit is contained in:
parent
b7161e2614
commit
344d6d3585
14 changed files with 130 additions and 138 deletions
|
@ -4,12 +4,12 @@ use serenity::{
|
||||||
model::gateway::{GatewayIntents, Ready},
|
model::gateway::{GatewayIntents, Ready},
|
||||||
Client,
|
Client,
|
||||||
};
|
};
|
||||||
use skynet_discord_bot::{get_config, Config};
|
|
||||||
use std::{process, sync::Arc};
|
|
||||||
use tokio::sync::RwLock;
|
|
||||||
use skynet_discord_bot::common::database::{db_init, DataBase};
|
use skynet_discord_bot::common::database::{db_init, DataBase};
|
||||||
use skynet_discord_bot::common::wolves::cns::get_wolves;
|
use skynet_discord_bot::common::wolves::cns::get_wolves;
|
||||||
use skynet_discord_bot::common::wolves::committees::get_cns;
|
use skynet_discord_bot::common::wolves::committees::get_cns;
|
||||||
|
use skynet_discord_bot::{get_config, Config};
|
||||||
|
use std::{process, sync::Arc};
|
||||||
|
use tokio::sync::RwLock;
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() {
|
async fn main() {
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
use skynet_discord_bot::get_config;
|
|
||||||
use std::collections::HashSet;
|
|
||||||
use skynet_discord_bot::common::database::db_init;
|
use skynet_discord_bot::common::database::db_init;
|
||||||
use skynet_discord_bot::common::minecraft::{get_minecraft_config, update_server, whitelist_wipe};
|
use skynet_discord_bot::common::minecraft::{get_minecraft_config, update_server, whitelist_wipe};
|
||||||
|
use skynet_discord_bot::get_config;
|
||||||
|
use std::collections::HashSet;
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() {
|
async fn main() {
|
||||||
|
|
|
@ -4,11 +4,11 @@ use serenity::{
|
||||||
model::gateway::{GatewayIntents, Ready},
|
model::gateway::{GatewayIntents, Ready},
|
||||||
Client,
|
Client,
|
||||||
};
|
};
|
||||||
|
use skynet_discord_bot::common::database::{db_init, get_server_config_bulk, DataBase};
|
||||||
|
use skynet_discord_bot::common::set_roles::{committee, normal};
|
||||||
use skynet_discord_bot::{get_config, Config};
|
use skynet_discord_bot::{get_config, Config};
|
||||||
use std::{process, sync::Arc};
|
use std::{process, sync::Arc};
|
||||||
use tokio::sync::RwLock;
|
use tokio::sync::RwLock;
|
||||||
use skynet_discord_bot::common::database::{db_init, get_server_config_bulk, DataBase};
|
|
||||||
use skynet_discord_bot::common::set_roles::{committee, normal};
|
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() {
|
async fn main() {
|
||||||
|
|
|
@ -6,11 +6,11 @@ use serenity::{
|
||||||
prelude::{command::CommandOptionType, interaction::application_command::CommandDataOptionValue},
|
prelude::{command::CommandOptionType, interaction::application_command::CommandDataOptionValue},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
use skynet_discord_bot::common::database::{get_server_config, DataBase, Servers};
|
||||||
|
use skynet_discord_bot::common::set_roles::normal::update_server;
|
||||||
use skynet_discord_bot::common::wolves::cns::get_wolves;
|
use skynet_discord_bot::common::wolves::cns::get_wolves;
|
||||||
use skynet_discord_bot::is_admin;
|
use skynet_discord_bot::is_admin;
|
||||||
use sqlx::{Error, Pool, Sqlite};
|
use sqlx::{Error, Pool, Sqlite};
|
||||||
use skynet_discord_bot::common::database::{get_server_config, DataBase, Servers};
|
|
||||||
use skynet_discord_bot::common::set_roles::normal::update_server;
|
|
||||||
|
|
||||||
pub async fn run(command: &ApplicationCommandInteraction, ctx: &Context) -> String {
|
pub async fn run(command: &ApplicationCommandInteraction, ctx: &Context) -> String {
|
||||||
// check if user has high enough permisssions
|
// check if user has high enough permisssions
|
||||||
|
|
|
@ -13,9 +13,9 @@ use serenity::{
|
||||||
prelude::{command::CommandOptionType, interaction::application_command::CommandDataOptionValue},
|
prelude::{command::CommandOptionType, interaction::application_command::CommandDataOptionValue},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
use skynet_discord_bot::common::database::{DataBase, Wolves, WolvesVerify};
|
||||||
use skynet_discord_bot::{get_now_iso, random_string, Config};
|
use skynet_discord_bot::{get_now_iso, random_string, Config};
|
||||||
use sqlx::{Pool, Sqlite};
|
use sqlx::{Pool, Sqlite};
|
||||||
use skynet_discord_bot::common::database::{DataBase, Wolves, WolvesVerify};
|
|
||||||
|
|
||||||
pub mod link {
|
pub mod link {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
@ -241,8 +241,8 @@ pub mod verify {
|
||||||
use crate::commands::link_email::link::{db_pending_clear_expired, get_verify_from_db};
|
use crate::commands::link_email::link::{db_pending_clear_expired, get_verify_from_db};
|
||||||
use serenity::model::user::User;
|
use serenity::model::user::User;
|
||||||
use skynet_discord_bot::common::database::get_server_config;
|
use skynet_discord_bot::common::database::get_server_config;
|
||||||
use sqlx::Error;
|
|
||||||
use skynet_discord_bot::common::database::{ServerMembersWolves, Servers};
|
use skynet_discord_bot::common::database::{ServerMembersWolves, Servers};
|
||||||
|
use sqlx::Error;
|
||||||
|
|
||||||
pub async fn run(command: &ApplicationCommandInteraction, ctx: &Context) -> String {
|
pub async fn run(command: &ApplicationCommandInteraction, ctx: &Context) -> String {
|
||||||
let db_lock = {
|
let db_lock = {
|
||||||
|
|
|
@ -16,10 +16,10 @@ pub(crate) mod user {
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::commands::link_email::link::get_server_member_discord;
|
use crate::commands::link_email::link::get_server_member_discord;
|
||||||
use serenity::model::id::UserId;
|
use serenity::model::id::UserId;
|
||||||
use skynet_discord_bot::Config;
|
|
||||||
use sqlx::Error;
|
|
||||||
use skynet_discord_bot::common::database::Wolves;
|
use skynet_discord_bot::common::database::Wolves;
|
||||||
use skynet_discord_bot::common::minecraft::{whitelist_update, Minecraft};
|
use skynet_discord_bot::common::minecraft::{whitelist_update, Minecraft};
|
||||||
|
use skynet_discord_bot::Config;
|
||||||
|
use sqlx::Error;
|
||||||
|
|
||||||
pub fn register(command: &mut CreateApplicationCommand) -> &mut CreateApplicationCommand {
|
pub fn register(command: &mut CreateApplicationCommand) -> &mut CreateApplicationCommand {
|
||||||
command.name("link_minecraft").description("Link your minecraft account").create_option(|option| {
|
command.name("link_minecraft").description("Link your minecraft account").create_option(|option| {
|
||||||
|
@ -124,9 +124,9 @@ pub(crate) mod server {
|
||||||
use sqlx::Error;
|
use sqlx::Error;
|
||||||
// this is to managfe the server side of commands related to minecraft
|
// this is to managfe the server side of commands related to minecraft
|
||||||
use super::*;
|
use super::*;
|
||||||
use skynet_discord_bot::{is_admin, Config};
|
|
||||||
use skynet_discord_bot::common::minecraft::Minecraft;
|
|
||||||
use skynet_discord_bot::common::minecraft::update_server;
|
use skynet_discord_bot::common::minecraft::update_server;
|
||||||
|
use skynet_discord_bot::common::minecraft::Minecraft;
|
||||||
|
use skynet_discord_bot::{is_admin, Config};
|
||||||
|
|
||||||
pub fn register(command: &mut CreateApplicationCommand) -> &mut CreateApplicationCommand {
|
pub fn register(command: &mut CreateApplicationCommand) -> &mut CreateApplicationCommand {
|
||||||
command.name("minecraft_add").description("Add a minecraft server").create_option(|option| {
|
command.name("minecraft_add").description("Add a minecraft server").create_option(|option| {
|
||||||
|
@ -205,9 +205,9 @@ pub(crate) mod server {
|
||||||
use serenity::builder::CreateApplicationCommand;
|
use serenity::builder::CreateApplicationCommand;
|
||||||
use serenity::client::Context;
|
use serenity::client::Context;
|
||||||
use serenity::model::prelude::application_command::ApplicationCommandInteraction;
|
use serenity::model::prelude::application_command::ApplicationCommandInteraction;
|
||||||
use skynet_discord_bot::{is_admin, Config};
|
|
||||||
use skynet_discord_bot::common::database::DataBase;
|
use skynet_discord_bot::common::database::DataBase;
|
||||||
use skynet_discord_bot::common::minecraft::{get_minecraft_config_server, server_information};
|
use skynet_discord_bot::common::minecraft::{get_minecraft_config_server, server_information};
|
||||||
|
use skynet_discord_bot::{is_admin, Config};
|
||||||
|
|
||||||
pub fn register(command: &mut CreateApplicationCommand) -> &mut CreateApplicationCommand {
|
pub fn register(command: &mut CreateApplicationCommand) -> &mut CreateApplicationCommand {
|
||||||
command.name("minecraft_list").description("List your minecraft servers")
|
command.name("minecraft_list").description("List your minecraft servers")
|
||||||
|
@ -268,10 +268,10 @@ pub(crate) mod server {
|
||||||
use serenity::model::application::command::CommandOptionType;
|
use serenity::model::application::command::CommandOptionType;
|
||||||
use serenity::model::id::GuildId;
|
use serenity::model::id::GuildId;
|
||||||
use serenity::model::prelude::application_command::{ApplicationCommandInteraction, CommandDataOptionValue};
|
use serenity::model::prelude::application_command::{ApplicationCommandInteraction, CommandDataOptionValue};
|
||||||
use skynet_discord_bot::is_admin;
|
|
||||||
use sqlx::{Error, Pool, Sqlite};
|
|
||||||
use skynet_discord_bot::common::database::DataBase;
|
use skynet_discord_bot::common::database::DataBase;
|
||||||
use skynet_discord_bot::common::minecraft::Minecraft;
|
use skynet_discord_bot::common::minecraft::Minecraft;
|
||||||
|
use skynet_discord_bot::is_admin;
|
||||||
|
use sqlx::{Error, Pool, Sqlite};
|
||||||
|
|
||||||
pub fn register(command: &mut CreateApplicationCommand) -> &mut CreateApplicationCommand {
|
pub fn register(command: &mut CreateApplicationCommand) -> &mut CreateApplicationCommand {
|
||||||
command.name("minecraft_delete").description("Delete a minecraft server").create_option(|option| {
|
command.name("minecraft_delete").description("Delete a minecraft server").create_option(|option| {
|
||||||
|
|
|
@ -7,9 +7,9 @@ use serenity::{
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
use skynet_discord_bot::common::database::{DataBase, RoleAdder};
|
||||||
use skynet_discord_bot::is_admin;
|
use skynet_discord_bot::is_admin;
|
||||||
use sqlx::{Error, Pool, Sqlite};
|
use sqlx::{Error, Pool, Sqlite};
|
||||||
use skynet_discord_bot::common::database::{DataBase, RoleAdder};
|
|
||||||
|
|
||||||
pub mod edit {
|
pub mod edit {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
use serenity::prelude::TypeMapKey;
|
use crate::Config;
|
||||||
use std::sync::Arc;
|
|
||||||
use tokio::sync::RwLock;
|
|
||||||
use sqlx::{Error, FromRow, Pool, Row, Sqlite};
|
|
||||||
use sqlx::sqlite::{SqliteConnectOptions, SqlitePoolOptions, SqliteRow};
|
|
||||||
use serenity::model::id::{ChannelId, GuildId, RoleId, UserId};
|
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use serenity::model::guild;
|
use serenity::model::guild;
|
||||||
|
use serenity::model::id::{ChannelId, GuildId, RoleId, UserId};
|
||||||
|
use serenity::prelude::TypeMapKey;
|
||||||
|
use sqlx::sqlite::{SqliteConnectOptions, SqlitePoolOptions, SqliteRow};
|
||||||
|
use sqlx::{Error, FromRow, Pool, Row, Sqlite};
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
use crate::Config;
|
use std::sync::Arc;
|
||||||
|
use tokio::sync::RwLock;
|
||||||
|
|
||||||
pub struct DataBase;
|
pub struct DataBase;
|
||||||
impl TypeMapKey for DataBase {
|
impl TypeMapKey for DataBase {
|
||||||
|
|
|
@ -1,11 +1,10 @@
|
||||||
use serde::{Deserialize, Serialize};
|
use crate::common::set_roles::normal::get_server_member_bulk;
|
||||||
|
use crate::Config;
|
||||||
use serde::de::DeserializeOwned;
|
use serde::de::DeserializeOwned;
|
||||||
use sqlx::{Error, FromRow, Pool, Row, Sqlite};
|
use serde::{Deserialize, Serialize};
|
||||||
use serenity::model::id::GuildId;
|
use serenity::model::id::GuildId;
|
||||||
use sqlx::sqlite::SqliteRow;
|
use sqlx::sqlite::SqliteRow;
|
||||||
use crate::Config;
|
use sqlx::{Error, FromRow, Pool, Row, Sqlite};
|
||||||
use crate::common::set_roles::normal::get_server_member_bulk;
|
|
||||||
|
|
||||||
|
|
||||||
#[derive(Debug, Clone, Deserialize, Serialize)]
|
#[derive(Debug, Clone, Deserialize, Serialize)]
|
||||||
pub struct Minecraft {
|
pub struct Minecraft {
|
||||||
|
@ -25,7 +24,6 @@ impl<'r> FromRow<'r, SqliteRow> for Minecraft {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
loop through all members of server
|
loop through all members of server
|
||||||
get a list of folks with mc accounts that are members
|
get a list of folks with mc accounts that are members
|
||||||
|
@ -164,4 +162,3 @@ pub async fn get_minecraft_config_server(db: &Pool<Sqlite>, g_id: GuildId) -> Ve
|
||||||
.await
|
.await
|
||||||
.unwrap_or_default()
|
.unwrap_or_default()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
pub mod wolves;
|
|
||||||
pub mod database;
|
pub mod database;
|
||||||
pub mod minecraft;
|
pub mod minecraft;
|
||||||
pub mod set_roles;
|
pub mod set_roles;
|
||||||
|
pub mod wolves;
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
pub mod normal {
|
pub mod normal {
|
||||||
|
use crate::common::database::{DataBase, ServerMembersWolves, Servers, Wolves};
|
||||||
|
use crate::get_now_iso;
|
||||||
use serenity::client::Context;
|
use serenity::client::Context;
|
||||||
use serenity::model::id::{GuildId, RoleId, UserId};
|
use serenity::model::id::{GuildId, RoleId, UserId};
|
||||||
use sqlx::{Pool, Sqlite};
|
use sqlx::{Pool, Sqlite};
|
||||||
use crate::common::database::{DataBase, ServerMembersWolves, Servers, Wolves};
|
|
||||||
use crate::get_now_iso;
|
|
||||||
|
|
||||||
pub async fn update_server(ctx: &Context, server: &Servers, remove_roles: &[Option<RoleId>], members_changed: &[UserId]) {
|
pub async fn update_server(ctx: &Context, server: &Servers, remove_roles: &[Option<RoleId>], members_changed: &[UserId]) {
|
||||||
let db_lock = {
|
let db_lock = {
|
||||||
|
@ -131,14 +131,14 @@ pub mod normal {
|
||||||
|
|
||||||
// for updating committee members
|
// for updating committee members
|
||||||
pub mod committee {
|
pub mod committee {
|
||||||
use std::collections::HashMap;
|
use crate::common::database::{DataBase, Wolves};
|
||||||
use std::sync::Arc;
|
use crate::common::wolves::committees::Committees;
|
||||||
use serenity::client::Context;
|
use serenity::client::Context;
|
||||||
use serenity::model::guild::Member;
|
use serenity::model::guild::Member;
|
||||||
use serenity::model::id::{GuildId, RoleId};
|
use serenity::model::id::{GuildId, RoleId};
|
||||||
use sqlx::{Pool, Sqlite};
|
use sqlx::{Pool, Sqlite};
|
||||||
use crate::common::database::{DataBase, Wolves};
|
use std::collections::HashMap;
|
||||||
use crate::common::wolves::committees::Committees;
|
use std::sync::Arc;
|
||||||
|
|
||||||
pub async fn check_committee(ctx: Arc<Context>) {
|
pub async fn check_committee(ctx: Arc<Context>) {
|
||||||
let db_lock = {
|
let db_lock = {
|
||||||
|
@ -168,24 +168,21 @@ pub mod committee {
|
||||||
roles_name.insert(role.name.to_owned(), role.to_owned());
|
roles_name.insert(role.name.to_owned(), role.to_owned());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// a map of users and the roles they are goign to be getting
|
// a map of users and the roles they are goign to be getting
|
||||||
let mut users_roles = HashMap::new();
|
let mut users_roles = HashMap::new();
|
||||||
|
|
||||||
// a list of all the roles that can be removed from folks who should have them
|
// a list of all the roles that can be removed from folks who should have them
|
||||||
let mut committee_roles = vec![
|
let mut committee_roles = vec![committee_member];
|
||||||
committee_member
|
|
||||||
];
|
|
||||||
|
|
||||||
for committee in &committees {
|
for committee in &committees {
|
||||||
// get the role for this committee/club/soc
|
// get the role for this committee/club/soc
|
||||||
let role = match roles_name.get(&committee.name) {
|
let role = match roles_name.get(&committee.name) {
|
||||||
Some(x) => {Some(x.to_owned())}
|
Some(x) => Some(x.to_owned()),
|
||||||
None => {
|
None => {
|
||||||
// create teh role if it does not exist
|
// create teh role if it does not exist
|
||||||
match server.create_role(&ctx, |r| r.hoist(false).mentionable(true).name(&committee.name)).await {
|
match server.create_role(&ctx, |r| r.hoist(false).mentionable(true).name(&committee.name)).await {
|
||||||
Ok(x) => { Some(x) }
|
Ok(x) => Some(x),
|
||||||
Err(_) => {None}
|
Err(_) => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -196,7 +193,7 @@ pub mod committee {
|
||||||
|
|
||||||
for id_wolves in &committee.committee {
|
for id_wolves in &committee.committee {
|
||||||
// ID in this is the wolves ID, so we need to get a matching discord ID (if one exists)
|
// ID in this is the wolves ID, so we need to get a matching discord ID (if one exists)
|
||||||
if let Some(x) = get_server_member_discord(&db, id_wolves).await {
|
if let Some(x) = get_server_member_discord(db, id_wolves).await {
|
||||||
if let Some(member_tmp) = x.discord {
|
if let Some(member_tmp) = x.discord {
|
||||||
let values = users_roles.entry(member_tmp).or_insert(vec![]);
|
let values = users_roles.entry(member_tmp).or_insert(vec![]);
|
||||||
values.push(r.id);
|
values.push(r.id);
|
||||||
|
|
|
@ -1,13 +1,11 @@
|
||||||
|
use crate::common::database::Wolves;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use sqlx::{Pool, Sqlite};
|
use sqlx::{Pool, Sqlite};
|
||||||
use crate::common::database::Wolves;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
This file relates to anything that directly interacts with teh wolves API
|
This file relates to anything that directly interacts with teh wolves API
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#[derive(Deserialize, Serialize, Debug)]
|
#[derive(Deserialize, Serialize, Debug)]
|
||||||
struct WolvesResultUserMin {
|
struct WolvesResultUserMin {
|
||||||
// committee: String,
|
// committee: String,
|
||||||
|
@ -46,20 +44,19 @@ async fn add_users_wolves(db: &Pool<Sqlite>, user: &WolvesResultUserMin) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
This is getting data for Clubs and Socs
|
This is getting data for Clubs and Socs
|
||||||
*/
|
*/
|
||||||
pub mod cns {
|
pub mod cns {
|
||||||
|
use crate::common::database::{get_server_config_bulk, DataBase, ServerMembers, ServerMembersWolves, Servers};
|
||||||
use crate::common::set_roles::normal::update_server;
|
use crate::common::set_roles::normal::update_server;
|
||||||
use std::collections::BTreeMap;
|
use crate::common::wolves::{add_users_wolves, WolvesResultUserMin};
|
||||||
|
use crate::Config;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use serenity::client::Context;
|
use serenity::client::Context;
|
||||||
use serenity::model::id::GuildId;
|
use serenity::model::id::GuildId;
|
||||||
use sqlx::{Pool, Sqlite};
|
use sqlx::{Pool, Sqlite};
|
||||||
use crate::Config;
|
use std::collections::BTreeMap;
|
||||||
use crate::common::database::{get_server_config_bulk, DataBase, ServerMembers, ServerMembersWolves, Servers, Wolves};
|
|
||||||
use crate::common::wolves::{add_users_wolves, WolvesResultUserMin};
|
|
||||||
|
|
||||||
#[derive(Deserialize, Serialize, Debug)]
|
#[derive(Deserialize, Serialize, Debug)]
|
||||||
struct WolvesResultUser {
|
struct WolvesResultUser {
|
||||||
|
@ -222,11 +219,11 @@ pub mod cns {
|
||||||
Get and store the data on C&S committees
|
Get and store the data on C&S committees
|
||||||
*/
|
*/
|
||||||
pub mod committees {
|
pub mod committees {
|
||||||
|
use crate::common::database::DataBase;
|
||||||
|
use crate::Config;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use serenity::client::Context;
|
use serenity::client::Context;
|
||||||
use sqlx::{Pool, Sqlite};
|
use sqlx::{Pool, Sqlite};
|
||||||
use crate::common::database::{DataBase};
|
|
||||||
use crate::Config;
|
|
||||||
|
|
||||||
// This is what Wolves returns to us
|
// This is what Wolves returns to us
|
||||||
#[derive(Deserialize, Serialize, Debug)]
|
#[derive(Deserialize, Serialize, Debug)]
|
||||||
|
@ -243,7 +240,7 @@ pub mod committees {
|
||||||
// Link to their page such as https://ulwolves.ie/society/computer
|
// Link to their page such as https://ulwolves.ie/society/computer
|
||||||
link: String,
|
link: String,
|
||||||
// array of Committee members member_id's
|
// array of Committee members member_id's
|
||||||
committee: Vec<String>
|
committee: Vec<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Database entry for it
|
// Database entry for it
|
||||||
|
@ -299,7 +296,11 @@ pub mod committees {
|
||||||
|
|
||||||
// get wolves data
|
// get wolves data
|
||||||
if let Ok(mut res) = surf::post(&url).header("X-AM-Identity", wolves_api).await {
|
if let Ok(mut res) = surf::post(&url).header("X-AM-Identity", wolves_api).await {
|
||||||
if let Ok(WolvesResult { success, result, }) = res.body_json().await {
|
if let Ok(WolvesResult {
|
||||||
|
success,
|
||||||
|
result,
|
||||||
|
}) = res.body_json().await
|
||||||
|
{
|
||||||
if success != 1 {
|
if success != 1 {
|
||||||
return vec![];
|
return vec![];
|
||||||
}
|
}
|
||||||
|
@ -339,12 +340,11 @@ pub mod committees {
|
||||||
get the data for an individual user
|
get the data for an individual user
|
||||||
*/
|
*/
|
||||||
pub mod individual {
|
pub mod individual {
|
||||||
use serde::{Deserialize, Serialize};
|
|
||||||
use serenity::client::Context;
|
|
||||||
use crate::common::database::DataBase;
|
use crate::common::database::DataBase;
|
||||||
use crate::common::wolves::{add_users_wolves, WolvesResultUserMin};
|
use crate::common::wolves::{add_users_wolves, WolvesResultUserMin};
|
||||||
use crate::Config;
|
use crate::Config;
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
use serenity::client::Context;
|
||||||
|
|
||||||
#[derive(Deserialize, Serialize, Debug)]
|
#[derive(Deserialize, Serialize, Debug)]
|
||||||
struct WolvesResultUser {
|
struct WolvesResultUser {
|
||||||
|
@ -378,7 +378,6 @@ pub mod individual {
|
||||||
result: WolvesResultUser,
|
result: WolvesResultUser,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
pub async fn get_user(ctx: &Context, email: &str) -> bool {
|
pub async fn get_user(ctx: &Context, email: &str) -> bool {
|
||||||
let db_lock = {
|
let db_lock = {
|
||||||
let data_read = ctx.data.read().await;
|
let data_read = ctx.data.read().await;
|
||||||
|
@ -396,9 +395,7 @@ pub mod individual {
|
||||||
let api_key = "";
|
let api_key = "";
|
||||||
// request data from wolves
|
// request data from wolves
|
||||||
match get_user_sub(&config, api_key, email).await {
|
match get_user_sub(&config, api_key, email).await {
|
||||||
None => {
|
None => false,
|
||||||
false
|
|
||||||
}
|
|
||||||
// if exists save it and return true
|
// if exists save it and return true
|
||||||
Some(user) => {
|
Some(user) => {
|
||||||
// add to db
|
// add to db
|
||||||
|
@ -409,7 +406,7 @@ pub mod individual {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn get_user_sub(config: &Config, wolves_api: &str, email: &str) -> Option<WolvesResultUser> {
|
async fn get_user_sub(config: &Config, wolves_api: &str, _email: &str) -> Option<WolvesResultUser> {
|
||||||
if config.wolves_url.is_empty() {
|
if config.wolves_url.is_empty() {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
@ -419,7 +416,11 @@ pub mod individual {
|
||||||
|
|
||||||
// get wolves data
|
// get wolves data
|
||||||
if let Ok(mut res) = surf::post(&url).header("X-AM-Identity", wolves_api).await {
|
if let Ok(mut res) = surf::post(&url).header("X-AM-Identity", wolves_api).await {
|
||||||
if let Ok(WolvesResult { success, result, }) = res.body_json().await {
|
if let Ok(WolvesResult {
|
||||||
|
success,
|
||||||
|
result,
|
||||||
|
}) = res.body_json().await
|
||||||
|
{
|
||||||
if success != 1 {
|
if success != 1 {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,14 +1,11 @@
|
||||||
pub mod common;
|
pub mod common;
|
||||||
|
|
||||||
use dotenvy::dotenv;
|
|
||||||
use serde::{Deserialize, Serialize};
|
|
||||||
use serenity::prelude::TypeMapKey;
|
|
||||||
|
|
||||||
use chrono::{Datelike, SecondsFormat, Utc};
|
use chrono::{Datelike, SecondsFormat, Utc};
|
||||||
|
use dotenvy::dotenv;
|
||||||
use rand::{distributions::Alphanumeric, thread_rng, Rng};
|
use rand::{distributions::Alphanumeric, thread_rng, Rng};
|
||||||
use serde::de::DeserializeOwned;
|
|
||||||
use serenity::client::Context;
|
use serenity::client::Context;
|
||||||
use serenity::model::prelude::application_command::ApplicationCommandInteraction;
|
use serenity::model::prelude::application_command::ApplicationCommandInteraction;
|
||||||
|
use serenity::prelude::TypeMapKey;
|
||||||
use std::{env, sync::Arc};
|
use std::{env, sync::Arc};
|
||||||
use tokio::sync::RwLock;
|
use tokio::sync::RwLock;
|
||||||
pub struct Config {
|
pub struct Config {
|
||||||
|
|
|
@ -2,6 +2,7 @@ pub mod commands;
|
||||||
|
|
||||||
use crate::commands::role_adder::tools::on_role_change;
|
use crate::commands::role_adder::tools::on_role_change;
|
||||||
use serenity::model::guild::Member;
|
use serenity::model::guild::Member;
|
||||||
|
use serenity::model::id::GuildId;
|
||||||
use serenity::{
|
use serenity::{
|
||||||
async_trait,
|
async_trait,
|
||||||
client::{Context, EventHandler},
|
client::{Context, EventHandler},
|
||||||
|
@ -13,12 +14,11 @@ use serenity::{
|
||||||
},
|
},
|
||||||
Client,
|
Client,
|
||||||
};
|
};
|
||||||
use skynet_discord_bot::{get_config, Config};
|
|
||||||
use std::sync::Arc;
|
|
||||||
use serenity::model::id::GuildId;
|
|
||||||
use tokio::sync::RwLock;
|
|
||||||
use skynet_discord_bot::common::database::{db_init, get_server_config, get_server_member, DataBase};
|
use skynet_discord_bot::common::database::{db_init, get_server_config, get_server_member, DataBase};
|
||||||
use skynet_discord_bot::common::set_roles::committee::update_committees;
|
use skynet_discord_bot::common::set_roles::committee::update_committees;
|
||||||
|
use skynet_discord_bot::{get_config, Config};
|
||||||
|
use std::sync::Arc;
|
||||||
|
use tokio::sync::RwLock;
|
||||||
|
|
||||||
struct Handler;
|
struct Handler;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue