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 message: Type = parse_quote!(&serenity::model::channel::Message);
let args: Type = parse_quote!(serenity::framework::standard::Args);
let args2: Type = parse_quote!(&mut serenity::framework::standard::Args);
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]);
@ -209,7 +208,6 @@ pub fn create_declaration_validations(fun: &mut CommandFun, dec_for: DeclarFor)
spoof_or_check(message, "_msg");
if dec_for == DeclarFor::Check {
spoof_or_check(args2, "_args");
spoof_or_check(options, "_options");
return Ok(());

View File

@ -7,15 +7,14 @@ use serenity::{
Message,
},
},
framework::standard::{
Args, CommandResult,
},
framework::standard::CommandResult,
};
use crate::THEME_COLOR;
#[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
.embed(|e| e
.title("Help")
@ -28,7 +27,7 @@ async fn help(ctx: &Context, msg: &Message, _args: Args) -> CommandResult {
}
#[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
.embed(|e| e
.title("Info")
@ -41,7 +40,7 @@ async fn info(ctx: &Context, msg: &Message, _args: Args) -> CommandResult {
}
#[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
.embed(|e| e
.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,
framework::{
Framework,
standard::{
Args, CommandFn,
},
standard::CommandResult,
},
model::{
guild::{
@ -17,6 +15,7 @@ use serenity::{
Channel, GuildChannel, Message,
}
},
futures::prelude::future::BoxFuture,
};
use log::{
@ -37,6 +36,8 @@ use std::{
use crate::SQLPool;
type CommandFn = for<'fut> fn(&'fut Context, &'fut Message, String) -> BoxFuture<'fut, CommandResult>;
#[derive(Debug)]
pub enum PermissionLevel {
Unrestricted,
@ -311,20 +312,18 @@ impl Framework for RegexFramework {
Ok(perms) => match perms {
PermissionCheck::All => {
let command = self.commands.get(full_match.name("cmd").unwrap().as_str()).unwrap();
let args = Args::new(
full_match.name("args")
.map(|m| m.as_str())
.unwrap_or(""),
&[]
);
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;
(command.func)(&ctx, &msg, args).await.unwrap();
}
}
PermissionCheck::Basic => {
msg.channel_id.say(&ctx, "Not enough perms").await;
let _ = msg.channel_id.say(&ctx, "Not enough perms").await;
}
PermissionCheck::None => {
@ -344,14 +343,12 @@ impl Framework for RegexFramework {
else {
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 args = Args::new(
full_match.name("args")
.map(|m| m.as_str())
.unwrap_or(""),
&[]
);
let args = full_match.name("args")
.map(|m| m.as_str())
.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::{
client::{
bridge::gateway::GatewayIntents,
Client, Context,
},
model::{
channel::{
Message,
},
},
framework::standard::{
Args, CommandResult,
Client,
},
prelude::TypeMapKey,
};
use regex_command_attr::command;
use sqlx::{
Pool,
mysql::{
@ -85,12 +75,3 @@ async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
Ok(())
}
#[command]
#[permission_level(Managed)]
#[supports_dm(false)]
async fn look(_ctx: &Context, _msg: &Message, _args: Args) -> CommandResult {
println!("Help command called");
Ok(())
}