world's simplest bot ever but it works so whatever

This commit is contained in:
Soph :3 2026-02-07 20:52:27 +02:00
parent 42b928f6e1
commit 50b7a7099f
3 changed files with 51 additions and 22 deletions

BIN
ViaProxy-3.4.8.jar Normal file

Binary file not shown.

View file

@ -1,18 +1,17 @@
//! A bot that logs chat messages and the number that we've received to the console.
mod mfc; mod mfc;
mod viaversion; mod viaversion;
use std::sync::Arc;
use azalea::prelude::*; use azalea::prelude::*;
use bevy_app::PluginGroup; use bevy_app::PluginGroup;
use parking_lot::Mutex; use lazy_regex::regex_replace_all;
use std::env;
#[tokio::main] #[tokio::main]
async fn main() -> AppExit { async fn main() -> AppExit {
let account = Account::microsoft("no lmao").await.unwrap(); let account = Account::microsoft(env::var("EMAIL").expect("no EMAIL found!").as_str())
// or Account::microsoft("example@example.com").await.unwrap(); .await
.unwrap();
ClientBuilder::new_without_plugins() ClientBuilder::new_without_plugins()
.add_plugins( .add_plugins(
@ -29,25 +28,53 @@ async fn main() -> AppExit {
} }
#[derive(Default, Clone, Component)] #[derive(Default, Clone, Component)]
pub struct State { 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>>,
}
async fn handle(bot: Client, event: Event, state: State) -> anyhow::Result<()> { async fn handle(bot: Client, event: Event, state: State) -> anyhow::Result<()> {
match event { match event {
Event::Chat(m) => { Event::Chat(m) => {
let mut messages_received = state.messages_received.lock(); let message = m.message().to_string();
*messages_received += 1;
println!("#{messages_received}: {}", m.message().to_string()); let parts: Vec<&str> = message.split_terminator(":").collect();
let parts: Vec<&str> = m.message().to_string().split_terminator(":").collect(); println!("{:?}", parts);
println!("{:#?}", parts);
// messages_received gets implicitly unlocked here because it's dropped 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)
}
}
} }
_ => {} _ => {}
} }

View file

@ -1,3 +1,4 @@
#![allow(dead_code)]
use std::{io::Cursor, net::SocketAddr, path::Path, process::Stdio}; use std::{io::Cursor, net::SocketAddr, path::Path, process::Stdio};
use anyhow::{Context, Result}; use anyhow::{Context, Result};
@ -189,6 +190,7 @@ impl ViaVersionPlugin {
if line.contains("/WARN]") if line.contains("/WARN]")
&& !line.contains("Missing 1.20.2 blockstate") && !line.contains("Missing 1.20.2 blockstate")
&& !line.contains("Missing 1.20.2 item") && !line.contains("Missing 1.20.2 item")
&& !line.contains("Missing 1.20.2 block")
{ {
warn!("{line}"); warn!("{line}");
} else { } else {