minor regex fixes
This commit is contained in:
		@@ -8,12 +8,15 @@ use std::{collections::HashMap, env};
 | 
				
			|||||||
use tokio_postgres::NoTls;
 | 
					use tokio_postgres::NoTls;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#[command]
 | 
					#[command]
 | 
				
			||||||
pub async fn kitna(ctx: &Context, msg: &Message, mut args: Args) -> CommandResult {
 | 
					pub async fn kitna(ctx: &Context, msg: &Message, args: Args) -> CommandResult {
 | 
				
			||||||
    let query: String = args.single::<String>()?;
 | 
					    let query: String = args.raw().collect::<Vec<&str>>().join(" ");
 | 
				
			||||||
 | 
					    if query == "" {
 | 
				
			||||||
 | 
					        msg.reply(ctx, "bruh kitna kya?");
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
    let words: HashMap<&str, Regex> = [
 | 
					    let words: HashMap<&str, Regex> = [
 | 
				
			||||||
        ("nword", Regex::new(r"(?i)(nig+(er|a)|nig{2,})").unwrap()),
 | 
					        ("nword", Regex::new(r"(?i)(nig+(er|a)|nig{2,})").unwrap()),
 | 
				
			||||||
        ("acha", Regex::new(r"(?i)a(c??h??|6??)a+").unwrap()),
 | 
					        ("acha", Regex::new(r"(?i)a((c+?h+?|6+?)a+").unwrap()),
 | 
				
			||||||
        ("sus", Regex::new(r"(?i)sus|(?i)amon?g\s?us").unwrap()),
 | 
					        ("sus", Regex::new(r"(?i)sus|(?i)amon??g\s??us").unwrap()),
 | 
				
			||||||
    ]
 | 
					    ]
 | 
				
			||||||
    .iter()
 | 
					    .iter()
 | 
				
			||||||
    .cloned()
 | 
					    .cloned()
 | 
				
			||||||
@@ -38,7 +41,8 @@ pub async fn kitna(ctx: &Context, msg: &Message, mut args: Args) -> CommandResul
 | 
				
			|||||||
                .await
 | 
					                .await
 | 
				
			||||||
                .expect("cant select the count");
 | 
					                .expect("cant select the count");
 | 
				
			||||||
            let count: i32 = query_result.get("count");
 | 
					            let count: i32 = query_result.get("count");
 | 
				
			||||||
            msg.reply(ctx, format!("{} count for you: {}", name, count)).await?;
 | 
					            msg.reply(ctx, format!("{} count for you: {}", name, count))
 | 
				
			||||||
 | 
					                .await?;
 | 
				
			||||||
            break;
 | 
					            break;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -5,8 +5,8 @@ use serenity::{
 | 
				
			|||||||
    prelude::*,
 | 
					    prelude::*,
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
use std::time::Duration;
 | 
					use std::time::Duration;
 | 
				
			||||||
#[command]
 | 
					
 | 
				
			||||||
pub async fn challenge(ctx: &Context, msg: &Message) -> CommandResult {
 | 
					async fn chall(ctx: &Context, msg: &Message) -> CommandResult {
 | 
				
			||||||
    if msg.mentions.is_empty() {
 | 
					    if msg.mentions.is_empty() {
 | 
				
			||||||
        msg.reply(ctx, "mention to daal chutiye").await?;
 | 
					        msg.reply(ctx, "mention to daal chutiye").await?;
 | 
				
			||||||
        return Ok(());
 | 
					        return Ok(());
 | 
				
			||||||
@@ -35,7 +35,7 @@ pub async fn challenge(ctx: &Context, msg: &Message) -> CommandResult {
 | 
				
			|||||||
        } else if ["no", "nahi", "n"].contains(&answer.content.to_lowercase().as_str()) {
 | 
					        } else if ["no", "nahi", "n"].contains(&answer.content.to_lowercase().as_str()) {
 | 
				
			||||||
            msg.reply(ctx, "Challenge not accepted").await?;
 | 
					            msg.reply(ctx, "Challenge not accepted").await?;
 | 
				
			||||||
            challenge.delete(&ctx.http).await?;
 | 
					            challenge.delete(&ctx.http).await?;
 | 
				
			||||||
            return Ok(());
 | 
					            return 1;
 | 
				
			||||||
        } else {
 | 
					        } else {
 | 
				
			||||||
            answer
 | 
					            answer
 | 
				
			||||||
                .reply(
 | 
					                .reply(
 | 
				
			||||||
@@ -43,11 +43,17 @@ pub async fn challenge(ctx: &Context, msg: &Message) -> CommandResult {
 | 
				
			|||||||
                    "Please only answer in no/nahi/n or yes/ha/y\ndeleting challenge ...",
 | 
					                    "Please only answer in no/nahi/n or yes/ha/y\ndeleting challenge ...",
 | 
				
			||||||
                )
 | 
					                )
 | 
				
			||||||
                .await?;
 | 
					                .await?;
 | 
				
			||||||
 | 
					            return 1;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    } else {
 | 
					    } else {
 | 
				
			||||||
        msg.reply(ctx, "Challenge not accepted in 60s").await?;
 | 
					        msg.reply(ctx, "Challenge not accepted in 60s").await?;
 | 
				
			||||||
        return Ok(());
 | 
					        return 1;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					    return 0;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#[command]
 | 
				
			||||||
 | 
					pub async fn challenge(ctx: &Context, msg: &Message) -> CommandResult {
 | 
				
			||||||
    let won = random();
 | 
					    let won = random();
 | 
				
			||||||
    let winner = if won {
 | 
					    let winner = if won {
 | 
				
			||||||
        msg.mentions[0].mention()
 | 
					        msg.mentions[0].mention()
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,14 +1,14 @@
 | 
				
			|||||||
 | 
					use regex::Regex;
 | 
				
			||||||
use serenity::model::channel::Message;
 | 
					use serenity::model::channel::Message;
 | 
				
			||||||
use std::collections::HashMap;
 | 
					use std::collections::HashMap;
 | 
				
			||||||
use std::env;
 | 
					use std::env;
 | 
				
			||||||
use regex::Regex;
 | 
					 | 
				
			||||||
use tokio_postgres::NoTls;
 | 
					use tokio_postgres::NoTls;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
pub async fn count(msg: Message) {
 | 
					pub async fn count(msg: Message) {
 | 
				
			||||||
    let words: HashMap<&str, Regex> = [
 | 
					    let words: HashMap<&str, Regex> = [
 | 
				
			||||||
        ("nword", Regex::new(r"(?i)(nig+(er|a)|nig{2,})").unwrap()),
 | 
					        ("nword", Regex::new(r"(?i)(nig+(er|a)|nig{2,})").unwrap()),
 | 
				
			||||||
        ("acha", Regex::new(r"(?i)a(c??h??|6??)a+").unwrap()),
 | 
					        ("acha", Regex::new(r"(?i)a(c+?h+?|6+?)a+").unwrap()),
 | 
				
			||||||
        ("sus", Regex::new(r"(?i)sus|(?i)amon?g\s?us").unwrap()),
 | 
					        ("sus", Regex::new(r"(?i)sus|(?i)amon??g\s??us").unwrap()),
 | 
				
			||||||
    ]
 | 
					    ]
 | 
				
			||||||
    .iter()
 | 
					    .iter()
 | 
				
			||||||
    .cloned()
 | 
					    .cloned()
 | 
				
			||||||
@@ -42,7 +42,8 @@ pub async fn count(msg: Message) {
 | 
				
			|||||||
        .expect("cant create table");
 | 
					        .expect("cant create table");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    for name in ["nword", "acha", "sus"] {
 | 
					    for name in ["nword", "acha", "sus"] {
 | 
				
			||||||
        if words[name].is_match(&msg.content) {
 | 
					        let count = words[name].captures_iter(&msg.content).count();
 | 
				
			||||||
 | 
					        if count > 0 {
 | 
				
			||||||
            let query_result = client
 | 
					            let query_result = client
 | 
				
			||||||
                .query(
 | 
					                .query(
 | 
				
			||||||
                    format!("SELECT count FROM user{} where name='{}'", id, name).as_str(),
 | 
					                    format!("SELECT count FROM user{} where name='{}'", id, name).as_str(),
 | 
				
			||||||
@@ -53,7 +54,11 @@ pub async fn count(msg: Message) {
 | 
				
			|||||||
            if query_result.is_empty() {
 | 
					            if query_result.is_empty() {
 | 
				
			||||||
                client
 | 
					                client
 | 
				
			||||||
                    .execute(
 | 
					                    .execute(
 | 
				
			||||||
                        format!("insert into user{} (name, count) values ('{}', 0)", id, name).as_str(),
 | 
					                        format!(
 | 
				
			||||||
 | 
					                            "insert into user{} (name, count) values ('{}', 0)",
 | 
				
			||||||
 | 
					                            id, name
 | 
				
			||||||
 | 
					                        )
 | 
				
			||||||
 | 
					                        .as_str(),
 | 
				
			||||||
                        &[],
 | 
					                        &[],
 | 
				
			||||||
                    )
 | 
					                    )
 | 
				
			||||||
                    .await
 | 
					                    .await
 | 
				
			||||||
@@ -61,7 +66,11 @@ pub async fn count(msg: Message) {
 | 
				
			|||||||
            }
 | 
					            }
 | 
				
			||||||
            client
 | 
					            client
 | 
				
			||||||
                .execute(
 | 
					                .execute(
 | 
				
			||||||
                    format!("UPDATE user{} SET count = count + 1 where name='{}'", id, name).as_str(),
 | 
					                    format!(
 | 
				
			||||||
 | 
					                        "UPDATE user{} SET count = count + {} where name='{}'",
 | 
				
			||||||
 | 
					                        id, count, name
 | 
				
			||||||
 | 
					                    )
 | 
				
			||||||
 | 
					                    .as_str(),
 | 
				
			||||||
                    &[],
 | 
					                    &[],
 | 
				
			||||||
                )
 | 
					                )
 | 
				
			||||||
                .await
 | 
					                .await
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user