removed language_manager.rs. framework reworked for slash commands. updated info commands for new framework
This commit is contained in:
@ -1,9 +1,10 @@
|
||||
[package]
|
||||
name = "regex_command_attr"
|
||||
version = "0.2.0"
|
||||
version = "0.3.6"
|
||||
authors = ["acdenisSK <acdenissk69@gmail.com>", "jellywx <judesouthworth@pm.me>"]
|
||||
edition = "2018"
|
||||
description = "Procedural macros for command creation for the RegexFramework for serenity."
|
||||
description = "Procedural macros for command creation for the Serenity library."
|
||||
license = "ISC"
|
||||
|
||||
[lib]
|
||||
proc-macro = true
|
||||
|
@ -1,13 +1,17 @@
|
||||
use proc_macro2::Span;
|
||||
use syn::parse::{Error, Result};
|
||||
use syn::spanned::Spanned;
|
||||
use syn::{Attribute, Ident, Lit, LitStr, Meta, NestedMeta, Path};
|
||||
|
||||
use crate::structures::PermissionLevel;
|
||||
use crate::util::{AsOption, LitExt};
|
||||
|
||||
use std::fmt::{self, Write};
|
||||
|
||||
use proc_macro2::Span;
|
||||
use syn::{
|
||||
parse::{Error, Result},
|
||||
spanned::Spanned,
|
||||
Attribute, Ident, Lit, LitStr, Meta, NestedMeta, Path,
|
||||
};
|
||||
|
||||
use crate::{
|
||||
structures::{ApplicationCommandOptionType, Arg, PermissionLevel},
|
||||
util::{AsOption, LitExt},
|
||||
};
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq)]
|
||||
pub enum ValueKind {
|
||||
// #[<name>]
|
||||
@ -19,6 +23,9 @@ pub enum ValueKind {
|
||||
// #[<name>([<value>, <value>, <value>, ...])]
|
||||
List,
|
||||
|
||||
// #[<name>([<prop> = <value>, <prop> = <value>, ...])]
|
||||
EqualsList,
|
||||
|
||||
// #[<name>(<value>)]
|
||||
SingleList,
|
||||
}
|
||||
@ -29,6 +36,9 @@ impl fmt::Display for ValueKind {
|
||||
ValueKind::Name => f.pad("`#[<name>]`"),
|
||||
ValueKind::Equals => f.pad("`#[<name> = <value>]`"),
|
||||
ValueKind::List => f.pad("`#[<name>([<value>, <value>, <value>, ...])]`"),
|
||||
ValueKind::EqualsList => {
|
||||
f.pad("`#[<name>([<prop> = <value>, <prop> = <value>, ...])]`")
|
||||
}
|
||||
ValueKind::SingleList => f.pad("`#[<name>(<value>)]`"),
|
||||
}
|
||||
}
|
||||
@ -62,14 +72,19 @@ fn to_ident(p: Path) -> Result<Ident> {
|
||||
#[derive(Debug)]
|
||||
pub struct Values {
|
||||
pub name: Ident,
|
||||
pub literals: Vec<Lit>,
|
||||
pub literals: Vec<(Option<String>, Lit)>,
|
||||
pub kind: ValueKind,
|
||||
pub span: Span,
|
||||
}
|
||||
|
||||
impl Values {
|
||||
#[inline]
|
||||
pub fn new(name: Ident, kind: ValueKind, literals: Vec<Lit>, span: Span) -> Self {
|
||||
pub fn new(
|
||||
name: Ident,
|
||||
kind: ValueKind,
|
||||
literals: Vec<(Option<String>, Lit)>,
|
||||
span: Span,
|
||||
) -> Self {
|
||||
Values {
|
||||
name,
|
||||
literals,
|
||||
@ -80,6 +95,19 @@ impl Values {
|
||||
}
|
||||
|
||||
pub fn parse_values(attr: &Attribute) -> Result<Values> {
|
||||
fn is_list_or_named_list(meta: &NestedMeta) -> ValueKind {
|
||||
match meta {
|
||||
// catch if the nested value is a literal value
|
||||
NestedMeta::Lit(_) => ValueKind::List,
|
||||
// catch if the nested value is a meta value
|
||||
NestedMeta::Meta(m) => match m {
|
||||
// path => some quoted value
|
||||
Meta::Path(_) => ValueKind::List,
|
||||
Meta::List(_) | Meta::NameValue(_) => ValueKind::EqualsList,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
let meta = attr.parse_meta()?;
|
||||
|
||||
match meta {
|
||||
@ -96,36 +124,71 @@ pub fn parse_values(attr: &Attribute) -> Result<Values> {
|
||||
return Err(Error::new(attr.span(), "list cannot be empty"));
|
||||
}
|
||||
|
||||
let mut lits = Vec::with_capacity(nested.len());
|
||||
if is_list_or_named_list(nested.first().unwrap()) == ValueKind::List {
|
||||
let mut lits = Vec::with_capacity(nested.len());
|
||||
|
||||
for meta in nested {
|
||||
match meta {
|
||||
NestedMeta::Lit(l) => lits.push(l),
|
||||
NestedMeta::Meta(m) => match m {
|
||||
Meta::Path(path) => {
|
||||
let i = to_ident(path)?;
|
||||
lits.push(Lit::Str(LitStr::new(&i.to_string(), i.span())))
|
||||
}
|
||||
Meta::List(_) | Meta::NameValue(_) => {
|
||||
return Err(Error::new(attr.span(), "cannot nest a list; only accept literals and identifiers at this level"))
|
||||
}
|
||||
},
|
||||
for meta in nested {
|
||||
match meta {
|
||||
// catch if the nested value is a literal value
|
||||
NestedMeta::Lit(l) => lits.push((None, l)),
|
||||
// catch if the nested value is a meta value
|
||||
NestedMeta::Meta(m) => match m {
|
||||
// path => some quoted value
|
||||
Meta::Path(path) => {
|
||||
let i = to_ident(path)?;
|
||||
lits.push((None, Lit::Str(LitStr::new(&i.to_string(), i.span()))))
|
||||
}
|
||||
Meta::List(_) | Meta::NameValue(_) => {
|
||||
return Err(Error::new(attr.span(), "cannot nest a list; only accept literals and identifiers at this level"))
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let kind = if lits.len() == 1 {
|
||||
ValueKind::SingleList
|
||||
let kind = if lits.len() == 1 {
|
||||
ValueKind::SingleList
|
||||
} else {
|
||||
ValueKind::List
|
||||
};
|
||||
|
||||
Ok(Values::new(name, kind, lits, attr.span()))
|
||||
} else {
|
||||
ValueKind::List
|
||||
};
|
||||
let mut lits = Vec::with_capacity(nested.len());
|
||||
|
||||
Ok(Values::new(name, kind, lits, attr.span()))
|
||||
for meta in nested {
|
||||
match meta {
|
||||
// catch if the nested value is a literal value
|
||||
NestedMeta::Lit(_) => {
|
||||
return Err(Error::new(attr.span(), "key-value pairs expected"))
|
||||
}
|
||||
// catch if the nested value is a meta value
|
||||
NestedMeta::Meta(m) => match m {
|
||||
Meta::NameValue(n) => {
|
||||
let name = to_ident(n.path)?.to_string();
|
||||
let value = n.lit;
|
||||
|
||||
lits.push((Some(name), value));
|
||||
}
|
||||
Meta::List(_) | Meta::Path(_) => {
|
||||
return Err(Error::new(attr.span(), "key-value pairs expected"))
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
Ok(Values::new(name, ValueKind::EqualsList, lits, attr.span()))
|
||||
}
|
||||
}
|
||||
Meta::NameValue(meta) => {
|
||||
let name = to_ident(meta.path)?;
|
||||
let lit = meta.lit;
|
||||
|
||||
Ok(Values::new(name, ValueKind::Equals, vec![lit], attr.span()))
|
||||
Ok(Values::new(
|
||||
name,
|
||||
ValueKind::Equals,
|
||||
vec![(None, lit)],
|
||||
attr.span(),
|
||||
))
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -194,7 +257,7 @@ impl AttributeOption for Vec<String> {
|
||||
Ok(values
|
||||
.literals
|
||||
.into_iter()
|
||||
.map(|lit| lit.to_str())
|
||||
.map(|(_, l)| l.to_str())
|
||||
.collect())
|
||||
}
|
||||
}
|
||||
@ -204,7 +267,7 @@ impl AttributeOption for String {
|
||||
fn parse(values: Values) -> Result<Self> {
|
||||
validate(&values, &[ValueKind::Equals, ValueKind::SingleList])?;
|
||||
|
||||
Ok(values.literals[0].to_str())
|
||||
Ok(values.literals[0].1.to_str())
|
||||
}
|
||||
}
|
||||
|
||||
@ -213,7 +276,7 @@ impl AttributeOption for bool {
|
||||
fn parse(values: Values) -> Result<Self> {
|
||||
validate(&values, &[ValueKind::Name, ValueKind::SingleList])?;
|
||||
|
||||
Ok(values.literals.get(0).map_or(true, |l| l.to_bool()))
|
||||
Ok(values.literals.get(0).map_or(true, |(_, l)| l.to_bool()))
|
||||
}
|
||||
}
|
||||
|
||||
@ -222,7 +285,7 @@ impl AttributeOption for Ident {
|
||||
fn parse(values: Values) -> Result<Self> {
|
||||
validate(&values, &[ValueKind::SingleList])?;
|
||||
|
||||
Ok(values.literals[0].to_ident())
|
||||
Ok(values.literals[0].1.to_ident())
|
||||
}
|
||||
}
|
||||
|
||||
@ -231,15 +294,22 @@ impl AttributeOption for Vec<Ident> {
|
||||
fn parse(values: Values) -> Result<Self> {
|
||||
validate(&values, &[ValueKind::List])?;
|
||||
|
||||
Ok(values.literals.into_iter().map(|l| l.to_ident()).collect())
|
||||
Ok(values
|
||||
.literals
|
||||
.into_iter()
|
||||
.map(|(_, l)| l.to_ident())
|
||||
.collect())
|
||||
}
|
||||
}
|
||||
|
||||
impl AttributeOption for Option<String> {
|
||||
fn parse(values: Values) -> Result<Self> {
|
||||
validate(&values, &[ValueKind::Name, ValueKind::Equals, ValueKind::SingleList])?;
|
||||
validate(
|
||||
&values,
|
||||
&[ValueKind::Name, ValueKind::Equals, ValueKind::SingleList],
|
||||
)?;
|
||||
|
||||
Ok(values.literals.get(0).map(|l| l.to_str()))
|
||||
Ok(values.literals.get(0).map(|(_, l)| l.to_str()))
|
||||
}
|
||||
}
|
||||
|
||||
@ -247,7 +317,44 @@ impl AttributeOption for PermissionLevel {
|
||||
fn parse(values: Values) -> Result<Self> {
|
||||
validate(&values, &[ValueKind::SingleList])?;
|
||||
|
||||
Ok(values.literals.get(0).map(|l| PermissionLevel::from_str(&*l.to_str()).unwrap()).unwrap())
|
||||
Ok(values
|
||||
.literals
|
||||
.get(0)
|
||||
.map(|(_, l)| PermissionLevel::from_str(&*l.to_str()).unwrap())
|
||||
.unwrap())
|
||||
}
|
||||
}
|
||||
|
||||
impl AttributeOption for Arg {
|
||||
fn parse(values: Values) -> Result<Self> {
|
||||
validate(&values, &[ValueKind::EqualsList])?;
|
||||
|
||||
let mut arg: Arg = Default::default();
|
||||
|
||||
for (key, value) in &values.literals {
|
||||
match key {
|
||||
Some(s) => match s.as_str() {
|
||||
"name" => {
|
||||
arg.name = value.to_str();
|
||||
}
|
||||
"description" => {
|
||||
arg.description = value.to_str();
|
||||
}
|
||||
"required" => {
|
||||
arg.required = value.to_bool();
|
||||
}
|
||||
"kind" => arg.kind = ApplicationCommandOptionType::from_str(value.to_str()),
|
||||
_ => {
|
||||
return Err(Error::new(key.span(), "unexpected attribute"));
|
||||
}
|
||||
},
|
||||
_ => {
|
||||
return Err(Error::new(key.span(), "unnamed attribute"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Ok(arg)
|
||||
}
|
||||
}
|
||||
|
||||
@ -265,7 +372,7 @@ macro_rules! attr_option_num {
|
||||
fn parse(values: Values) -> Result<Self> {
|
||||
validate(&values, &[ValueKind::SingleList])?;
|
||||
|
||||
Ok(match &values.literals[0] {
|
||||
Ok(match &values.literals[0].1 {
|
||||
Lit::Int(l) => l.base10_parse::<$n>()?,
|
||||
l => {
|
||||
let s = l.to_str();
|
||||
|
@ -1,5 +1,6 @@
|
||||
pub mod suffixes {
|
||||
pub const COMMAND: &str = "COMMAND";
|
||||
pub const ARG: &str = "ARG";
|
||||
}
|
||||
|
||||
pub use self::suffixes::*;
|
||||
|
@ -1,14 +1,10 @@
|
||||
#![deny(rust_2018_idioms)]
|
||||
// FIXME: Remove this in a foreseeable future.
|
||||
// Currently exists for backwards compatibility to previous Rust versions.
|
||||
#![recursion_limit = "128"]
|
||||
|
||||
#[allow(unused_extern_crates)]
|
||||
extern crate proc_macro;
|
||||
#![deny(broken_intra_doc_links)]
|
||||
|
||||
use proc_macro::TokenStream;
|
||||
use proc_macro2::Ident;
|
||||
use quote::quote;
|
||||
use syn::{parse::Error, parse_macro_input, spanned::Spanned, Lit};
|
||||
use syn::{parse::Error, parse_macro_input, parse_quote, spanned::Spanned, Lit, Type};
|
||||
|
||||
pub(crate) mod attributes;
|
||||
pub(crate) mod consts;
|
||||
@ -41,7 +37,7 @@ macro_rules! match_options {
|
||||
pub fn command(attr: TokenStream, input: TokenStream) -> TokenStream {
|
||||
let mut fun = parse_macro_input!(input as CommandFun);
|
||||
|
||||
let lit_name = if !attr.is_empty() {
|
||||
let _name = if !attr.is_empty() {
|
||||
parse_macro_input!(attr as Lit).to_str()
|
||||
} else {
|
||||
fun.name.to_string()
|
||||
@ -56,17 +52,40 @@ pub fn command(attr: TokenStream, input: TokenStream) -> TokenStream {
|
||||
let name = values.name.to_string();
|
||||
let name = &name[..];
|
||||
|
||||
match_options!(name, values, options, span => [
|
||||
permission_level;
|
||||
supports_dm;
|
||||
can_blacklist
|
||||
]);
|
||||
match name {
|
||||
"arg" => options
|
||||
.cmd_args
|
||||
.push(propagate_err!(attributes::parse(values))),
|
||||
"example" => {
|
||||
options
|
||||
.examples
|
||||
.push(propagate_err!(attributes::parse(values)));
|
||||
}
|
||||
"description" => {
|
||||
let line: String = propagate_err!(attributes::parse(values));
|
||||
util::append_line(&mut options.description, line);
|
||||
}
|
||||
_ => {
|
||||
match_options!(name, values, options, span => [
|
||||
aliases;
|
||||
group;
|
||||
required_permissions;
|
||||
can_blacklist;
|
||||
supports_dm
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let Options {
|
||||
permission_level,
|
||||
supports_dm,
|
||||
aliases,
|
||||
description,
|
||||
group,
|
||||
examples,
|
||||
required_permissions,
|
||||
can_blacklist,
|
||||
supports_dm,
|
||||
mut cmd_args,
|
||||
} = options;
|
||||
|
||||
let visibility = fun.visibility;
|
||||
@ -78,25 +97,88 @@ pub fn command(attr: TokenStream, input: TokenStream) -> TokenStream {
|
||||
let cooked = fun.cooked.clone();
|
||||
|
||||
let command_path = quote!(crate::framework::Command);
|
||||
let arg_path = quote!(crate::framework::Arg);
|
||||
|
||||
populate_fut_lifetimes_on_refs(&mut fun.args);
|
||||
let args = fun.args;
|
||||
|
||||
(quote! {
|
||||
#(#cooked)*
|
||||
pub static #n: #command_path = #command_path {
|
||||
func: #name,
|
||||
name: #lit_name,
|
||||
required_perms: #permission_level,
|
||||
supports_dm: #supports_dm,
|
||||
can_blacklist: #can_blacklist,
|
||||
};
|
||||
let arg_idents = cmd_args
|
||||
.iter()
|
||||
.map(|arg| {
|
||||
n.with_suffix(arg.name.replace(" ", "_").replace("-", "_").as_str())
|
||||
.with_suffix(ARG)
|
||||
})
|
||||
.collect::<Vec<Ident>>();
|
||||
|
||||
let mut tokens = cmd_args
|
||||
.iter_mut()
|
||||
.map(|arg| {
|
||||
let Arg {
|
||||
name,
|
||||
description,
|
||||
kind,
|
||||
required,
|
||||
} = arg;
|
||||
|
||||
let an = n.with_suffix(name.as_str()).with_suffix(ARG);
|
||||
|
||||
quote! {
|
||||
#(#cooked)*
|
||||
#[allow(missing_docs)]
|
||||
pub static #an: #arg_path = #arg_path {
|
||||
name: #name,
|
||||
description: #description,
|
||||
kind: #kind,
|
||||
required: #required,
|
||||
};
|
||||
}
|
||||
})
|
||||
.fold(quote! {}, |mut a, b| {
|
||||
a.extend(b);
|
||||
a
|
||||
});
|
||||
|
||||
let variant = if args.len() == 2 {
|
||||
quote!(crate::framework::CommandFnType::Multi)
|
||||
} else {
|
||||
let string: Type = parse_quote!(std::string::String);
|
||||
|
||||
let final_arg = args.get(2).unwrap();
|
||||
|
||||
if final_arg.kind == string {
|
||||
quote!(crate::framework::CommandFnType::Text)
|
||||
} else {
|
||||
quote!(crate::framework::CommandFnType::Slash)
|
||||
}
|
||||
};
|
||||
|
||||
tokens.extend(quote! {
|
||||
#(#cooked)*
|
||||
#[allow(missing_docs)]
|
||||
pub static #n: #command_path = #command_path {
|
||||
fun: #variant(#name),
|
||||
names: &[#_name, #(#aliases),*],
|
||||
desc: #description,
|
||||
group: #group,
|
||||
examples: &[#(#examples),*],
|
||||
required_permissions: #required_permissions,
|
||||
can_blacklist: #can_blacklist,
|
||||
supports_dm: #supports_dm,
|
||||
args: &[#(&#arg_idents),*],
|
||||
};
|
||||
});
|
||||
|
||||
tokens.extend(quote! {
|
||||
#(#cooked)*
|
||||
#[allow(missing_docs)]
|
||||
#visibility fn #name<'fut> (#(#args),*) -> ::serenity::futures::future::BoxFuture<'fut, ()> {
|
||||
use ::serenity::futures::future::FutureExt;
|
||||
|
||||
async move { #(#body)* }.boxed()
|
||||
async move {
|
||||
#(#body)*;
|
||||
}.boxed()
|
||||
}
|
||||
})
|
||||
.into()
|
||||
});
|
||||
|
||||
tokens.into()
|
||||
}
|
||||
|
@ -1,14 +1,14 @@
|
||||
use crate::util::{Argument, Parenthesised};
|
||||
use proc_macro2::Span;
|
||||
use proc_macro2::TokenStream as TokenStream2;
|
||||
use quote::{quote, ToTokens};
|
||||
use syn::{
|
||||
braced,
|
||||
parse::{Error, Parse, ParseStream, Result},
|
||||
spanned::Spanned,
|
||||
Attribute, Block, FnArg, Ident, Pat, Path, PathSegment, Stmt, Token, Visibility,
|
||||
Attribute, Block, FnArg, Ident, Pat, Stmt, Token, Visibility,
|
||||
};
|
||||
|
||||
use crate::util::{Argument, Parenthesised};
|
||||
|
||||
fn parse_argument(arg: FnArg) -> Result<Argument> {
|
||||
match arg {
|
||||
FnArg::Typed(typed) => {
|
||||
@ -53,7 +53,7 @@ fn parse_argument(arg: FnArg) -> Result<Argument> {
|
||||
/// Test if the attribute is cooked.
|
||||
fn is_cooked(attr: &Attribute) -> bool {
|
||||
const COOKED_ATTRIBUTE_NAMES: &[&str] = &[
|
||||
"cfg", "cfg_attr", "doc", "derive", "inline", "allow", "warn", "deny", "forbid",
|
||||
"cfg", "cfg_attr", "derive", "inline", "allow", "warn", "deny", "forbid",
|
||||
];
|
||||
|
||||
COOKED_ATTRIBUTE_NAMES.iter().any(|n| attr.path.is_ident(n))
|
||||
@ -98,17 +98,6 @@ impl Parse for CommandFun {
|
||||
fn parse(input: ParseStream<'_>) -> Result<Self> {
|
||||
let mut attributes = input.call(Attribute::parse_outer)?;
|
||||
|
||||
// `#[doc = "..."]` is a cooked attribute but it is special-cased for commands.
|
||||
for attr in &mut attributes {
|
||||
// Rename documentation comment attributes (`#[doc = "..."]`) to `#[description = "..."]`.
|
||||
if attr.path.is_ident("doc") {
|
||||
attr.path = Path::from(PathSegment::from(Ident::new(
|
||||
"description",
|
||||
Span::call_site(),
|
||||
)));
|
||||
}
|
||||
}
|
||||
|
||||
let cooked = remove_cooked(&mut attributes);
|
||||
|
||||
let visibility = input.parse::<Visibility>()?;
|
||||
@ -155,7 +144,7 @@ impl ToTokens for CommandFun {
|
||||
|
||||
stream.extend(quote! {
|
||||
#(#cooked)*
|
||||
#visibility async fn #name (#(#args),*) -> () {
|
||||
#visibility async fn #name (#(#args),*) {
|
||||
#(#body)*
|
||||
}
|
||||
});
|
||||
@ -211,21 +200,98 @@ impl ToTokens for PermissionLevel {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub(crate) enum ApplicationCommandOptionType {
|
||||
SubCommand,
|
||||
SubCommandGroup,
|
||||
String,
|
||||
Integer,
|
||||
Boolean,
|
||||
User,
|
||||
Channel,
|
||||
Role,
|
||||
Mentionable,
|
||||
Unknown,
|
||||
}
|
||||
|
||||
impl ApplicationCommandOptionType {
|
||||
pub fn from_str(s: String) -> Self {
|
||||
match s.as_str() {
|
||||
"SubCommand" => Self::SubCommand,
|
||||
"SubCommandGroup" => Self::SubCommandGroup,
|
||||
"String" => Self::String,
|
||||
"Integer" => Self::Integer,
|
||||
"Boolean" => Self::Boolean,
|
||||
"User" => Self::User,
|
||||
"Channel" => Self::Channel,
|
||||
"Role" => Self::Role,
|
||||
"Mentionable" => Self::Mentionable,
|
||||
_ => Self::Unknown,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ToTokens for ApplicationCommandOptionType {
|
||||
fn to_tokens(&self, stream: &mut TokenStream2) {
|
||||
let path = quote!(
|
||||
serenity::model::interactions::application_command::ApplicationCommandOptionType
|
||||
);
|
||||
let variant = match self {
|
||||
ApplicationCommandOptionType::SubCommand => quote!(SubCommand),
|
||||
ApplicationCommandOptionType::SubCommandGroup => quote!(SubCommandGroup),
|
||||
ApplicationCommandOptionType::String => quote!(String),
|
||||
ApplicationCommandOptionType::Integer => quote!(Integer),
|
||||
ApplicationCommandOptionType::Boolean => quote!(Boolean),
|
||||
ApplicationCommandOptionType::User => quote!(User),
|
||||
ApplicationCommandOptionType::Channel => quote!(Channel),
|
||||
ApplicationCommandOptionType::Role => quote!(Role),
|
||||
ApplicationCommandOptionType::Mentionable => quote!(Mentionable),
|
||||
ApplicationCommandOptionType::Unknown => quote!(Unknown),
|
||||
};
|
||||
|
||||
stream.extend(quote! {
|
||||
#path::#variant
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub(crate) struct Arg {
|
||||
pub name: String,
|
||||
pub description: String,
|
||||
pub kind: ApplicationCommandOptionType,
|
||||
pub required: bool,
|
||||
}
|
||||
|
||||
impl Default for Arg {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
name: String::new(),
|
||||
description: String::new(),
|
||||
kind: ApplicationCommandOptionType::String,
|
||||
required: false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Default)]
|
||||
pub struct Options {
|
||||
pub permission_level: PermissionLevel,
|
||||
pub supports_dm: bool,
|
||||
pub(crate) struct Options {
|
||||
pub aliases: Vec<String>,
|
||||
pub description: String,
|
||||
pub group: String,
|
||||
pub examples: Vec<String>,
|
||||
pub required_permissions: PermissionLevel,
|
||||
pub can_blacklist: bool,
|
||||
pub supports_dm: bool,
|
||||
pub cmd_args: Vec<Arg>,
|
||||
}
|
||||
|
||||
impl Options {
|
||||
#[inline]
|
||||
pub fn new() -> Self {
|
||||
let mut options = Self::default();
|
||||
|
||||
options.can_blacklist = true;
|
||||
options.supports_dm = true;
|
||||
|
||||
options
|
||||
Self {
|
||||
group: "Other".to_string(),
|
||||
..Default::default()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,5 @@
|
||||
use proc_macro::TokenStream;
|
||||
use proc_macro2::Span;
|
||||
use proc_macro2::TokenStream as TokenStream2;
|
||||
use proc_macro2::{Span, TokenStream as TokenStream2};
|
||||
use quote::{format_ident, quote, ToTokens};
|
||||
use syn::{
|
||||
braced, bracketed, parenthesized,
|
||||
@ -158,3 +157,20 @@ pub fn populate_fut_lifetimes_on_refs(args: &mut Vec<Argument>) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn append_line(desc: &mut String, mut line: String) {
|
||||
if line.starts_with(' ') {
|
||||
line.remove(0);
|
||||
}
|
||||
|
||||
match line.rfind("\\$") {
|
||||
Some(i) => {
|
||||
desc.push_str(line[..i].trim_end());
|
||||
desc.push(' ');
|
||||
}
|
||||
None => {
|
||||
desc.push_str(&line);
|
||||
desc.push('\n');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user