Signed-off-by: Ken Swenson <flat@esoteric.moe>
---
Tested and this proper grabs a themed comic from gocomics.
src/comic.rs | 2 +-
src/main.rs | 22 +++++++++++++++-------
src/theme.rs | 29 +++++++++++++++++++++--------
3 files changed, 37 insertions(+), 16 deletions(-)
diff --git a/src/comic.rs b/src/comic.rs
index 8572b72..24a5fec 100644
--- a/src/comic.rs
+++ b/src/comic.rs
@@ -101,7 +101,7 @@ impl ComicEmbed {
));
self.0.url = Some(format!(
- "https://garfield.com/comic/{}/{}/{}",
+ "https://gocomics.com/garfield/{}/{:02}/{:02}",
date.year(),
date.month(),
date.day()
diff --git a/src/main.rs b/src/main.rs
index 4801e73..836aab6 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -4,9 +4,9 @@ use std::sync::Arc;
use twilight::command_parser::{Command, CommandParserConfig, Parser};
//use twilight::gateway::shard::Event;
-use twilight::model::gateway::event::Event;
use twilight::http::Client as HttpClient;
use twilight::model::channel::message::Message;
+use twilight::model::gateway::event::Event;
use twilight::model::gateway::presence::Activity;
use twilight::model::gateway::presence::ActivityType;
use twilight::model::id::*;
@@ -88,7 +88,7 @@ async fn async_main() -> GarfieldResult<()> {
tokio::task::spawn_blocking(move || exporter.run());
pretty_env_logger::init_timed();
-
+
let db = sled::open("./lasagne.db")?;
let subs = db.open_tree(b"syndicate")?;
@@ -143,16 +143,16 @@ async fn async_main() -> GarfieldResult<()> {
let theme_client = ThemeClient::new_rwc(rqc.clone())?;
let queue: Arc<Box<dyn Queue>> = Arc::new(Box::new(
- twilight::gateway::queue::LargeBotQueue::new(1, &http).await
+ twilight::gateway::queue::LargeBotQueue::new(1, &http).await,
));
let cache = InMemoryCache::new();
-
+
let cluster_config = ClusterConfig::builder(&token)
.http_client(http.clone())
.queue(queue)
.build();
-
+
let cluster = Cluster::new(cluster_config).await?;
let cluster_spawn = cluster.clone();
@@ -163,8 +163,16 @@ async fn async_main() -> GarfieldResult<()> {
let mut events = cluster.events().await;
- let ctx = Context::new(http, rqc, theme_client, parser, cluster, subs, cache.clone());
-
+ let ctx = Context::new(
+ http,
+ rqc,
+ theme_client,
+ parser,
+ cluster,
+ subs,
+ cache.clone(),
+ );
+
while let Some((_, event)) = events.next().await {
trace!("New Event: {:?}", event.kind());
cache.cache_event(&event);
diff --git a/src/theme.rs b/src/theme.rs
index 0af270f..ebad0c4 100644
--- a/src/theme.rs
+++ b/src/theme.rs
@@ -1,4 +1,4 @@
-const COMICS_PER_PAGE: u64 = 6;
+const COMICS_PER_PAGE: u64 = 10;
use regex::Regex;
use reqwest::Client as ReqwestClient;
@@ -16,9 +16,9 @@ pub struct ThemeClient {
impl ThemeClient {
pub fn new_rwc(rwc: ReqwestClient) -> GarfieldResult<Self> {
- let count_re = Regex::new(r#"<span class="pull-right">(?:\d+) of (\d+)</span>"#)?;
+ let count_re = Regex::new(r#">(\d.*) Results for Garfield"#)?;
let comic_re = Regex::new(
- r#"src="https://d1ejxu6vysztl5.cloudfront.net/comics/garfield/[0-9]{4}/([0-9]{4}-[0-9]{2}-[0-9]{2}).gif"#,
+ r#"href="/garfield/([0-9]+/[0-9]+/[0-9]+)""#,
)?;
Ok(Self {
rwc,
@@ -28,8 +28,15 @@ impl ThemeClient {
}
async fn get_count(&self, theme: &str) -> GarfieldResult<Option<u64>> {
- let url =
- reqwest::Url::parse_with_params("https://garfield.com/comic", &[("keywords", theme)])?;
+ let url = reqwest::Url::parse_with_params(
+ "https://www.gocomics.com/search/full_results",
+ &[
+ ("terms", theme),
+ ("category", "comic"),
+ ("short_name", "garfield"),
+ ("sort", "date_desc"),
+ ],
+ )?;
let page = self
.rwc
@@ -54,8 +61,14 @@ impl ThemeClient {
) -> GarfieldResult<Option<String>> {
let page = n / COMICS_PER_PAGE;
let url = reqwest::Url::parse_with_params(
- "https://garfield.com/comic",
- &[("keywords", theme), ("page", &format!("{}", page))],
+ "https://www.gocomics.com/search/full_results",
+ &[
+ ("category", "comic"),
+ ("short_name", "garfield"),
+ ("sort", "date_desc"),
+ ("terms", theme),
+ ("page", &format!("{}", page)),
+ ],
)?;
let text = self
.rwc
@@ -73,7 +86,7 @@ impl ThemeClient {
let mut rng = rand::thread_rng();
match cap.choose(&mut rng) {
- Some(c) => Ok(Some(c[1].to_string())),
+ Some(c) => Ok(Some(c[1].to_string().replace("/", "-"))),
None => Ok(None),
}
}
--
2.27.0