ruma-bot

git clone git://archive.git.mtrnord.blog/MTRNord/ruma-bot.git
Log | Files | Refs

commit d5ecf7938770cf96214d242895c9ea253b5f65cc
parent 24cfa32bffaa9c4770b6be4dab84333d5fbbc257
Author: Jonas Platte <jplatte+git@posteo.de>
Date:   Mon, 18 Nov 2019 22:06:30 +0100

Update dependencies, address clippy lints

Diffstat:
MCargo.toml | 22++++++++--------------
Mexamples/echo.rs | 2--
Mmacros/Cargo.toml | 6+++---
Mmacros/src/args.rs | 15+++++++--------
Mmacros/src/lib.rs | 13++++++++-----
Msrc/lib.rs | 20+++++++++++++++-----
6 files changed, 41 insertions(+), 37 deletions(-)

diff --git a/Cargo.toml b/Cargo.toml @@ -6,24 +6,18 @@ edition = "2018" [dependencies] anymap = "0.12.1" -failure = "0.1.5" -futures-preview = "0.3.0-alpha.17" -hyper = { git = "https://github.com/hyperium/hyper" } -hyper-tls = { git = "https://github.com/hyperium/hyper-tls" } -ruma-client = { git = "https://github.com/ruma/ruma-client", branch = "async_await" } -tokio = { git = "https://github.com/tokio-rs/tokio" } -url = "2.0.0" +failure = "0.1.6" +futures-preview = "=0.3.0-alpha.19" +hyper = { version = "=0.13.0-alpha.4", features = ["unstable-stream"] } +hyper-tls = { version = "=0.4.0-alpha.4", optional = true } +ruma-client = "0.3.0-beta.1" +tokio = "0.2.0-alpha.6" +url = "2.1.0" [dependencies.ruma-bot-macros] path = "macros" -[patch.crates-io.ruma-events] -git = "https://github.com/ruma/ruma-events" -rev = "1b0be0d0e7fa1040fc51b748256b290e24677b19" - -[patch.'https://github.com/ruma/ruma-client-api'.ruma-client-api] -# Cargo doesn't allow using a different branch of the same repository. Trick it into thinking that -# we're using a different repository. +[patch.crates-io.ruma-client-api] git = "https://github.com/ruma/ruma-client-api.git" branch = "request-ctors" diff --git a/examples/echo.rs b/examples/echo.rs @@ -1,5 +1,3 @@ -#![feature(async_await)] - use std::{ collections::HashMap, sync::{Arc, Mutex}, diff --git a/macros/Cargo.toml b/macros/Cargo.toml @@ -8,9 +8,9 @@ edition = "2018" proc-macro = true [dependencies] -proc-macro2 = "0.4.30" -quote = "0.6.13" +proc-macro2 = "1.0.6" +quote = "1.0.2" [dependencies.syn] -version = "0.15.42" +version = "1.0.8" features = ["full", "extra-traits"] diff --git a/macros/src/args.rs b/macros/src/args.rs @@ -2,7 +2,6 @@ use std::collections::HashSet; use syn::{ parse::{Parse, ParseStream}, punctuated::{Pair, Punctuated}, - spanned::Spanned, Expr, ExprArray, ExprLit, Ident, Lit, LitStr, Token, }; @@ -31,8 +30,8 @@ impl Parse for Arg { let array: ExprArray = input.parse()?; if !array.attrs.is_empty() { - return Err(syn::Error::new( - array.attrs[0].tts.span(), + return Err(syn::Error::new_spanned( + &array.attrs[0], "attributes are not allowed here", )); } @@ -44,8 +43,8 @@ impl Parse for Arg { .map(|expr| { if let Expr::Lit(ExprLit { attrs, lit }) = expr { if !attrs.is_empty() { - return Err(syn::Error::new( - attrs[0].tts.span(), + return Err(syn::Error::new_spanned( + &attrs[0], "attributes are not allowed here", )); } @@ -53,10 +52,10 @@ impl Parse for Arg { if let Lit::Str(s) = lit { Ok(s) } else { - Err(syn::Error::new(lit.span(), "expected string literal")) + Err(syn::Error::new_spanned(lit, "expected string literal")) } } else { - Err(syn::Error::new(expr.span(), "expected string literal")) + Err(syn::Error::new_spanned(expr, "expected string literal")) } }) .collect::<Result<_, _>>()?; @@ -66,7 +65,7 @@ impl Parse for Arg { Err(input.error("expected `=`")) } } - _ => Err(syn::Error::new(ident.span(), "unknown ruma_bot option")), + _ => Err(syn::Error::new_spanned(ident, "unknown ruma_bot option")), } } } diff --git a/macros/src/lib.rs b/macros/src/lib.rs @@ -17,20 +17,23 @@ pub fn command_handler(args: TokenStream, input: TokenStream) -> TokenStream { let macro_args = parse_macro_input!(args as Args); assert!( - handler_fn.decl.variadic.is_none(), + handler_fn.sig.variadic.is_none(), "handler functions are not allowed to be variadic", ); assert!( - handler_fn.unsafety.is_none(), + handler_fn.sig.unsafety.is_none(), "handler functions are not allowed to be `unsafe`", ); - let fn_ident = Ident::new(&format!("_{}_impl", handler_fn.ident), Span::call_site()); - let ident = mem::replace(&mut handler_fn.ident, fn_ident.clone()); + let fn_ident = Ident::new( + &format!("_{}_impl", handler_fn.sig.ident), + Span::call_site(), + ); + let ident = mem::replace(&mut handler_fn.sig.ident, fn_ident.clone()); // TODO: Error handling (required for State parameters) - let get_calls = (0..handler_fn.decl.inputs.len()).map(|_| quote!(param_matcher.get().unwrap())); + let get_calls = (0..handler_fn.sig.inputs.len()).map(|_| quote!(param_matcher.get().unwrap())); let mut commands = Vec::new(); for arg in macro_args.0 { diff --git a/src/lib.rs b/src/lib.rs @@ -5,7 +5,6 @@ //! //! [matrix]: https://matrix.org/ -#![feature(async_await)] #![warn(missing_debug_implementations, missing_docs)] use std::{collections::HashMap, pin::Pin, sync::Arc}; @@ -69,6 +68,7 @@ pub struct BotBuilder { impl BotBuilder { /// Crate a new `BotBuilder` + #[allow(clippy::new_without_default)] pub fn new() -> Self { Self { handlers: HashMap::new(), @@ -141,7 +141,7 @@ impl BotBuilder { env_var("RUMA_BOT_HOMESERVER_URL") .map(|s| s.parse().expect("valid url for RUMA_BOT_HOMESERVER_URL")) }) - .ok_or(err_msg("ruma_bot: homeserver_url not configured"))?, + .ok_or_else(|| err_msg("ruma_bot: homeserver_url not configured"))?, None, )?, handlers: Arc::new(self.handlers), @@ -150,11 +150,11 @@ impl BotBuilder { username: self .username .or_else(|| env_var("RUMA_BOT_USERNAME")) - .ok_or(err_msg("ruma_bot: username not configured"))?, + .ok_or_else(|| err_msg("ruma_bot: username not configured"))?, password: self .password .or_else(|| env_var("RUMA_BOT_PASSWORD")) - .ok_or(err_msg("ruma_bot: password not configured"))?, + .ok_or_else(|| err_msg("ruma_bot: password not configured"))?, }), }) } @@ -213,7 +213,13 @@ impl Bot { while let Some(res) = sync_stream.try_next().await? { for (_room_id, room) in res.rooms.join { - for event in room.timeline.events { + for event in room + .timeline + .events + .into_iter() + // ignore invalid events + .flat_map(|ev_res| ev_res.into_result()) + { // Filter out the text messages if let RoomEvent::RoomMessage(MessageEvent { content: MessageEventContent::Text(TextMessageEventContent { body, .. }), @@ -233,6 +239,10 @@ impl Bot { } } } + + for (_room_id, _invited_room) in res.rooms.invite { + // TODO + } } Ok(())