refactor a bit

This commit is contained in:
notohh 2024-06-07 15:20:29 -04:00
parent 0a66ed2834
commit 79e7cc1ffa
Signed by: notohh
GPG key ID: BD47506D475EE86D
7 changed files with 47 additions and 30 deletions

View file

@ -1,7 +1,3 @@
[workspace]
members = ["helix", "commands"]
resolver = "2"
[package]
name = "botoh"
version = "0.1.0"

View file

@ -1,6 +0,0 @@
[package]
name = "commands"
version = "0.1.0"
edition = "2021"
[dependencies]

View file

@ -1,3 +0,0 @@
fn main() {
println!("Hello, world!");
}

View file

@ -46,7 +46,7 @@
hooks = {
# rust
rustfmt.enable = true;
clippy.enable = true;
clippy.enable = false;
taplo.enable = true;
# nix
statix.enable = true;

View file

@ -1,6 +0,0 @@
[package]
name = "helix"
version = "0.1.0"
edition = "2021"
[dependencies]

View file

@ -1,3 +0,0 @@
fn main() {
println!("Hello, world!");
}

View file

@ -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();
}