forked from Skynet/discord-bot
Compare commits
No commits in common. "062f826d28b4d385423656b10cca84b3644c8e60" and "7526a82bb7c384c16a09992458868b2f669ed279" have entirely different histories.
062f826d28
...
7526a82bb7
21 changed files with 96 additions and 73 deletions
|
@ -1,2 +0,0 @@
|
||||||
# Fix typos
|
|
||||||
7e90f451965b0edbd331765ad295a02f31d2bf24
|
|
|
@ -1,2 +0,0 @@
|
||||||
[formatting]
|
|
||||||
column_width = 120
|
|
|
@ -18,8 +18,8 @@ use tokio::sync::RwLock;
|
||||||
|
|
||||||
/// Cleanup teh Committee server
|
/// Cleanup teh Committee server
|
||||||
///
|
///
|
||||||
/// This removes any invalid roles/channels which have been set up accidentally
|
/// This removes any invalid roles/channels which ay have been set up accidentally
|
||||||
/// DO NOT run this locally unless you have a fresh copy of the live database handy.
|
/// DO NOT run this locally unless you have a fresh copy of teh live database handy.
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() {
|
async fn main() {
|
||||||
let config = get_config();
|
let config = get_config();
|
||||||
|
@ -41,7 +41,7 @@ async fn main() {
|
||||||
let mut data = client.data.write().await;
|
let mut data = client.data.write().await;
|
||||||
|
|
||||||
data.insert::<Config>(Arc::new(RwLock::new(config)));
|
data.insert::<Config>(Arc::new(RwLock::new(config)));
|
||||||
data.insert::<DataBase>(Arc::new(db));
|
data.insert::<DataBase>(Arc::new(RwLock::new(db)));
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Err(why) = client.start().await {
|
if let Err(why) = client.start().await {
|
||||||
|
@ -69,11 +69,13 @@ impl EventHandler for Handler {
|
||||||
async fn guild_members_chunk(&self, ctx: Context, chunk: GuildMembersChunkEvent) {
|
async fn guild_members_chunk(&self, ctx: Context, chunk: GuildMembersChunkEvent) {
|
||||||
if (chunk.chunk_index + 1) == chunk.chunk_count {
|
if (chunk.chunk_index + 1) == chunk.chunk_count {
|
||||||
println!("Cache built successfully!");
|
println!("Cache built successfully!");
|
||||||
let db = {
|
let db_lock = {
|
||||||
let data_read = ctx.data.read().await;
|
let data_read = ctx.data.read().await;
|
||||||
data_read.get::<DataBase>().expect("Expected Config in TypeMap.").clone()
|
data_read.get::<DataBase>().expect("Expected Config in TypeMap.").clone()
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let db = db_lock.read().await;
|
||||||
|
|
||||||
let config_lock = {
|
let config_lock = {
|
||||||
let data_read = ctx.data.read().await;
|
let data_read = ctx.data.read().await;
|
||||||
data_read.get::<Config>().expect("Expected Config in TypeMap.").clone()
|
data_read.get::<Config>().expect("Expected Config in TypeMap.").clone()
|
||||||
|
@ -96,7 +98,7 @@ async fn cleanup(db: &Pool<Sqlite>, ctx: &Context, config: &Config) {
|
||||||
let name = &channel.name;
|
let name = &channel.name;
|
||||||
let committee_tmp = committees.iter().filter(|x| &x.name_channel == name).collect::<Vec<_>>();
|
let committee_tmp = committees.iter().filter(|x| &x.name_channel == name).collect::<Vec<_>>();
|
||||||
let committee = match committee_tmp.first() {
|
let committee = match committee_tmp.first() {
|
||||||
// if there are no committees which match then this is not a channel we care about
|
// if there are no committees which match then this is not a channelw e care about
|
||||||
None => {
|
None => {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -118,7 +120,7 @@ async fn cleanup(db: &Pool<Sqlite>, ctx: &Context, config: &Config) {
|
||||||
let name = &role.name;
|
let name = &role.name;
|
||||||
let committee_tmp = committees.iter().filter(|x| &x.name_role == name).collect::<Vec<_>>();
|
let committee_tmp = committees.iter().filter(|x| &x.name_role == name).collect::<Vec<_>>();
|
||||||
let committee = match committee_tmp.first() {
|
let committee = match committee_tmp.first() {
|
||||||
// if there are no committees which match then this is not a channel we care about
|
// if there are no committees which match then this is not a channelw e care about
|
||||||
None => {
|
None => {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,7 +36,7 @@ async fn main() {
|
||||||
let mut data = client.data.write().await;
|
let mut data = client.data.write().await;
|
||||||
|
|
||||||
data.insert::<Config>(Arc::new(RwLock::new(config)));
|
data.insert::<Config>(Arc::new(RwLock::new(config)));
|
||||||
data.insert::<DataBase>(Arc::new(db));
|
data.insert::<DataBase>(Arc::new(RwLock::new(db)));
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Err(why) = client.start().await {
|
if let Err(why) = client.start().await {
|
||||||
|
|
|
@ -38,7 +38,7 @@ async fn main() {
|
||||||
let mut data = client.data.write().await;
|
let mut data = client.data.write().await;
|
||||||
|
|
||||||
data.insert::<Config>(Arc::new(RwLock::new(config)));
|
data.insert::<Config>(Arc::new(RwLock::new(config)));
|
||||||
data.insert::<DataBase>(Arc::new(db));
|
data.insert::<DataBase>(Arc::new(RwLock::new(db)));
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Err(why) = client.start().await {
|
if let Err(why) = client.start().await {
|
||||||
|
|
|
@ -35,7 +35,7 @@ async fn main() {
|
||||||
let mut data = client.data.write().await;
|
let mut data = client.data.write().await;
|
||||||
|
|
||||||
data.insert::<Config>(Arc::new(RwLock::new(config)));
|
data.insert::<Config>(Arc::new(RwLock::new(config)));
|
||||||
data.insert::<DataBase>(Arc::new(db));
|
data.insert::<DataBase>(Arc::new(RwLock::new(db)));
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Err(why) = client.start().await {
|
if let Err(why) = client.start().await {
|
||||||
|
@ -50,10 +50,11 @@ impl EventHandler for Handler {
|
||||||
let ctx = Arc::new(ctx);
|
let ctx = Arc::new(ctx);
|
||||||
println!("{} is connected!", ready.user.name);
|
println!("{} is connected!", ready.user.name);
|
||||||
|
|
||||||
let db = {
|
let db_lock = {
|
||||||
let data_read = ctx.data.read().await;
|
let data_read = ctx.data.read().await;
|
||||||
data_read.get::<DataBase>().expect("Expected Config in TypeMap.").clone()
|
data_read.get::<DataBase>().expect("Expected Config in TypeMap.").clone()
|
||||||
};
|
};
|
||||||
|
let db = db_lock.read().await;
|
||||||
|
|
||||||
let config_lock = {
|
let config_lock = {
|
||||||
let data_read = ctx.data.read().await;
|
let data_read = ctx.data.read().await;
|
||||||
|
|
|
@ -12,13 +12,8 @@ use skynet_discord_bot::{
|
||||||
},
|
},
|
||||||
get_config, Config,
|
get_config, Config,
|
||||||
};
|
};
|
||||||
use std::{
|
use std::sync::atomic::{AtomicUsize, Ordering};
|
||||||
process,
|
use std::{process, sync::Arc};
|
||||||
sync::{
|
|
||||||
atomic::{AtomicUsize, Ordering},
|
|
||||||
Arc,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
use tokio::sync::RwLock;
|
use tokio::sync::RwLock;
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
|
@ -45,7 +40,7 @@ async fn main() {
|
||||||
let mut data = client.data.write().await;
|
let mut data = client.data.write().await;
|
||||||
|
|
||||||
data.insert::<Config>(Arc::new(RwLock::new(config)));
|
data.insert::<Config>(Arc::new(RwLock::new(config)));
|
||||||
data.insert::<DataBase>(Arc::new(db));
|
data.insert::<DataBase>(Arc::new(RwLock::new(db)));
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Err(why) = client.start().await {
|
if let Err(why) = client.start().await {
|
||||||
|
@ -84,11 +79,13 @@ impl EventHandler for Handler {
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn check_bulk(ctx: &Context) {
|
async fn check_bulk(ctx: &Context) {
|
||||||
let db = {
|
let db_lock = {
|
||||||
let data_read = ctx.data.read().await;
|
let data_read = ctx.data.read().await;
|
||||||
data_read.get::<DataBase>().expect("Expected Config in TypeMap.").clone()
|
data_read.get::<DataBase>().expect("Expected Config in TypeMap.").clone()
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let db = db_lock.read().await;
|
||||||
|
|
||||||
for server_config in get_server_config_bulk(&db).await {
|
for server_config in get_server_config_bulk(&db).await {
|
||||||
normal::update_server(ctx, &server_config, &[], &[]).await;
|
normal::update_server(ctx, &server_config, &[], &[]).await;
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,10 +56,11 @@ pub async fn run(command: &CommandInteraction, ctx: &Context) -> String {
|
||||||
return "Please provide a valid channel for ``Bot Channel``".to_string();
|
return "Please provide a valid channel for ``Bot Channel``".to_string();
|
||||||
};
|
};
|
||||||
|
|
||||||
let db = {
|
let db_lock = {
|
||||||
let data_read = ctx.data.read().await;
|
let data_read = ctx.data.read().await;
|
||||||
data_read.get::<DataBase>().expect("Expected Databse in TypeMap.").clone()
|
data_read.get::<DataBase>().expect("Expected Databse in TypeMap.").clone()
|
||||||
};
|
};
|
||||||
|
let db = db_lock.read().await;
|
||||||
|
|
||||||
let server_data = Servers {
|
let server_data = Servers {
|
||||||
server: command.guild_id.unwrap_or_default(),
|
server: command.guild_id.unwrap_or_default(),
|
||||||
|
@ -101,7 +102,7 @@ async fn add_server(db: &Pool<Sqlite>, ctx: &Context, server: &Servers) -> Resul
|
||||||
.fetch_optional(db)
|
.fetch_optional(db)
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
// if the entry does not exist already then do a user update
|
// if the entry does not exist already tehn do a user update
|
||||||
let (update, current_remove, current_role, past_remove, past_role) = match &existing {
|
let (update, current_remove, current_role, past_remove, past_role) = match &existing {
|
||||||
None => (true, false, None, false, None),
|
None => (true, false, None, false, None),
|
||||||
Some(x) => {
|
Some(x) => {
|
||||||
|
|
|
@ -27,10 +27,11 @@ pub mod committee {
|
||||||
false
|
false
|
||||||
};
|
};
|
||||||
|
|
||||||
let db = {
|
let db_lock = {
|
||||||
let data_read = ctx.data.read().await;
|
let data_read = ctx.data.read().await;
|
||||||
data_read.get::<DataBase>().expect("Expected Databse in TypeMap.").clone()
|
data_read.get::<DataBase>().expect("Expected Databse in TypeMap.").clone()
|
||||||
};
|
};
|
||||||
|
let db = db_lock.read().await;
|
||||||
|
|
||||||
let mut cs = vec![];
|
let mut cs = vec![];
|
||||||
// pull it from a DB
|
// pull it from a DB
|
||||||
|
@ -94,10 +95,11 @@ pub mod servers {
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
pub async fn run(_command: &CommandInteraction, ctx: &Context) -> String {
|
pub async fn run(_command: &CommandInteraction, ctx: &Context) -> String {
|
||||||
let db = {
|
let db_lock = {
|
||||||
let data_read = ctx.data.read().await;
|
let data_read = ctx.data.read().await;
|
||||||
data_read.get::<DataBase>().expect("Expected Databse in TypeMap.").clone()
|
data_read.get::<DataBase>().expect("Expected Databse in TypeMap.").clone()
|
||||||
};
|
};
|
||||||
|
let db = db_lock.read().await;
|
||||||
|
|
||||||
let mut committees = HashMap::new();
|
let mut committees = HashMap::new();
|
||||||
if let Some(x) = get_committees(&db).await {
|
if let Some(x) = get_committees(&db).await {
|
||||||
|
@ -150,7 +152,7 @@ pub mod servers {
|
||||||
|
|
||||||
let length = line.len() + 1;
|
let length = line.len() + 1;
|
||||||
|
|
||||||
// +3 is to account for the closing fence
|
// +3 is to account for the closing fense
|
||||||
if length < (limit + 3) {
|
if length < (limit + 3) {
|
||||||
response.push(line);
|
response.push(line);
|
||||||
limit -= length;
|
limit -= length;
|
||||||
|
|
|
@ -23,10 +23,11 @@ pub(crate) mod user {
|
||||||
use sqlx::Error;
|
use sqlx::Error;
|
||||||
|
|
||||||
pub async fn run(command: &CommandInteraction, ctx: &Context) -> String {
|
pub async fn run(command: &CommandInteraction, ctx: &Context) -> String {
|
||||||
let db = {
|
let db_lock = {
|
||||||
let data_read = ctx.data.read().await;
|
let data_read = ctx.data.read().await;
|
||||||
data_read.get::<DataBase>().expect("Expected Databse in TypeMap.").clone()
|
data_read.get::<DataBase>().expect("Expected Databse in TypeMap.").clone()
|
||||||
};
|
};
|
||||||
|
let db = db_lock.read().await;
|
||||||
|
|
||||||
let config_lock = {
|
let config_lock = {
|
||||||
let data_read = ctx.data.read().await;
|
let data_read = ctx.data.read().await;
|
||||||
|
@ -195,7 +196,7 @@ pub(crate) mod server {
|
||||||
model::id::GuildId,
|
model::id::GuildId,
|
||||||
};
|
};
|
||||||
use sqlx::Error;
|
use sqlx::Error;
|
||||||
// this is to manage 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::{
|
use skynet_discord_bot::{
|
||||||
common::minecraft::{update_server, Minecraft},
|
common::minecraft::{update_server, Minecraft},
|
||||||
|
@ -228,10 +229,11 @@ pub(crate) mod server {
|
||||||
return String::from("Expected Server ID");
|
return String::from("Expected Server ID");
|
||||||
};
|
};
|
||||||
|
|
||||||
let db = {
|
let db_lock = {
|
||||||
let data_read = ctx.data.read().await;
|
let data_read = ctx.data.read().await;
|
||||||
data_read.get::<DataBase>().expect("Expected Databse in TypeMap.").clone()
|
data_read.get::<DataBase>().expect("Expected Databse in TypeMap.").clone()
|
||||||
};
|
};
|
||||||
|
let db = db_lock.read().await;
|
||||||
|
|
||||||
match add_server(&db, &g_id, &server_minecraft).await {
|
match add_server(&db, &g_id, &server_minecraft).await {
|
||||||
Ok(_) => {}
|
Ok(_) => {}
|
||||||
|
@ -288,10 +290,11 @@ pub(crate) mod server {
|
||||||
Some(x) => x,
|
Some(x) => x,
|
||||||
};
|
};
|
||||||
|
|
||||||
let db = {
|
let db_lock = {
|
||||||
let data_read = ctx.data.read().await;
|
let data_read = ctx.data.read().await;
|
||||||
data_read.get::<DataBase>().expect("Expected Databse in TypeMap.").clone()
|
data_read.get::<DataBase>().expect("Expected Databse in TypeMap.").clone()
|
||||||
};
|
};
|
||||||
|
let db = db_lock.read().await;
|
||||||
|
|
||||||
let servers = get_minecraft_config_server(&db, g_id).await;
|
let servers = get_minecraft_config_server(&db, g_id).await;
|
||||||
|
|
||||||
|
@ -363,10 +366,11 @@ pub(crate) mod server {
|
||||||
return String::from("Expected Server ID");
|
return String::from("Expected Server ID");
|
||||||
};
|
};
|
||||||
|
|
||||||
let db = {
|
let db_lock = {
|
||||||
let data = ctx.data.read().await;
|
let data_read = ctx.data.read().await;
|
||||||
data.get::<DataBase>().expect("Expected Databse in TypeMap.").clone()
|
data_read.get::<DataBase>().expect("Expected Databse in TypeMap.").clone()
|
||||||
};
|
};
|
||||||
|
let db = db_lock.read().await;
|
||||||
|
|
||||||
match server_remove(&db, &g_id, &server_minecraft).await {
|
match server_remove(&db, &g_id, &server_minecraft).await {
|
||||||
Ok(_) => {}
|
Ok(_) => {}
|
||||||
|
|
|
@ -62,10 +62,11 @@ pub mod edit {
|
||||||
false
|
false
|
||||||
};
|
};
|
||||||
|
|
||||||
let db = {
|
let db_lock = {
|
||||||
let data_read = ctx.data.read().await;
|
let data_read = ctx.data.read().await;
|
||||||
data_read.get::<DataBase>().expect("Expected Databse in TypeMap.").clone()
|
data_read.get::<DataBase>().expect("Expected Databse in TypeMap.").clone()
|
||||||
};
|
};
|
||||||
|
let db = db_lock.read().await;
|
||||||
|
|
||||||
let server = command.guild_id.unwrap_or_default();
|
let server = command.guild_id.unwrap_or_default();
|
||||||
let server_data = RoleAdder {
|
let server_data = RoleAdder {
|
||||||
|
@ -146,7 +147,7 @@ pub mod tools {
|
||||||
use sqlx::{Pool, Sqlite};
|
use sqlx::{Pool, Sqlite};
|
||||||
|
|
||||||
pub async fn on_role_change(db: &Pool<Sqlite>, ctx: &Context, new_data: Member) {
|
pub async fn on_role_change(db: &Pool<Sqlite>, ctx: &Context, new_data: Member) {
|
||||||
// check if the role changed is part of the ones for this server
|
// check if the role changed is part of the oens for this server
|
||||||
if let Ok(role_adders) = sqlx::query_as::<_, RoleAdder>(
|
if let Ok(role_adders) = sqlx::query_as::<_, RoleAdder>(
|
||||||
r#"
|
r#"
|
||||||
SELECT *
|
SELECT *
|
||||||
|
@ -162,7 +163,7 @@ pub mod tools {
|
||||||
let mut roles_remove = vec![];
|
let mut roles_remove = vec![];
|
||||||
|
|
||||||
for role_adder in role_adders {
|
for role_adder in role_adders {
|
||||||
// if the user has both A and B give them C
|
// if the user has both A dnd B give them C
|
||||||
if new_data.roles.contains(&role_adder.role_a) && new_data.roles.contains(&role_adder.role_b) && !new_data.roles.contains(&role_adder.role_c)
|
if new_data.roles.contains(&role_adder.role_a) && new_data.roles.contains(&role_adder.role_b) && !new_data.roles.contains(&role_adder.role_c)
|
||||||
{
|
{
|
||||||
roles_add.push(role_adder.role_c);
|
roles_add.push(role_adder.role_c);
|
||||||
|
|
|
@ -18,10 +18,11 @@ pub(crate) mod admin {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
pub async fn run(_command: &CommandInteraction, ctx: &Context) -> String {
|
pub async fn run(_command: &CommandInteraction, ctx: &Context) -> String {
|
||||||
let db = {
|
let db_lock = {
|
||||||
let data_read = ctx.data.read().await;
|
let data_read = ctx.data.read().await;
|
||||||
data_read.get::<DataBase>().expect("Expected Databse in TypeMap.").clone()
|
data_read.get::<DataBase>().expect("Expected Databse in TypeMap.").clone()
|
||||||
};
|
};
|
||||||
|
let db = db_lock.read().await;
|
||||||
|
|
||||||
let config_lock = {
|
let config_lock = {
|
||||||
let data_read = ctx.data.read().await;
|
let data_read = ctx.data.read().await;
|
||||||
|
@ -68,10 +69,11 @@ pub(crate) mod user {
|
||||||
use sqlx::{Pool, Sqlite};
|
use sqlx::{Pool, Sqlite};
|
||||||
|
|
||||||
pub async fn run(command: &CommandInteraction, ctx: &Context) -> String {
|
pub async fn run(command: &CommandInteraction, ctx: &Context) -> String {
|
||||||
let db = {
|
let db_lock = {
|
||||||
let data_read = ctx.data.read().await;
|
let data_read = ctx.data.read().await;
|
||||||
data_read.get::<DataBase>().expect("Expected Databse in TypeMap.").clone()
|
data_read.get::<DataBase>().expect("Expected Databse in TypeMap.").clone()
|
||||||
};
|
};
|
||||||
|
let db = db_lock.read().await;
|
||||||
|
|
||||||
let config_toml = get_config_icons::minimal();
|
let config_toml = get_config_icons::minimal();
|
||||||
|
|
||||||
|
@ -143,10 +145,11 @@ pub(crate) mod user {
|
||||||
use sqlx::{Pool, Sqlite};
|
use sqlx::{Pool, Sqlite};
|
||||||
|
|
||||||
pub async fn run(_command: &CommandInteraction, ctx: &Context) -> String {
|
pub async fn run(_command: &CommandInteraction, ctx: &Context) -> String {
|
||||||
let db = {
|
let db_lock = {
|
||||||
let data_read = ctx.data.read().await;
|
let data_read = ctx.data.read().await;
|
||||||
data_read.get::<DataBase>().expect("Expected Databse in TypeMap.").clone()
|
data_read.get::<DataBase>().expect("Expected Databse in TypeMap.").clone()
|
||||||
};
|
};
|
||||||
|
let db = db_lock.read().await;
|
||||||
|
|
||||||
let config_toml = get_config_icons::minimal();
|
let config_toml = get_config_icons::minimal();
|
||||||
|
|
||||||
|
@ -208,7 +211,7 @@ pub(crate) mod user {
|
||||||
|
|
||||||
let length = line.len() + 1;
|
let length = line.len() + 1;
|
||||||
|
|
||||||
// +3 is to account for the closing fence
|
// +3 is to account for the closing fense
|
||||||
if length < (limit + 3) {
|
if length < (limit + 3) {
|
||||||
response.push(line);
|
response.push(line);
|
||||||
limit -= length;
|
limit -= length;
|
||||||
|
|
|
@ -21,10 +21,11 @@ pub mod link {
|
||||||
use serenity::all::{CommandDataOption, CommandDataOptionValue, CommandInteraction};
|
use serenity::all::{CommandDataOption, CommandDataOptionValue, CommandInteraction};
|
||||||
|
|
||||||
pub async fn run(command: &CommandInteraction, ctx: &Context) -> String {
|
pub async fn run(command: &CommandInteraction, ctx: &Context) -> String {
|
||||||
let db = {
|
let db_lock = {
|
||||||
let data_read = ctx.data.read().await;
|
let data_read = ctx.data.read().await;
|
||||||
data_read.get::<DataBase>().expect("Expected Databse in TypeMap.").clone()
|
data_read.get::<DataBase>().expect("Expected Databse in TypeMap.").clone()
|
||||||
};
|
};
|
||||||
|
let db = db_lock.read().await;
|
||||||
|
|
||||||
let config_lock = {
|
let config_lock = {
|
||||||
let data_read = ctx.data.read().await;
|
let data_read = ctx.data.read().await;
|
||||||
|
@ -100,7 +101,7 @@ pub mod link {
|
||||||
return "Email already verified".to_string();
|
return "Email already verified".to_string();
|
||||||
}
|
}
|
||||||
|
|
||||||
// generate an auth key
|
// generate a auth key
|
||||||
let auth = random_string(20);
|
let auth = random_string(20);
|
||||||
match send_mail(&config, &details.email, &auth, &command.user.name) {
|
match send_mail(&config, &details.email, &auth, &command.user.name) {
|
||||||
Ok(_) => match save_to_db(&db, &details, &auth, &command.user.id).await {
|
Ok(_) => match save_to_db(&db, &details, &auth, &command.user.id).await {
|
||||||
|
@ -209,7 +210,7 @@ pub mod link {
|
||||||
.subject("Skynet: Link Discord to Wolves.")
|
.subject("Skynet: Link Discord to Wolves.")
|
||||||
.multipart(
|
.multipart(
|
||||||
// This is composed of two parts.
|
// This is composed of two parts.
|
||||||
// also helps not trip spam settings (uneven number of urls)
|
// also helps not trip spam settings (uneven number of url's
|
||||||
MultiPart::alternative()
|
MultiPart::alternative()
|
||||||
.singlepart(SinglePart::builder().header(header::ContentType::TEXT_PLAIN).body(body_text))
|
.singlepart(SinglePart::builder().header(header::ContentType::TEXT_PLAIN).body(body_text))
|
||||||
.singlepart(SinglePart::builder().header(header::ContentType::TEXT_HTML).body(html.into_string())),
|
.singlepart(SinglePart::builder().header(header::ContentType::TEXT_HTML).body(html.into_string())),
|
||||||
|
@ -313,10 +314,11 @@ pub mod verify {
|
||||||
use sqlx::Error;
|
use sqlx::Error;
|
||||||
|
|
||||||
pub async fn run(command: &CommandInteraction, ctx: &Context) -> String {
|
pub async fn run(command: &CommandInteraction, ctx: &Context) -> String {
|
||||||
let db = {
|
let db_lock = {
|
||||||
let data_read = ctx.data.read().await;
|
let data_read = ctx.data.read().await;
|
||||||
data_read.get::<DataBase>().expect("Expected Database in TypeMap.").clone()
|
data_read.get::<DataBase>().expect("Expected Database in TypeMap.").clone()
|
||||||
};
|
};
|
||||||
|
let db = db_lock.read().await;
|
||||||
|
|
||||||
// check if user has used /link_wolves
|
// check if user has used /link_wolves
|
||||||
let details = if let Some(x) = get_verify_from_db(&db, &command.user.id).await {
|
let details = if let Some(x) = get_verify_from_db(&db, &command.user.id).await {
|
||||||
|
@ -458,7 +460,7 @@ pub mod verify {
|
||||||
let config = config_lock.read().await;
|
let config = config_lock.read().await;
|
||||||
|
|
||||||
if let Some(x) = get_server_member_discord(db, &discord.id).await {
|
if let Some(x) = get_server_member_discord(db, &discord.id).await {
|
||||||
// if they are a member of one or more committees, and in teh committee server then give them the general committee role
|
// if they are a member of one or more committees, and in teh committee server then give the teh general committee role
|
||||||
// they will get teh more specific vanity role later
|
// they will get teh more specific vanity role later
|
||||||
if !get_committees_id(db, x.id_wolves).await.is_empty() {
|
if !get_committees_id(db, x.id_wolves).await.is_empty() {
|
||||||
let server = config.committee_server;
|
let server = config.committee_server;
|
||||||
|
@ -492,12 +494,13 @@ pub mod unlink {
|
||||||
use sqlx::{Pool, Sqlite};
|
use sqlx::{Pool, Sqlite};
|
||||||
|
|
||||||
pub async fn run(command: &CommandInteraction, ctx: &Context) -> String {
|
pub async fn run(command: &CommandInteraction, ctx: &Context) -> String {
|
||||||
let db = {
|
let db_lock = {
|
||||||
let data_read = ctx.data.read().await;
|
let data_read = ctx.data.read().await;
|
||||||
data_read.get::<DataBase>().expect("Expected Databse in TypeMap.").clone()
|
data_read.get::<DataBase>().expect("Expected Databse in TypeMap.").clone()
|
||||||
};
|
};
|
||||||
|
let db = db_lock.read().await;
|
||||||
|
|
||||||
// doesn't matter if there is one or not, it will be removed regardless
|
// dosent matter if there is one or not, it will be removed regardless
|
||||||
delete_link(&db, &command.user.id).await;
|
delete_link(&db, &command.user.id).await;
|
||||||
|
|
||||||
"Discord link removed".to_string()
|
"Discord link removed".to_string()
|
||||||
|
|
|
@ -12,10 +12,11 @@ use sqlx::{
|
||||||
Error, FromRow, Pool, Row, Sqlite,
|
Error, FromRow, Pool, Row, Sqlite,
|
||||||
};
|
};
|
||||||
use std::{str::FromStr, sync::Arc};
|
use std::{str::FromStr, sync::Arc};
|
||||||
|
use tokio::sync::RwLock;
|
||||||
|
|
||||||
pub struct DataBase;
|
pub struct DataBase;
|
||||||
impl TypeMapKey for DataBase {
|
impl TypeMapKey for DataBase {
|
||||||
type Value = Arc<Pool<Sqlite>>;
|
type Value = Arc<RwLock<Pool<Sqlite>>>;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Deserialize, Serialize)]
|
#[derive(Debug, Clone, Deserialize, Serialize)]
|
||||||
|
|
|
@ -24,7 +24,7 @@ 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
|
||||||
and a list that aren't members
|
and a list that arent members
|
||||||
*/
|
*/
|
||||||
pub async fn update_server(server_id: &str, db: &Pool<Sqlite>, g_id: &GuildId, config: &Config) {
|
pub async fn update_server(server_id: &str, db: &Pool<Sqlite>, g_id: &GuildId, config: &Config) {
|
||||||
let mut usernames = vec![];
|
let mut usernames = vec![];
|
||||||
|
@ -109,7 +109,7 @@ pub async fn whitelist_wipe(server: &str, token: &str) {
|
||||||
};
|
};
|
||||||
post(&format!("{url_base}/files/delete"), &bearer, &deletion).await;
|
post(&format!("{url_base}/files/delete"), &bearer, &deletion).await;
|
||||||
|
|
||||||
// recreate the file, passing in the type here so the compiler knows what type of Vec it is
|
// recreate teh file, passing in the type here so the compiler knows what type of vec it is
|
||||||
post::<Vec<&str>>(&format!("{url_base}/files/write?file=%2Fwhitelist.json"), &bearer, &vec![]).await;
|
post::<Vec<&str>>(&format!("{url_base}/files/write?file=%2Fwhitelist.json"), &bearer, &vec![]).await;
|
||||||
|
|
||||||
// reload the whitelist
|
// reload the whitelist
|
||||||
|
|
|
@ -1,11 +1,12 @@
|
||||||
// this code is taken from https://github.com/MCorange99/svg2colored-png/tree/main
|
// this code is taken from https://github.com/MCorange99/svg2colored-png/tree/main
|
||||||
// I was unable to figure out how to use usvg myself so yoinked it from here.
|
// I was unable to figure out how to use usvg myself so younked it from here.
|
||||||
|
|
||||||
use std::{
|
use std::{
|
||||||
ffi::OsStr,
|
ffi::OsStr,
|
||||||
path::{Path, PathBuf},
|
path::{Path, PathBuf},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// use clap::builder::OsStr;
|
||||||
use color_eyre::{eyre::bail, Result};
|
use color_eyre::{eyre::bail, Result};
|
||||||
use usvg_text_layout::TreeTextToPath;
|
use usvg_text_layout::TreeTextToPath;
|
||||||
|
|
||||||
|
@ -16,7 +17,7 @@ pub struct Args {
|
||||||
/// Output folder where the PNG's will be placed
|
/// Output folder where the PNG's will be placed
|
||||||
pub output: PathBuf,
|
pub output: PathBuf,
|
||||||
|
|
||||||
/// Comma separated colors that will be used in HEX Eg. 000000,ffffff
|
/// Comma seperated colors that will be used in HEX Eg. 000000,ffffff
|
||||||
/// Can be like an object: black:000000,white:ffffff
|
/// Can be like an object: black:000000,white:ffffff
|
||||||
pub colors: String,
|
pub colors: String,
|
||||||
|
|
||||||
|
|
|
@ -281,7 +281,7 @@ pub mod update_icon {
|
||||||
|
|
||||||
// check if exists
|
// check if exists
|
||||||
if !path_new.exists() {
|
if !path_new.exists() {
|
||||||
// convert if it hasn't been converted already
|
// convert if it hasnt been converted already
|
||||||
match r.render(&path_local, &args) {
|
match r.render(&path_local, &args) {
|
||||||
Ok(_) => {}
|
Ok(_) => {}
|
||||||
Err(_e) => {
|
Err(_e) => {
|
||||||
|
|
|
@ -17,11 +17,13 @@ pub mod normal {
|
||||||
}
|
}
|
||||||
|
|
||||||
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 = {
|
let db_lock = {
|
||||||
let data_read = ctx.data.read().await;
|
let data_read = ctx.data.read().await;
|
||||||
data_read.get::<DataBase>().expect("Expected Database in TypeMap.").clone()
|
data_read.get::<DataBase>().expect("Expected Database in TypeMap.").clone()
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let db = db_lock.read().await;
|
||||||
|
|
||||||
let Servers {
|
let Servers {
|
||||||
server,
|
server,
|
||||||
role_past,
|
role_past,
|
||||||
|
@ -46,7 +48,7 @@ pub mod normal {
|
||||||
|
|
||||||
if let Ok(x) = server.members(ctx, None, None).await {
|
if let Ok(x) = server.members(ctx, None, None).await {
|
||||||
for member in x {
|
for member in x {
|
||||||
// members_changed acts as an override to only deal with the users in it
|
// members_changed acts as an override to only deal with teh users in it
|
||||||
if !members_changed.is_empty() && !members_changed.contains(&member.user.id) {
|
if !members_changed.is_empty() && !members_changed.contains(&member.user.id) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -82,7 +84,7 @@ pub mod normal {
|
||||||
|
|
||||||
if member.roles.contains(role_current) {
|
if member.roles.contains(role_current) {
|
||||||
roles_set.current_rem += 1;
|
roles_set.current_rem += 1;
|
||||||
// if they're not a current member and have the role then remove it
|
// if theya re not a current member and have the role then remove it
|
||||||
if let Err(e) = member.remove_role(ctx, role_current).await {
|
if let Err(e) = member.remove_role(ctx, role_current).await {
|
||||||
println!("{e:?}");
|
println!("{e:?}");
|
||||||
}
|
}
|
||||||
|
@ -172,11 +174,13 @@ pub mod committee {
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
pub async fn check_committee(ctx: &Context) {
|
pub async fn check_committee(ctx: &Context) {
|
||||||
let db = {
|
let db_lock = {
|
||||||
let data_read = ctx.data.read().await;
|
let data_read = ctx.data.read().await;
|
||||||
data_read.get::<DataBase>().expect("Expected Config in TypeMap.").clone()
|
data_read.get::<DataBase>().expect("Expected Config in TypeMap.").clone()
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let db = db_lock.read().await;
|
||||||
|
|
||||||
let config_lock = {
|
let config_lock = {
|
||||||
let data_read = ctx.data.read().await;
|
let data_read = ctx.data.read().await;
|
||||||
data_read.get::<Config>().expect("Expected Config in TypeMap.").clone()
|
data_read.get::<Config>().expect("Expected Config in TypeMap.").clone()
|
||||||
|
@ -192,7 +196,7 @@ pub mod committee {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
This function can take a Vec of members (or just one) and gives them the appropriate roles on teh committee server
|
This function can take a vec of members (or just one) and gives tehm the appropiate roles on teh committee server
|
||||||
*/
|
*/
|
||||||
pub async fn update_committees(db: &Pool<Sqlite>, ctx: &Context, config: &Config, members: &mut Vec<Member>) {
|
pub async fn update_committees(db: &Pool<Sqlite>, ctx: &Context, config: &Config, members: &mut Vec<Member>) {
|
||||||
let server = config.committee_server;
|
let server = config.committee_server;
|
||||||
|
@ -224,11 +228,11 @@ pub mod committee {
|
||||||
|
|
||||||
let mut channels = server.channels(&ctx).await.unwrap_or_default();
|
let mut channels = server.channels(&ctx).await.unwrap_or_default();
|
||||||
|
|
||||||
// a map of users and the roles they are going 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();
|
||||||
|
|
||||||
let mut re_order = false;
|
let mut re_order = false;
|
||||||
// we need to create roles and channels if they don't already exist
|
// we need to create roles and channels if tehy dont already exist
|
||||||
let mut category_index = 0;
|
let mut category_index = 0;
|
||||||
let mut i = 0;
|
let mut i = 0;
|
||||||
loop {
|
loop {
|
||||||
|
@ -363,7 +367,7 @@ pub mod committee {
|
||||||
let has_committee_role = roles_current_id.contains(&committee_member);
|
let has_committee_role = roles_current_id.contains(&committee_member);
|
||||||
|
|
||||||
if on_committee && !has_committee_role {
|
if on_committee && !has_committee_role {
|
||||||
// if there are committee roles then give the general purpose role
|
// if there are committee roles then give the general purporse role
|
||||||
roles_add.push(committee_member);
|
roles_add.push(committee_member);
|
||||||
}
|
}
|
||||||
if !on_committee && has_committee_role {
|
if !on_committee && has_committee_role {
|
||||||
|
|
|
@ -69,10 +69,11 @@ pub mod cns {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn get_wolves(ctx: &Context) {
|
pub async fn get_wolves(ctx: &Context) {
|
||||||
let db = {
|
let db_lock = {
|
||||||
let data_read = ctx.data.read().await;
|
let data_read = ctx.data.read().await;
|
||||||
data_read.get::<DataBase>().expect("Expected Database in TypeMap.").clone()
|
data_read.get::<DataBase>().expect("Expected Database in TypeMap.").clone()
|
||||||
};
|
};
|
||||||
|
let db = db_lock.read().await;
|
||||||
|
|
||||||
let config_lock = {
|
let config_lock = {
|
||||||
let data_read = ctx.data.read().await;
|
let data_read = ctx.data.read().await;
|
||||||
|
@ -223,10 +224,11 @@ pub mod committees {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn get_cns(ctx: &Context) {
|
pub async fn get_cns(ctx: &Context) {
|
||||||
let db = {
|
let db_lock = {
|
||||||
let data_read = ctx.data.read().await;
|
let data_read = ctx.data.read().await;
|
||||||
data_read.get::<DataBase>().expect("Expected Database in TypeMap.").clone()
|
data_read.get::<DataBase>().expect("Expected Database in TypeMap.").clone()
|
||||||
};
|
};
|
||||||
|
let db = db_lock.read().await;
|
||||||
|
|
||||||
let config_lock = {
|
let config_lock = {
|
||||||
let data_read = ctx.data.read().await;
|
let data_read = ctx.data.read().await;
|
||||||
|
|
|
@ -36,7 +36,7 @@ pub struct Config {
|
||||||
pub committee_role: RoleId,
|
pub committee_role: RoleId,
|
||||||
pub committee_category: Vec<ChannelId>,
|
pub committee_category: Vec<ChannelId>,
|
||||||
|
|
||||||
// items pertaining to CompSoc only
|
// items pertaining to compsoc only
|
||||||
pub compsoc_server: GuildId,
|
pub compsoc_server: GuildId,
|
||||||
}
|
}
|
||||||
impl TypeMapKey for Config {
|
impl TypeMapKey for Config {
|
||||||
|
|
19
src/main.rs
19
src/main.rs
|
@ -27,6 +27,7 @@ use sqlx::{Pool, Sqlite};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use tokio::sync::RwLock;
|
use tokio::sync::RwLock;
|
||||||
|
|
||||||
|
// Need To Define The Stuct (Committed To Bump The Bot)
|
||||||
struct Handler;
|
struct Handler;
|
||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
|
@ -41,11 +42,13 @@ impl EventHandler for Handler {
|
||||||
|
|
||||||
// handles previously linked accounts joining the server
|
// handles previously linked accounts joining the server
|
||||||
async fn guild_member_addition(&self, ctx: Context, new_member: Member) {
|
async fn guild_member_addition(&self, ctx: Context, new_member: Member) {
|
||||||
let db = {
|
let db_lock = {
|
||||||
let data_read = ctx.data.read().await;
|
let data_read = ctx.data.read().await;
|
||||||
data_read.get::<DataBase>().expect("Expected Config in TypeMap.").clone()
|
data_read.get::<DataBase>().expect("Expected Config in TypeMap.").clone()
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let db = db_lock.read().await;
|
||||||
|
|
||||||
let config_lock = {
|
let config_lock = {
|
||||||
let data_read = ctx.data.read().await;
|
let data_read = ctx.data.read().await;
|
||||||
data_read.get::<Config>().expect("Expected Config in TypeMap.").clone()
|
data_read.get::<Config>().expect("Expected Config in TypeMap.").clone()
|
||||||
|
@ -107,12 +110,14 @@ Sign up on [UL Wolves]({}) and go to https://discord.com/channels/{}/{} and use
|
||||||
// handles role updates
|
// handles role updates
|
||||||
async fn guild_member_update(&self, ctx: Context, _old_data: Option<Member>, new_data: Option<Member>, _: GuildMemberUpdateEvent) {
|
async fn guild_member_update(&self, ctx: Context, _old_data: Option<Member>, new_data: Option<Member>, _: GuildMemberUpdateEvent) {
|
||||||
// get config/db
|
// get config/db
|
||||||
let db = {
|
let db_lock = {
|
||||||
let data_read = ctx.data.read().await;
|
let data_read = ctx.data.read().await;
|
||||||
data_read.get::<DataBase>().expect("Expected Config in TypeMap.").clone()
|
data_read.get::<DataBase>().expect("Expected Config in TypeMap.").clone()
|
||||||
};
|
};
|
||||||
|
|
||||||
// check if the role changed is part of the ones for this server
|
let db = db_lock.read().await;
|
||||||
|
|
||||||
|
// check if the role changed is part of the oens for this server
|
||||||
if let Some(x) = new_data {
|
if let Some(x) = new_data {
|
||||||
on_role_change(&db, &ctx, x).await;
|
on_role_change(&db, &ctx, x).await;
|
||||||
}
|
}
|
||||||
|
@ -154,13 +159,13 @@ Sign up on [UL Wolves]({}) and go to https://discord.com/channels/{}/{} and use
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// CompSoc Server
|
// compsoc Server
|
||||||
match config
|
match config
|
||||||
.compsoc_server
|
.compsoc_server
|
||||||
.set_commands(
|
.set_commands(
|
||||||
&ctx.http,
|
&ctx.http,
|
||||||
vec![
|
vec![
|
||||||
// commands just for the CompSoc server
|
// commands just for the compsoc server
|
||||||
commands::count::servers::register(),
|
commands::count::servers::register(),
|
||||||
commands::server_icon::user::register(),
|
commands::server_icon::user::register(),
|
||||||
],
|
],
|
||||||
|
@ -177,7 +182,7 @@ Sign up on [UL Wolves]({}) and go to https://discord.com/channels/{}/{} and use
|
||||||
async fn interaction_create(&self, ctx: Context, interaction: Interaction) {
|
async fn interaction_create(&self, ctx: Context, interaction: Interaction) {
|
||||||
if let Interaction::Command(command) = interaction {
|
if let Interaction::Command(command) = interaction {
|
||||||
let _ = command.defer_ephemeral(&ctx.http).await;
|
let _ = command.defer_ephemeral(&ctx.http).await;
|
||||||
// println!("Received command interaction: {:#?}", command);
|
//println!("Received command interaction: {:#?}", command);
|
||||||
|
|
||||||
let content = match command.data.name.as_str() {
|
let content = match command.data.name.as_str() {
|
||||||
// user commands
|
// user commands
|
||||||
|
@ -300,7 +305,7 @@ async fn main() {
|
||||||
let mut data = client.data.write().await;
|
let mut data = client.data.write().await;
|
||||||
|
|
||||||
data.insert::<Config>(Arc::new(RwLock::new(config)));
|
data.insert::<Config>(Arc::new(RwLock::new(config)));
|
||||||
data.insert::<DataBase>(Arc::new(db));
|
data.insert::<DataBase>(Arc::new(RwLock::new(db)));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Finally, start a single shard, and start listening to events.
|
// Finally, start a single shard, and start listening to events.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue