refactor(http)!: get address from lua
This commit is contained in:
parent
caec5fa7f8
commit
a98b6814b1
@ -1,6 +1,6 @@
|
||||
use crate::build_info;
|
||||
use clap::Parser;
|
||||
use std::{net::SocketAddr, path::PathBuf};
|
||||
use std::path::PathBuf;
|
||||
|
||||
/// A Minecraft utility bot
|
||||
#[derive(Parser)]
|
||||
@ -9,8 +9,4 @@ pub struct Arguments {
|
||||
/// Path to main Lua file
|
||||
#[arg(short, long)]
|
||||
pub script: Option<PathBuf>,
|
||||
|
||||
/// Socket address to bind HTTP server to
|
||||
#[arg(short = 'a', long)]
|
||||
pub http_address: Option<SocketAddr>,
|
||||
}
|
||||
|
@ -16,6 +16,7 @@ use hyper_util::rt::TokioIo;
|
||||
use log::{debug, error, info, trace};
|
||||
use mlua::{Error, Function, IntoLuaMulti, Table};
|
||||
use ncr::utils::trim_header;
|
||||
use std::net::SocketAddr;
|
||||
use tokio::net::TcpListener;
|
||||
|
||||
#[allow(clippy::too_many_lines)]
|
||||
@ -191,7 +192,11 @@ pub async fn handle_event(client: Client, event: Event, state: State) -> anyhow:
|
||||
)?;
|
||||
call_listeners(&state, "init", ()).await;
|
||||
|
||||
let Some(address) = state.http_address else {
|
||||
let Some(address): Option<SocketAddr> = globals
|
||||
.get::<String>("HttpAddress")
|
||||
.ok()
|
||||
.and_then(|string| string.parse().ok())
|
||||
else {
|
||||
return Ok(());
|
||||
};
|
||||
|
||||
|
@ -28,7 +28,6 @@ use std::{
|
||||
collections::HashMap,
|
||||
env,
|
||||
fs::{OpenOptions, read_to_string},
|
||||
net::SocketAddr,
|
||||
path::PathBuf,
|
||||
sync::Arc,
|
||||
};
|
||||
@ -39,7 +38,6 @@ type ListenerMap = Arc<RwLock<HashMap<String, Vec<(String, Function)>>>>;
|
||||
|
||||
#[derive(Default, Clone, Component)]
|
||||
pub struct State {
|
||||
http_address: Option<SocketAddr>,
|
||||
lua: Arc<Lua>,
|
||||
event_listeners: ListenerMap,
|
||||
commands: Arc<CommandDispatcher<Mutex<CommandSource>>>,
|
||||
@ -116,7 +114,6 @@ async fn main() -> anyhow::Result<()> {
|
||||
.add_plugins(DefaultBotPlugins)
|
||||
.set_handler(events::handle_event)
|
||||
.set_state(State {
|
||||
http_address: args.http_address,
|
||||
lua: Arc::new(lua),
|
||||
event_listeners,
|
||||
commands: Arc::new(commands),
|
||||
|
Loading…
x
Reference in New Issue
Block a user