From 5b998f4b54995b3a20c98eb76ef02b0b934f3db4 Mon Sep 17 00:00:00 2001 From: Agatha Rose Date: Sat, 6 Jun 2020 21:34:24 +0300 Subject: [PATCH] Add different channel support for pinned command, update host info --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/main.rs | 23 ++++++++++++++--------- 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index cc8a358..65aebab 100755 --- a/Cargo.lock +++ b/Cargo.lock @@ -1071,7 +1071,7 @@ dependencies = [ [[package]] name = "rustcord" -version = "1.0.2" +version = "1.1.0" dependencies = [ "brainfrick 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "colored 1.9.3 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/Cargo.toml b/Cargo.toml index 4a1a68b..e1c6b1b 100755 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "rustcord" -version = "1.0.2" +version = "1.1.0" authors = ["Agatha Rose "] edition = "2018" diff --git a/src/main.rs b/src/main.rs index 4b06776..2ba1c42 100755 --- a/src/main.rs +++ b/src/main.rs @@ -15,7 +15,7 @@ use serenity::{ Args, CheckResult, CommandError, CommandOptions, CommandResult, DispatchError, Reason, StandardFramework, }, - model::{channel::Message, gateway::Ready, id::UserId, user::OnlineStatus}, + model::{channel::Message, gateway::Ready, id::{ChannelId, UserId}, user::OnlineStatus}, prelude::*, }; use std::collections::hash_map::DefaultHasher; @@ -221,7 +221,7 @@ fn host(ctx: &mut Context, message: &Message) -> CommandResult { let _ = message.channel_id.say( &ctx.http, format!( - "Debug\nOS: {os}; {release}\nHost: {host}\nCPU: {cpu}MHz", + "OS: {os}; {release}\nHost: {host}\nCPU: {cpu}MHz", os = sys_info::os_type().unwrap(), host = sys_info::hostname().unwrap(), release = sys_info::linux_os_release() @@ -527,8 +527,8 @@ fn help(ctx: &mut Context, message: &Message) -> CommandResult { ), ("owo!desc", "Display channel's topic", true), ( - "owo!pinned ``[num]``", - "Display channel's Nth pinned message", + "owo!pinned ``num`` ````", + "Display channel's Nth pinned message. Channel name is optional", true, ), ("owo!brainfuck ``input``", "execute input code", true), @@ -648,7 +648,16 @@ fn desc(ctx: &mut Context, message: &Message) -> CommandResult { #[command] fn pinned(ctx: &mut Context, message: &Message, mut args: Args) -> CommandResult { - let pinned = match message.channel_id.pins(&ctx.http) { + let mut idx = args.single::().unwrap_or(1); + if idx != 0 { + idx -= 1; + } + let target_channel = match args.single::() { + Ok(v) => v, + Err(_) => message.channel_id + }; + dbg!(target_channel); + let pinned = match target_channel.pins(&ctx.http) { Ok(v) => v, Err(e) => { return Err(CommandError( @@ -656,10 +665,6 @@ fn pinned(ctx: &mut Context, message: &Message, mut args: Args) -> CommandResult )); } }; - let mut idx = args.single::().unwrap_or(1); - if idx != 0 { - idx -= 1; - } if pinned.is_empty() { return Err(CommandError("No pinned messages found!".to_string())); }