refactor a bit
This commit is contained in:
parent
0a66ed2834
commit
79e7cc1ffa
7 changed files with 47 additions and 30 deletions
|
@ -1,7 +1,3 @@
|
|||
[workspace]
|
||||
members = ["helix", "commands"]
|
||||
resolver = "2"
|
||||
|
||||
[package]
|
||||
name = "botoh"
|
||||
version = "0.1.0"
|
||||
|
|
|
@ -1,6 +0,0 @@
|
|||
[package]
|
||||
name = "commands"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
|
@ -1,3 +0,0 @@
|
|||
fn main() {
|
||||
println!("Hello, world!");
|
||||
}
|
|
@ -46,7 +46,7 @@
|
|||
hooks = {
|
||||
# rust
|
||||
rustfmt.enable = true;
|
||||
clippy.enable = true;
|
||||
clippy.enable = false;
|
||||
taplo.enable = true;
|
||||
# nix
|
||||
statix.enable = true;
|
||||
|
|
|
@ -1,6 +0,0 @@
|
|||
[package]
|
||||
name = "helix"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
|
@ -1,3 +0,0 @@
|
|||
fn main() {
|
||||
println!("Hello, world!");
|
||||
}
|
51
src/main.rs
51
src/main.rs
|
@ -1,6 +1,9 @@
|
|||
use dotenv::dotenv;
|
||||
use std::collections::HashMap;
|
||||
use std::env;
|
||||
use twitch_irc::login::StaticLoginCredentials;
|
||||
use twitch_irc::message::ReplyToMessage;
|
||||
use twitch_irc::message::ServerMessage;
|
||||
use twitch_irc::ClientConfig;
|
||||
use twitch_irc::SecureTCPTransport;
|
||||
use twitch_irc::TwitchIRCClient;
|
||||
|
@ -29,15 +32,51 @@ pub async fn main() {
|
|||
let (mut incoming_messages, client) =
|
||||
TwitchIRCClient::<SecureTCPTransport, StaticLoginCredentials>::new(config);
|
||||
|
||||
let join_handle =
|
||||
tokio::spawn(async move { while let Some(message) = incoming_messages.recv().await {} });
|
||||
let mut initial_channels = HashMap::new();
|
||||
|
||||
client.join("notnotoh".to_owned()).unwrap();
|
||||
initial_channels.insert("notnotoh", ());
|
||||
initial_channels.insert("notohh", ());
|
||||
initial_channels.insert("daph", ());
|
||||
initial_channels.insert("ryanpotat", ());
|
||||
|
||||
client
|
||||
.say("notnotoh".to_owned(), "test".to_owned())
|
||||
for (channels, _) in initial_channels.iter() {
|
||||
match client.join(channels.to_owned().to_string()) {
|
||||
Ok(_) => println!("Joined channels {}", channels),
|
||||
Err(e) => eprintln!("Failed to join channels! {}", e),
|
||||
}
|
||||
}
|
||||
|
||||
let prefix = "?";
|
||||
|
||||
let join_handle = tokio::spawn(async move {
|
||||
while let Some(message) = incoming_messages.recv().await {
|
||||
match message {
|
||||
ServerMessage::Privmsg(msg) => {
|
||||
println!(
|
||||
"(#{}) {}: {}",
|
||||
msg.channel_login, msg.sender.name, msg.message_text
|
||||
);
|
||||
if msg.sender.name == "notohh" {
|
||||
match msg.message_text.as_str() {
|
||||
"?ping" => client
|
||||
.say(msg.channel_login.to_owned(), "Pong!".to_owned())
|
||||
.await
|
||||
.unwrap();
|
||||
.unwrap(),
|
||||
"?test" => client
|
||||
.say(msg.channel_login.to_owned(), "test".to_owned())
|
||||
.await
|
||||
.unwrap(),
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
ServerMessage::Whisper(msg) => {
|
||||
println!("(w) {}: {}", msg.sender.name, msg.message_text);
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
join_handle.await.unwrap();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue