forked from Skynet/discord-bot
feat: updated teh bot to use the new wolves_id for clubs/socs
This commit is contained in:
parent
9ce5b8136b
commit
6481fcb89f
5 changed files with 21 additions and 15 deletions
6
db/migrations/9_member_committee-id.sql
Normal file
6
db/migrations/9_member_committee-id.sql
Normal file
|
@ -0,0 +1,6 @@
|
|||
-- No need for this col since it is goign to be in "committees" anyways
|
||||
ALTER TABLE servers DROP COLUMN server_name;
|
||||
|
||||
-- we do care about teh ID of the club/soc though
|
||||
ALTER TABLE servers ADD COLUMN wolves_id integer DEFAULT 0;
|
||||
|
|
@ -61,12 +61,12 @@ pub async fn run(command: &CommandInteraction, ctx: &Context) -> String {
|
|||
let server_data = Servers {
|
||||
server: command.guild_id.unwrap_or_default(),
|
||||
wolves_api,
|
||||
wolves_id: 0,
|
||||
role_past,
|
||||
role_current,
|
||||
member_past: 0,
|
||||
member_current: 0,
|
||||
bot_channel_id,
|
||||
server_name: "".to_string(),
|
||||
};
|
||||
|
||||
match add_server(&db, ctx, &server_data).await {
|
||||
|
|
|
@ -121,12 +121,12 @@ impl<'r> FromRow<'r, SqliteRow> for WolvesVerify {
|
|||
pub struct Servers {
|
||||
pub server: GuildId,
|
||||
pub wolves_api: String,
|
||||
pub wolves_id: i64,
|
||||
pub role_past: Option<RoleId>,
|
||||
pub role_current: RoleId,
|
||||
pub member_past: i64,
|
||||
pub member_current: i64,
|
||||
pub bot_channel_id: ChannelId,
|
||||
pub server_name: String,
|
||||
}
|
||||
|
||||
impl<'r> FromRow<'r, SqliteRow> for Servers {
|
||||
|
@ -158,12 +158,12 @@ impl<'r> FromRow<'r, SqliteRow> for Servers {
|
|||
Ok(Self {
|
||||
server,
|
||||
wolves_api: row.try_get("wolves_api")?,
|
||||
wolves_id: row.try_get("wolves_id").unwrap_or(0),
|
||||
role_past,
|
||||
role_current,
|
||||
member_past: row.try_get("member_past")?,
|
||||
member_current: row.try_get("member_current")?,
|
||||
bot_channel_id,
|
||||
server_name: row.try_get("server_name")?,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -87,7 +87,7 @@ pub mod cns {
|
|||
server,
|
||||
// this is the unique api key for each club/soc
|
||||
wolves_api,
|
||||
server_name,
|
||||
wolves_id,
|
||||
..
|
||||
} = &server_config;
|
||||
// dbg!(&server_config);
|
||||
|
@ -101,7 +101,7 @@ pub mod cns {
|
|||
for user in wolves.get_members(wolves_api).await {
|
||||
// dbg!(&user.committee);
|
||||
if server_name_tmp.is_none() {
|
||||
server_name_tmp = Some(user.committee.to_owned());
|
||||
server_name_tmp = Some(user.committee_id);
|
||||
}
|
||||
let id = user.member_id.parse::<u64>().unwrap_or_default();
|
||||
match existing.get(&(id as i64)) {
|
||||
|
@ -124,9 +124,9 @@ pub mod cns {
|
|||
}
|
||||
}
|
||||
|
||||
if let Some(name) = server_name_tmp {
|
||||
if &name != server_name {
|
||||
set_server_member(&db, server, &name).await;
|
||||
if let Some(cs_id) = server_name_tmp {
|
||||
if &cs_id != wolves_id {
|
||||
set_server_member(&db, server, cs_id).await;
|
||||
}
|
||||
}
|
||||
if !user_to_update.is_empty() {
|
||||
|
@ -135,15 +135,15 @@ pub mod cns {
|
|||
}
|
||||
}
|
||||
|
||||
async fn set_server_member(db: &Pool<Sqlite>, server: &GuildId, name: &str) {
|
||||
async fn set_server_member(db: &Pool<Sqlite>, server: &GuildId, wolves_id: i64) {
|
||||
match sqlx::query_as::<_, Servers>(
|
||||
"
|
||||
UPDATE servers
|
||||
SET server_name = ?
|
||||
SET wolves_id = ?
|
||||
WHERE server = ?
|
||||
",
|
||||
)
|
||||
.bind(name)
|
||||
.bind(wolves_id)
|
||||
.bind(server.get() as i64)
|
||||
.fetch_optional(db)
|
||||
.await
|
||||
|
|
|
@ -68,7 +68,7 @@ impl EventHandler for Handler {
|
|||
println!("{:?}", e);
|
||||
}
|
||||
} else {
|
||||
let tmp = get_committee(&db, &config_server.server_name).await;
|
||||
let tmp = get_committee(&db, config_server.wolves_id).await;
|
||||
if !tmp.is_empty() {
|
||||
let committee = &tmp[0];
|
||||
let msg = format!(
|
||||
|
@ -158,15 +158,15 @@ Sign up on [UL Wolves]({}) and go to https://discord.com/channels/{}/{} and use
|
|||
}
|
||||
}
|
||||
|
||||
async fn get_committee(db: &Pool<Sqlite>, committee: &str) -> Vec<Committees> {
|
||||
async fn get_committee(db: &Pool<Sqlite>, wolves_id: i64) -> Vec<Committees> {
|
||||
sqlx::query_as::<_, Committees>(
|
||||
r#"
|
||||
SELECT *
|
||||
FROM committees
|
||||
WHERE name_plain = ?
|
||||
WHERE id = ?
|
||||
"#,
|
||||
)
|
||||
.bind(committee)
|
||||
.bind(wolves_id)
|
||||
.fetch_all(db)
|
||||
.await
|
||||
.unwrap_or_default()
|
||||
|
|
Loading…
Add table
Reference in a new issue