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]
|
[package]
|
||||||
name = "botoh"
|
name = "botoh"
|
||||||
version = "0.1.0"
|
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 = {
|
hooks = {
|
||||||
# rust
|
# rust
|
||||||
rustfmt.enable = true;
|
rustfmt.enable = true;
|
||||||
clippy.enable = true;
|
clippy.enable = false;
|
||||||
taplo.enable = true;
|
taplo.enable = true;
|
||||||
# nix
|
# nix
|
||||||
statix.enable = true;
|
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!");
|
|
||||||
}
|
|
53
src/main.rs
53
src/main.rs
|
@ -1,6 +1,9 @@
|
||||||
use dotenv::dotenv;
|
use dotenv::dotenv;
|
||||||
|
use std::collections::HashMap;
|
||||||
use std::env;
|
use std::env;
|
||||||
use twitch_irc::login::StaticLoginCredentials;
|
use twitch_irc::login::StaticLoginCredentials;
|
||||||
|
use twitch_irc::message::ReplyToMessage;
|
||||||
|
use twitch_irc::message::ServerMessage;
|
||||||
use twitch_irc::ClientConfig;
|
use twitch_irc::ClientConfig;
|
||||||
use twitch_irc::SecureTCPTransport;
|
use twitch_irc::SecureTCPTransport;
|
||||||
use twitch_irc::TwitchIRCClient;
|
use twitch_irc::TwitchIRCClient;
|
||||||
|
@ -29,15 +32,51 @@ pub async fn main() {
|
||||||
let (mut incoming_messages, client) =
|
let (mut incoming_messages, client) =
|
||||||
TwitchIRCClient::<SecureTCPTransport, StaticLoginCredentials>::new(config);
|
TwitchIRCClient::<SecureTCPTransport, StaticLoginCredentials>::new(config);
|
||||||
|
|
||||||
let join_handle =
|
let mut initial_channels = HashMap::new();
|
||||||
tokio::spawn(async move { while let Some(message) = incoming_messages.recv().await {} });
|
|
||||||
|
|
||||||
client.join("notnotoh".to_owned()).unwrap();
|
initial_channels.insert("notnotoh", ());
|
||||||
|
initial_channels.insert("notohh", ());
|
||||||
|
initial_channels.insert("daph", ());
|
||||||
|
initial_channels.insert("ryanpotat", ());
|
||||||
|
|
||||||
client
|
for (channels, _) in initial_channels.iter() {
|
||||||
.say("notnotoh".to_owned(), "test".to_owned())
|
match client.join(channels.to_owned().to_string()) {
|
||||||
.await
|
Ok(_) => println!("Joined channels {}", channels),
|
||||||
.unwrap();
|
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(),
|
||||||
|
"?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();
|
join_handle.await.unwrap();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue