Add different channel support for pinned command, update host info

This commit is contained in:
Agatha Rose 2020-06-06 21:34:24 +03:00
parent 49c4c57f94
commit 5b998f4b54
No known key found for this signature in database
GPG Key ID: 3F9F2317B3D5C3AC
3 changed files with 16 additions and 11 deletions

2
Cargo.lock generated
View File

@ -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)",

View File

@ -1,6 +1,6 @@
[package]
name = "rustcord"
version = "1.0.2"
version = "1.1.0"
authors = ["Agatha Rose <EvilDeaaaadd@protonmail.com>"]
edition = "2018"

View File

@ -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`` ``<channel>``",
"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::<usize>().unwrap_or(1);
if idx != 0 {
idx -= 1;
}
let target_channel = match args.single::<ChannelId>() {
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::<usize>().unwrap_or(1);
if idx != 0 {
idx -= 1;
}
if pinned.is_empty() {
return Err(CommandError("No pinned messages found!".to_string()));
}