Initial commit
This commit is contained in:
@@ -0,0 +1 @@
|
||||
/target
|
||||
Generated
+8
@@ -0,0 +1,8 @@
|
||||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
# Editor-based HTTP Client requests
|
||||
/httpRequests/
|
||||
# Datasource local storage ignored files
|
||||
/dataSources/
|
||||
/dataSources.local.xml
|
||||
Generated
+8
@@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/.idea/rss_library.iml" filepath="$PROJECT_DIR$/.idea/rss_library.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
||||
Generated
+11
@@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="EMPTY_MODULE" version="4">
|
||||
<component name="NewModuleRootManager">
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/target" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
||||
Generated
+6
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
||||
Generated
+1615
File diff suppressed because it is too large
Load Diff
+16
@@ -0,0 +1,16 @@
|
||||
[package]
|
||||
name = "rss_library"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
rss = "2.0.12"
|
||||
|
||||
[dependencies.reqwest]
|
||||
version = "0.12.15"
|
||||
features = ["rustls-tls", "json"]
|
||||
default-features = false
|
||||
|
||||
[dependencies.serde]
|
||||
version = "1.0.219"
|
||||
features = ["derive"]
|
||||
@@ -0,0 +1,81 @@
|
||||
use serde::Serialize;
|
||||
|
||||
#[derive(Serialize)]
|
||||
struct WebhookUrl {
|
||||
url: String,
|
||||
}
|
||||
|
||||
#[derive(Serialize)]
|
||||
struct WebhookEmbed {
|
||||
title: String,
|
||||
url: String,
|
||||
description: String,
|
||||
r#type: String,
|
||||
thumbnail: Option<WebhookUrl>,
|
||||
image: WebhookUrl,
|
||||
color: u32,
|
||||
}
|
||||
|
||||
#[derive(Serialize)]
|
||||
pub struct Webhook {
|
||||
username: String,
|
||||
avatar_url: String,
|
||||
embeds: [WebhookEmbed; 1],
|
||||
}
|
||||
|
||||
impl Webhook {
|
||||
pub fn new(
|
||||
username: &str,
|
||||
avatar_url: &str,
|
||||
title: &str,
|
||||
description: &str,
|
||||
url: &str,
|
||||
color: u32,
|
||||
image_url: &str,
|
||||
thumbnail: &str,
|
||||
) -> Self {
|
||||
Self {
|
||||
username: String::from(username),
|
||||
avatar_url: String::from(avatar_url),
|
||||
embeds: [WebhookEmbed {
|
||||
title: String::from(title),
|
||||
r#type: String::from("link"),
|
||||
description: String::from(description),
|
||||
url: String::from(url),
|
||||
color,
|
||||
image: WebhookUrl {
|
||||
url: String::from(image_url),
|
||||
},
|
||||
thumbnail: Some(WebhookUrl {
|
||||
url: String::from(thumbnail),
|
||||
}),
|
||||
}],
|
||||
}
|
||||
}
|
||||
|
||||
pub fn new_no_thumbnail(
|
||||
username: &str,
|
||||
avatar_url: &str,
|
||||
title: &str,
|
||||
description: &str,
|
||||
url: &str,
|
||||
color: u32,
|
||||
image_url: &str,
|
||||
) -> Self {
|
||||
Self {
|
||||
username: String::from(username),
|
||||
avatar_url: String::from(avatar_url),
|
||||
embeds: [WebhookEmbed {
|
||||
title: String::from(title),
|
||||
r#type: String::from("link"),
|
||||
description: String::from(description),
|
||||
url: String::from(url),
|
||||
color,
|
||||
image: WebhookUrl {
|
||||
url: String::from(image_url),
|
||||
},
|
||||
thumbnail: None,
|
||||
}],
|
||||
}
|
||||
}
|
||||
}
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
use rss::{Channel, Guid, Item};
|
||||
use std::error::Error;
|
||||
|
||||
pub mod discord;
|
||||
|
||||
pub async fn get_content(source: &str) -> Result<Channel, Box<dyn Error>> {
|
||||
let content = reqwest::get(source)
|
||||
.await?
|
||||
.bytes()
|
||||
.await?;
|
||||
let channel = Channel::read_from(&content[..])?;
|
||||
Ok(channel)
|
||||
}
|
||||
|
||||
pub fn get_latest(rss: &Channel) -> Option<&Item> {
|
||||
rss.items().first()
|
||||
}
|
||||
|
||||
pub fn get_new<'a>(rss: &'a Channel, latest: &Guid) -> &'a [Item] {
|
||||
match rss
|
||||
.items()
|
||||
.iter()
|
||||
.position(|item| item.guid().map(|guid| guid == latest).unwrap_or(false))
|
||||
.map(|i| &rss.items()[0..i])
|
||||
{
|
||||
None => rss.items(),
|
||||
Some(list) => list,
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user