Skip to main content

OneBotConfig

Struct OneBotConfig 

Source
pub struct OneBotConfig {
    pub access_token: Option<String>,
    pub mode: OneBotTransport,
}
Expand description

适配器配置。端点 / 绑定完全落在 mode 里(如默认正向 WS 模式的 OneBotTransport::Forward { url })。

Fields§

§access_token: Option<String>§mode: OneBotTransport

传输模式。默认 Forward { url }

Implementations§

Source§

impl OneBotConfig

Source

pub fn new(url: impl Into<String>) -> OneBotConfig

正向 WS 配置(默认模式),如 ws://127.0.0.1:8080/onebot/v11/ws

Examples found in repository?
examples/event_plugin.rs (line 43)
41async fn main() -> Result<()> {
42    let shutdown = ctrl_c_shutdown();
43    App::new().run_onebot(OneBotConfig::new("ws://127.0.0.1:8080/onebot/v11/ws"), shutdown).await
44}
More examples
Hide additional examples
examples/word_guess.rs (line 53)
51async fn main() -> Result<()> {
52    let shutdown = nagisa::ctrl_c_shutdown();
53    App::new().run_onebot(OneBotConfig::new("ws://127.0.0.1:8080/onebot/v11/ws"), shutdown).await
54}
examples/echo_bot.rs (line 93)
88async fn main() -> Result<()> {
89    let shutdown = ctrl_c_shutdown();
90    App::new()
91        .data(Counter { hits: AtomicU64::new(0) })
92        .on(group_only)
93        .run_onebot(OneBotConfig::new("ws://127.0.0.1:8080/onebot/v11/ws"), shutdown)
94        .await
95}
examples/plugin_switches.rs (line 75)
68async fn main() -> Result<()> {
69    let shutdown = ctrl_c_shutdown();
70    App::new()
71        // 观察每一次开关改动 —— 在这里把快照持久化到你的存储。
72        .on_switch_change(|key, peer, value| {
73            println!("switch {key} {peer:?} -> {value}");
74        })
75        .run_onebot(OneBotConfig::new("ws://127.0.0.1:8080/onebot/v11/ws"), shutdown)
76        .await
77}
examples/token_bind.rs (line 45)
40async fn main() -> Result<()> {
41    let shutdown = nagisa::ctrl_c_shutdown();
42    // `Rendezvous<String, Uin>` 由 `App::new` 自动提供(默认 TTL 5 分钟),所以
43    // token/bind handler 的 `State<Rendezvous<..>>` 无需手动 `.data(..)` 就能用。要覆盖就自己
44    // 注册一个。
45    App::new().run_onebot(OneBotConfig::new("ws://127.0.0.1:8080/onebot/v11/ws"), shutdown).await
46}
Source

pub fn reverse_ws(bind: SocketAddr, path: impl Into<String>) -> OneBotConfig

反向 WS 配置:nagisa 绑 bind,在 path 上接受 WS 升级。

Source

pub fn http( api_url: impl Into<String>, post_bind: SocketAddr, post_path: impl Into<String>, ) -> OneBotConfig

HTTP-POST 配置:事件 POST 到 post_bind+post_path,动作发往 api_url

Source

pub fn http_api(api_url: impl Into<String>) -> OneBotConfig

纯 HTTP-API 动作配置:动作 POST 到 api_url,起 webhook。与独立的纯事件适配器 (Forward/ReverseWs)配对,即可实现「HTTP 动作 + WS 事件」的拆分。

Source

pub fn llonebot_http_sse(api_url: impl Into<String>) -> OneBotConfig

LLOneBot HTTP 客户端 + SSE /_events 事件流:actions POST 到 api_url, 事件经 SSE 推送(首选)。无公网回调即可收事件。

Source

pub fn llonebot_http_long_poll( api_url: impl Into<String>, interval: Duration, ) -> OneBotConfig

LLOneBot HTTP 客户端 + get_event 长轮询事件源:actions POST 到 api_url, 每 interval 拉一批排队事件。SSE 不可用时的回退方案。

Source

pub fn with_token(self, token: impl Into<String>) -> OneBotConfig

Source

pub fn with_secret(self, secret: impl Into<String>) -> OneBotConfig

设置 HTTP-POST 的 X-Signature 密钥(仅 Http 模式有意义)。

Trait Implementations§

Source§

impl Clone for OneBotConfig

Source§

fn clone(&self) -> OneBotConfig

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for OneBotConfig

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FromRef<T> for T
where T: Clone,

Source§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
Source§

impl<A, B, T> HttpServerConnExec<A, B> for T
where B: Body,

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more