Added butt command - still works to do
All checks were successful
ci/woodpecker/pr/cargo-checks Pipeline was successful
All checks were successful
ci/woodpecker/pr/cargo-checks Pipeline was successful
Working on a "change the text" command/listener
This commit is contained in:
parent
bb2222e42b
commit
6a71e3375b
1 changed files with 81 additions and 17 deletions
|
@ -1,5 +1,7 @@
|
|||
use std::collections::HashMap;
|
||||
use std::sync::Arc;
|
||||
use rand::{thread_rng, Rng};
|
||||
|
||||
use crate::core::bot_actions::{actions_util, ExecBodyParams};
|
||||
use crate::core::botinstance::Channel;
|
||||
use crate::core::botmodules::{BotActionTrait, BotCommand, BotModule, Listener, ModulesManager};
|
||||
|
@ -36,8 +38,66 @@ pub async fn init(mgr: Arc<ModulesManager>) {
|
|||
help:String::from("Forsen helper"),
|
||||
};
|
||||
forsen_listener.add_to_modmgr(Arc::clone(&mgr)).await;
|
||||
|
||||
|
||||
let butt = BotCommand{
|
||||
module:BotModule(String::from("ButtModule")),
|
||||
command:String::from("butt"),
|
||||
alias:vec![],
|
||||
exec_body:actions_util::asyncbox(butt),
|
||||
help:String::from("butt helper"),
|
||||
required_roles:vec![
|
||||
BotAdmin,
|
||||
Broadcaster,
|
||||
Mod(OF_CMD_CHANNEL),
|
||||
]
|
||||
};
|
||||
butt.add_to_modmgr(Arc::clone(&mgr)).await;
|
||||
|
||||
}
|
||||
|
||||
async fn butt(params : ExecBodyParams)
|
||||
{
|
||||
//getting User message
|
||||
let mut userm = usermsg(¶ms);
|
||||
|
||||
//choose a random word from the user phrase
|
||||
let w = thread_rng().gen_range(1..userm.len());
|
||||
|
||||
//change the random word to butt :pepepains
|
||||
userm.insert(w, String::from("Butt"));
|
||||
|
||||
|
||||
let mut bot_reply = String::new();
|
||||
|
||||
for index in 1..userm.len()
|
||||
{
|
||||
if let Some(word) = userm.get(&index)
|
||||
{
|
||||
bot_reply.push_str(word);
|
||||
bot_reply.push(' ');
|
||||
}
|
||||
}
|
||||
|
||||
let bot = Arc::clone(¶ms.bot);
|
||||
let botlock = bot.read().await;
|
||||
|
||||
// uses chat.say_in_reply_to() for the bot controls for messages
|
||||
botlock
|
||||
.botmgrs
|
||||
.chat
|
||||
.say_in_reply_to(
|
||||
¶ms.msg,
|
||||
bot_reply,
|
||||
params.clone()
|
||||
).await;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
async fn forsenforsen(params : ExecBodyParams)
|
||||
{
|
||||
if params.msg.message_text == "forsen" || params.msg.message_text == "Forsen"
|
||||
|
@ -59,27 +119,13 @@ pub async fn init(mgr: Arc<ModulesManager>) {
|
|||
|
||||
async fn thereplyer(params : ExecBodyParams)
|
||||
{
|
||||
//getting the user message
|
||||
let sender_message = ¶ms.msg.message_text;
|
||||
|
||||
//vector to store the words
|
||||
let words: Vec<&str> = sender_message.split_whitespace().collect();
|
||||
|
||||
//using Hashmap to store the words
|
||||
let mut index_words:HashMap<usize,String> = HashMap::new();
|
||||
|
||||
//adding to the hashmap each word
|
||||
for(index,word) in words.iter().enumerate()
|
||||
{
|
||||
index_words.insert(index, String::from(*word));
|
||||
}
|
||||
|
||||
let user: HashMap<usize,String> = usermsg(¶ms);
|
||||
//reply message
|
||||
let mut bot_reply = String::new();
|
||||
|
||||
for index in 1..index_words.len()
|
||||
for index in 1..user.len()
|
||||
{
|
||||
if let Some(word) = index_words.get(&index)
|
||||
if let Some(word) = user.get(&index)
|
||||
{
|
||||
bot_reply.push_str(word);
|
||||
bot_reply.push(' ');
|
||||
|
@ -102,7 +148,25 @@ pub async fn init(mgr: Arc<ModulesManager>) {
|
|||
|
||||
}
|
||||
|
||||
pub fn usermsg(params : &ExecBodyParams) -> HashMap<usize,String>
|
||||
{
|
||||
//getting the user message
|
||||
let sender_message = ¶ms.msg.message_text;
|
||||
|
||||
//vector to store the words
|
||||
let words: Vec<&str> = sender_message.split_whitespace().collect();
|
||||
|
||||
//using Hashmap to store the words
|
||||
let mut index_words:HashMap<usize,String> = HashMap::new();
|
||||
|
||||
//adding to the hashmap each word
|
||||
for(index,word) in words.iter().enumerate()
|
||||
{
|
||||
index_words.insert(index, String::from(*word));
|
||||
}
|
||||
index_words
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue