about summary refs log tree commit diff
path: root/fun/paroxysm/src/main.rs
diff options
context:
space:
mode:
authoreta <eta@theta.eu.org>2020-08-28T23·18+0100
committereta <eta@theta.eu.org>2020-08-28T23·57+0000
commit9e118c6d69cfe69f1d133bd6de76c949fda23c1a (patch)
treec1d7d54de9b2e7a4d5f711e9bb7a867841faab01 /fun/paroxysm/src/main.rs
parent13088392e2fbb358b00fb5f6a3b9c16928d70a97 (diff)
feat(paroxysm): upload queries for all quotes to eta's pastebin r/1733
- Currently, asking for all your quotes either stalls the bot, or
  doesn't result in you getting all your quotes, or both. This aims
  to resolve this oversight by shoving them all in a pastebin.
- This uses the lovely `crimp` library by tazjin, which is really
  good at just doing HTTP stuff with minimal fuss. Amazing!
  (although we should probably actually use the depot version)
- Everything is hard coded for now, but we probably don't care.
- Stuff expires after 24 hours, for privacy reasons?
- We also had to add a function to format entries without colours,
  and took the opportunity to clean up the format!() a bit.

Change-Id: I6e75968c7da48a51fff327355b8fa2c025d0db75
Reviewed-on: https://cl.tvl.fyi/c/depot/+/1872
Tested-by: BuildkiteCI
Reviewed-by: glittershark <grfn@gws.fyi>
Reviewed-by: lukegb <lukegb@tvl.fyi>
Diffstat (limited to 'fun/paroxysm/src/main.rs')
-rw-r--r--fun/paroxysm/src/main.rs35
1 files changed, 31 insertions, 4 deletions
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;