blacklist command

This commit is contained in:
jude
2020-08-26 18:26:28 +01:00
parent afe3dbc525
commit ff09ccfd62
7 changed files with 31 additions and 2 deletions

View File

@ -14,6 +14,7 @@ use crate::THEME_COLOR;
#[command]
#[can_blacklist(false)]
async fn help(ctx: &Context, msg: &Message, _args: String) -> CommandResult {
msg.channel_id.send_message(ctx, |m| m
.embed(|e| e

View File

@ -10,11 +10,17 @@ use serenity::{
framework::standard::CommandResult,
};
use regex::Regex;
use crate::{
models::ChannelData,
SQLPool,
};
lazy_static! {
static ref REGEX_CHANNEL: Regex = Regex::new(r#"^\s*<#(\d+)>\s*$"#).unwrap();
}
#[command]
#[supports_dm(false)]
#[permission_level(Restricted)]
@ -23,7 +29,15 @@ async fn blacklist(ctx: &Context, msg: &Message, args: String) -> CommandResult
let pool = ctx.data.read().await
.get::<SQLPool>().cloned().expect("Could not get SQLPool from data");
let mut channel = ChannelData::from_channel(msg.channel(&ctx).await.unwrap(), pool.clone()).await.unwrap();
let capture_opt = REGEX_CHANNEL.captures(&args).map(|cap| cap.get(1)).flatten();
let mut channel = match capture_opt {
Some(capture) =>
ChannelData::from_id(capture.as_str().parse::<u64>().unwrap(), pool.clone()).await.unwrap(),
None =>
ChannelData::from_channel(msg.channel(&ctx).await.unwrap(), pool.clone()).await.unwrap(),
};
channel.blacklisted = !channel.blacklisted;
channel.commit_changes(pool).await;