world's simplest bot ever but it works so whatever
This commit is contained in:
parent
42b928f6e1
commit
50b7a7099f
3 changed files with 51 additions and 22 deletions
71
src/main.rs
71
src/main.rs
|
|
@ -1,18 +1,17 @@
|
|||
//! A bot that logs chat messages and the number that we've received to the console.
|
||||
|
||||
mod mfc;
|
||||
mod viaversion;
|
||||
|
||||
use std::sync::Arc;
|
||||
|
||||
use azalea::prelude::*;
|
||||
use bevy_app::PluginGroup;
|
||||
use parking_lot::Mutex;
|
||||
use lazy_regex::regex_replace_all;
|
||||
|
||||
use std::env;
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> AppExit {
|
||||
let account = Account::microsoft("no lmao").await.unwrap();
|
||||
// or Account::microsoft("example@example.com").await.unwrap();
|
||||
let account = Account::microsoft(env::var("EMAIL").expect("no EMAIL found!").as_str())
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
ClientBuilder::new_without_plugins()
|
||||
.add_plugins(
|
||||
|
|
@ -29,25 +28,53 @@ async fn main() -> AppExit {
|
|||
}
|
||||
|
||||
#[derive(Default, Clone, Component)]
|
||||
pub struct State {
|
||||
/// An example field that stores the number of messages that've been
|
||||
/// received by the client so far.
|
||||
///
|
||||
/// The state gets cloned whenever the handler is called, so to have all
|
||||
/// the clones point to the same data and have it be mutable, we use an
|
||||
/// Arc<Mutex<T>>.
|
||||
pub messages_received: Arc<Mutex<usize>>,
|
||||
}
|
||||
pub struct State {}
|
||||
|
||||
async fn handle(bot: Client, event: Event, state: State) -> anyhow::Result<()> {
|
||||
match event {
|
||||
Event::Chat(m) => {
|
||||
let mut messages_received = state.messages_received.lock();
|
||||
*messages_received += 1;
|
||||
println!("#{messages_received}: {}", m.message().to_string());
|
||||
let parts: Vec<&str> = m.message().to_string().split_terminator(":").collect();
|
||||
println!("{:#?}", parts);
|
||||
// messages_received gets implicitly unlocked here because it's dropped
|
||||
let message = m.message().to_string();
|
||||
|
||||
let parts: Vec<&str> = message.split_terminator(":").collect();
|
||||
println!("{:?}", parts);
|
||||
|
||||
if parts[0].starts_with("Tip!") {
|
||||
// ignore
|
||||
} else if parts[0].starts_with("\u{e009}") {
|
||||
let username = parts[0].replace("\u{e009} ", "");
|
||||
let message = parts[1].trim();
|
||||
|
||||
//bot.chat(format!("DISCORD({}): {}", username, message));
|
||||
} else if parts[0].contains("requested to teleport to you.\n") {
|
||||
let username = parts[0]
|
||||
.split_terminator("\n")
|
||||
.next()
|
||||
.unwrap()
|
||||
.replace("requested to teleport to you.", "");
|
||||
|
||||
bot.chat(format!("tpa: {}", username.trim()));
|
||||
} else if parts[0].contains("requested you to teleport to them.\n") {
|
||||
let username = parts[0]
|
||||
.split_terminator("\n")
|
||||
.next()
|
||||
.unwrap()
|
||||
.replace("requested you to teleport to them.", "");
|
||||
|
||||
bot.chat(format!("tpahere: {}", username.trim()));
|
||||
} else {
|
||||
if parts.len() >= 2 {
|
||||
let username = regex_replace_all!(
|
||||
r#"\[[^]]*\]"#m, // removes all [BOT] [ALT] [CLANKER] et cetera
|
||||
parts[0].trim_ascii_start(), // removes all icons (like \u{e009})
|
||||
|_| ""
|
||||
);
|
||||
|
||||
let joined_message = parts[1..].join(":");
|
||||
let message = joined_message.trim();
|
||||
|
||||
println!("MC {}: {}", username.trim(), message)
|
||||
}
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
#![allow(dead_code)]
|
||||
use std::{io::Cursor, net::SocketAddr, path::Path, process::Stdio};
|
||||
|
||||
use anyhow::{Context, Result};
|
||||
|
|
@ -189,6 +190,7 @@ impl ViaVersionPlugin {
|
|||
if line.contains("/WARN]")
|
||||
&& !line.contains("Missing 1.20.2 blockstate")
|
||||
&& !line.contains("Missing 1.20.2 item")
|
||||
&& !line.contains("Missing 1.20.2 block")
|
||||
{
|
||||
warn!("{line}");
|
||||
} else {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue