random uffs and docker container

This commit is contained in:
LordMZTE 2021-01-12 15:36:14 +01:00
parent e9d387358f
commit b69378763c
4 changed files with 54 additions and 3 deletions

24
Dockerfile Normal file
View file

@ -0,0 +1,24 @@
# this uses buster as alpine would always segfault
FROM rust:buster as builder
LABEL maintainer="LordMZTE <https://github.com/lordmzte>"
RUN apt install \
gcc \
libssl-dev
WORKDIR /usr/src/ruff
COPY Cargo.toml ./
COPY src/ src/
RUN cargo build --release
FROM debian:buster
COPY --from=builder /usr/src/ruff/target/release/ruff /usr/bin
RUN apt update
RUN apt install \
libssl1.1
VOLUME /ruffconfig
CMD /usr/bin/ruff -c /ruffconfig/config.toml

View file

@ -3,7 +3,7 @@ nickname = "RUFF"
# what matterbridge gateways the bot should work on
gateways = ["gateway1"]
# the api endpoint the bot should use
api = "http://localhost:4242/api"
api = "http://127.0.0.1:4242/api"
[memes]
uffat = "https://jensmemes.tilera.xyz/images/584309714544fbe5961cdb4ddbc880d0/uffat.png"

View file

@ -14,6 +14,11 @@ pub struct Message {
pub gateway: String,
}
#[derive(Deserialize, Debug)]
pub struct MemeResponse {
pub link: String,
}
#[derive(Debug)]
pub enum Event {
ApiConnected,

View file

@ -1,5 +1,5 @@
use anyhow::{anyhow, Result};
use api::{Event, Message};
use api::{Event, Message, MemeResponse};
use bytes::Bytes;
use pin_project_lite::pin_project;
use reqwest::Client;
@ -40,6 +40,8 @@ async fn main() -> Result<()> {
))
})
.level(log::LevelFilter::Debug)
// hyper is quite spammy
.level_for("hyper", log::LevelFilter::Info)
.chain(std::io::stdout())
.apply()?;
@ -100,7 +102,27 @@ async fn process_message(client: &Client, message: Message) -> Result<()> {
} => log::info!("got api connected event"),
Message { text, gateway, .. } if config.gateways.contains(&gateway) && !text.is_empty() => {
if let Some(start) = text.split(" ").next() {
if let Some(meme) = config.memes.get(&start.to_lowercase()) {
let lower = start.to_lowercase();
if lower == "uff" {
// TODO this is temporary, once JM3.0 is out, we will request uff memes at
// startup and take a random one when needed, so we don't make a request each
// time (which slows the bot down significantly)
let res = client.get("https://data.tilera.xyz/api/jensmemes/random?category=uff").send().await?.text().await?;
let MemeResponse { link } = serde_json::from_str(&res)?;
let message = Message {
text: link,
gateway,
username: config.nickname.clone(),
event: None,
};
send_message(client, &message).await?;
return Ok(());
}
if let Some(meme) = config.memes.get(&lower) {
log::info!(
r#"found meme matching message "{}". responding with "{}""#,
text,