init commands

This commit is contained in:
notohh 2024-06-07 21:59:05 -04:00
parent 29473f1c1e
commit 63ca475a50
Signed by: notohh
GPG key ID: BD47506D475EE86D
2 changed files with 37 additions and 18 deletions

27
src/commands.rs Normal file
View file

@ -0,0 +1,27 @@
use crate::client::create_client;
use twitch_irc::{
login::StaticLoginCredentials, message::PrivmsgMessage, SecureTCPTransport, TwitchIRCClient,
};
pub async fn ping(m: &PrivmsgMessage) {
let client = create_client();
let (mut _incoming_messages, client) =
TwitchIRCClient::<SecureTCPTransport, StaticLoginCredentials>::new(client);
let s = format!("Pong!");
let _message = client.say(m.channel_login.to_owned(), s.to_owned()).await;
}
pub async fn test(m: &PrivmsgMessage) {
let client = create_client();
let (mut _incoming_messages, client) =
TwitchIRCClient::<SecureTCPTransport, StaticLoginCredentials>::new(client);
let _message = client
.say(m.channel_login.to_owned(), "test".to_owned())
.await;
}

View file

@ -1,11 +1,13 @@
use client::create_client;
use commands::*;
use std::collections::HashMap;
use twitch_irc::login::StaticLoginCredentials;
use twitch_irc::message::ServerMessage;
use twitch_irc::SecureTCPTransport;
use twitch_irc::TwitchIRCClient;
use twitch_irc::{
login::StaticLoginCredentials, message::ServerMessage, SecureTCPTransport, TwitchIRCClient,
};
mod client;
mod commands;
#[tokio::main]
pub async fn main() {
@ -28,7 +30,7 @@ pub async fn main() {
}
}
let join_handle = tokio::spawn(async move {
let message_handler = tokio::spawn(async move {
while let Some(message) = incoming_messages.recv().await {
match message {
ServerMessage::Privmsg(msg) => {
@ -38,18 +40,8 @@ pub async fn main() {
);
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(),
"*uptime" => client
.say(msg.channel_login.to_owned(), "aaa".to_owned())
.await
.unwrap(),
"*ping" => ping(&msg).await,
"*test" => test(&msg).await,
_ => {}
}
}
@ -62,5 +54,5 @@ pub async fn main() {
}
});
join_handle.await.unwrap();
message_handler.await.unwrap();
}