diff --git a/Justfile.top b/Justfile.top new file mode 100644 index 00000000..a66ed1d4 --- /dev/null +++ b/Justfile.top @@ -0,0 +1,22 @@ +rebot: update build stop deploy start status + +update: + (cd bot-src; git pull) + +build: + (cd bot-src; just build) + +deploy: + (cd bot-src; just deploy) + +stop: + sudo service aeglbot stop + +start: + sudo service aeglbot start + +status: + sudo service aeglbot status + +dbdump: + pg_dump -U aeglbot -d aeglbot -f aeglbot.sql diff --git a/bot/src/commands/editguar_command.rs b/bot/src/commands/editguar_command.rs index 0d8e8648..00f4d562 100644 --- a/bot/src/commands/editguar_command.rs +++ b/bot/src/commands/editguar_command.rs @@ -79,7 +79,7 @@ impl Message for EditGuardianCommand { if args.len() == 1 { let info = format!( - "{clan}{name} {email} {admin}", + "{clan}{name} {email} {admin} {rising}", clan = guardian .psn_clan .clone() @@ -94,6 +94,7 @@ impl Message for EditGuardianCommand { } else { "" }, + rising = guardian.format_destiny_rising_id(), ); return self.send_reply(&message, info).await; } @@ -124,6 +125,60 @@ impl Message for EditGuardianCommand { } self.send_reply(&message, "✅ Updated guardian clan").await; } + "rising" => { + if value.is_empty() { + return self + .send_reply( + &message, + "❌ Rising needs at least an UID, but better UID and nickname", + ) + .await; + } + + let split = value.split_once(' '); + if split.is_none() { + let Ok(uid) = value.parse::() else { + return self + .send_reply(&message, "❌ Destiny: Rising uid must be a number") + .await; + }; + + let mut guardian: guardians::ActiveModel = guardian.into(); + guardian.rising_uid = Set(Some(uid)); + if guardian.update(connection).await.is_err() { + return self + .send_reply(&message, "❌ Failed to update Destiny: Rising uid") + .await; + } + return self + .send_reply(&message, "✅ Updated guardian Destiny: Rising uid") + .await; + } + let (uid, nickname) = split.unwrap(); + let Ok(uid) = uid.parse::() else { + return self + .send_reply(&message, "❌ Destiny: Rising uid must be a number") + .await; + }; + + let mut guardian: guardians::ActiveModel = guardian.into(); + guardian.rising_uid = Set(Some(uid)); + guardian.rising_nickname = Set(Some(nickname.to_string())); + + if guardian.update(connection).await.is_err() { + return self + .send_reply( + &message, + "❌ Failed to update Destiny: Rising uid and nickname", + ) + .await; + } + self.send_reply( + &message, + "✅ Updated guardian Destiny: Rising uid and nickname", + ) + .await; + } "email" => { let email_value = if value == "delete" { None diff --git a/bot/src/commands/mod.rs b/bot/src/commands/mod.rs index 6f12c5a9..dda8fcd7 100644 --- a/bot/src/commands/mod.rs +++ b/bot/src/commands/mod.rs @@ -185,10 +185,10 @@ pub async fn validate_username( .await; None } - Err(_) => { + Err(e) => { let _ = bot .tell(SendMessageReply( - "❌ Error querying guardian info.".into(), + format!("❌ Error querying guardian info. {e}"), message.clone(), Format::Plain, Notify::Off, diff --git a/bot/src/commands/whois_command.rs b/bot/src/commands/whois_command.rs index 395ce817..a35bf75a 100644 --- a/bot/src/commands/whois_command.rs +++ b/bot/src/commands/whois_command.rs @@ -41,9 +41,10 @@ impl Message for WhoisCommand { self.send_reply( &message, format!( - "✅ Guardian @{telegram_name} PSN {psn_name}", + "✅ Guardian @{telegram_name} PSN {psn_name} {rising}", telegram_name = guardian.telegram_name, - psn_name = guardian.psn_name + psn_name = guardian.psn_name, + rising = guardian.format_destiny_rising_id(), ), ) .await; diff --git a/bot/templates/editguar/usage.tera b/bot/templates/editguar/usage.tera index 95432276..4823cd79 100644 --- a/bot/templates/editguar/usage.tera +++ b/bot/templates/editguar/usage.tera @@ -2,9 +2,15 @@ Edit guardian information: /editguar List known guardian information + /editguar psn Change guardian's PSN + /editguar clan Change guardian's clan + /editguar email Change guardian's email + +/editguar rising [] + Change guardian's `Destiny: Rising` uid and optionally nickname. diff --git a/bot/templates/list/member.tera b/bot/templates/list/member.tera index 2bb43112..009e32d6 100644 --- a/bot/templates/list/member.tera +++ b/bot/templates/list/member.tera @@ -1 +1 @@ -{{ member.icon }} {{ member.psn_name }} (t.me/{{ member.telegram_name }}) +{{ member.icon }} {{ member.psn_name }} (t.me/{{ member.telegram_name }}) {{ member.rising_uid_and_nick }} diff --git a/entity/src/guardians.rs b/entity/src/guardians.rs index c2f20cb9..efd2ad05 100644 --- a/entity/src/guardians.rs +++ b/entity/src/guardians.rs @@ -21,6 +21,7 @@ use {sea_orm::entity::prelude::*, std::fmt}; // pending_activation_code -> Nullable, // is_admin -> Bool, // is_superadmin -> Bool, +// rising_uid -> Nullable, // } // } @@ -48,6 +49,8 @@ pub struct Model { pub pending_activation_code: Option, pub is_admin: bool, pub is_superadmin: bool, + pub rising_uid: Option, + pub rising_nickname: Option, } #[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] @@ -80,7 +83,24 @@ impl fmt::Display for Model { impl Model { pub fn format_name(&self) -> String { - format!("{} (t.me/{})", self.psn_name, self.telegram_name) + format!( + "{} (t.me/{}) {}", + self.psn_name, + self.telegram_name, + self.format_destiny_rising_id() + ) + } + + pub fn format_destiny_rising_id(&self) -> String { + if let Some(uid) = self.rising_uid { + if let Some(nickname) = &self.rising_nickname { + format!("(D:R uid {} nickname {})", uid, nickname) + } else { + format!("(D:R uid {})", uid) + } + } else { + String::new() + } } pub fn names(&self) -> (String, String) { diff --git a/entity/src/plannedactivitymembers.rs b/entity/src/plannedactivitymembers.rs index cb71fbb4..69be1267 100644 --- a/entity/src/plannedactivitymembers.rs +++ b/entity/src/plannedactivitymembers.rs @@ -68,6 +68,7 @@ impl ActiveModelBehavior for ActiveModel {} pub struct ActivityMemberTemplate { pub psn_name: String, pub telegram_name: String, + pub rising_uid_and_nick: String, pub icon: String, } @@ -95,9 +96,11 @@ impl Model { .ok_or(DbErr::RecordNotFound("Guardian not found".to_string()))?; let (telegram_name, psn_name) = guardian.names(); + let rising_uid_and_nick = guardian.format_destiny_rising_id(); ActivityMemberTemplate { psn_name, telegram_name, + rising_uid_and_nick, icon: self.icon(), } } diff --git a/migration/src/lib.rs b/migration/src/lib.rs index 680888b3..8aa10078 100644 --- a/migration/src/lib.rs +++ b/migration/src/lib.rs @@ -8,6 +8,7 @@ mod m20180508_101326_populate_activities; mod m20180905_090102_populate_activities; mod m20180921_110336_add_admins; mod m20180922_104727_add_superadmins; +mod m20250828_224244_add_destiny_rising_uids; mod tables; pub use tables::*; @@ -29,6 +30,7 @@ impl MigratorTrait for Migrator { Box::new(m20180905_090102_populate_activities::Migration), Box::new(m20180921_110336_add_admins::Migration), Box::new(m20180922_104727_add_superadmins::Migration), + Box::new(m20250828_224244_add_destiny_rising_uids::Migration), ] } } diff --git a/migration/src/m20250828_224244_add_destiny_rising_uids.rs b/migration/src/m20250828_224244_add_destiny_rising_uids.rs new file mode 100644 index 00000000..e14d401c --- /dev/null +++ b/migration/src/m20250828_224244_add_destiny_rising_uids.rs @@ -0,0 +1,34 @@ +use { + crate::Guardians, + sea_orm_migration::{prelude::*, schema::*}, +}; + +#[derive(DeriveMigrationName)] +pub struct Migration; + +#[async_trait::async_trait] +impl MigrationTrait for Migration { + async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> { + manager + .alter_table( + Table::alter() + .table(Guardians::Table) + .add_column(big_integer_null(Guardians::RisingUid)) + .add_column(string_null(Guardians::RisingNickname)) + .to_owned(), + ) + .await + } + + async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> { + manager + .alter_table( + Table::alter() + .table(Guardians::Table) + .drop_column(Guardians::RisingUid) + .drop_column(Guardians::RisingNickname) + .to_owned(), + ) + .await + } +} diff --git a/migration/src/tables.rs b/migration/src/tables.rs index 576150e8..79325e5f 100644 --- a/migration/src/tables.rs +++ b/migration/src/tables.rs @@ -69,4 +69,6 @@ pub enum Guardians { PendingActivationCode, IsAdmin, IsSuperadmin, + RisingUid, + RisingNickname, }