~phate/rsPhate

de5ca910d1f3321137d19b7a3ae13d4b543ab689 — Ash 1 year, 2 months ago b018de1
add new command, add some trims
5 files changed, 57 insertions(+), 5 deletions(-)

A scripts/noice
M src/commands/iv.rs
M src/commands/mod.rs
A src/commands/noice.rs
M src/main.rs
A scripts/noice => scripts/noice +6 -0
@@ 0,0 1,6 @@
#!/bin/bash

case "$1" in
    file) find /home/valley/downloads/just_yes/ -type f -exec file --mime-type {} + | awk -F: '{if ($2 ~/image\//) print $1}' | shuf -n1;;
    name) echo "$2" | sed 's/.*\///';;
esac
\ No newline at end of file

M src/commands/iv.rs => src/commands/iv.rs +2 -2
@@ 23,10 23,10 @@ fn iv(ctx: &mut Context, msg: &Message, args: Args) -> CommandResult {
        .arg(args)
        .output()
        .expect("Could not generate link.");
    info!("video id: {}", String::from_utf8_lossy(&id.stdout));
    info!("video id: {}", String::from_utf8_lossy(&id.stdout).trim());

    let link: String =
        "https://invidio.us/watch?v=".to_string() + &String::from_utf8_lossy(&id.stdout);
        "https://invidio.us/watch?v=".to_string() + &String::from_utf8_lossy(&id.stdout).trim();
    info!("invidio link: {}", link);

    if let Err(why) = msg.channel_id.say(&ctx.http, link) {

M src/commands/mod.rs => src/commands/mod.rs +1 -0
@@ 10,6 10,7 @@ pub mod hmm;
pub mod iv;
pub mod math;
pub mod meme;
pub mod noice;
pub mod owo;
pub mod projects;
pub mod quit;

A src/commands/noice.rs => src/commands/noice.rs +45 -0
@@ 0,0 1,45 @@
use serenity::{
    framework::standard::{macros::command, CommandResult},
    http::AttachmentType,
    model::channel::Message,
    prelude::*,
};
use std::path::Path;
use std::process::Command;

#[command]
#[description = "Bot will post a random picture from Phate's \"just yes\" folder. May or may not post NSFW material. Use at own discretion."]
fn noice(ctx: &mut Context, msg: &Message) -> CommandResult {
    let file = Command::new("scripts/noice")
        .arg("file")
        .output()
        .expect("Could not obtain random image");
    let path = format!("{}", String::from_utf8_lossy(&file.stdout).trim());
    let name = Command::new("scripts/noice")
        .arg("name")
        .arg(path)
        .output()
        .expect("Could not get base name.");
    let path2 = format!("{}", String::from_utf8_lossy(&file.stdout).trim());
    let attachment = format!("attachment://{}", String::from_utf8_lossy(&name.stdout).trim());
    println!(
        "file: {}\nname: {}\nattachment: {}",
        String::from_utf8_lossy(&file.stdout).trim(),
        String::from_utf8_lossy(&name.stdout).trim(),
        attachment
    );
    let msg = msg.channel_id.send_message(&ctx.http, |m| {
        m.embed(|e| {
            e.image(attachment);
            e
        });
        m.add_file(AttachmentType::Path(Path::new(&path2)));
        m
    });

    if let Err(why) = msg {
        println!("Error sending message: {:?}", why);
    }

    Ok(())
}

M src/main.rs => src/main.rs +3 -3
@@ 20,8 20,8 @@ use std::{
// Load and use commands from src/commands/
mod commands;
use commands::{
    about::*, date::*, embed::*, fortune::*, git::*, hmm::*, iv::*, math::*, meme::*, owo::*,
    projects::*, quit::*, rng::*, rr::*, star::*, wipltrn::*, ww::*,
    about::*, date::*, embed::*, fortune::*, git::*, hmm::*, iv::*, math::*, meme::*, noice::*,
    owo::*, projects::*, quit::*, rng::*, rr::*, star::*, wipltrn::*, ww::*,
};

// Load and use extra functions from src/functions/


@@ 73,7 73,7 @@ impl EventHandler for Handler {
// Groups
#[group]
#[description = "Functions for the bot that do not belong in any specific category."]
#[commands(date, hmm, iv, fortune, meme, rr, wipltrn, ww)]
#[commands(date, hmm, iv, fortune, meme, noice, rr, wipltrn, ww)]
struct Functions;

#[group]