feat: send new members instructions to link wolves #19
4 changed files with 22 additions and 33 deletions
|
@ -39,7 +39,7 @@ 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();
|
||||
};
|
||||
|
@ -175,7 +175,6 @@ 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>(
|
||||
"
|
||||
|
@ -186,7 +185,7 @@ async fn add_server(db: &Pool<Sqlite>, ctx: &Context, server: &Servers) -> Resul
|
|||
.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)
|
||||
|
@ -204,7 +203,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;
|
||||
|
|
|
@ -352,10 +352,8 @@ pub mod verify {
|
|||
}
|
||||
}
|
||||
|
||||
if let Some(role) = &role_current {
|
||||
if !member.roles.contains(role) {
|
||||
roles.push(role.to_owned());
|
||||
}
|
||||
if !member.roles.contains(&role_current) {
|
||||
roles.push(role_current.to_owned());
|
||||
}
|
||||
|
||||
if let Err(e) = member.add_roles(&ctx, &roles).await {
|
||||
|
|
36
src/lib.rs
36
src/lib.rs
|
@ -228,8 +228,7 @@ pub struct Servers {
|
|||
pub server: GuildId,
|
||||
pub wolves_api: String,
|
||||
pub role_past: Option<RoleId>,
|
||||
// TODO: this should not be option
|
||||
pub role_current: Option<RoleId>,
|
||||
pub role_current: RoleId,
|
||||
pub member_past: i64,
|
||||
pub member_current: i64,
|
||||
pub bot_channel_id: ChannelId,
|
||||
|
@ -255,13 +254,9 @@ impl<'r> FromRow<'r, SqliteRow> for Servers {
|
|||
let role_current = match row.try_get("role_current") {
|
||||
Ok(x) => {
|
||||
let tmp: i64 = x;
|
||||
if tmp == 0 {
|
||||
None
|
||||
} else {
|
||||
Some(RoleId::from(tmp as u64))
|
||||
}
|
||||
}
|
||||
_ => None,
|
||||
RoleId::from(tmp as u64)
|
||||
}
|
||||
_ => RoleId::from(0u64),
|
||||
};
|
||||
|
||||
let bot_channel_tmp: i64 = row.try_get("bot_channel_id")?;
|
||||
|
@ -414,13 +409,13 @@ pub mod set_roles {
|
|||
}
|
||||
}
|
||||
|
||||
if let Some(role) = &role_current {
|
||||
if !member.roles.contains(role) {
|
||||
roles_set[1] += 1;
|
||||
roles.push(role.to_owned());
|
||||
}
|
||||
|
||||
if !member.roles.contains(role_current) {
|
||||
roles_set[1] += 1;
|
||||
roles.push(role_current.to_owned());
|
||||
}
|
||||
|
||||
|
||||
if let Err(e) = member.add_roles(ctx, &roles).await {
|
||||
println!("{:?}", e);
|
||||
}
|
||||
|
@ -433,13 +428,12 @@ pub mod set_roles {
|
|||
}
|
||||
}
|
||||
|
||||
if let Some(role) = &role_current {
|
||||
if member.roles.contains(role) {
|
||||
roles_set[2] += 1;
|
||||
// if theya re not a current member and have the role then remove it
|
||||
if let Err(e) = member.remove_role(ctx, role).await {
|
||||
println!("{:?}", e);
|
||||
}
|
||||
|
||||
if member.roles.contains(role_current) {
|
||||
roles_set[2] += 1;
|
||||
// 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 {
|
||||
println!("{:?}", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -42,10 +42,8 @@ impl EventHandler for Handler {
|
|||
}
|
||||
}
|
||||
|
||||
if let Some(role) = &config.role_current {
|
||||
if !new_member.roles.contains(role) {
|
||||
roles.push(role.to_owned());
|
||||
}
|
||||
if !new_member.roles.contains(&config.role_current) {
|
||||
roles.push(config.role_current.to_owned());
|
||||
}
|
||||
|
||||
if let Err(e) = new_member.add_roles(&ctx, &roles).await {
|
||||
|
|
Loading…
Reference in a new issue