sql sanitation
This commit is contained in:
@@ -18,46 +18,38 @@ pub async fn count(msg: Message, db: std::sync::Arc<Client>) {
|
||||
&[],
|
||||
)
|
||||
.await
|
||||
.expect("cant create a user table");
|
||||
.expect("Can't create a user table");
|
||||
|
||||
for row in db
|
||||
.query("SELECT name, reg FROM words", &[])
|
||||
.await
|
||||
.expect("can't get the words to count")
|
||||
.expect("Can't get the words to count")
|
||||
{
|
||||
let name: &str = row.get(0);
|
||||
let regex: Regex = Regex::new(row.get(1)).unwrap();
|
||||
let count = regex.captures_iter(&msg.content).count();
|
||||
let count: i32 = regex.captures_iter(&msg.content).count() as i32;
|
||||
if count > 0 {
|
||||
let query_result = db
|
||||
.query(
|
||||
format!("SELECT count FROM user{} where name='{}'", id, name).as_str(),
|
||||
&[],
|
||||
format!("SELECT count FROM user{} WHERE name=$1", id).as_str(),
|
||||
&[&name],
|
||||
)
|
||||
.await
|
||||
.expect("cant select the count");
|
||||
.expect("Can't select count");
|
||||
if query_result.is_empty() {
|
||||
db.execute(
|
||||
format!(
|
||||
"insert into user{} (name, count) values ('{}', 0)",
|
||||
id, name
|
||||
)
|
||||
.as_str(),
|
||||
&[],
|
||||
format!("INSERT INTO user{} (name, count) values ($1, 0)", id).as_str(),
|
||||
&[&name],
|
||||
)
|
||||
.await
|
||||
.expect("cant insert shit");
|
||||
.expect("Can't insert count");
|
||||
}
|
||||
db.execute(
|
||||
format!(
|
||||
"UPDATE user{} SET count = count + {} where name='{}'",
|
||||
id, count, name
|
||||
)
|
||||
.as_str(),
|
||||
&[],
|
||||
format!("UPDATE user{} SET count = count + $1 WHERE name=$2", id).as_str(),
|
||||
&[&count, &name],
|
||||
)
|
||||
.await
|
||||
.expect("cant update");
|
||||
.expect("Can't update count");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user