Advertisement
Guest User

Untitled

a guest
Sep 14th, 2019
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Rust 2.19 KB | None | 0 0
  1. use serenity::{
  2.     model::{channel::Message, gateway::Ready},
  3.     prelude::*,
  4.     http::AttachmentType
  5. };
  6.  
  7. use std::process::Command;
  8.  
  9. use std::fs::create_dir;
  10. use std::fs::read_to_string;
  11. use std::fs::File;
  12. use std::io::Write;
  13.  
  14. use std::path::Path;
  15.  
  16. struct Handler;
  17.  
  18. impl EventHandler for Handler {
  19.     fn message(&self, ctx: Context, msg: Message) {
  20.     if msg.author.bot {
  21.         return;
  22.     }
  23.     if msg.content.starts_with(":") {
  24.         if msg.content.starts_with(":org") {
  25.         let args: Vec<&str> = msg.content.split(" ").collect();
  26.         if args.len() == 1 {
  27.             return;
  28.         }
  29.         let org = "#+LATEX_HEADER: \\usepackage{nopageno}\n#+LATEX_HEADER: \\usepackage[margin=0in]{geometry}\n#+OPTIONS: toc:nil\n".to_owned() + &args[1..].join(" ");
  30.  
  31.         let filepath = format!("/home/nmcdaniel/temp/{}", msg.id);
  32.         create_dir(&filepath).unwrap();
  33.  
  34.         let mut file = File::create(filepath.clone() + "/file.org").unwrap();
  35.         file.write_all(org.as_bytes()).unwrap();
  36.        
  37.         println!("{:?}", Command::new("emacs")
  38.              .arg("-nw")
  39.              .arg(filepath.clone() + "/file.org")
  40.              .arg("--batch")
  41.              .arg("-f")
  42.              .arg("org-latex-export-to-latex")
  43.              .arg("--kill")
  44.              .output().unwrap());
  45.  
  46.         println!("{:?}", Command::new("dvilualatex")
  47.             .arg(filepath.clone() + "/file.tex")
  48.             .arg("--output-directory=".to_owned() + &filepath.clone())
  49.             .output().unwrap());
  50.  
  51.         println!("{:?}", Command::new("dvipng")
  52.             .arg("./file.dvi")
  53.             .arg("-T tight")
  54.             //.arg("-o ".to_owned() + &filepath.clone() + &"/file.png".to_owned())
  55.             .output().unwrap());
  56.  
  57.         let pngpath = "./file1.png";
  58.         println!("{}", pngpath);
  59.  
  60.         let sending = msg.channel_id.send_message(&ctx.http, |m| {
  61.             m.content("Done");
  62.             m.add_file(AttachmentType::Path(Path::new(&pngpath)));
  63.             m
  64.         });
  65.         if let Err(why) = sending {
  66.             println!("E: {}", why);
  67.         }
  68.         }
  69.     }
  70.     }
  71.  
  72.     fn ready(&self, _: Context, ready: Ready) {
  73.     println!("Connected as {}", ready.user.name);
  74.     }
  75. }
  76.  
  77. fn main() {
  78.     println!("Hello, world!");
  79.  
  80.     let tok = "token";
  81.  
  82.     let mut client = Client::new(&tok, Handler).expect("Error making client");
  83.  
  84.     if let Err(e) = client.start() {
  85.     println!("Error: {}", e);
  86.     }
  87. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement