blacklist command
This commit is contained in:
@ -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
|
||||
|
@ -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;
|
||||
|
Reference in New Issue
Block a user