Merge branch 'main' into #17-automate-onboarding-mk-ii
# Conflicts: # .gitignore # src/commands/committee.rs
This commit is contained in:
commit
b2d8238c17
12 changed files with 447 additions and 47 deletions
|
@ -39,18 +39,60 @@ pub async fn run(command: &ApplicationCommandInteraction, ctx: &Context) -> Stri
|
|||
.as_ref()
|
||||
.expect("Expected role object")
|
||||
{
|
||||
Some(role.id.to_owned())
|
||||
role.id.to_owned()
|
||||
} else {
|
||||
return "Please provide a valid role for ``Role Current``".to_string();
|
||||
};
|
||||
|
||||
let mut role_past = None;
|
||||
if let Some(x) = command.data.options.get(2) {
|
||||
if let Some(x) = command.data.options.get(5) {
|
||||
if let Some(CommandDataOptionValue::Role(role)) = &x.resolved {
|
||||
role_past = Some(role.id.to_owned());
|
||||
}
|
||||
};
|
||||
|
||||
let bot_channel_id = if let CommandDataOptionValue::Channel(channel) = command
|
||||
.data
|
||||
.options
|
||||
.get(2)
|
||||
.expect("Expected channel option")
|
||||
.resolved
|
||||
.as_ref()
|
||||
.expect("Expected channel object")
|
||||
{
|
||||
channel.id.to_owned()
|
||||
} else {
|
||||
return "Please provide a valid channel for ``Bot Channel``".to_string();
|
||||
};
|
||||
|
||||
let server_name = if let CommandDataOptionValue::String(name) = command
|
||||
.data
|
||||
.options
|
||||
.get(3)
|
||||
.expect("Expected Server Name option")
|
||||
.resolved
|
||||
.as_ref()
|
||||
.expect("Expected Server Name object")
|
||||
{
|
||||
name
|
||||
} else {
|
||||
&"UL Computer Society".to_string()
|
||||
};
|
||||
|
||||
let wolves_link = if let CommandDataOptionValue::String(wolves) = command
|
||||
.data
|
||||
.options
|
||||
.get(4)
|
||||
.expect("Expected Wolves Link option")
|
||||
.resolved
|
||||
.as_ref()
|
||||
.expect("Expected Server Name object")
|
||||
{
|
||||
wolves
|
||||
} else {
|
||||
&"https://ulwolves.ie/society/computer".to_string()
|
||||
};
|
||||
|
||||
let db_lock = {
|
||||
let data_read = ctx.data.read().await;
|
||||
data_read.get::<DataBase>().expect("Expected Databse in TypeMap.").clone()
|
||||
|
@ -64,6 +106,9 @@ pub async fn run(command: &ApplicationCommandInteraction, ctx: &Context) -> Stri
|
|||
role_current,
|
||||
member_past: 0,
|
||||
member_current: 0,
|
||||
bot_channel_id,
|
||||
server_name: server_name.to_owned(),
|
||||
wolves_link: wolves_link.to_string(),
|
||||
};
|
||||
|
||||
match add_server(&db, ctx, &server_data).await {
|
||||
|
@ -95,6 +140,27 @@ pub fn register(command: &mut CreateApplicationCommand) -> &mut CreateApplicatio
|
|||
.kind(CommandOptionType::Role)
|
||||
.required(true)
|
||||
})
|
||||
.create_option(|option| {
|
||||
option
|
||||
.name("bot_channel")
|
||||
.description("Safe space for folks to use the bot commands.")
|
||||
.kind(CommandOptionType::Channel)
|
||||
.required(true)
|
||||
})
|
||||
.create_option(|option| {
|
||||
option
|
||||
.name("server_name")
|
||||
.description("Name of the Discord Server.")
|
||||
.kind(CommandOptionType::String)
|
||||
.required(true)
|
||||
})
|
||||
.create_option(|option| {
|
||||
option
|
||||
.name("wolves_link")
|
||||
.description("Link to the Club/Society on UL Wolves.")
|
||||
.kind(CommandOptionType::String)
|
||||
.required(true)
|
||||
})
|
||||
.create_option(|option| {
|
||||
option
|
||||
.name("role_past")
|
||||
|
@ -107,18 +173,20 @@ pub fn register(command: &mut CreateApplicationCommand) -> &mut CreateApplicatio
|
|||
async fn add_server(db: &Pool<Sqlite>, ctx: &Context, server: &Servers) -> Result<Option<Servers>, Error> {
|
||||
let existing = get_server_config(db, &server.server).await;
|
||||
let role_past = server.role_past.map(|x| *x.as_u64() as i64);
|
||||
let role_current = server.role_current.map(|x| *x.as_u64() as i64);
|
||||
|
||||
let insert = sqlx::query_as::<_, Servers>(
|
||||
"
|
||||
INSERT OR REPLACE INTO servers (server, wolves_api, role_past, role_current)
|
||||
VALUES (?1, ?2, ?3, ?4)
|
||||
INSERT OR REPLACE INTO servers (server, wolves_api, role_past, role_current, bot_channel_id, server_name, wolves_link)
|
||||
VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7)
|
||||
",
|
||||
)
|
||||
.bind(*server.server.as_u64() as i64)
|
||||
.bind(&server.wolves_api)
|
||||
.bind(role_past)
|
||||
.bind(role_current)
|
||||
.bind(*server.role_current.as_u64() as i64)
|
||||
.bind(*server.bot_channel_id.as_u64() as i64)
|
||||
.bind(&server.server_name)
|
||||
.bind(&server.wolves_link)
|
||||
.fetch_optional(db)
|
||||
.await;
|
||||
|
||||
|
@ -133,7 +201,7 @@ async fn add_server(db: &Pool<Sqlite>, ctx: &Context, server: &Servers) -> Resul
|
|||
if x.role_current != server.role_current {
|
||||
result.0 = true;
|
||||
result.1 = true;
|
||||
result.2 = x.role_current;
|
||||
result.2 = Some(x.role_current);
|
||||
}
|
||||
if x.role_past != server.role_past {
|
||||
result.0 = true;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue