author | unc0rr |
Tue, 08 Jun 2021 18:31:46 +0200 | |
changeset 15789 | d97ea528ce95 |
child 15792 | 191e51179d1b |
permissions | -rw-r--r-- |
15789
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
1 |
use lapin::{ |
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
2 |
message::Delivery, options::*, types::FieldTable, BasicProperties, Connection, |
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
3 |
ConnectionProperties, |
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
4 |
}; |
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
5 |
use tokio_amqp::*; |
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
6 |
|
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
7 |
use futures::prelude::*; |
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
8 |
use irc::client::prelude::*; |
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
9 |
|
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
10 |
use anyhow::{bail, Result as AHResult}; |
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
11 |
|
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
12 |
use url::Url; |
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
13 |
|
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
14 |
use rand::distributions::Alphanumeric; |
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
15 |
use rand::{thread_rng, Rng}; |
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
16 |
|
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
17 |
fn url2irc_config(url: &str) -> AHResult<Config> { |
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
18 |
let url = Url::parse(url)?; |
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
19 |
|
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
20 |
if url.scheme() != "irc" { |
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
21 |
bail!("Expected 'irc' scheme") |
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
22 |
} |
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
23 |
|
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
24 |
Ok(Config { |
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
25 |
nickname: Some(url.username().to_owned()), |
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
26 |
nick_password: url.password().map(|s| s.to_owned()), |
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
27 |
server: url.host_str().map(|s| s.to_owned()), |
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
28 |
port: url.port(), |
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
29 |
channels: vec![format!("#{}", &url.path()[1..])], |
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
30 |
//use_mock_connection: true, |
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
31 |
..Config::default() |
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
32 |
}) |
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
33 |
} |
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
34 |
|
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
35 |
fn random_string(size: usize) -> String { |
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
36 |
thread_rng() |
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
37 |
.sample_iter(&Alphanumeric) |
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
38 |
.take(size) |
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
39 |
.map(char::from) |
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
40 |
.collect() |
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
41 |
} |
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
42 |
|
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
43 |
async fn handle_irc(pub_channel: &lapin::Channel, irc_message: &Message) -> AHResult<()> { |
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
44 |
if let Command::PRIVMSG(msgtarget, message) = &irc_message.command { |
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
45 |
let target = irc_message |
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
46 |
.response_target() |
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
47 |
.expect("Really expected PRIVMSG would have a source"); |
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
48 |
let target = if target.starts_with('#') { |
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
49 |
&target[1..] |
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
50 |
} else { |
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
51 |
&target |
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
52 |
}; |
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
53 |
|
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
54 |
if message.starts_with("!") { |
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
55 |
if let Some((cmd, param)) = message.split_once(' ') { |
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
56 |
pub_channel |
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
57 |
.basic_publish( |
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
58 |
"irc", |
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
59 |
&format!("cmd.{}.{}", &cmd[1..], target), |
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
60 |
BasicPublishOptions::default(), |
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
61 |
format!("{}\n{}", msgtarget, param).as_bytes().to_vec(), |
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
62 |
BasicProperties::default(), |
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
63 |
) |
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
64 |
.await?; |
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
65 |
} else { |
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
66 |
pub_channel |
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
67 |
.basic_publish( |
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
68 |
"irc", |
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
69 |
&format!("cmd.{}.{}", &message[1..], target), |
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
70 |
BasicPublishOptions::default(), |
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
71 |
msgtarget.as_bytes().to_vec(), |
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
72 |
BasicProperties::default(), |
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
73 |
) |
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
74 |
.await?; |
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
75 |
} |
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
76 |
} else { |
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
77 |
pub_channel |
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
78 |
.basic_publish( |
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
79 |
"irc", |
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
80 |
&format!("msg.{}", target), |
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
81 |
BasicPublishOptions::default(), |
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
82 |
format!("{}\n{}", msgtarget, message).as_bytes().to_vec(), |
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
83 |
BasicProperties::default(), |
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
84 |
) |
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
85 |
.await?; |
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
86 |
} |
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
87 |
} |
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
88 |
|
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
89 |
Ok(()) |
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
90 |
} |
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
91 |
|
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
92 |
async fn handle_amqp( |
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
93 |
irc_client: &mut Client, |
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
94 |
irc_channel: &str, |
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
95 |
delivery: Delivery, |
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
96 |
) -> AHResult<()> { |
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
97 |
let message = String::from_utf8(delivery.data)?; |
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
98 |
Ok(irc_client.send_privmsg(irc_channel, message)?) |
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
99 |
} |
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
100 |
|
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
101 |
#[tokio::main] |
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
102 |
async fn main() -> AHResult<()> { |
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
103 |
let amqp_url = std::env::var("AMQP_URL").expect("expected AMQP_URL env variabe"); |
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
104 |
let irc_url = std::env::var("IRC_URL").expect("expected IRC_URL env variabe"); |
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
105 |
let conn = Connection::connect(&amqp_url, ConnectionProperties::default().with_tokio()).await?; |
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
106 |
|
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
107 |
let pub_channel = conn.create_channel().await?; |
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
108 |
let sub_channel = conn.create_channel().await?; |
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
109 |
|
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
110 |
let irc_config = url2irc_config(&irc_url)?; |
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
111 |
let irc_channel = irc_config.channels[0].to_owned(); |
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
112 |
let mut irc_client = Client::from_config(irc_config).await?; |
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
113 |
let mut irc_stream = irc_client.stream()?; |
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
114 |
irc_client.identify()?; |
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
115 |
|
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
116 |
let queue = sub_channel |
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
117 |
.queue_declare( |
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
118 |
&random_string(32), |
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
119 |
QueueDeclareOptions { |
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
120 |
exclusive: true, |
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
121 |
auto_delete: true, |
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
122 |
..QueueDeclareOptions::default() |
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
123 |
}, |
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
124 |
FieldTable::default(), |
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
125 |
) |
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
126 |
.await?; |
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
127 |
|
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
128 |
sub_channel |
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
129 |
.queue_bind( |
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
130 |
queue.name().as_str(), |
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
131 |
"irc", |
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
132 |
&format!("say.{}", &irc_channel[1..]), |
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
133 |
QueueBindOptions::default(), |
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
134 |
FieldTable::default(), |
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
135 |
) |
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
136 |
.await?; |
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
137 |
|
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
138 |
let mut subscriber = sub_channel |
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
139 |
.basic_consume( |
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
140 |
queue.name().as_str(), |
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
141 |
&random_string(32), |
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
142 |
BasicConsumeOptions::default(), |
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
143 |
FieldTable::default(), |
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
144 |
) |
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
145 |
.await?; |
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
146 |
|
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
147 |
loop { |
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
148 |
tokio::select! { |
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
149 |
Some(irc_message) = irc_stream.next() => handle_irc(&pub_channel, &irc_message?).await?, |
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
150 |
Some(amqp_message) = subscriber.next() => { |
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
151 |
let (_, delivery) = amqp_message.expect("error in consumer"); |
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
152 |
delivery |
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
153 |
.ack(BasicAckOptions::default()) |
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
154 |
.await?; |
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
155 |
|
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
156 |
handle_amqp(&mut irc_client, &irc_channel, delivery).await? |
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
157 |
} |
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
158 |
} |
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
159 |
} |
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
160 |
} |