Initial code dump: matrix feedbot, aka bender

This is a rewrite of our old feedbot in rust, heavily inspired from
rek2's INN matrix bot and making use of some bits from matrix-rust-sdk

This is an asynchronous tokio-based matrix client using a stateless feed
fetcher implementation based on reqwest, it uses feed_rs for parsing RSS
and Atom feeds. State persistence is achieved using a simple file-backed
datastore with serde_yaml as a serialization format.

Published under the GNU General Public License version 3 or later.
This commit is contained in:
2024-11-22 13:08:34 +00:00
commit cd590b73fe
10 changed files with 4457 additions and 0 deletions

46
src/config.rs Normal file
View File

@ -0,0 +1,46 @@
/**
* matrix-feedbot v0.1.0
*
* Copyright (C) 2024 The 1312 Media Collective
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
use serde::Deserialize;
use std::error::Error;
use std::fs;
#[derive(Deserialize, Clone, Debug)]
pub struct FeedConfig {
pub url: String,
pub rooms: Vec<String>,
pub delay: u64
}
#[derive(Deserialize, Debug)]
pub struct Config {
pub default_room: String,
pub feeds: Vec<FeedConfig>,
pub username: String,
pub password: String,
pub homeserver_uri: String
}
impl Config {
pub fn load(config_file: &str) -> Result<Self, Box<dyn Error>> {
let serialized_config = fs::read_to_string(config_file)?;
let config: Config = serde_yaml::from_str(&serialized_config)?;
Ok(config)
}
}