chore: clippy

This commit is contained in:
sinavir 2024-05-22 12:39:31 +02:00
parent a98da9d47c
commit 435a85732c
3 changed files with 14 additions and 18 deletions

View file

@ -13,13 +13,10 @@ pub struct BridgeConfig {
pub mapping: BiMap<String, String>, pub mapping: BiMap<String, String>,
} }
impl<'a> BridgeConfig { impl BridgeConfig {
pub fn load<'b>() -> Result<BridgeConfig, String> { pub fn load() -> Result<BridgeConfig, String> {
initialize(Args { initialize(Args {
config_path: env::var("CONFIG_PATH") config_path: env::var("CONFIG_PATH").ok().as_ref().map(Path::new),
.ok()
.as_ref()
.map(|p| Path::new(p).as_ref()),
logging: Logging::StdOut, logging: Logging::StdOut,
auto_map_env: Some(AutoMapEnvArgs { auto_map_env: Some(AutoMapEnvArgs {
divider: "__", divider: "__",

View file

@ -12,7 +12,6 @@ use serde_json::Value;
use tokio::time::sleep; use tokio::time::sleep;
use core::time::Duration; use core::time::Duration;
use transform::Bridge; use transform::Bridge;
use {log, pretty_env_logger};
use crate::jsonrpc::RpcClient; use crate::jsonrpc::RpcClient;
use crate::config::BridgeConfig; use crate::config::BridgeConfig;
@ -36,7 +35,7 @@ async fn main() -> Result<(), String> {
.map_err(|e| format!("Error while initializing irc stream: {e}"))?; .map_err(|e| format!("Error while initializing irc stream: {e}"))?;
log::debug!("Initializing IRC"); log::debug!("Initializing IRC");
while client.list_channels().is_some_and(|x| x.len() == 0) { while client.list_channels().is_some_and(|x| x.is_empty()) {
stream stream
.next() .next()
.await .await
@ -59,7 +58,7 @@ async fn main() -> Result<(), String> {
} }
sleep(Duration::from_secs(1)).await; sleep(Duration::from_secs(1)).await;
}; };
return Err("Trying too many times to open socket"); Err("Trying too many times to open socket")
}).await.map_err(|e| format!("failed to connect to signal socket: {e}"))?; }).await.map_err(|e| format!("failed to connect to signal socket: {e}"))?;
let signal_stream = signal_client let signal_stream = signal_client

View file

@ -14,23 +14,23 @@ struct SignalMessageBuilder<'a> {
} }
impl<'b> SignalMessageBuilder<'b> { impl<'b> SignalMessageBuilder<'b> {
pub fn message(self: &mut Self, message: String) { pub fn message(&mut self, message: String) {
self.message = Some(message); self.message = Some(message);
} }
pub fn from(self: &mut Self, from: String) { pub fn from(&mut self, from: String) {
self.from = Some(from); self.from = Some(from);
} }
pub fn attach(self: &mut Self, attach: Vec<String>) { pub fn attach(&mut self, attach: Vec<String>) {
self.attachments_urls.extend_from_slice(&attach); self.attachments_urls.extend_from_slice(&attach);
} }
pub fn target(self: &mut Self, channel: Option<&'b String>) { pub fn target(&mut self, channel: Option<&'b String>) {
self.target = channel; self.target = channel;
} }
pub fn build(self: Self) -> Option<(&'b String, String)> pub fn build(self) -> Option<(&'b String, String)>
{ {
let attachments_text = self.attachments_urls.join(", "); let attachments_text = self.attachments_urls.join(", ");
(match (&self.message, attachments_text.len()) { (match (&self.message, attachments_text.len()) {
@ -70,7 +70,7 @@ impl<'a> Bridge<'a> {
} }
} }
async fn handle_attachment(self: &Self, attachment: &Value) -> Option<String> { async fn handle_attachment(&self, attachment: &Value) -> Option<String> {
if let Value::Object(a) = attachment { if let Value::Object(a) = attachment {
if let Some(Value::String(fname)) = a.get("id") { if let Some(Value::String(fname)) = a.get("id") {
match copy( match copy(
@ -94,7 +94,7 @@ impl<'a> Bridge<'a> {
} }
async fn process_signal( async fn process_signal(
self: &Self, &self,
message: &Map<String, Value>, message: &Map<String, Value>,
result: &mut SignalMessageBuilder<'a>, result: &mut SignalMessageBuilder<'a>,
) { ) {
@ -119,7 +119,7 @@ impl<'a> Bridge<'a> {
} }
} }
pub async fn signal2irc(self: &Self, signal: Value) -> Option<(&String, String)> { pub async fn signal2irc(&self, signal: Value) -> Option<(&String, String)> {
let mut result: SignalMessageBuilder = SignalMessageBuilder::default(); let mut result: SignalMessageBuilder = SignalMessageBuilder::default();
if let Value::Object(map) = signal { if let Value::Object(map) = signal {
if let Some(Value::Object(envelope)) = map.get("envelope") { if let Some(Value::Object(envelope)) = map.get("envelope") {
@ -139,7 +139,7 @@ impl<'a> Bridge<'a> {
result.build() result.build()
} }
pub fn irc2signal(self: &Self, message: Message) -> Option<(&String, String)> { pub fn irc2signal(&self, message: Message) -> Option<(&String, String)> {
match (message.prefix, message.command) { match (message.prefix, message.command) {
(Some(Prefix::Nickname(from, _, _)), Command::PRIVMSG(channel, message)) => { (Some(Prefix::Nickname(from, _, _)), Command::PRIVMSG(channel, message)) => {
Some((channel, format!("<{from}>: {message}"))) Some((channel, format!("<{from}>: {message}")))