working identity > can_user_run()
This commit is contained in:
parent
e61f9fd4ac
commit
4aaab7e2fa
4 changed files with 224 additions and 39 deletions
src/core
|
@ -22,7 +22,7 @@ use crate::core::ratelimiter;
|
|||
|
||||
use crate::core::botmodules;
|
||||
use crate::core::botmodules::ModulesManager;
|
||||
use crate::core::identity::IdentityManager;
|
||||
use crate::core::identity::{IdentityManager,Permissible};
|
||||
|
||||
|
||||
#[derive(Debug, PartialEq, Eq, Hash, Clone)]
|
||||
|
@ -222,7 +222,7 @@ impl BotInstance
|
|||
|
||||
while let Some(message) = self.incoming_messages.recv().await {
|
||||
// Below can be used to debug if I want to capture all messages
|
||||
println!("Received message: {:?}", message);
|
||||
// println!("Received message: {:?}", message);
|
||||
|
||||
match message {
|
||||
ServerMessage::Notice(msg) => {
|
||||
|
@ -271,7 +271,8 @@ impl BotInstance
|
|||
// PRIVATE FUNCTIONS
|
||||
|
||||
|
||||
async fn listener_main_prvmsg(&mut self,msg:PrivmsgMessage) -> () {
|
||||
// async fn listener_main_prvmsg(&mut self,msg:PrivmsgMessage) -> () {
|
||||
async fn listener_main_prvmsg(&self,msg:PrivmsgMessage) -> () {
|
||||
|
||||
// println!("(#{}) {}: {}", msg.channel_login, msg.sender.name, msg.message_text);
|
||||
|
||||
|
@ -286,6 +287,11 @@ impl BotInstance
|
|||
/*
|
||||
BotCommand handling -
|
||||
- [x] Checks if the input message is a prefix with command name or alias
|
||||
- [ ] Validate User can run based on identityModule(From_Bot)::can_user_run(
|
||||
_usr:String,
|
||||
_channelname:ChType,
|
||||
_chat_badge:ChatBadge,
|
||||
_cmdreqroles:Vec<UserRole>)
|
||||
*/
|
||||
|
||||
let inpt = msg.message_text.split("\n").next().expect("ERROR during BotCommand");
|
||||
|
@ -293,20 +299,40 @@ impl BotInstance
|
|||
// [x] Check if a bot command based on ...
|
||||
// [x] prefix + command
|
||||
|
||||
let mut exec_bot_command = false;
|
||||
let mut confirmed_bot_command = false;
|
||||
if inpt == self.prefix.to_string() + c.command.as_str() {
|
||||
exec_bot_command = true;
|
||||
confirmed_bot_command = true;
|
||||
}
|
||||
|
||||
// [x] prefix + alias
|
||||
for alias in &c.alias {
|
||||
if inpt == self.prefix.to_string() + alias.as_str() {
|
||||
exec_bot_command = true;
|
||||
confirmed_bot_command = true;
|
||||
}
|
||||
}
|
||||
|
||||
if exec_bot_command {
|
||||
c.execute(self.chat.clone(), msg.clone()).await;
|
||||
if confirmed_bot_command {
|
||||
|
||||
// self.identity.clone().can_user_run_PRVMSG(&msg, c.required_roles.clone());
|
||||
|
||||
// [ ] Around here, validate if permissable before executing
|
||||
// match self.identity.clone().can_user_run_PRVMSG(&msg, c.required_roles.clone()) {
|
||||
// Ok(Permissible::Allow) => c.execute(self.chat.clone(), msg.clone()).await,
|
||||
// Ok(Permissible::Block) => println!("User Not allowed to run command"),
|
||||
// _ => (),
|
||||
// }
|
||||
|
||||
match self.identity.to_owned().can_user_run_PRVMSG(&msg, c.required_roles.clone()) {
|
||||
// Ok(Permissible::Allow) => (),
|
||||
Permissible::Allow => {
|
||||
println!("Executed as permissible");
|
||||
c.execute(self.chat.clone(), msg.clone()).await;
|
||||
}
|
||||
Permissible::Block => println!("User Not allowed to run command"),
|
||||
// _ => (),
|
||||
}
|
||||
|
||||
// c.execute(self.chat.clone(), msg.clone()).await;
|
||||
}
|
||||
},
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue