comments and small edits
This commit is contained in:
parent
13663d1ae3
commit
12da47253d
1 changed files with 39 additions and 43 deletions
|
@ -1,3 +1,5 @@
|
|||
//! A module about editing and messing around with user text
|
||||
//!
|
||||
use std::collections::HashMap;
|
||||
use std::sync::Arc;
|
||||
use rand::{thread_rng, Rng};
|
||||
|
@ -8,13 +10,11 @@ use crate::core::botinstance::Channel;
|
|||
use crate::core::botmodules::{BotActionTrait, BotCommand, BotModule, Listener, ModulesManager};
|
||||
use crate::core::identity::UserRole::*;
|
||||
const OF_CMD_CHANNEL:Channel = Channel(String::new());
|
||||
//use rand::{thread_rng, Rng};
|
||||
|
||||
pub async fn init(mgr: Arc<ModulesManager>) {
|
||||
|
||||
//DEFINING BOT COMMAND
|
||||
let replyer = BotCommand {
|
||||
module: BotModule(String::from("TextMods")),
|
||||
module: BotModule(String::from("Replyer")),
|
||||
command: String::from("Reply"),
|
||||
alias: vec![
|
||||
String::from("reply")
|
||||
|
@ -23,17 +23,16 @@ pub async fn init(mgr: Arc<ModulesManager>) {
|
|||
help: String::from("txt mods help"),
|
||||
required_roles: vec![
|
||||
BotAdmin,
|
||||
//I had to add Broadcaster, just the BotAdmin didn't work, it
|
||||
//said I had no permission, even if being the broadcaster of the channel
|
||||
Broadcaster,
|
||||
Mod(OF_CMD_CHANNEL),
|
||||
VIP(OF_CMD_CHANNEL),
|
||||
Chatter
|
||||
],
|
||||
};
|
||||
//ADDINNG BOT ACTION TO MODULE MANAGER
|
||||
|
||||
replyer.add_to_modmgr(Arc::clone(&mgr)).await;
|
||||
|
||||
|
||||
let forsen_listener = Listener{
|
||||
module:BotModule(String::from("TextMods")),
|
||||
name:String::from("Forsen Listener"),
|
||||
|
@ -61,8 +60,10 @@ pub async fn init(mgr: Arc<ModulesManager>) {
|
|||
let shuffler = BotCommand{
|
||||
module:BotModule(String::from("Shuffler")),
|
||||
command:String::from("Shuffle"),
|
||||
alias: vec![],
|
||||
exec_body: actions_util::asyncbox(shuff),
|
||||
alias: vec![
|
||||
String::from("shuffle")
|
||||
],
|
||||
exec_body: actions_util::asyncbox(shuffle),
|
||||
help:String::from("Shuffle Help"),
|
||||
required_roles:vec![
|
||||
BotAdmin,
|
||||
|
@ -75,8 +76,14 @@ pub async fn init(mgr: Arc<ModulesManager>) {
|
|||
shuffler.add_to_modmgr(Arc::clone(&mgr)).await;
|
||||
|
||||
}
|
||||
|
||||
async fn shuff(params : ExecBodyParams)
|
||||
/// Shuffle Function
|
||||
///
|
||||
/// Grabs The user message and checks how many words it has
|
||||
///
|
||||
/// If the user message constains more the one word, it shuffles the words
|
||||
///
|
||||
/// If its only One word, it shuffles the letters in the word
|
||||
async fn shuffle(params : ExecBodyParams)
|
||||
{
|
||||
let usermessage = usermsg(¶ms);
|
||||
|
||||
|
@ -89,7 +96,6 @@ pub async fn init(mgr: Arc<ModulesManager>) {
|
|||
let mut new_reply: HashMap<usize, String> = HashMap::new();
|
||||
for (index, &new_index) in indexes.iter().enumerate() {
|
||||
new_reply.insert(index, usermessage[&new_index].clone());
|
||||
//println!("{:?}", new_reply[&index]);
|
||||
}
|
||||
let mut botreply = String::new();
|
||||
for value in new_reply.values(){
|
||||
|
@ -100,8 +106,6 @@ pub async fn init(mgr: Arc<ModulesManager>) {
|
|||
|
||||
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
|
||||
|
@ -118,7 +122,11 @@ pub async fn init(mgr: Arc<ModulesManager>) {
|
|||
|
||||
}
|
||||
|
||||
|
||||
///butt command hehe
|
||||
///
|
||||
/// All this function does is grab the user message, and randomly pick one of the words
|
||||
/// in the phrase to change the random word for `butt`
|
||||
///
|
||||
async fn butt(params : ExecBodyParams)
|
||||
{
|
||||
//getting User message
|
||||
|
@ -144,8 +152,6 @@ pub async fn init(mgr: Arc<ModulesManager>) {
|
|||
|
||||
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
|
||||
|
@ -157,14 +163,13 @@ pub async fn init(mgr: Arc<ModulesManager>) {
|
|||
|
||||
}
|
||||
|
||||
///Forsen.
|
||||
async fn forsenforsen(params : ExecBodyParams)
|
||||
{
|
||||
if params.msg.message_text == "forsen" || params.msg.message_text == "Forsen"
|
||||
{
|
||||
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
|
||||
|
@ -176,15 +181,19 @@ pub async fn init(mgr: Arc<ModulesManager>) {
|
|||
}
|
||||
}
|
||||
|
||||
///Thereplyer Function
|
||||
///
|
||||
/// This Function grabs the user message and reply the same message, without the command
|
||||
/// at the beginning
|
||||
///
|
||||
async fn thereplyer(params : ExecBodyParams)
|
||||
{
|
||||
let user: HashMap<usize,String> = usermsg(¶ms);
|
||||
//reply message
|
||||
let user_message: HashMap<usize,String> = usermsg(¶ms);
|
||||
let mut bot_reply = String::new();
|
||||
|
||||
for index in 1..user.len()
|
||||
for index in 1..user_message.len()
|
||||
{
|
||||
if let Some(word) = user.get(&index)
|
||||
if let Some(word) = user_message.get(&index)
|
||||
{
|
||||
bot_reply.push_str(word);
|
||||
bot_reply.push(' ');
|
||||
|
@ -194,8 +203,6 @@ pub async fn init(mgr: Arc<ModulesManager>) {
|
|||
|
||||
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
|
||||
|
@ -207,6 +214,13 @@ pub async fn init(mgr: Arc<ModulesManager>) {
|
|||
|
||||
}
|
||||
|
||||
///Usermsg Function
|
||||
///
|
||||
/// Usage: this function grabs the user message, and indexate with a vector and hashmap
|
||||
///
|
||||
/// It returns the User message as a `Hashmap<usize,String>`, with indexs so you can utilize especific words
|
||||
///
|
||||
/// Where `Usize` is index and `String` is the word
|
||||
pub fn usermsg(params : &ExecBodyParams) -> HashMap<usize,String>
|
||||
{
|
||||
//getting the user message
|
||||
|
@ -225,22 +239,4 @@ pub fn usermsg(params : &ExecBodyParams) -> HashMap<usize,String>
|
|||
}
|
||||
index_words
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// //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));
|
||||
// }
|
||||
}
|
Loading…
Reference in a new issue