Compare commits
2 Commits
8717f31a1b
...
16bb6a48a2
Author | SHA1 | Date | |
---|---|---|---|
16bb6a48a2 | |||
516c2529e2 |
8
README.md
Normal file
8
README.md
Normal file
@ -0,0 +1,8 @@
|
||||
# Scam Police
|
||||
A rust bot for Matrix designed to call out scams
|
||||
|
||||
# Build
|
||||
`cargo build --release`
|
||||
|
||||
# Run
|
||||
On first run, you will need to login. To do this, run `cargo run --release [MXID]` where MXID is the Matrix ID of the user the bot will run on. The only currently supported login flow is Password. (SSO planned)
|
@ -122,7 +122,7 @@ impl Config {
|
||||
.as_object()
|
||||
.unwrap()
|
||||
.into_iter()
|
||||
.map(|a| (a.0.to_owned(), KeywordSection::load(a.1)))
|
||||
.map(|a| (a.0.to_owned(), KeywordSection::load(a.1).unwrap()))
|
||||
.collect();
|
||||
|
||||
Self {
|
||||
|
@ -1,7 +1,8 @@
|
||||
use serde_json::Value;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
#[derive(Debug, Clone, Deserialize, Serialize)]
|
||||
pub struct KeywordSection {
|
||||
pub threshold: u64,
|
||||
pub required: Vec<String>,
|
||||
@ -9,25 +10,10 @@ pub struct KeywordSection {
|
||||
}
|
||||
|
||||
impl KeywordSection {
|
||||
pub fn load(json: &Value) -> Self {
|
||||
let threshold: u64 = json["threshold"].as_u64().unwrap();
|
||||
let required: Vec<String> = json["requiredKeywords"]
|
||||
.as_array()
|
||||
.unwrap()
|
||||
.into_iter()
|
||||
.map(|a| a.as_str().unwrap().to_string())
|
||||
.collect();
|
||||
let keywords: Vec<String> = json["keywords"]
|
||||
.as_array()
|
||||
.unwrap()
|
||||
.into_iter()
|
||||
.map(|a| a.as_str().unwrap().to_string())
|
||||
.collect();
|
||||
|
||||
Self {
|
||||
threshold,
|
||||
required,
|
||||
keywords,
|
||||
pub fn load(json: &Value) -> Option<Self> {
|
||||
match serde_json::from_value(json.to_owned()) {
|
||||
Ok(j) => Some(j),
|
||||
Err(e) => { eprintln!("{e}"); None }
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user