reformat
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
d0577cc66f
commit
cd1875240d
|
@ -1,7 +1,8 @@
|
|||
use crate::meme::Meme;
|
||||
use crate::meme::MemeIdent;
|
||||
use serde::de::{self, Deserializer, MapAccess, Visitor};
|
||||
use serde::Deserialize;
|
||||
use crate::meme::{Meme, MemeIdent};
|
||||
use serde::{
|
||||
de::{self, Deserializer, MapAccess, Visitor},
|
||||
Deserialize,
|
||||
};
|
||||
use std::path::PathBuf;
|
||||
use url::Url;
|
||||
|
||||
|
@ -92,7 +93,7 @@ impl<'de> Deserialize<'de> for Meme {
|
|||
}
|
||||
|
||||
keyword = Some(map.next_value()?);
|
||||
}
|
||||
},
|
||||
|
||||
Field::Ident(i) => {
|
||||
if ident.is_some() {
|
||||
|
@ -104,12 +105,12 @@ impl<'de> Deserialize<'de> for Meme {
|
|||
match i {
|
||||
IdentField::Id => {
|
||||
ident = Some(MemeIdent::Id(map.next_value()?));
|
||||
}
|
||||
},
|
||||
IdentField::RandomCat => {
|
||||
ident = Some(MemeIdent::RandomCat(map.next_value()?));
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
let keyword = keyword.ok_or_else(|| de::Error::missing_field("keyword"))?;
|
||||
|
|
20
src/main.rs
20
src/main.rs
|
@ -10,11 +10,14 @@ use matrix_sdk::{
|
|||
member::MemberEventContent,
|
||||
message::{MessageEventContent, MessageType, TextMessageEventContent},
|
||||
},
|
||||
AnyToDeviceEvent, StrippedStateEvent, SyncMessageEvent,
|
||||
AnyToDeviceEvent,
|
||||
StrippedStateEvent,
|
||||
SyncMessageEvent,
|
||||
},
|
||||
room::Room,
|
||||
verification::Verification,
|
||||
EventHandler, LoopCtrl,
|
||||
EventHandler,
|
||||
LoopCtrl,
|
||||
};
|
||||
use rand::{rngs::StdRng, SeedableRng};
|
||||
use sled::Db;
|
||||
|
@ -28,8 +31,7 @@ use std::{
|
|||
time::Duration,
|
||||
};
|
||||
use structopt::StructOpt;
|
||||
use tokio::sync::Mutex;
|
||||
use tokio::sync::RwLock;
|
||||
use tokio::sync::{Mutex, RwLock};
|
||||
|
||||
use config::Config;
|
||||
|
||||
|
@ -121,8 +123,8 @@ pub struct Bot {
|
|||
memecache: Db,
|
||||
config: Arc<Config>,
|
||||
/// used to keep track of how many memes have been sent.
|
||||
/// this is reset once the threshold set in the config has been reached, and the JMClient cache
|
||||
/// is cleared.
|
||||
/// this is reset once the threshold set in the config has been reached, and
|
||||
/// the JMClient cache is cleared.
|
||||
meme_count: AtomicU32,
|
||||
rng: Mutex<StdRng>,
|
||||
}
|
||||
|
@ -230,7 +232,7 @@ async fn on_response(response: &SyncResponse, client: &Client) -> anyhow::Result
|
|||
error!("Error accepting key verification request: {}", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
AnyToDeviceEvent::KeyVerificationKey(e) => {
|
||||
if let Some(Verification::SasV1(sas)) = &client
|
||||
|
@ -241,9 +243,9 @@ async fn on_response(response: &SyncResponse, client: &Client) -> anyhow::Result
|
|||
error!("Error confirming key verification request: {}", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
_ => {}
|
||||
_ => {},
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -5,7 +5,10 @@ use matrix_sdk::{
|
|||
api::r0::media::create_content,
|
||||
events::{
|
||||
room::message::{
|
||||
ImageMessageEventContent, MessageEventContent, MessageType, VideoMessageEventContent,
|
||||
ImageMessageEventContent,
|
||||
MessageEventContent,
|
||||
MessageType,
|
||||
VideoMessageEventContent,
|
||||
},
|
||||
AnyMessageEventContent,
|
||||
},
|
||||
|
@ -13,8 +16,7 @@ use matrix_sdk::{
|
|||
room::{Joined, Room},
|
||||
};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::io::Cursor;
|
||||
use std::sync::atomic::Ordering;
|
||||
use std::{io::Cursor, sync::atomic::Ordering};
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize)]
|
||||
struct CachedMeme {
|
||||
|
@ -63,7 +65,7 @@ pub async fn on_msg(msg: &str, room: Room, bot: &Bot) -> anyhow::Result<()> {
|
|||
room.name()
|
||||
);
|
||||
return Ok(());
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
for meme in &bot.config.memes {
|
||||
|
@ -74,8 +76,12 @@ pub async fn on_msg(msg: &str, room: Room, bot: &Bot) -> anyhow::Result<()> {
|
|||
if let Some(meme) = meme.get_meme(bot).await? {
|
||||
match meme.id.parse::<u32>() {
|
||||
Err(e) => {
|
||||
error!("Meme {:?} has invalid ID! tilera, you messed up with your stupid php again: {}", &meme, e);
|
||||
}
|
||||
error!(
|
||||
"Meme {:?} has invalid ID! tilera, you messed up with your stupid php \
|
||||
again: {}",
|
||||
&meme, e
|
||||
);
|
||||
},
|
||||
Ok(id) => {
|
||||
if let Some(ivec) = bot.memecache.get(id.to_le_bytes())? {
|
||||
let cached = bincode::deserialize::<CachedMeme>(&ivec)?;
|
||||
|
@ -119,7 +125,7 @@ pub async fn on_msg(msg: &str, room: Room, bot: &Bot) -> anyhow::Result<()> {
|
|||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
} else {
|
||||
error!("Found meme with invalid id! {:?}", &meme);
|
||||
|
|
Loading…
Reference in New Issue