refactor(http)!: get address from lua
This commit is contained in:
parent
caec5fa7f8
commit
18540aa223
@ -1,6 +1,6 @@
|
|||||||
use crate::build_info;
|
use crate::build_info;
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
use std::{net::SocketAddr, path::PathBuf};
|
use std::path::PathBuf;
|
||||||
|
|
||||||
/// A Minecraft utility bot
|
/// A Minecraft utility bot
|
||||||
#[derive(Parser)]
|
#[derive(Parser)]
|
||||||
@ -9,8 +9,4 @@ pub struct Arguments {
|
|||||||
/// Path to main Lua file
|
/// Path to main Lua file
|
||||||
#[arg(short, long)]
|
#[arg(short, long)]
|
||||||
pub script: Option<PathBuf>,
|
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 log::{debug, error, info, trace};
|
||||||
use mlua::{Error, Function, IntoLuaMulti, Table};
|
use mlua::{Error, Function, IntoLuaMulti, Table};
|
||||||
use ncr::utils::trim_header;
|
use ncr::utils::trim_header;
|
||||||
|
use std::net::SocketAddr;
|
||||||
use tokio::net::TcpListener;
|
use tokio::net::TcpListener;
|
||||||
|
|
||||||
#[allow(clippy::too_many_lines)]
|
#[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;
|
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(());
|
return Ok(());
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -28,7 +28,6 @@ use std::{
|
|||||||
collections::HashMap,
|
collections::HashMap,
|
||||||
env,
|
env,
|
||||||
fs::{OpenOptions, read_to_string},
|
fs::{OpenOptions, read_to_string},
|
||||||
net::SocketAddr,
|
|
||||||
path::PathBuf,
|
path::PathBuf,
|
||||||
sync::Arc,
|
sync::Arc,
|
||||||
};
|
};
|
||||||
@ -39,7 +38,6 @@ type ListenerMap = Arc<RwLock<HashMap<String, Vec<(String, Function)>>>>;
|
|||||||
|
|
||||||
#[derive(Default, Clone, Component)]
|
#[derive(Default, Clone, Component)]
|
||||||
pub struct State {
|
pub struct State {
|
||||||
http_address: Option<SocketAddr>,
|
|
||||||
lua: Arc<Lua>,
|
lua: Arc<Lua>,
|
||||||
event_listeners: ListenerMap,
|
event_listeners: ListenerMap,
|
||||||
commands: Arc<CommandDispatcher<Mutex<CommandSource>>>,
|
commands: Arc<CommandDispatcher<Mutex<CommandSource>>>,
|
||||||
@ -116,7 +114,6 @@ async fn main() -> anyhow::Result<()> {
|
|||||||
.add_plugins(DefaultBotPlugins)
|
.add_plugins(DefaultBotPlugins)
|
||||||
.set_handler(events::handle_event)
|
.set_handler(events::handle_event)
|
||||||
.set_state(State {
|
.set_state(State {
|
||||||
http_address: args.http_address,
|
|
||||||
lua: Arc::new(lua),
|
lua: Arc::new(lua),
|
||||||
event_listeners,
|
event_listeners,
|
||||||
commands: Arc::new(commands),
|
commands: Arc::new(commands),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user