Created
February 25, 2023 15:14
-
-
Save d33tah/0a660a6183179a574bda376ab9288384 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[package] | |
name = "ircclient" | |
version = "0.1.0" | |
edition = "2021" | |
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | |
[dependencies] | |
failure = "0.1.8" | |
futures = "0.3.26" | |
irc = "0.15.0" | |
tokio = { version = "1", features = ["macros", "rt-multi-thread"] } | |
[[bin]] | |
name = "ircclient" | |
path = "main.rs" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM rust as build | |
ADD ./Cargo.toml /app/Cargo.toml | |
ADD ./src /app/src | |
WORKDIR /app | |
RUN cargo build --release | |
FROM scratch | |
COPY --from=build /app/target/release/ircclient /ircclient |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use irc::client::prelude::*; | |
use futures::prelude::*; | |
#[tokio::main] | |
async fn main() -> Result<(), failure::Error> { | |
// We can also load the Config at runtime via Config::load("path/to/config.toml") | |
let config = Config { | |
nickname: Some("the-irc-crate".to_owned()), | |
server: Some("irc.libera.chat".to_owned()), | |
channels: vec!["#hakierspejs".to_owned()], | |
..Config::default() | |
}; | |
let mut client = Client::from_config(config).await?; | |
client.identify()?; | |
let mut stream = client.stream()?; | |
while let Some(message) = stream.next().await.transpose()? { | |
match message.command { | |
Command::PRIVMSG(ref channel, ref cmd) => { | |
println!("{}", cmd); | |
} | |
_ => (), | |
} | |
} | |
Ok(()) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment