Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use serenity::{
- model::{channel::Message, gateway::Ready},
- prelude::*,
- http::AttachmentType
- };
- use std::process::Command;
- use std::fs::create_dir;
- use std::fs::read_to_string;
- use std::fs::File;
- use std::io::Write;
- use std::path::Path;
- struct Handler;
- impl EventHandler for Handler {
- fn message(&self, ctx: Context, msg: Message) {
- if msg.author.bot {
- return;
- }
- if msg.content.starts_with(":") {
- if msg.content.starts_with(":org") {
- let args: Vec<&str> = msg.content.split(" ").collect();
- if args.len() == 1 {
- return;
- }
- let org = "#+LATEX_HEADER: \\usepackage{nopageno}\n#+LATEX_HEADER: \\usepackage[margin=0in]{geometry}\n#+OPTIONS: toc:nil\n".to_owned() + &args[1..].join(" ");
- let filepath = format!("/home/nmcdaniel/temp/{}", msg.id);
- create_dir(&filepath).unwrap();
- let mut file = File::create(filepath.clone() + "/file.org").unwrap();
- file.write_all(org.as_bytes()).unwrap();
- println!("{:?}", Command::new("emacs")
- .arg("-nw")
- .arg(filepath.clone() + "/file.org")
- .arg("--batch")
- .arg("-f")
- .arg("org-latex-export-to-latex")
- .arg("--kill")
- .output().unwrap());
- println!("{:?}", Command::new("dvilualatex")
- .arg(filepath.clone() + "/file.tex")
- .arg("--output-directory=".to_owned() + &filepath.clone())
- .output().unwrap());
- println!("{:?}", Command::new("dvipng")
- .arg("./file.dvi")
- .arg("-T tight")
- //.arg("-o ".to_owned() + &filepath.clone() + &"/file.png".to_owned())
- .output().unwrap());
- let pngpath = "./file1.png";
- println!("{}", pngpath);
- let sending = msg.channel_id.send_message(&ctx.http, |m| {
- m.content("Done");
- m.add_file(AttachmentType::Path(Path::new(&pngpath)));
- m
- });
- if let Err(why) = sending {
- println!("E: {}", why);
- }
- }
- }
- }
- fn ready(&self, _: Context, ready: Ready) {
- println!("Connected as {}", ready.user.name);
- }
- }
- fn main() {
- println!("Hello, world!");
- let tok = "token";
- let mut client = Client::new(&tok, Handler).expect("Error making client");
- if let Err(e) = client.start() {
- println!("Error: {}", e);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement