~phate/rsPhate

15191e34eee9b6d0b5cd4b50ba7153e3482b330e — ValleyKnight 7 months ago 2589f3e
add neko command, remove rofl dependency
5 files changed, 54 insertions(+), 8 deletions(-)

M Cargo.toml
M src/commands/mod.rs
A src/commands/neko.rs
M src/commands/rng.rs
M src/main.rs
M Cargo.toml => Cargo.toml +5 -4
@@ 8,12 8,13 @@ edition = "2018"

[dependencies]
date_time = "2.1.0"
env_logger = "0.8.1"
env_logger = "0.8.2"
kankyo = "0.3.0"
log = "0.4.11"
mpd = "0.0.12"
owoify = "0.1.5"
rand = "0.7.3"
rofl = "0.0.1"
rand = "0.8.0"
reqwest = { version = "0.10.10", features = ["json"] }
sedregex = "0.2.4"
serenity = "0.8.7"
serde = "1.0.118"
serenity = "0.8.7"
\ No newline at end of file

M src/commands/mod.rs => src/commands/mod.rs +1 -0
@@ 8,6 8,7 @@ pub mod fortune;
pub mod git;
pub mod hmm;
pub mod math;
pub mod neko;
pub mod noice;
pub mod projects;
pub mod quit;

A src/commands/neko.rs => src/commands/neko.rs +44 -0
@@ 0,0 1,44 @@
use log::{error, info};
use serde::Deserialize;
use serenity::{
    framework::standard::{macros::command, Args, CommandResult},
    model::channel::Message,
    prelude::*
};
use std::fmt;

#[derive(Deserialize)]
struct Image {
    url: String,
}

impl fmt::Display for Image {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        write!(f, "{}", self.url)
    }
}

#[command]
#[description = "Post a random neko based on the category."]
#[usage = "category"]
#[example = "fox_girl"]
#[example = "hentai"]
#[example = "neko"]
#[example = "nsfw_neko_gif"]
#[example = "Random_hentai_gif"]
#[example = "smug"]
#[example = "waifu"]
#[num_args(1)]
fn neko(ctx: &mut Context, msg: &Message, mut args: Args) -> CommandResult {
    let cat = args.single::<String>()?;
    let url = format!("https://nekos.life/api/v2/img/{}", cat);
    let body: Image = reqwest::blocking::get(&url)?.json()?;
    let message = body.to_string();
    info!("message = {}", message.trim());

    if let Err(why) = msg.channel_id.say(&ctx.http, &message) {
        error!("Could not send image because: {}", why);
    }

    Ok(())
}

M src/commands/rng.rs => src/commands/rng.rs +1 -1
@@ 47,7 47,7 @@ fn rng(ctx: &mut Context, msg: &Message, args: Args) -> CommandResult {
        return Ok(());
    }

    let random_number = rand::thread_rng().gen_range(min, max);
    let random_number = rand::thread_rng().gen_range(min..max);

    if let Err(why) = msg.channel_id.say(&ctx.http, &random_number.to_string()) {
        error!("Could not send randomly generated number because: {}", why);

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::*, math::*, noice::*,
    projects::*, quit::*, rng::*, wipltrn::*, ww::*,
    about::*, date::*, embed::*, fortune::*, git::*, hmm::*, math::*,
    neko::*, noice::*, projects::*, quit::*, rng::*, 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, fortune, noice, wipltrn, ww)]
#[commands(date, hmm, fortune, neko, noice, wipltrn, ww)]
struct Functions;

#[group]