new chat BotInstance attribute
This commit is contained in:
parent
992a63467b
commit
b2344b14f7
1 changed files with 130 additions and 30 deletions
|
@ -59,12 +59,99 @@ pub use EnType::Enabled;
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
|
||||||
|
pub struct Chat {
|
||||||
|
pub ratelimiters : HashMap<ChType,RateLimiter>, // used to limit messages sent per channel
|
||||||
|
pub client : TwitchIRCClient<TCPTransport<TLS>,StaticLoginCredentials>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Chat {
|
||||||
|
|
||||||
|
|
||||||
|
pub fn init_channel(&mut self, chnl:ChType) -> () {
|
||||||
|
let n = RateLimiter::new();
|
||||||
|
self.ratelimiters.insert(chnl,n);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
pub async fn say_in_reply_to(&mut self, msg:& PrivmsgMessage , mut outmsg:String) -> () {
|
||||||
|
// envelops a message before sending a message
|
||||||
|
// [ ] This could include additional formatting (e.g., add in random number of blank spaces)
|
||||||
|
// [ ] Incrementing or checking with RateLimiters
|
||||||
|
// [ ] For BotActions of Enabled Modules , checking whether the caller is Permissible to run the comman
|
||||||
|
|
||||||
|
// self.client.say_in_reply_to(msg,outmsg).await.unwrap();
|
||||||
|
|
||||||
|
// // let contextratelimiter = ratelimiters.get_mut(&msg.channel_login).expect("ERROR: Issue with Rate limiters");
|
||||||
|
let contextratelimiter = self.ratelimiters
|
||||||
|
.get_mut(&Channel(String::from(&msg.channel_login)))
|
||||||
|
.expect("ERROR: Issue with Rate limiters");
|
||||||
|
// let contextratelimiter = self.ratelimiters.get(&msg.channel_login).expect("ERROR: Issue with Rate limiters");
|
||||||
|
|
||||||
|
match contextratelimiter.check_limiter() {
|
||||||
|
ratelimiter::LimiterResp::Allow => {
|
||||||
|
let maxblanks = rand::thread_rng().gen_range(1..=20);
|
||||||
|
//let mut outmsg = "GotTrolled ".to_owned();
|
||||||
|
// let mut outmsg = "annytfLurk ".to_owned();
|
||||||
|
|
||||||
|
for _i in 1..maxblanks {
|
||||||
|
let blankspace: &str = "";
|
||||||
|
outmsg.push_str(blankspace);
|
||||||
|
}
|
||||||
|
|
||||||
|
// client.say_in_reply_to(&msg,outmsg).await.unwrap();
|
||||||
|
self.client.say_in_reply_to(msg,outmsg).await.unwrap();
|
||||||
|
println!("(#{}) > {}", msg.channel_login, "rate limit counter increase");
|
||||||
|
contextratelimiter.increment_counter();
|
||||||
|
println!("{:?}",self.ratelimiters);
|
||||||
|
},
|
||||||
|
ratelimiter::LimiterResp::Skip => {
|
||||||
|
(); // do nothing otherwise
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn say(&self, _:String, _:String) -> () {
|
||||||
|
// more info https://docs.rs/twitch-irc/latest/twitch_irc/client/struct.TwitchIRCClient.html#method.say
|
||||||
|
|
||||||
|
|
||||||
|
// self.client.say(msg,outmsg).await.unwrap();
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
async fn me(&self, _:String, _:String) -> () {
|
||||||
|
// more info https://docs.rs/twitch-irc/latest/twitch_irc/client/struct.TwitchIRCClient.html#method.say
|
||||||
|
|
||||||
|
|
||||||
|
// self.client.me(msg,outmsg).await.unwrap();
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn me_in_reply_to(&self, _:String, _:String) -> () {
|
||||||
|
// more info https://docs.rs/twitch-irc/latest/twitch_irc/client/struct.TwitchIRCClient.html#method.say
|
||||||
|
|
||||||
|
|
||||||
|
// self.client.me(msg,outmsg).await.unwrap();
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
pub struct BotInstance {
|
pub struct BotInstance {
|
||||||
prefix : char,
|
prefix : char,
|
||||||
bot_channel : ChType,
|
bot_channel : ChType,
|
||||||
pub client : TwitchIRCClient<TCPTransport<TLS>,StaticLoginCredentials>,
|
//pub client : TwitchIRCClient<TCPTransport<TLS>,StaticLoginCredentials>,
|
||||||
pub incoming_messages : UnboundedReceiver<ServerMessage>,
|
pub incoming_messages : UnboundedReceiver<ServerMessage>,
|
||||||
pub ratelimiters : HashMap<ChType,RateLimiter>, // used to limit messages sent per channel
|
// pub ratelimiters : HashMap<ChType,RateLimiter>, // used to limit messages sent per channel
|
||||||
|
chat : Chat,
|
||||||
// botmodules : HashMap<ModType,Vec<EnType>>,
|
// botmodules : HashMap<ModType,Vec<EnType>>,
|
||||||
pub botmodules : ModulesManager,
|
pub botmodules : ModulesManager,
|
||||||
twitch_oauth : String,
|
twitch_oauth : String,
|
||||||
|
@ -115,16 +202,23 @@ impl BotInstance {
|
||||||
// ratelimiters are a hashmap of channel and a corresponding rate limiter
|
// ratelimiters are a hashmap of channel and a corresponding rate limiter
|
||||||
let n = RateLimiter::new();
|
let n = RateLimiter::new();
|
||||||
ratelimiters.insert(Channel(String::from(chnl)),n);
|
ratelimiters.insert(Channel(String::from(chnl)),n);
|
||||||
|
//self.chat.ratelimiters.insert(Channel(String::from(chnl)),n);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
let b = BotInstance {
|
let b = BotInstance {
|
||||||
prefix : prefix,
|
prefix : prefix,
|
||||||
bot_channel : Channel(login_name) ,
|
bot_channel : Channel(login_name) ,
|
||||||
incoming_messages : incoming_messages,
|
incoming_messages : incoming_messages,
|
||||||
|
//client : client,
|
||||||
|
chat : Chat {
|
||||||
|
ratelimiters : ratelimiters,
|
||||||
client : client,
|
client : client,
|
||||||
ratelimiters : ratelimiters, // used to limit messages sent per channel
|
} ,
|
||||||
|
// ratelimiters : ratelimiters, // used to limit messages sent per channel
|
||||||
// botmodules : HashMap::new(),
|
// botmodules : HashMap::new(),
|
||||||
botmodules : ModulesManager::init(),
|
botmodules : ModulesManager::init(),
|
||||||
twitch_oauth : oauth_token,
|
twitch_oauth : oauth_token,
|
||||||
|
@ -137,7 +231,7 @@ impl BotInstance {
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
println!("{:?}",b.ratelimiters);
|
println!("{:?}",b.chat.ratelimiters);
|
||||||
|
|
||||||
|
|
||||||
b
|
b
|
||||||
|
@ -198,39 +292,45 @@ impl BotInstance {
|
||||||
println!("(#{}) {}: {}", msg.channel_login, msg.sender.name, msg.message_text);
|
println!("(#{}) {}: {}", msg.channel_login, msg.sender.name, msg.message_text);
|
||||||
|
|
||||||
|
|
||||||
// // let contextratelimiter = ratelimiters.get_mut(&msg.channel_login).expect("ERROR: Issue with Rate limiters");
|
// // // let contextratelimiter = ratelimiters.get_mut(&msg.channel_login).expect("ERROR: Issue with Rate limiters");
|
||||||
let contextratelimiter = self.ratelimiters
|
// let contextratelimiter = self.ratelimiters
|
||||||
.get_mut(&Channel(String::from(&msg.channel_login)))
|
// .get_mut(&Channel(String::from(&msg.channel_login)))
|
||||||
.expect("ERROR: Issue with Rate limiters");
|
// .expect("ERROR: Issue with Rate limiters");
|
||||||
// let contextratelimiter = self.ratelimiters.get(&msg.channel_login).expect("ERROR: Issue with Rate limiters");
|
// // let contextratelimiter = self.ratelimiters.get(&msg.channel_login).expect("ERROR: Issue with Rate limiters");
|
||||||
|
|
||||||
match contextratelimiter.check_limiter() {
|
// match contextratelimiter.check_limiter() {
|
||||||
ratelimiter::LimiterResp::Allow => {
|
// ratelimiter::LimiterResp::Allow => {
|
||||||
let maxblanks = rand::thread_rng().gen_range(1..=20);
|
// let maxblanks = rand::thread_rng().gen_range(1..=20);
|
||||||
//let mut outmsg = "GotTrolled ".to_owned();
|
// //let mut outmsg = "GotTrolled ".to_owned();
|
||||||
let mut outmsg = "annytfLurk ".to_owned();
|
// let mut outmsg = "annytfLurk ".to_owned();
|
||||||
|
|
||||||
for _i in 1..maxblanks {
|
// for _i in 1..maxblanks {
|
||||||
let blankspace: &str = "";
|
// let blankspace: &str = "";
|
||||||
outmsg.push_str(blankspace);
|
// outmsg.push_str(blankspace);
|
||||||
}
|
// }
|
||||||
|
|
||||||
// client.say_in_reply_to(&msg,outmsg).await.unwrap();
|
// // client.say_in_reply_to(&msg,outmsg).await.unwrap();
|
||||||
self.client.say_in_reply_to(msg,outmsg).await.unwrap();
|
// self.client.say_in_reply_to(msg,outmsg).await.unwrap();
|
||||||
println!("(#{}) > {}", msg.channel_login, "rate limit counter increase");
|
// println!("(#{}) > {}", msg.channel_login, "rate limit counter increase");
|
||||||
contextratelimiter.increment_counter();
|
// contextratelimiter.increment_counter();
|
||||||
println!("{:?}",self.ratelimiters);
|
// println!("{:?}",self.ratelimiters);
|
||||||
},
|
// },
|
||||||
ratelimiter::LimiterResp::Skip => {
|
// ratelimiter::LimiterResp::Skip => {
|
||||||
(); // do nothing otherwise
|
// (); // do nothing otherwise
|
||||||
}
|
// }
|
||||||
}
|
|
||||||
|
|
||||||
|
self.chat.say_in_reply_to(msg,String::from("annytfLurk")).await;
|
||||||
|
|
||||||
println!("End of Separate Listener Main prvmsg");
|
println!("End of Separate Listener Main prvmsg");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue