forked from lavina/lavina
- change trait's signature
This commit is contained in:
parent
07f2730c8f
commit
f2ccdee9d5
|
@ -1,12 +1,19 @@
|
||||||
use lavina_core::prelude::Str;
|
use lavina_core::prelude::Str;
|
||||||
use lavina_core::repo::Storage;
|
use lavina_core::repo::Storage;
|
||||||
|
use proto_irc::response::SendResponseBody;
|
||||||
use std::future::Future;
|
use std::future::Future;
|
||||||
use tokio::io::AsyncWrite;
|
use tokio::io::AsyncWrite;
|
||||||
use proto_irc::response::SendResponseBody;
|
|
||||||
|
|
||||||
pub mod whois;
|
pub mod whois;
|
||||||
|
|
||||||
pub trait Handler<Command> {
|
struct HandlerY<T: AsyncWrite + Unpin> {
|
||||||
|
server_name: Str,
|
||||||
|
client: Str,
|
||||||
|
writer: T,
|
||||||
|
storage: Storage,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub trait Handler {
|
||||||
fn handle(
|
fn handle(
|
||||||
&self,
|
&self,
|
||||||
server_name: &Str,
|
server_name: &Str,
|
||||||
|
|
|
@ -3,33 +3,37 @@ use tokio::io::{AsyncWrite, AsyncWriteExt};
|
||||||
use lavina_core::prelude::Str;
|
use lavina_core::prelude::Str;
|
||||||
use proto_irc::response::SendResponseBody;
|
use proto_irc::response::SendResponseBody;
|
||||||
|
|
||||||
pub struct ERR_NOSUCHNICK_401 {
|
/// ERR_NOSUCHNICK (401)
|
||||||
|
pub struct ErrNoSuchNick401 {
|
||||||
client: Str,
|
client: Str,
|
||||||
nick: Str,
|
nick: Str,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ERR_NOSUCHNICK_401 {
|
impl ErrNoSuchNick401 {
|
||||||
pub fn new(client: Str, nick: Str) -> Self {
|
pub fn new(client: Str, nick: Str) -> Self {
|
||||||
ERR_NOSUCHNICK_401 { client, nick }
|
ErrNoSuchNick401 { client, nick }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct ERR_NOSUCHSERVER_402 {
|
/// ERR_NOSUCHSERVER (402)
|
||||||
|
struct ErrNoSuchServer402 {
|
||||||
client: Str,
|
client: Str,
|
||||||
/// target parameter in WHOIS
|
/// target parameter in WHOIS
|
||||||
/// example: `/whois <target> <nick>`
|
/// example: `/whois <target> <nick>`
|
||||||
server_name: Str,
|
server_name: Str,
|
||||||
}
|
}
|
||||||
pub struct ERR_NONICKNAMEGIVEN_431 {
|
|
||||||
|
/// ERR_NONICKNAMEGIVEN (431)
|
||||||
|
pub struct ErrNoNicknameGiven431 {
|
||||||
client: Str,
|
client: Str,
|
||||||
}
|
}
|
||||||
impl ERR_NONICKNAMEGIVEN_431 {
|
impl ErrNoNicknameGiven431 {
|
||||||
pub fn new(client: Str) -> Self {
|
pub fn new(client: Str) -> Self {
|
||||||
ERR_NONICKNAMEGIVEN_431 { client }
|
ErrNoNicknameGiven431 { client }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl SendResponseBody for ERR_NOSUCHNICK_401 {
|
impl SendResponseBody for ErrNoSuchNick401 {
|
||||||
async fn write_response(self, writer: &mut (impl AsyncWrite + Unpin)) -> std::io::Result<()> {
|
async fn write_response(self, writer: &mut (impl AsyncWrite + Unpin)) -> std::io::Result<()> {
|
||||||
writer.write_all(b"401 ").await?;
|
writer.write_all(b"401 ").await?;
|
||||||
writer.write_all(self.client.as_bytes()).await?;
|
writer.write_all(self.client.as_bytes()).await?;
|
||||||
|
@ -41,7 +45,7 @@ impl SendResponseBody for ERR_NOSUCHNICK_401 {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl SendResponseBody for ERR_NONICKNAMEGIVEN_431 {
|
impl SendResponseBody for ErrNoNicknameGiven431 {
|
||||||
async fn write_response(self, writer: &mut (impl AsyncWrite + Unpin)) -> std::io::Result<()> {
|
async fn write_response(self, writer: &mut (impl AsyncWrite + Unpin)) -> std::io::Result<()> {
|
||||||
writer.write_all(b"431").await?;
|
writer.write_all(b"431").await?;
|
||||||
writer.write_all(self.client.as_bytes()).await?;
|
writer.write_all(self.client.as_bytes()).await?;
|
||||||
|
@ -51,7 +55,7 @@ impl SendResponseBody for ERR_NONICKNAMEGIVEN_431 {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl SendResponseBody for ERR_NOSUCHSERVER_402 {
|
impl SendResponseBody for ErrNoSuchServer402 {
|
||||||
async fn write_response(self, writer: &mut (impl AsyncWrite + Unpin)) -> std::io::Result<()> {
|
async fn write_response(self, writer: &mut (impl AsyncWrite + Unpin)) -> std::io::Result<()> {
|
||||||
writer.write_all(b"402 ").await?;
|
writer.write_all(b"402 ").await?;
|
||||||
writer.write_all(self.client.as_bytes()).await?;
|
writer.write_all(self.client.as_bytes()).await?;
|
||||||
|
|
|
@ -6,14 +6,14 @@ use lavina_core::repo::Storage;
|
||||||
use proto_irc::client::command_args::Whois;
|
use proto_irc::client::command_args::Whois;
|
||||||
use proto_irc::response::{IrcResponseMessage, SendResponseBody, SendResponseMessage};
|
use proto_irc::response::{IrcResponseMessage, SendResponseBody, SendResponseMessage};
|
||||||
|
|
||||||
use crate::commands::whois::error::{ERR_NONICKNAMEGIVEN_431, ERR_NOSUCHNICK_401};
|
use crate::commands::whois::error::{ErrNoNicknameGiven431, ErrNoSuchNick401};
|
||||||
use crate::commands::whois::response::{RplWhoIsUser311, RPL_ENDOFWHOIS_318};
|
use crate::commands::whois::response::{RplWhoIsUser311, RPL_ENDOFWHOIS_318};
|
||||||
use crate::commands::Handler;
|
use crate::commands::Handler;
|
||||||
|
|
||||||
pub mod error;
|
pub mod error;
|
||||||
pub mod response;
|
pub mod response;
|
||||||
|
|
||||||
impl Handler<Whois> for Whois {
|
impl Handler for Whois {
|
||||||
async fn handle(
|
async fn handle(
|
||||||
&self,
|
&self,
|
||||||
server_name: &Str,
|
server_name: &Str,
|
||||||
|
@ -29,7 +29,7 @@ impl Handler<Whois> for Whois {
|
||||||
Whois::EmptyArgs => {
|
Whois::EmptyArgs => {
|
||||||
IrcResponseMessage::empty_tags(
|
IrcResponseMessage::empty_tags(
|
||||||
Some(server_name.clone()),
|
Some(server_name.clone()),
|
||||||
ERR_NONICKNAMEGIVEN_431::new(server_name.clone()),
|
ErrNoNicknameGiven431::new(server_name.clone()),
|
||||||
)
|
)
|
||||||
.write_response(writer)
|
.write_response(writer)
|
||||||
.await?
|
.await?
|
||||||
|
@ -68,7 +68,7 @@ async fn handle_nick_target(
|
||||||
.write_response(writer)
|
.write_response(writer)
|
||||||
.await?
|
.await?
|
||||||
} else {
|
} else {
|
||||||
ERR_NOSUCHNICK_401::new(client.clone(), nick.clone()).write_response(writer).await?
|
ErrNoSuchNick401::new(client.clone(), nick.clone()).write_response(writer).await?
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,8 +3,8 @@ use tokio::io::{AsyncWrite, AsyncWriteExt};
|
||||||
use lavina_core::prelude::Str;
|
use lavina_core::prelude::Str;
|
||||||
use proto_irc::response::SendResponseBody;
|
use proto_irc::response::SendResponseBody;
|
||||||
|
|
||||||
struct RplWhoiscertfp276;
|
struct RplWhoisCertfp276;
|
||||||
struct RplWhoIsRegNick307;
|
struct RplWhoisRegNick307;
|
||||||
pub struct RplWhoIsUser311 {
|
pub struct RplWhoIsUser311 {
|
||||||
client: Str,
|
client: Str,
|
||||||
/// unique name
|
/// unique name
|
||||||
|
@ -26,16 +26,16 @@ impl RplWhoIsUser311 {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct _RplWhoisserver312;
|
struct _RplWhoisServer312;
|
||||||
struct _RplWhoisoperator313;
|
struct _RplWhoisOperator313;
|
||||||
struct _RplWhoisidle317;
|
struct _RplWhoisIdle317;
|
||||||
struct _RplWhoischannels319;
|
struct _RplWhoisChannels319;
|
||||||
struct _RplWhoisspecial320;
|
struct _RplWhoisSpecial320;
|
||||||
struct _RplWhoisaccount330;
|
struct _RplWhoisAccount330;
|
||||||
struct _RplWhoisactually338;
|
struct _RplWhoisActually338;
|
||||||
struct _RplWhoishost378;
|
struct _RplWhoisHost378;
|
||||||
struct _RplWhoismodes379;
|
struct _RplWhoisModes379;
|
||||||
struct _RplWhoissecure671;
|
struct _RplWhoisSecure671;
|
||||||
struct _RplAway301;
|
struct _RplAway301;
|
||||||
pub struct RPL_ENDOFWHOIS_318 {
|
pub struct RPL_ENDOFWHOIS_318 {
|
||||||
client: Str,
|
client: Str,
|
||||||
|
|
Loading…
Reference in New Issue