url_bot_rs/plugins/
mod.rs

1use reqwest::Url;
2use failure::Error;
3use serde::{Serialize, Deserialize};
4
5use crate::config::Rtd;
6
7pub trait TitlePlugin {
8    /// Get the name of the plugin
9    fn name(&self) -> &'static str;
10    /// Check to see if the token is a viable candidate for running the plugin
11    fn check(&self, config: &PluginConfig, url: &Url) -> bool;
12    /// Run the plugin to get a title
13    fn evaluate(&self, rtd: &Rtd, url: &Url) -> Result<String, Error>;
14}
15
16/// Plugin includes
17pub mod imgur;
18pub mod youtube;
19pub mod vimeo;
20
21/// Plugin configuration structures
22#[derive(Serialize, Deserialize, Default, Clone)]
23#[serde(default)]
24pub struct PluginConfig {
25    imgur: imgur::Config,
26    youtube: youtube::Config,
27    vimeo: vimeo::Config,
28}
29
30/// Plugin instantiations (as trait objects)
31pub const TITLE_PLUGINS: [&dyn TitlePlugin; 3] = [
32    &imgur::ImgurPlugin {},
33    &youtube::YouTubePlugin {},
34    &vimeo::VimeoPlugin {},
35];
36
37#[macro_export]
38macro_rules! plugin_conf {
39    ($rtd:expr, $name:ident) => {
40        $rtd.conf.plugins.$name
41    };
42}