Cucked alt for promote #75

Merged
modulatingforce merged 4 commits from cucked into master 2024-04-09 13:39:35 -04:00
Showing only changes of commit 74d938751f - Show all commits

View file

@ -8,6 +8,7 @@ use std::sync::Arc;
use tokio::sync::RwLock;
use tokio::time::{sleep,Duration};
use twitch_irc::message::PrivmsgMessage;
use casual_logger::Log;
@ -59,7 +60,10 @@ pub async fn init(mgr: Arc<ModulesManager>) {
let tempb = BotCommand {
module: BotModule(String::from("identity")),
command: String::from("promote"), // command call name
alias: vec![], // String of alternative names
alias: vec![
"cucked".to_string(),
"cuck".to_string(),
], // String of alternative names
exec_body: actions_util::asyncbox(cmd_promote),
help: String::from("promote"),
required_roles: vec![
@ -164,7 +168,7 @@ async fn cmd_promote(params : ExecBodyParams) {
let mut argv = params.msg.message_text.split(' ');
argv.next(); // Skip the command name
let cmdname = argv.next(); // Skip the command name
let arg1 = argv.next();
@ -202,7 +206,7 @@ async fn cmd_promote(params : ExecBodyParams) {
// [x] 1. Get trgusr (regardless of -admin flag)
// let targetusr = if arg1 == Some("-admin") { arg2 } else { arg1 };
let targetusr = if
let mut targetusr = if
arg1 == Some("-admin")
|| arg1 == Some("-v")
|| arg1 == Some("-vip")
@ -222,6 +226,50 @@ async fn cmd_promote(params : ExecBodyParams) {
}
else { arg1 };
// [x] Check if target is an existing user
targetusr = if let Some(chkusr) = targetusr {
match twitch_irc::validate::validate_login(chkusr.to_lowercase().as_str()) {
Ok(_) => Some(chkusr),
Err(_) => None,
}
} else { None } ;
// [x] Check if cmd passed is cucked, then go through special cucked handling
if let Some(cmd_to_check) = cmdname {
if cmd_to_check.to_lowercase() == String::from(botlock.get_prefix()) + "cucked"
|| cmd_to_check.to_lowercase() == String::from(botlock.get_prefix()) + "cuck"
{
let idlock = botlock.botmgrs.identity.read().await;
let senderroles = idlock.getspecialuserroles(sendername.clone(), Some(Channel(targetchnl.to_lowercase()))).await;
if senderroles.contains(&UserRole::BotAdmin) && targetusr.is_none() {
targetusr = Some(sendername.as_str())
}
botlock.botmgrs.chat.send_botmsg(super::chat::BotMsgType::Notif(
"uuh ".to_string()
),
params.clone(),
).await;
sleep(Duration::from_secs_f64(1.0)).await;
botlock.botmgrs.chat.send_botmsg(super::chat::BotMsgType::Notif(
"... ".to_string()
),
params.clone(),
).await;
sleep(Duration::from_secs_f64(2.0)).await;
}
}
// [x] 2. promote trguser
// [x] Get a required lock first
@ -272,14 +320,23 @@ async fn cmd_promote(params : ExecBodyParams) {
// [x] 3. Output resulting change
let outmsg = match rslt {
ChangeResult::Success(a) => {
format!("o7 Successfully promoted : {a}")
ChangeResult::Success(rsltstr) => {
format!("o7 Successfully promoted {} : {}",
targetusr.unwrap().to_string(),
rsltstr
)
}
ChangeResult::Failed(a) => {
format!("PoroSad failed to promote : {a}")
ChangeResult::Failed(rsltstr) => {
format!("PoroSad failed to promote {} : {}",
targetusr.unwrap().to_string(),
rsltstr
)
}
ChangeResult::NoChange(a) => {
format!("uuh No Promotion Change : {a}")
ChangeResult::NoChange(rsltstr) => {
format!("uuh No Promotion Change {} : {}",
targetusr.unwrap().to_string(),
rsltstr
)
}
};
@ -499,14 +556,23 @@ async fn cmd_demote(params : ExecBodyParams) {
*/
let outmsg = match rslt {
ChangeResult::Success(a) => {
format!("o7 Successfully demoted : {a}")
ChangeResult::Success(rsltstr) => {
format!("o7 Successfully demoted {} : {}",
targetusr.unwrap().to_string(),
rsltstr
)
}
ChangeResult::Failed(a) => {
format!("PoroSad failed to demote : {a}")
ChangeResult::Failed(rsltstr) => {
format!("PoroSad failed to demote {} : {}",
targetusr.unwrap().to_string(),
rsltstr
)
}
ChangeResult::NoChange(a) => {
format!("uuh No Demotion Change : {a}")
ChangeResult::NoChange(rsltstr) => {
format!("uuh No Demotion Change {} : {}",
targetusr.unwrap().to_string(),
rsltstr
)
}
};