removed standard_framework completely
This commit is contained in:
parent
19b3eb067e
commit
3e490bb5c4
67
Cargo.lock
generated
67
Cargo.lock
generated
@ -203,6 +203,12 @@ version = "0.1.10"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822"
|
||||
|
||||
[[package]]
|
||||
name = "cfg-if"
|
||||
version = "1.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
||||
|
||||
[[package]]
|
||||
name = "chrono"
|
||||
version = "0.4.19"
|
||||
@ -227,16 +233,6 @@ dependencies = [
|
||||
"parse-zoneinfo",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "command_attr"
|
||||
version = "0.3.0-rc.3"
|
||||
source = "git+https://github.com/jellywx/serenity?branch=jellywx-member_permissions#6d96e6837bbbc09127bd728b80daccce538daf09"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "core-foundation"
|
||||
version = "0.7.0"
|
||||
@ -261,11 +257,11 @@ checksum = "8aebca1129a03dc6dc2b127edd729435bbc4a37e1d5f4d7513165089ceb02634"
|
||||
|
||||
[[package]]
|
||||
name = "crc32fast"
|
||||
version = "1.2.0"
|
||||
version = "1.2.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ba125de2af0df55319f41944744ad91c71113bf74a4646efff39afe1f6842db1"
|
||||
checksum = "81156fece84ab6a9f2afdb109ce3ae577e42b1228441eded99bd77f627953b1a"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"cfg-if 1.0.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -274,7 +270,7 @@ version = "0.2.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "774ba60a54c213d409d5353bda12d49cd68d14e45036a285234c8d6f91f92570"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"cfg-if 0.1.10",
|
||||
"crossbeam-utils",
|
||||
"maybe-uninit",
|
||||
]
|
||||
@ -286,7 +282,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c3c7c73a2d1e9fc0886a08b93e98eb643461230d5f1925e4036204d5f2e261a8"
|
||||
dependencies = [
|
||||
"autocfg",
|
||||
"cfg-if",
|
||||
"cfg-if 0.1.10",
|
||||
"lazy_static",
|
||||
]
|
||||
|
||||
@ -332,7 +328,7 @@ version = "0.8.24"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a51b8cf747471cb9499b6d59e59b0444f4c90eba8968c4e44874e92b5b64ace2"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"cfg-if 0.1.10",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -360,7 +356,7 @@ version = "1.0.18"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "da80be589a72651dcda34d8b35bcdc9b7254ad06325611074d9cc0fbb19f60ee"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"cfg-if 0.1.10",
|
||||
"crc32fast",
|
||||
"libc",
|
||||
"miniz_oxide",
|
||||
@ -523,7 +519,7 @@ version = "0.1.15"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fc587bc0ec293155d5bfa6b9891ec18a1e330c234f896ea47fbada4cadbe47e6"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"cfg-if 0.1.10",
|
||||
"libc",
|
||||
"wasi 0.9.0+wasi-snapshot-preview1",
|
||||
]
|
||||
@ -757,7 +753,7 @@ version = "0.4.11"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4fabed175da42fed1fa0746b0ea71f412aa9d35e76e95e59b192c64b9dc2bf8b"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"cfg-if 0.1.10",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -816,7 +812,7 @@ version = "0.6.22"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fce347092656428bc8eaf6201042cb551b8d67855af7374542a92a0fbfcac430"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"cfg-if 0.1.10",
|
||||
"fuchsia-zircon",
|
||||
"fuchsia-zircon-sys",
|
||||
"iovec",
|
||||
@ -898,7 +894,7 @@ version = "0.2.35"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3ebc3ec692ed7c9a255596c67808dee269f64655d8baf7b4f0638e51ba1d6853"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"cfg-if 0.1.10",
|
||||
"libc",
|
||||
"winapi 0.3.9",
|
||||
]
|
||||
@ -968,7 +964,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8d575eff3665419f9b83678ff2815858ad9d11567e082f5ac1814baba4e2bcb4"
|
||||
dependencies = [
|
||||
"bitflags",
|
||||
"cfg-if",
|
||||
"cfg-if 0.1.10",
|
||||
"foreign-types",
|
||||
"lazy_static",
|
||||
"libc",
|
||||
@ -1383,19 +1379,16 @@ dependencies = [
|
||||
"bitflags",
|
||||
"bytes",
|
||||
"chrono",
|
||||
"command_attr",
|
||||
"flate2",
|
||||
"futures",
|
||||
"reqwest",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"static_assertions",
|
||||
"tokio",
|
||||
"tracing",
|
||||
"tracing-futures",
|
||||
"typemap_rev",
|
||||
"url",
|
||||
"uwl",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -1417,7 +1410,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "170a36ea86c864a3f16dd2687712dd6646f7019f301e57537c7f4dc9f5916770"
|
||||
dependencies = [
|
||||
"block-buffer 0.9.0",
|
||||
"cfg-if",
|
||||
"cfg-if 0.1.10",
|
||||
"cpuid-bool",
|
||||
"digest 0.9.0",
|
||||
"opaque-debug 0.3.0",
|
||||
@ -1457,7 +1450,7 @@ version = "0.3.15"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b1fa70dc5c8104ec096f4fe7ede7a221d35ae13dcd19ba1ad9a81d2cab9a1c44"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"cfg-if 0.1.10",
|
||||
"libc",
|
||||
"redox_syscall",
|
||||
"winapi 0.3.9",
|
||||
@ -1542,12 +1535,6 @@ dependencies = [
|
||||
"url",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "static_assertions"
|
||||
version = "1.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f"
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "1.0.45"
|
||||
@ -1565,7 +1552,7 @@ version = "3.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7a6e24d9338a0a5be79593e2fa15a648add6138caa803e2d5bc782c371732ca9"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"cfg-if 0.1.10",
|
||||
"libc",
|
||||
"rand",
|
||||
"redox_syscall",
|
||||
@ -1711,7 +1698,7 @@ version = "0.1.21"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b0987850db3733619253fe60e17cb59b82d37c7e6c0236bb81e4d6b87c879f27"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"cfg-if 0.1.10",
|
||||
"log",
|
||||
"pin-project-lite",
|
||||
"tracing-attributes",
|
||||
@ -1847,12 +1834,6 @@ version = "0.7.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "05e42f7c18b8f902290b009cde6d651262f956c98bc51bca4cd1d511c9cd85c7"
|
||||
|
||||
[[package]]
|
||||
name = "uwl"
|
||||
version = "0.6.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f4bf03e0ca70d626ecc4ba6b0763b934b6f2976e8c744088bb3c1d646fbb1ad0"
|
||||
|
||||
[[package]]
|
||||
name = "vcpkg"
|
||||
version = "0.2.10"
|
||||
@ -1893,7 +1874,7 @@ version = "0.2.68"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1ac64ead5ea5f05873d7c12b545865ca2b8d28adfc50a49b84770a3a97265d42"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"cfg-if 0.1.10",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"wasm-bindgen-macro",
|
||||
@ -1920,7 +1901,7 @@ version = "0.4.18"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b7866cab0aa01de1edf8b5d7936938a7e397ee50ce24119aef3e1eaa3b6171da"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"cfg-if 0.1.10",
|
||||
"js-sys",
|
||||
"wasm-bindgen",
|
||||
"web-sys",
|
||||
|
@ -5,7 +5,6 @@ authors = ["jellywx <judesouthworth@pm.me>"]
|
||||
edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
serenity = { git = "https://github.com/jellywx/serenity", branch = "jellywx-member_permissions", features = ["collector", "rustls_backend"] }
|
||||
dotenv = "0.15"
|
||||
tokio = { version = "0.2", features = ["process"] }
|
||||
reqwest = { version = "0.10", features = ["rustls-tls"] }
|
||||
@ -25,5 +24,11 @@ serde_json = "1.0"
|
||||
rand = "0.7"
|
||||
Inflector = "0.11"
|
||||
|
||||
[dependencies.serenity]
|
||||
git = "https://github.com/jellywx/serenity"
|
||||
branch = "jellywx-member_permissions"
|
||||
default-features = false
|
||||
features = ["builder", "client", "framework", "cache", "gateway", "http", "model", "utils", "rustls_backend", "collector"]
|
||||
|
||||
[dependencies.regex_command_attr]
|
||||
path = "./regex_command_attr"
|
||||
|
@ -8,12 +8,7 @@ extern crate proc_macro;
|
||||
|
||||
use proc_macro::TokenStream;
|
||||
use quote::quote;
|
||||
use syn::{
|
||||
parse::Error,
|
||||
parse_macro_input, parse_quote,
|
||||
spanned::Spanned,
|
||||
Lit,
|
||||
};
|
||||
use syn::{parse::Error, parse_macro_input, spanned::Spanned, Lit};
|
||||
|
||||
pub(crate) mod attributes;
|
||||
pub(crate) mod consts;
|
||||
@ -74,15 +69,9 @@ pub fn command(attr: TokenStream, input: TokenStream) -> TokenStream {
|
||||
can_blacklist,
|
||||
} = options;
|
||||
|
||||
propagate_err!(create_declaration_validations(&mut fun, DeclarFor::Command));
|
||||
|
||||
let res = parse_quote!(serenity::framework::standard::CommandResult);
|
||||
create_return_type_validation(&mut fun, res);
|
||||
|
||||
let visibility = fun.visibility;
|
||||
let name = fun.name.clone();
|
||||
let body = fun.body;
|
||||
let ret = fun.ret;
|
||||
|
||||
let n = name.with_suffix(COMMAND);
|
||||
|
||||
@ -103,7 +92,7 @@ pub fn command(attr: TokenStream, input: TokenStream) -> TokenStream {
|
||||
can_blacklist: #can_blacklist,
|
||||
};
|
||||
|
||||
#visibility fn #name<'fut> (#(#args),*) -> ::serenity::futures::future::BoxFuture<'fut, #ret> {
|
||||
#visibility fn #name<'fut> (#(#args),*) -> ::serenity::futures::future::BoxFuture<'fut, ()> {
|
||||
use ::serenity::futures::future::FutureExt;
|
||||
|
||||
async move { #(#body)* }.boxed()
|
||||
|
@ -6,8 +6,7 @@ use syn::{
|
||||
braced,
|
||||
parse::{Error, Parse, ParseStream, Result},
|
||||
spanned::Spanned,
|
||||
Attribute, Block, FnArg, Ident, Pat, Path, PathSegment, ReturnType, Stmt,
|
||||
Token, Type, Visibility,
|
||||
Attribute, Block, FnArg, Ident, Pat, Path, PathSegment, Stmt, Token, Visibility,
|
||||
};
|
||||
|
||||
fn parse_argument(arg: FnArg) -> Result<Argument> {
|
||||
@ -54,15 +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", "doc", "derive", "inline", "allow", "warn", "deny", "forbid",
|
||||
];
|
||||
|
||||
COOKED_ATTRIBUTE_NAMES.iter().any(|n| attr.path.is_ident(n))
|
||||
@ -100,7 +91,6 @@ pub struct CommandFun {
|
||||
pub visibility: Visibility,
|
||||
pub name: Ident,
|
||||
pub args: Vec<Argument>,
|
||||
pub ret: Type,
|
||||
pub body: Vec<Stmt>,
|
||||
}
|
||||
|
||||
@ -131,14 +121,6 @@ impl Parse for CommandFun {
|
||||
// (...)
|
||||
let Parenthesised(args) = input.parse::<Parenthesised<FnArg>>()?;
|
||||
|
||||
let ret = match input.parse::<ReturnType>()? {
|
||||
ReturnType::Type(_, t) => (*t).clone(),
|
||||
ReturnType::Default => {
|
||||
return Err(input
|
||||
.error("expected a result type of either `CommandResult` or `CheckResult`"))
|
||||
}
|
||||
};
|
||||
|
||||
// { ... }
|
||||
let bcont;
|
||||
braced!(bcont in input);
|
||||
@ -155,7 +137,6 @@ impl Parse for CommandFun {
|
||||
visibility,
|
||||
name,
|
||||
args,
|
||||
ret,
|
||||
body,
|
||||
})
|
||||
}
|
||||
@ -169,13 +150,12 @@ impl ToTokens for CommandFun {
|
||||
visibility,
|
||||
name,
|
||||
args,
|
||||
ret,
|
||||
body,
|
||||
} = self;
|
||||
|
||||
stream.extend(quote! {
|
||||
#(#cooked)*
|
||||
#visibility async fn #name (#(#args),*) -> #ret {
|
||||
#visibility async fn #name (#(#args),*) -> () {
|
||||
#(#body)*
|
||||
}
|
||||
});
|
||||
|
@ -1,4 +1,3 @@
|
||||
use crate::structures::CommandFun;
|
||||
use proc_macro::TokenStream;
|
||||
use proc_macro2::Span;
|
||||
use proc_macro2::TokenStream as TokenStream2;
|
||||
@ -6,9 +5,7 @@ use quote::{format_ident, quote, ToTokens};
|
||||
use syn::{
|
||||
braced, bracketed, parenthesized,
|
||||
parse::{Error, Parse, ParseStream, Result as SynResult},
|
||||
parse_quote,
|
||||
punctuated::Punctuated,
|
||||
spanned::Spanned,
|
||||
token::{Comma, Mut},
|
||||
Ident, Lifetime, Lit, Type,
|
||||
};
|
||||
@ -153,83 +150,6 @@ impl ToTokens for Argument {
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn generate_type_validation(have: Type, expect: Type) -> syn::Stmt {
|
||||
parse_quote! {
|
||||
serenity::static_assertions::assert_type_eq_all!(#have, #expect);
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub enum DeclarFor {
|
||||
Command,
|
||||
Help,
|
||||
Check,
|
||||
}
|
||||
|
||||
pub fn create_declaration_validations(fun: &mut CommandFun, dec_for: DeclarFor) -> SynResult<()> {
|
||||
let len = match dec_for {
|
||||
DeclarFor::Command => 3,
|
||||
DeclarFor::Help => 6,
|
||||
DeclarFor::Check => 4,
|
||||
};
|
||||
|
||||
if fun.args.len() > len {
|
||||
return Err(Error::new(
|
||||
fun.args.last().unwrap().span(),
|
||||
format_args!("function's arity exceeds more than {} arguments", len),
|
||||
));
|
||||
}
|
||||
|
||||
let context: Type = parse_quote!(&serenity::client::Context);
|
||||
let message: Type = parse_quote!(&serenity::model::channel::Message);
|
||||
let args: Type = parse_quote!(String);
|
||||
let options: Type = parse_quote!(&serenity::framework::standard::CommandOptions);
|
||||
let hoptions: Type = parse_quote!(&'static serenity::framework::standard::HelpOptions);
|
||||
let groups: Type = parse_quote!(&[&'static serenity::framework::standard::CommandGroup]);
|
||||
let owners: Type = parse_quote!(std::collections::HashSet<serenity::model::id::UserId>);
|
||||
|
||||
let mut index = 0;
|
||||
|
||||
let mut spoof_or_check = |kind: Type, name: &str| {
|
||||
match fun.args.get(index) {
|
||||
Some(x) => fun.body.insert(0, generate_type_validation(x.kind.clone(), kind)),
|
||||
None => fun.args.push(Argument {
|
||||
mutable: None,
|
||||
name: Ident::new(name, Span::call_site()),
|
||||
kind,
|
||||
}),
|
||||
}
|
||||
|
||||
index += 1;
|
||||
};
|
||||
|
||||
spoof_or_check(context, "_ctx");
|
||||
spoof_or_check(message, "_msg");
|
||||
|
||||
if dec_for == DeclarFor::Check {
|
||||
spoof_or_check(options, "_options");
|
||||
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
spoof_or_check(args, "_args");
|
||||
|
||||
if dec_for == DeclarFor::Help {
|
||||
spoof_or_check(hoptions, "_hoptions");
|
||||
spoof_or_check(groups, "_groups");
|
||||
spoof_or_check(owners, "_owners");
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn create_return_type_validation(r#fn: &mut CommandFun, expect: Type) {
|
||||
let stmt = generate_type_validation(r#fn.ret.clone(), expect);
|
||||
r#fn.body.insert(0, stmt);
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn populate_fut_lifetimes_on_refs(args: &mut Vec<Argument>) {
|
||||
for arg in args {
|
||||
|
@ -1,6 +1,6 @@
|
||||
use regex_command_attr::command;
|
||||
|
||||
use serenity::{client::Context, framework::standard::CommandResult, model::channel::Message};
|
||||
use serenity::{client::Context, model::channel::Message};
|
||||
|
||||
use chrono::offset::Utc;
|
||||
|
||||
@ -14,7 +14,7 @@ use std::time::{SystemTime, UNIX_EPOCH};
|
||||
|
||||
#[command]
|
||||
#[can_blacklist(false)]
|
||||
async fn ping(ctx: &Context, msg: &Message, _args: String) -> CommandResult {
|
||||
async fn ping(ctx: &Context, msg: &Message, _args: String) {
|
||||
let now = SystemTime::now();
|
||||
let since_epoch = now
|
||||
.duration_since(UNIX_EPOCH)
|
||||
@ -26,13 +26,11 @@ async fn ping(ctx: &Context, msg: &Message, _args: String) -> CommandResult {
|
||||
.channel_id
|
||||
.say(&ctx, format!("Time taken to receive message: {}ms", delta))
|
||||
.await;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[command]
|
||||
#[can_blacklist(false)]
|
||||
async fn help(ctx: &Context, msg: &Message, _args: String) -> CommandResult {
|
||||
async fn help(ctx: &Context, msg: &Message, _args: String) {
|
||||
let pool = ctx
|
||||
.data
|
||||
.read()
|
||||
@ -44,7 +42,8 @@ async fn help(ctx: &Context, msg: &Message, _args: String) -> CommandResult {
|
||||
let user_data = UserData::from_user(&msg.author, &ctx, &pool).await.unwrap();
|
||||
let desc = user_data.response(&pool, "help").await;
|
||||
|
||||
msg.channel_id
|
||||
let _ = msg
|
||||
.channel_id
|
||||
.send_message(ctx, |m| {
|
||||
m.embed(move |e| {
|
||||
e.title("Help")
|
||||
@ -59,13 +58,11 @@ async fn help(ctx: &Context, msg: &Message, _args: String) -> CommandResult {
|
||||
.color(*THEME_COLOR)
|
||||
})
|
||||
})
|
||||
.await?;
|
||||
|
||||
Ok(())
|
||||
.await;
|
||||
}
|
||||
|
||||
#[command]
|
||||
async fn info(ctx: &Context, msg: &Message, _args: String) -> CommandResult {
|
||||
async fn info(ctx: &Context, msg: &Message, _args: String) {
|
||||
let pool = ctx
|
||||
.data
|
||||
.read()
|
||||
@ -86,7 +83,8 @@ async fn info(ctx: &Context, msg: &Message, _args: String) -> CommandResult {
|
||||
.replace("{default_prefix}", &*DEFAULT_PREFIX)
|
||||
.replace("{prefix}", &guild_data.prefix);
|
||||
|
||||
msg.channel_id
|
||||
let _ = msg
|
||||
.channel_id
|
||||
.send_message(ctx, |m| {
|
||||
m.embed(move |e| {
|
||||
e.title("Info")
|
||||
@ -101,13 +99,11 @@ async fn info(ctx: &Context, msg: &Message, _args: String) -> CommandResult {
|
||||
.color(*THEME_COLOR)
|
||||
})
|
||||
})
|
||||
.await?;
|
||||
|
||||
Ok(())
|
||||
.await;
|
||||
}
|
||||
|
||||
#[command]
|
||||
async fn donate(ctx: &Context, msg: &Message, _args: String) -> CommandResult {
|
||||
async fn donate(ctx: &Context, msg: &Message, _args: String) {
|
||||
let pool = ctx
|
||||
.data
|
||||
.read()
|
||||
@ -119,7 +115,8 @@ async fn donate(ctx: &Context, msg: &Message, _args: String) -> CommandResult {
|
||||
let user_data = UserData::from_user(&msg.author, &ctx, &pool).await.unwrap();
|
||||
let desc = user_data.response(&pool, "donate").await;
|
||||
|
||||
msg.channel_id
|
||||
let _ = msg
|
||||
.channel_id
|
||||
.send_message(ctx, |m| {
|
||||
m.embed(move |e| {
|
||||
e.title("Donate")
|
||||
@ -134,14 +131,13 @@ async fn donate(ctx: &Context, msg: &Message, _args: String) -> CommandResult {
|
||||
.color(*THEME_COLOR)
|
||||
})
|
||||
})
|
||||
.await?;
|
||||
|
||||
Ok(())
|
||||
.await;
|
||||
}
|
||||
|
||||
#[command]
|
||||
async fn dashboard(ctx: &Context, msg: &Message, _args: String) -> CommandResult {
|
||||
msg.channel_id
|
||||
async fn dashboard(ctx: &Context, msg: &Message, _args: String) {
|
||||
let _ = msg
|
||||
.channel_id
|
||||
.send_message(ctx, |m| {
|
||||
m.embed(move |e| {
|
||||
e.title("Dashboard")
|
||||
@ -156,13 +152,11 @@ async fn dashboard(ctx: &Context, msg: &Message, _args: String) -> CommandResult
|
||||
.color(*THEME_COLOR)
|
||||
})
|
||||
})
|
||||
.await?;
|
||||
|
||||
Ok(())
|
||||
.await;
|
||||
}
|
||||
|
||||
#[command]
|
||||
async fn clock(ctx: &Context, msg: &Message, args: String) -> CommandResult {
|
||||
async fn clock(ctx: &Context, msg: &Message, args: String) {
|
||||
let pool = ctx
|
||||
.data
|
||||
.read()
|
||||
@ -200,6 +194,4 @@ async fn clock(ctx: &Context, msg: &Message, args: String) -> CommandResult {
|
||||
)
|
||||
.await;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
@ -2,7 +2,7 @@ use regex_command_attr::command;
|
||||
|
||||
use serenity::{
|
||||
client::Context,
|
||||
framework::{standard::CommandResult, Framework},
|
||||
framework::Framework,
|
||||
model::{channel::Message, id::RoleId},
|
||||
};
|
||||
|
||||
@ -25,7 +25,7 @@ use std::iter;
|
||||
#[supports_dm(false)]
|
||||
#[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) {
|
||||
let pool = ctx
|
||||
.data
|
||||
.read()
|
||||
@ -57,12 +57,10 @@ async fn blacklist(ctx: &Context, msg: &Message, args: String) -> CommandResult
|
||||
} else {
|
||||
let _ = msg.channel_id.say(&ctx, "Unblacklisted").await;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[command]
|
||||
async fn timezone(ctx: &Context, msg: &Message, args: String) -> CommandResult {
|
||||
async fn timezone(ctx: &Context, msg: &Message, args: String) {
|
||||
let pool = ctx
|
||||
.data
|
||||
.read()
|
||||
@ -112,12 +110,10 @@ async fn timezone(ctx: &Context, msg: &Message, args: String) -> CommandResult {
|
||||
|
||||
let _ = msg.channel_id.say(&ctx, content).await;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[command]
|
||||
async fn language(ctx: &Context, msg: &Message, args: String) -> CommandResult {
|
||||
async fn language(ctx: &Context, msg: &Message, args: String) {
|
||||
let pool = ctx
|
||||
.data
|
||||
.read()
|
||||
@ -174,14 +170,12 @@ SELECT code FROM languages WHERE code = ? OR name = ?
|
||||
let _ = msg.channel_id.say(&ctx, content).await;
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[command]
|
||||
#[supports_dm(false)]
|
||||
#[permission_level(Restricted)]
|
||||
async fn prefix(ctx: &Context, msg: &Message, args: String) -> CommandResult {
|
||||
async fn prefix(ctx: &Context, msg: &Message, args: String) {
|
||||
let pool = ctx
|
||||
.data
|
||||
.read()
|
||||
@ -217,14 +211,12 @@ async fn prefix(ctx: &Context, msg: &Message, args: String) -> CommandResult {
|
||||
|
||||
let _ = msg.channel_id.say(&ctx, content).await;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[command]
|
||||
#[supports_dm(false)]
|
||||
#[permission_level(Restricted)]
|
||||
async fn restrict(ctx: &Context, msg: &Message, args: String) -> CommandResult {
|
||||
async fn restrict(ctx: &Context, msg: &Message, args: String) {
|
||||
let pool = ctx
|
||||
.data
|
||||
.read()
|
||||
@ -345,14 +337,12 @@ WHERE
|
||||
.say(&ctx, user_data.response(&pool, "restrict/help").await)
|
||||
.await;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[command]
|
||||
#[supports_dm(false)]
|
||||
#[permission_level(Managed)]
|
||||
async fn alias(ctx: &Context, msg: &Message, args: String) -> CommandResult {
|
||||
async fn alias(ctx: &Context, msg: &Message, args: String) {
|
||||
let pool = ctx
|
||||
.data
|
||||
.read()
|
||||
@ -488,6 +478,4 @@ SELECT command FROM command_aliases WHERE guild_id = (SELECT id FROM guilds WHER
|
||||
|
||||
let _ = msg.channel_id.say(&ctx, content).await;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
@ -5,7 +5,6 @@ use regex_command_attr::command;
|
||||
use serenity::{
|
||||
cache::Cache,
|
||||
client::Context,
|
||||
framework::standard::CommandResult,
|
||||
http::CacheHttp,
|
||||
model::{
|
||||
channel::GuildChannel,
|
||||
@ -113,7 +112,7 @@ async fn create_webhook(
|
||||
#[command]
|
||||
#[supports_dm(false)]
|
||||
#[permission_level(Restricted)]
|
||||
async fn pause(ctx: &Context, msg: &Message, args: String) -> CommandResult {
|
||||
async fn pause(ctx: &Context, msg: &Message, args: String) {
|
||||
let pool = ctx
|
||||
.data
|
||||
.read()
|
||||
@ -172,13 +171,11 @@ async fn pause(ctx: &Context, msg: &Message, args: String) -> CommandResult {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[command]
|
||||
#[permission_level(Restricted)]
|
||||
async fn offset(ctx: &Context, msg: &Message, args: String) -> CommandResult {
|
||||
async fn offset(ctx: &Context, msg: &Message, args: String) {
|
||||
let pool = ctx
|
||||
.data
|
||||
.read()
|
||||
@ -243,13 +240,11 @@ UPDATE reminders SET `time` = `time` + ? WHERE reminders.channel_id = ?
|
||||
.await;
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[command]
|
||||
#[permission_level(Restricted)]
|
||||
async fn nudge(ctx: &Context, msg: &Message, args: String) -> CommandResult {
|
||||
async fn nudge(ctx: &Context, msg: &Message, args: String) {
|
||||
let pool = ctx
|
||||
.data
|
||||
.read()
|
||||
@ -304,8 +299,6 @@ async fn nudge(ctx: &Context, msg: &Message, args: String) -> CommandResult {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
enum TimeDisplayType {
|
||||
@ -372,7 +365,7 @@ struct LookReminder {
|
||||
|
||||
#[command]
|
||||
#[permission_level(Managed)]
|
||||
async fn look(ctx: &Context, msg: &Message, args: String) -> CommandResult {
|
||||
async fn look(ctx: &Context, msg: &Message, args: String) {
|
||||
let pool = ctx
|
||||
.data
|
||||
.read()
|
||||
@ -482,13 +475,11 @@ LIMIT
|
||||
|
||||
let _ = msg.channel_id.say_lines(&ctx, display).await;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[command]
|
||||
#[permission_level(Managed)]
|
||||
async fn delete(ctx: &Context, msg: &Message, _args: String) -> CommandResult {
|
||||
async fn delete(ctx: &Context, msg: &Message, _args: String) {
|
||||
let pool = ctx
|
||||
.data
|
||||
.read()
|
||||
@ -650,13 +641,11 @@ INSERT INTO events (event_name, bulk_count, guild_id, user_id) VALUES ('delete',
|
||||
let _ = msg.channel_id.say(&ctx, content).await;
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[command]
|
||||
#[permission_level(Managed)]
|
||||
async fn timer(ctx: &Context, msg: &Message, args: String) -> CommandResult {
|
||||
async fn timer(ctx: &Context, msg: &Message, args: String) {
|
||||
fn time_difference(start_time: NaiveDateTime) -> String {
|
||||
let unix_time = SystemTime::now()
|
||||
.duration_since(UNIX_EPOCH)
|
||||
@ -777,8 +766,6 @@ DELETE FROM timers WHERE owner = ? AND name = ?
|
||||
.await;
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[derive(PartialEq)]
|
||||
@ -880,18 +867,14 @@ fn generate_uid() -> String {
|
||||
|
||||
#[command]
|
||||
#[permission_level(Managed)]
|
||||
async fn remind(ctx: &Context, msg: &Message, args: String) -> CommandResult {
|
||||
async fn remind(ctx: &Context, msg: &Message, args: String) {
|
||||
remind_command(ctx, msg, args, RemindCommand::Remind).await;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[command]
|
||||
#[permission_level(Managed)]
|
||||
async fn interval(ctx: &Context, msg: &Message, args: String) -> CommandResult {
|
||||
async fn interval(ctx: &Context, msg: &Message, args: String) {
|
||||
remind_command(ctx, msg, args, RemindCommand::Interval).await;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn remind_command(ctx: &Context, msg: &Message, args: String, command: RemindCommand) {
|
||||
@ -1030,7 +1013,7 @@ async fn remind_command(ctx: &Context, msg: &Message, args: String, command: Rem
|
||||
|
||||
#[command]
|
||||
#[permission_level(Managed)]
|
||||
async fn natural(ctx: &Context, msg: &Message, args: String) -> CommandResult {
|
||||
async fn natural(ctx: &Context, msg: &Message, args: String) {
|
||||
let pool = ctx
|
||||
.data
|
||||
.read()
|
||||
@ -1217,8 +1200,6 @@ async fn natural(ctx: &Context, msg: &Message, args: String) -> CommandResult {
|
||||
.send_message(&ctx, |m| m.embed(|e| e.description(resp)))
|
||||
.await;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn create_reminder<T: TryInto<i64>, S: ToString + Type<MySql> + Encode<MySql>>(
|
||||
|
@ -3,7 +3,6 @@ use regex_command_attr::command;
|
||||
use serenity::{
|
||||
client::Context,
|
||||
constants::MESSAGE_CODE_LIMIT,
|
||||
framework::standard::CommandResult,
|
||||
model::{
|
||||
channel::Message,
|
||||
id::{ChannelId, GuildId, UserId},
|
||||
@ -382,7 +381,7 @@ impl Execute for Result<SubCommand, ()> {
|
||||
|
||||
#[command]
|
||||
#[permission_level(Managed)]
|
||||
async fn todo_user(ctx: &Context, msg: &Message, args: String) -> CommandResult {
|
||||
async fn todo_user(ctx: &Context, msg: &Message, args: String) {
|
||||
let mut split = args.split(' ');
|
||||
|
||||
let target = TodoTarget {
|
||||
@ -396,14 +395,12 @@ async fn todo_user(ctx: &Context, msg: &Message, args: String) -> CommandResult
|
||||
subcommand_opt
|
||||
.execute(ctx, msg, split.collect::<Vec<&str>>().join(" "), target)
|
||||
.await;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[command]
|
||||
#[supports_dm(false)]
|
||||
#[permission_level(Managed)]
|
||||
async fn todo_channel(ctx: &Context, msg: &Message, args: String) -> CommandResult {
|
||||
async fn todo_channel(ctx: &Context, msg: &Message, args: String) {
|
||||
let mut split = args.split(' ');
|
||||
|
||||
let target = TodoTarget {
|
||||
@ -417,14 +414,12 @@ async fn todo_channel(ctx: &Context, msg: &Message, args: String) -> CommandResu
|
||||
subcommand_opt
|
||||
.execute(ctx, msg, split.collect::<Vec<&str>>().join(" "), target)
|
||||
.await;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[command]
|
||||
#[supports_dm(false)]
|
||||
#[permission_level(Managed)]
|
||||
async fn todo_guild(ctx: &Context, msg: &Message, args: String) -> CommandResult {
|
||||
async fn todo_guild(ctx: &Context, msg: &Message, args: String) {
|
||||
let mut split = args.split(' ');
|
||||
|
||||
let target = TodoTarget {
|
||||
@ -438,8 +433,6 @@ async fn todo_guild(ctx: &Context, msg: &Message, args: String) -> CommandResult
|
||||
subcommand_opt
|
||||
.execute(ctx, msg, split.collect::<Vec<&str>>().join(" "), target)
|
||||
.await;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn show_help(ctx: &Context, msg: &Message, target: Option<TodoTarget>) {
|
||||
|
@ -3,7 +3,7 @@ use async_trait::async_trait;
|
||||
use serenity::{
|
||||
client::Context,
|
||||
constants::MESSAGE_CODE_LIMIT,
|
||||
framework::{standard::CommandResult, Framework},
|
||||
framework::Framework,
|
||||
futures::prelude::future::BoxFuture,
|
||||
http::Http,
|
||||
model::{
|
||||
@ -23,8 +23,7 @@ use std::{collections::HashMap, fmt};
|
||||
use crate::models::{GuildData, UserData};
|
||||
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, ()>;
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
pub enum PermissionLevel {
|
||||
@ -387,7 +386,7 @@ impl Framework for RegexFramework {
|
||||
.to_string();
|
||||
|
||||
if command.check_permissions(&ctx, &guild, &member).await {
|
||||
(command.func)(&ctx, &msg, args).await.unwrap();
|
||||
(command.func)(&ctx, &msg, args).await;
|
||||
} else if command.required_perms == PermissionLevel::Restricted
|
||||
{
|
||||
let _ = msg
|
||||
@ -455,7 +454,7 @@ impl Framework for RegexFramework {
|
||||
.unwrap_or("")
|
||||
.to_string();
|
||||
|
||||
(command.func)(&ctx, &msg, args).await.unwrap();
|
||||
(command.func)(&ctx, &msg, args).await;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user