forked from Skynet/discord-bot
feat: updated command to get the extra information on signup
This commit is contained in:
parent
d3a975a1d1
commit
8d1c6b1bd1
1 changed files with 73 additions and 2 deletions
|
@ -51,6 +51,50 @@ pub async fn run(command: &ApplicationCommandInteraction, ctx: &Context) -> Stri
|
|||
}
|
||||
};
|
||||
|
||||
|
||||
let bot_channel_id = if let CommandDataOptionValue::Channel(channel) = command
|
||||
.data
|
||||
.options
|
||||
.get(3)
|
||||
.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(4)
|
||||
.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(5)
|
||||
.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 +108,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 {
|
||||
|
@ -102,6 +149,27 @@ pub fn register(command: &mut CreateApplicationCommand) -> &mut CreateApplicatio
|
|||
.kind(CommandOptionType::Role)
|
||||
.required(false)
|
||||
})
|
||||
.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(false)
|
||||
})
|
||||
.create_option(|option| {
|
||||
option
|
||||
.name("wolves_link")
|
||||
.description("Link to the Club/Society on UL Wolves.")
|
||||
.kind(CommandOptionType::String)
|
||||
.required(false)
|
||||
})
|
||||
}
|
||||
|
||||
async fn add_server(db: &Pool<Sqlite>, ctx: &Context, server: &Servers) -> Result<Option<Servers>, Error> {
|
||||
|
@ -111,14 +179,17 @@ async fn add_server(db: &Pool<Sqlite>, ctx: &Context, server: &Servers) -> Resul
|
|||
|
||||
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.bot_channel_id.as_u64() as i64)
|
||||
.bind(&server.server_name)
|
||||
.bind(&server.wolves_link)
|
||||
.fetch_optional(db)
|
||||
.await;
|
||||
|
||||
|
|
Loading…
Reference in a new issue