init commands
This commit is contained in:
parent
29473f1c1e
commit
63ca475a50
2 changed files with 37 additions and 18 deletions
27
src/commands.rs
Normal file
27
src/commands.rs
Normal 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;
|
||||||
|
}
|
28
src/main.rs
28
src/main.rs
|
@ -1,11 +1,13 @@
|
||||||
use client::create_client;
|
use client::create_client;
|
||||||
|
use commands::*;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use twitch_irc::login::StaticLoginCredentials;
|
|
||||||
use twitch_irc::message::ServerMessage;
|
use twitch_irc::{
|
||||||
use twitch_irc::SecureTCPTransport;
|
login::StaticLoginCredentials, message::ServerMessage, SecureTCPTransport, TwitchIRCClient,
|
||||||
use twitch_irc::TwitchIRCClient;
|
};
|
||||||
|
|
||||||
mod client;
|
mod client;
|
||||||
|
mod commands;
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
pub async fn 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 {
|
while let Some(message) = incoming_messages.recv().await {
|
||||||
match message {
|
match message {
|
||||||
ServerMessage::Privmsg(msg) => {
|
ServerMessage::Privmsg(msg) => {
|
||||||
|
@ -38,18 +40,8 @@ pub async fn main() {
|
||||||
);
|
);
|
||||||
if msg.sender.name == "notohh" {
|
if msg.sender.name == "notohh" {
|
||||||
match msg.message_text.as_str() {
|
match msg.message_text.as_str() {
|
||||||
"*ping" => client
|
"*ping" => ping(&msg).await,
|
||||||
.say(msg.channel_login.to_owned(), "Pong!".to_owned())
|
"*test" => test(&msg).await,
|
||||||
.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(),
|
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -62,5 +54,5 @@ pub async fn main() {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
join_handle.await.unwrap();
|
message_handler.await.unwrap();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue