blacklist stuff
This commit is contained in:
parent
e5334af999
commit
afe3dbc525
@ -18,20 +18,21 @@ use crate::{
|
|||||||
#[command]
|
#[command]
|
||||||
#[supports_dm(false)]
|
#[supports_dm(false)]
|
||||||
#[permission_level(Restricted)]
|
#[permission_level(Restricted)]
|
||||||
|
#[can_blacklist(false)]
|
||||||
async fn blacklist(ctx: &Context, msg: &Message, args: String) -> CommandResult {
|
async fn blacklist(ctx: &Context, msg: &Message, args: String) -> CommandResult {
|
||||||
let pool = ctx.data.read().await
|
let pool = ctx.data.read().await
|
||||||
.get::<SQLPool>().cloned().expect("Could not get SQLPool from data");
|
.get::<SQLPool>().cloned().expect("Could not get SQLPool from data");
|
||||||
|
|
||||||
let mut channel = ChannelData::from_id(msg.channel(&ctx).await.unwrap(), pool.clone()).await.unwrap();
|
let mut channel = ChannelData::from_channel(msg.channel(&ctx).await.unwrap(), pool.clone()).await.unwrap();
|
||||||
|
|
||||||
channel.blacklisted = !channel.blacklisted;
|
channel.blacklisted = !channel.blacklisted;
|
||||||
channel.commit_changes(pool).await;
|
channel.commit_changes(pool).await;
|
||||||
|
|
||||||
if channel.blacklisted {
|
if channel.blacklisted {
|
||||||
|
let _ = msg.channel_id.say(&ctx, "Blacklisted").await;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
let _ = msg.channel_id.say(&ctx, "Unblacklisted").await;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -34,7 +34,10 @@ use std::{
|
|||||||
fmt,
|
fmt,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::SQLPool;
|
use crate::{
|
||||||
|
models::ChannelData,
|
||||||
|
SQLPool,
|
||||||
|
};
|
||||||
|
|
||||||
type CommandFn = for<'fut> fn(&'fut Context, &'fut Message, String) -> BoxFuture<'fut, CommandResult>;
|
type CommandFn = for<'fut> fn(&'fut Context, &'fut Message, String) -> BoxFuture<'fut, CommandResult>;
|
||||||
|
|
||||||
@ -311,14 +314,21 @@ impl Framework for RegexFramework {
|
|||||||
match check_self_permissions(&ctx, &guild, &channel).await {
|
match check_self_permissions(&ctx, &guild, &channel).await {
|
||||||
Ok(perms) => match perms {
|
Ok(perms) => match perms {
|
||||||
PermissionCheck::All => {
|
PermissionCheck::All => {
|
||||||
let command = self.commands.get(full_match.name("cmd").unwrap().as_str()).unwrap();
|
let pool = ctx.data.read().await
|
||||||
let args = full_match.name("args")
|
.get::<SQLPool>().cloned().expect("Could not get SQLPool from data");
|
||||||
.map(|m| m.as_str())
|
|
||||||
.unwrap_or("")
|
|
||||||
.to_string();
|
|
||||||
|
|
||||||
if command.check_permissions(&ctx, &guild, &member).await {
|
let command = self.commands.get(full_match.name("cmd").unwrap().as_str()).unwrap();
|
||||||
(command.func)(&ctx, &msg, args).await.unwrap();
|
let channel_data = ChannelData::from_channel(msg.channel(&ctx).await.unwrap(), pool).await;
|
||||||
|
|
||||||
|
if !command.can_blacklist || channel_data.map(|c| c.blacklisted).unwrap_or(false) {
|
||||||
|
let args = full_match.name("args")
|
||||||
|
.map(|m| m.as_str())
|
||||||
|
.unwrap_or("")
|
||||||
|
.to_string();
|
||||||
|
|
||||||
|
if command.check_permissions(&ctx, &guild, &member).await {
|
||||||
|
(command.func)(&ctx, &msg, args).await.unwrap();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
use serenity::model::{
|
use serenity::model::{
|
||||||
|
id::ChannelId,
|
||||||
guild::Guild,
|
guild::Guild,
|
||||||
channel::Channel
|
channel::Channel
|
||||||
};
|
};
|
||||||
@ -58,7 +59,7 @@ SELECT id, guild, name, prefix FROM guilds WHERE guild = ?
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl ChannelData {
|
impl ChannelData {
|
||||||
pub async fn from_id(channel: Channel, pool: MySqlPool) -> Result<Self, Box<dyn std::error::Error + Sync + Send>> {
|
pub async fn from_channel(channel: Channel, pool: MySqlPool) -> Result<Self, Box<dyn std::error::Error + Sync + Send>> {
|
||||||
let channel_id = channel.id().as_u64().clone();
|
let channel_id = channel.id().as_u64().clone();
|
||||||
|
|
||||||
if let Ok(c) = sqlx::query_as_unchecked!(Self,
|
if let Ok(c) = sqlx::query_as_unchecked!(Self,
|
||||||
|
Loading…
Reference in New Issue
Block a user