author | unc0rr |
Tue, 15 Jun 2021 20:45:46 +0200 | |
changeset 15792 | 191e51179d1b |
parent 15789 | d97ea528ce95 |
child 15814 | d9db7b763bd1 |
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 |
|
15792 | 54 |
let who = irc_message.source_nickname().unwrap_or(msgtarget); |
55 |
||
15789
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
56 |
if message.starts_with("!") { |
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
57 |
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
|
58 |
pub_channel |
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
59 |
.basic_publish( |
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
60 |
"irc", |
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
61 |
&format!("cmd.{}.{}", &cmd[1..], target), |
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
62 |
BasicPublishOptions::default(), |
15792 | 63 |
format!("{}\n{}", who, param).as_bytes().to_vec(), |
15789
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
64 |
BasicProperties::default(), |
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
65 |
) |
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
66 |
.await?; |
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
67 |
} else { |
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
68 |
pub_channel |
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
69 |
.basic_publish( |
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
70 |
"irc", |
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
71 |
&format!("cmd.{}.{}", &message[1..], target), |
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
72 |
BasicPublishOptions::default(), |
15792 | 73 |
who.as_bytes().to_vec(), |
15789
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
74 |
BasicProperties::default(), |
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 |
.await?; |
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
77 |
} |
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
78 |
} else { |
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
79 |
pub_channel |
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
80 |
.basic_publish( |
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
81 |
"irc", |
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
82 |
&format!("msg.{}", target), |
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
83 |
BasicPublishOptions::default(), |
15792 | 84 |
format!("{}\n{}", who, message).as_bytes().to_vec(), |
15789
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
85 |
BasicProperties::default(), |
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 |
.await?; |
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 |
} |
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 |
Ok(()) |
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
92 |
} |
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
93 |
|
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
94 |
async fn handle_amqp( |
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
95 |
irc_client: &mut Client, |
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
96 |
irc_channel: &str, |
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
97 |
delivery: Delivery, |
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
98 |
) -> AHResult<()> { |
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
99 |
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
|
100 |
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
|
101 |
} |
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
102 |
|
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
103 |
#[tokio::main] |
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
104 |
async fn main() -> AHResult<()> { |
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
105 |
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
|
106 |
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
|
107 |
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
|
108 |
|
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
109 |
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
|
110 |
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
|
111 |
|
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
112 |
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
|
113 |
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
|
114 |
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
|
115 |
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
|
116 |
irc_client.identify()?; |
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
117 |
|
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
118 |
let queue = sub_channel |
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
119 |
.queue_declare( |
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
120 |
&random_string(32), |
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
121 |
QueueDeclareOptions { |
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
122 |
exclusive: true, |
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
123 |
auto_delete: true, |
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
124 |
..QueueDeclareOptions::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 |
FieldTable::default(), |
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 |
.await?; |
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
129 |
|
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
130 |
sub_channel |
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
131 |
.queue_bind( |
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
132 |
queue.name().as_str(), |
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
133 |
"irc", |
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
134 |
&format!("say.{}", &irc_channel[1..]), |
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
135 |
QueueBindOptions::default(), |
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
136 |
FieldTable::default(), |
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 |
.await?; |
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
139 |
|
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
140 |
let mut subscriber = sub_channel |
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
141 |
.basic_consume( |
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
142 |
queue.name().as_str(), |
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
143 |
&random_string(32), |
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
144 |
BasicConsumeOptions::default(), |
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
145 |
FieldTable::default(), |
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 |
.await?; |
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
148 |
|
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
149 |
loop { |
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
150 |
tokio::select! { |
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
151 |
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
|
152 |
Some(amqp_message) = subscriber.next() => { |
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
153 |
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
|
154 |
delivery |
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
155 |
.ack(BasicAckOptions::default()) |
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
156 |
.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 |
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
|
159 |
} |
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
160 |
} |
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
161 |
} |
d97ea528ce95
Add main module for irc bot which serves as an irc<>rabbitmq relay
unc0rr
parents:
diff
changeset
|
162 |
} |