-
Notifications
You must be signed in to change notification settings - Fork 5
Autojoin IRC channels on connect #23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
a66b4ee
d285977
0ff270c
9dbc1de
8242cd0
8d45d48
9cf2761
4933a74
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,6 +10,8 @@ use tokio::net::TcpStream; | |
| use tokio::sync::mpsc; | ||
| use tokio_util::codec::Framed; | ||
|
|
||
| use crate::args::{args, AutoJoinOptions}; | ||
| use crate::matrix::room_mappings::RoomTargetType; | ||
| use crate::{matrirc::Matrirc, matrix::MatrixMessageType}; | ||
|
|
||
| /// it's a bit of a pain to redo the work twice for notice/privmsg, | ||
|
|
@@ -162,6 +164,44 @@ pub async fn ircd_sync_write( | |
| Ok(()) | ||
| } | ||
|
|
||
| pub async fn join_channels(matrirc: &Matrirc) -> Result<()> { | ||
| let irc = matrirc.irc(); | ||
| let matrix = matrirc.matrix(); | ||
| let mapping = matrirc.mappings(); | ||
|
|
||
| for joined in matrix.joined_rooms() { | ||
| if joined.is_tombstoned() { | ||
| trace!( | ||
| "Skipping tombstoned {}", | ||
| joined | ||
| .name() | ||
| .unwrap_or_else(|| joined.room_id().to_string()) | ||
| ); | ||
| continue; | ||
| } | ||
| let roomtarget = mapping.try_room_target(&joined).await?; | ||
| let chantype = roomtarget.target_type().await; | ||
| if [RoomTargetType::Chan, RoomTargetType::LeftChan].contains(&chantype) | ||
| && args().autojoin.join_channels() | ||
| { | ||
| roomtarget.join_chan(irc).await; | ||
| } else if chantype == RoomTargetType::Query { | ||
| let name = roomtarget.target().await; | ||
| let _ = irc.send(join(Some(format!("{}!{}@matrirc", name, name)), "matrirc".to_string())).await?; | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. clippy warns on this on my machine: you're using Either the error is safe to error and there should be no Looking around the rest of this loop I think we should be consistent: either we expect errors and we should perhaps I think that irc.send has no reason to fail in a way that's recoverable, so I'd make drop the The other comment I have reading this diff is that the abstraction for join() is rather annoying when making someone join when we don't have a string ready for their nick!user@host triplet, so perhaps it's make sense to make a second join helper, but I'm happy to let you judge on that as well |
||
| if args().autojoin.join_queries() { | ||
| let _ = irc | ||
| .send(privmsg( | ||
| name, | ||
| &irc.nick, | ||
| "* <Resumed connection to matrirc>", | ||
| )) | ||
| .await; | ||
| } | ||
| } | ||
| } | ||
| Ok(()) | ||
| } | ||
|
|
||
| pub async fn ircd_sync_read( | ||
| mut reader: SplitStream<Framed<TcpStream, IrcCodec>>, | ||
| matrirc: Matrirc, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AutoJoinOptions is unused since you've used the join_queries()/channels() methods