about summary refs log tree commit diff
path: root/fun/paroxysm/src
diff options
context:
space:
mode:
Diffstat (limited to 'fun/paroxysm/src')
-rw-r--r--fun/paroxysm/src/keyword.rs23
-rw-r--r--fun/paroxysm/src/main.rs35
2 files changed, 47 insertions, 11 deletions
diff --git a/fun/paroxysm/src/keyword.rs b/fun/paroxysm/src/keyword.rs
index 7bbc8cadf6a1..1b2b6ce592a0 100644
--- a/fun/paroxysm/src/keyword.rs
+++ b/fun/paroxysm/src/keyword.rs
@@ -108,8 +108,12 @@ impl KeywordDetails {
     }
 
     pub fn format_entry(&self, idx: usize) -> Option<String> {
+        self.format_entry_colours(idx, true)
+    }
+
+    pub fn format_entry_colours(&self, idx: usize, with_colours: bool) -> Option<String> {
         if let Some(ent) = self.entries.get(idx.saturating_sub(1)) {
-            let gen_clr = if self.keyword.chan == "*" {
+            let gen_clr = if self.keyword.chan == "*" && with_colours {
                 "\x0307"
             } else {
                 ""
@@ -117,13 +121,18 @@ impl KeywordDetails {
             let zwsp_name = Self::add_zwsp_to_name(&self.keyword.name)
                 .unwrap_or_else(|| self.keyword.name.clone());
             Some(format!(
-                "\x02{}{}\x0f\x0315[{}/{}]\x0f: {} \x0f\x0314[{}]\x0f",
+                "{}{}{name}{}[{idx}/{total}]{}: {text} {}[{date}]{}",
+                if with_colours { "\x02" } else { "" },
                 gen_clr,
-                zwsp_name,
-                idx,
-                self.entries.len(),
-                ent.text,
-                ent.creation_ts.date()
+                if with_colours { "\x0f\x0315" } else { "" },
+                if with_colours { "\x0f" } else { "" },
+                if with_colours { "\x0f\x0314" } else { "" },
+                if with_colours { "\x0f" } else { "" },
+                name = zwsp_name,
+                idx = idx,
+                total = self.entries.len(),
+                text = ent.text,
+                date = ent.creation_ts.date()
             ))
         } else {
             None
diff --git a/fun/paroxysm/src/main.rs b/fun/paroxysm/src/main.rs
index 7bfdf8cb435c..0fed3133f8f8 100644
--- a/fun/paroxysm/src/main.rs
+++ b/fun/paroxysm/src/main.rs
@@ -230,12 +230,39 @@ impl App {
                 if let Some(mut idx) = idx {
                     if idx == -1 {
                         // 'get all entries' ('*' parses into this)
+                        // step 1: make a blob of all the quotes
+                        let mut data_to_upload = String::new();
                         for i in 0..kwd.entries.len() {
-                            self.client.send_notice(
-                                nick,
-                                format!("[{}] {}", chan, kwd.format_entry(i + 1).unwrap()),
-                            )?;
+                            data_to_upload
+                                .push_str(&kwd.format_entry_colours(i + 1, false).unwrap());
+                            data_to_upload.push('\n');
+                        }
+                        // step 2: attempt to POST it to eta's pastebin
+                        // TODO(eta): make configurable
+                        let response = crimp::Request::put("https://theta.eu.org/lx/upload")
+                            .user_agent("paroxysm/0.0.2 crimp/0.2")?
+                            .header("Linx-Expiry", "86400")? // 24 hours
+                            .body("text/plain", data_to_upload.as_bytes())
+                            .timeout(std::time::Duration::from_secs(2))?
+                            .send()?
+                            .as_string()?;
+                        // step 3: tell the world about it
+                        if response.status != 200 {
+                            Err(format_err!(
+                                "upload returned {}: {}",
+                                response.status,
+                                response.body
+                            ))?
                         }
+                        self.client.send_notice(
+                            target,
+                            format!(
+                                "\x02{}\x0f: uploaded {} quotes to \x02\x0311{}\x0f (will expire in \x0224\x0f hours)",
+                                subj,
+                                kwd.entries.len(),
+                                response.body
+                            )
+                        )?;
                     } else {
                         if idx == 0 {
                             idx = 1;