permission_level attribute macro working
This commit is contained in:
parent
0e3c514f35
commit
7dac9f7895
@ -209,9 +209,24 @@ impl PermissionLevel {
|
|||||||
impl ToTokens for PermissionLevel {
|
impl ToTokens for PermissionLevel {
|
||||||
fn to_tokens(&self, stream: &mut TokenStream2) {
|
fn to_tokens(&self, stream: &mut TokenStream2) {
|
||||||
let path = quote!(crate::framework::PermissionLevel);
|
let path = quote!(crate::framework::PermissionLevel);
|
||||||
|
let variant;
|
||||||
|
|
||||||
|
match self {
|
||||||
|
Self::Unrestricted => {
|
||||||
|
variant = quote!(Unrestricted);
|
||||||
|
}
|
||||||
|
|
||||||
|
Self::Managed => {
|
||||||
|
variant = quote!(Managed);
|
||||||
|
}
|
||||||
|
|
||||||
|
Self::Restricted => {
|
||||||
|
variant = quote!(Restricted);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
stream.extend(quote! {
|
stream.extend(quote! {
|
||||||
#path::Unrestricted
|
#path::#variant
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -229,6 +244,7 @@ impl Options {
|
|||||||
let mut options = Self::default();
|
let mut options = Self::default();
|
||||||
|
|
||||||
options.can_blacklist = true;
|
options.can_blacklist = true;
|
||||||
|
options.supports_dm = true;
|
||||||
|
|
||||||
options
|
options
|
||||||
}
|
}
|
||||||
|
@ -6,10 +6,14 @@ use serenity::{
|
|||||||
model::channel::Message,
|
model::channel::Message,
|
||||||
};
|
};
|
||||||
|
|
||||||
use std::collections::HashMap;
|
use std::{
|
||||||
|
collections::HashMap,
|
||||||
|
fmt,
|
||||||
|
};
|
||||||
|
|
||||||
use serenity::framework::standard::CommandFn;
|
use serenity::framework::standard::CommandFn;
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
pub enum PermissionLevel {
|
pub enum PermissionLevel {
|
||||||
Unrestricted,
|
Unrestricted,
|
||||||
Managed,
|
Managed,
|
||||||
@ -19,11 +23,22 @@ pub enum PermissionLevel {
|
|||||||
pub struct Command {
|
pub struct Command {
|
||||||
pub name: &'static str,
|
pub name: &'static str,
|
||||||
pub required_perms: PermissionLevel,
|
pub required_perms: PermissionLevel,
|
||||||
pub can_blacklist: bool,
|
|
||||||
pub supports_dm: bool,
|
pub supports_dm: bool,
|
||||||
|
pub can_blacklist: bool,
|
||||||
pub func: CommandFn,
|
pub func: CommandFn,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl fmt::Debug for Command {
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
|
f.debug_struct("Command")
|
||||||
|
.field("name", &self.name)
|
||||||
|
.field("required_perms", &self.required_perms)
|
||||||
|
.field("supports_dm", &self.supports_dm)
|
||||||
|
.field("can_blacklist", &self.can_blacklist)
|
||||||
|
.finish()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// create event handler for bot
|
// create event handler for bot
|
||||||
pub struct RegexFramework {
|
pub struct RegexFramework {
|
||||||
commands: HashMap<String, &'static Command>,
|
commands: HashMap<String, &'static Command>,
|
||||||
|
@ -52,6 +52,8 @@ static THEME_COLOR: u32 = 0x00e0f3;
|
|||||||
async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
|
async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
|
||||||
dotenv()?;
|
dotenv()?;
|
||||||
|
|
||||||
|
println!("{:?}", HELP_COMMAND);
|
||||||
|
|
||||||
let framework = RegexFramework::new()
|
let framework = RegexFramework::new()
|
||||||
.ignore_bots(true)
|
.ignore_bots(true)
|
||||||
.default_prefix("$")
|
.default_prefix("$")
|
||||||
|
Loading…
Reference in New Issue
Block a user