aboutsummaryrefslogtreecommitdiff
path: root/macros
diff options
context:
space:
mode:
Diffstat (limited to 'macros')
-rw-r--r--macros/src/lib.rs20
-rw-r--r--macros/src/macro_types/mod.rs5
-rw-r--r--macros/src/macro_types/privmsg.rs17
3 files changed, 40 insertions, 2 deletions
diff --git a/macros/src/lib.rs b/macros/src/lib.rs
index 222f14d..5ccf1bb 100644
--- a/macros/src/lib.rs
+++ b/macros/src/lib.rs
@@ -156,3 +156,23 @@ pub fn catinator(tokens: TokenStream) -> TokenStream {
return gen.into();
}
+#[proc_macro]
+pub fn privmsg(tokens: TokenStream) -> TokenStream {
+ use crate::macro_types::privmsg::Item;
+ let item = parse_macro_input!(tokens as Item);
+
+ let msg = item.msg;
+ let func = item.func;
+
+ let gen = quote! {
+ match &#msg.command {
+ Command::PRIVMSG(target, text) => {
+ #func
+
+ Ok(())
+ }
+ _ => Ok(()),
+ }
+ };
+ return gen.into();
+}
diff --git a/macros/src/macro_types/mod.rs b/macros/src/macro_types/mod.rs
index 262b3df..818cea7 100644
--- a/macros/src/macro_types/mod.rs
+++ b/macros/src/macro_types/mod.rs
@@ -8,12 +8,13 @@ use syn::{
};
use syn::{LitStr, Token};
+pub mod privmsg;
+
pub trait IrcItem {
fn to_call(&self) -> proc_macro2::TokenStream;
fn help(&self) -> String;
}
-#[derive(Debug)]
pub struct Items {
pub inner: Vec<Item>,
}
@@ -75,7 +76,7 @@ impl IrcItem for Command {
quote! {
if #name == rest {
debug!(target: "command", "{} with {:?}", #name, message);
- let result = #function(message.clone());
+ let result = #function(&bot, message.clone());
}
}
}
diff --git a/macros/src/macro_types/privmsg.rs b/macros/src/macro_types/privmsg.rs
new file mode 100644
index 0000000..247d1b7
--- /dev/null
+++ b/macros/src/macro_types/privmsg.rs
@@ -0,0 +1,17 @@
+use syn::{Expr, Token, parse::{Parse, ParseStream}};
+
+pub struct Item {
+ pub msg: Expr,
+ pub tok2: Token![,],
+ pub func: Expr,
+}
+
+impl Parse for Item {
+ fn parse(input: ParseStream) -> syn::Result<Self> {
+ Ok(Self {
+ msg: input.parse()?,
+ tok2: input.parse()?,
+ func: input.parse()?,
+ })
+ }
+}