changed Args to String because we dont need that

This commit is contained in:
jude 2020-08-10 22:12:26 +01:00
parent 27c62e6ac2
commit f37bf23d9f
5 changed files with 69 additions and 47 deletions

View File

@ -183,8 +183,7 @@ pub fn create_declaration_validations(fun: &mut CommandFun, dec_for: DeclarFor)
let context: Type = parse_quote!(&serenity::client::Context); let context: Type = parse_quote!(&serenity::client::Context);
let message: Type = parse_quote!(&serenity::model::channel::Message); let message: Type = parse_quote!(&serenity::model::channel::Message);
let args: Type = parse_quote!(serenity::framework::standard::Args); let args: Type = parse_quote!(String);
let args2: Type = parse_quote!(&mut serenity::framework::standard::Args);
let options: Type = parse_quote!(&serenity::framework::standard::CommandOptions); let options: Type = parse_quote!(&serenity::framework::standard::CommandOptions);
let hoptions: Type = parse_quote!(&'static serenity::framework::standard::HelpOptions); let hoptions: Type = parse_quote!(&'static serenity::framework::standard::HelpOptions);
let groups: Type = parse_quote!(&[&'static serenity::framework::standard::CommandGroup]); let groups: Type = parse_quote!(&[&'static serenity::framework::standard::CommandGroup]);
@ -209,7 +208,6 @@ pub fn create_declaration_validations(fun: &mut CommandFun, dec_for: DeclarFor)
spoof_or_check(message, "_msg"); spoof_or_check(message, "_msg");
if dec_for == DeclarFor::Check { if dec_for == DeclarFor::Check {
spoof_or_check(args2, "_args");
spoof_or_check(options, "_options"); spoof_or_check(options, "_options");
return Ok(()); return Ok(());

View File

@ -7,15 +7,14 @@ use serenity::{
Message, Message,
}, },
}, },
framework::standard::{ framework::standard::CommandResult,
Args, CommandResult,
},
}; };
use crate::THEME_COLOR; use crate::THEME_COLOR;
#[command] #[command]
async fn help(ctx: &Context, msg: &Message, _args: Args) -> CommandResult { async fn help(ctx: &Context, msg: &Message, _args: String) -> CommandResult {
msg.channel_id.send_message(ctx, |m| m msg.channel_id.send_message(ctx, |m| m
.embed(|e| e .embed(|e| e
.title("Help") .title("Help")
@ -28,7 +27,7 @@ async fn help(ctx: &Context, msg: &Message, _args: Args) -> CommandResult {
} }
#[command] #[command]
async fn info(ctx: &Context, msg: &Message, _args: Args) -> CommandResult { async fn info(ctx: &Context, msg: &Message, _args: String) -> CommandResult {
msg.channel_id.send_message(ctx, |m| m msg.channel_id.send_message(ctx, |m| m
.embed(|e| e .embed(|e| e
.title("Info") .title("Info")
@ -41,7 +40,7 @@ async fn info(ctx: &Context, msg: &Message, _args: Args) -> CommandResult {
} }
#[command] #[command]
async fn donate(ctx: &Context, msg: &Message, _args: Args) -> CommandResult { async fn donate(ctx: &Context, msg: &Message, _args: String) -> CommandResult {
msg.channel_id.send_message(ctx, |m| m msg.channel_id.send_message(ctx, |m| m
.embed(|e| e .embed(|e| e
.title("Donate") .title("Donate")

View File

@ -0,0 +1,47 @@
use regex_command_attr::command;
use serenity::{
client::Context,
model::{
channel::{
Message,
},
},
framework::standard::CommandResult,
};
enum TodoTarget {
User,
Channel,
Guild,
}
impl TodoTarget {
fn from_str(string: &str) -> Option<Self> {
match string {
"user" => Some(Self::User),
"channel" => Some(Self::Channel),
"server" | "guild" => Some(Self::Guild),
_ => None
}
}
}
enum SubCommand {
View,
Add,
Remove,
Clear,
}
#[command]
async fn todo_parse(ctx: &Context, msg: &Message, args: String) -> CommandResult {
Ok(())
}
async fn todo(ctx: &Context, target: TodoTarget, subcommand: SubCommand) {
}

View File

@ -4,9 +4,7 @@ use serenity::{
client::Context, client::Context,
framework::{ framework::{
Framework, Framework,
standard::{ standard::CommandResult,
Args, CommandFn,
},
}, },
model::{ model::{
guild::{ guild::{
@ -17,6 +15,7 @@ use serenity::{
Channel, GuildChannel, Message, Channel, GuildChannel, Message,
} }
}, },
futures::prelude::future::BoxFuture,
}; };
use log::{ use log::{
@ -37,6 +36,8 @@ use std::{
use crate::SQLPool; use crate::SQLPool;
type CommandFn = for<'fut> fn(&'fut Context, &'fut Message, String) -> BoxFuture<'fut, CommandResult>;
#[derive(Debug)] #[derive(Debug)]
pub enum PermissionLevel { pub enum PermissionLevel {
Unrestricted, Unrestricted,
@ -311,20 +312,18 @@ impl Framework for RegexFramework {
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 command = self.commands.get(full_match.name("cmd").unwrap().as_str()).unwrap();
let args = Args::new( let args = full_match.name("args")
full_match.name("args")
.map(|m| m.as_str()) .map(|m| m.as_str())
.unwrap_or(""), .unwrap_or("")
&[] .to_string();
);
if command.check_permissions(&ctx, &guild, &member).await { if command.check_permissions(&ctx, &guild, &member).await {
(command.func)(&ctx, &msg, args).await; (command.func)(&ctx, &msg, args).await.unwrap();
} }
} }
PermissionCheck::Basic => { PermissionCheck::Basic => {
msg.channel_id.say(&ctx, "Not enough perms").await; let _ = msg.channel_id.say(&ctx, "Not enough perms").await;
} }
PermissionCheck::None => { PermissionCheck::None => {
@ -344,14 +343,12 @@ impl Framework for RegexFramework {
else { else {
if let Some(full_match) = self.dm_regex_matcher.captures(&msg.content[..]) { if let Some(full_match) = self.dm_regex_matcher.captures(&msg.content[..]) {
let command = self.commands.get(full_match.name("cmd").unwrap().as_str()).unwrap(); let command = self.commands.get(full_match.name("cmd").unwrap().as_str()).unwrap();
let args = Args::new( let args = full_match.name("args")
full_match.name("args")
.map(|m| m.as_str()) .map(|m| m.as_str())
.unwrap_or(""), .unwrap_or("")
&[] .to_string();
);
(command.func)(&ctx, &msg, args).await; (command.func)(&ctx, &msg, args).await.unwrap();
} }
} }
} }

View File

@ -4,21 +4,11 @@ mod commands;
use serenity::{ use serenity::{
client::{ client::{
bridge::gateway::GatewayIntents, bridge::gateway::GatewayIntents,
Client, Context, Client,
},
model::{
channel::{
Message,
},
},
framework::standard::{
Args, CommandResult,
}, },
prelude::TypeMapKey, prelude::TypeMapKey,
}; };
use regex_command_attr::command;
use sqlx::{ use sqlx::{
Pool, Pool,
mysql::{ mysql::{
@ -85,12 +75,3 @@ async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
Ok(()) Ok(())
} }
#[command]
#[permission_level(Managed)]
#[supports_dm(false)]
async fn look(_ctx: &Context, _msg: &Message, _args: Args) -> CommandResult {
println!("Help command called");
Ok(())
}