impl Parcelable for all RunnerConfig types
This commit is contained in:
parent
ad58587160
commit
b76392d597
107
src/botscript.rs
107
src/botscript.rs
@ -1,5 +1,6 @@
|
|||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
|
use crate::utils::parcelable::{ParcelType, Parcelable, ParcelableError, ParcelableResult};
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
use quickjs_rusty::serde::from_js;
|
use quickjs_rusty::serde::from_js;
|
||||||
use quickjs_rusty::utils::create_null;
|
use quickjs_rusty::utils::create_null;
|
||||||
@ -63,6 +64,22 @@ impl FunctionMarker {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Parcelable<Self> for BotFunction {
|
||||||
|
fn get_field(
|
||||||
|
&mut self,
|
||||||
|
_name: &str,
|
||||||
|
) -> crate::utils::parcelable::ParcelableResult<ParcelType<Self>> {
|
||||||
|
todo!()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn resolve(&mut self) -> ParcelableResult<ParcelType<Self>>
|
||||||
|
where
|
||||||
|
Self: Sized + 'static,
|
||||||
|
{
|
||||||
|
Ok(ParcelType::Function(self))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl BotFunction {
|
impl BotFunction {
|
||||||
pub fn by_name(name: String) -> Self {
|
pub fn by_name(name: String) -> Self {
|
||||||
Self {
|
Self {
|
||||||
@ -189,6 +206,21 @@ pub enum KeyboardDefinition {
|
|||||||
Function(BotFunction),
|
Function(BotFunction),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Parcelable<BotFunction> for KeyboardDefinition {
|
||||||
|
fn get_field(&mut self, _name: &str) -> ParcelableResult<ParcelType<BotFunction>> {
|
||||||
|
todo!()
|
||||||
|
}
|
||||||
|
fn resolve(&mut self) -> ParcelableResult<ParcelType<BotFunction>>
|
||||||
|
where
|
||||||
|
Self: Sized + 'static,
|
||||||
|
{
|
||||||
|
match self {
|
||||||
|
KeyboardDefinition::Rows(rows) => Ok(rows.resolve()?),
|
||||||
|
KeyboardDefinition::Function(f) => Ok(f.resolve()?),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl ResolveValue for KeyboardDefinition {
|
impl ResolveValue for KeyboardDefinition {
|
||||||
type Value = Vec<<RowDefinition as ResolveValue>::Value>;
|
type Value = Vec<<RowDefinition as ResolveValue>::Value>;
|
||||||
|
|
||||||
@ -209,6 +241,21 @@ pub enum RowDefinition {
|
|||||||
Function(BotFunction),
|
Function(BotFunction),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Parcelable<BotFunction> for RowDefinition {
|
||||||
|
fn get_field(&mut self, _name: &str) -> ParcelableResult<ParcelType<BotFunction>> {
|
||||||
|
todo!()
|
||||||
|
}
|
||||||
|
fn resolve(&mut self) -> ParcelableResult<ParcelType<BotFunction>>
|
||||||
|
where
|
||||||
|
Self: Sized + 'static,
|
||||||
|
{
|
||||||
|
match self {
|
||||||
|
Self::Buttons(buttons) => Ok(buttons.resolve()?),
|
||||||
|
Self::Function(f) => Ok(f.resolve()?),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl ResolveValue for RowDefinition {
|
impl ResolveValue for RowDefinition {
|
||||||
type Value = Vec<<ButtonDefinition as ResolveValue>::Value>;
|
type Value = Vec<<ButtonDefinition as ResolveValue>::Value>;
|
||||||
|
|
||||||
@ -246,12 +293,34 @@ impl ResolveValue for ButtonDefinition {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Parcelable<BotFunction> for ButtonDefinition {
|
||||||
|
fn get_field(&mut self, _name: &str) -> ParcelableResult<ParcelType<BotFunction>> {
|
||||||
|
todo!()
|
||||||
|
}
|
||||||
|
fn resolve(&mut self) -> ParcelableResult<ParcelType<BotFunction>>
|
||||||
|
where
|
||||||
|
Self: Sized + 'static,
|
||||||
|
{
|
||||||
|
match self {
|
||||||
|
Self::Button(braw) => Ok(braw.resolve()?),
|
||||||
|
Self::ButtonLiteral(s) => Ok(s.resolve()?),
|
||||||
|
Self::Function(f) => Ok(f.resolve()?),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||||
pub struct ButtonRaw {
|
pub struct ButtonRaw {
|
||||||
name: ButtonName,
|
name: ButtonName,
|
||||||
callback_name: String,
|
callback_name: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<F> Parcelable<F> for ButtonRaw {
|
||||||
|
fn get_field(&mut self, _name: &str) -> ParcelableResult<ParcelType<F>> {
|
||||||
|
todo!()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl ButtonRaw {
|
impl ButtonRaw {
|
||||||
pub fn from_literal(literal: String) -> Self {
|
pub fn from_literal(literal: String) -> Self {
|
||||||
ButtonRaw {
|
ButtonRaw {
|
||||||
@ -284,18 +353,56 @@ pub struct BotMessage {
|
|||||||
handler: Option<BotFunction>,
|
handler: Option<BotFunction>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Parcelable<BotFunction> for BotMessage {
|
||||||
|
fn get_field(&mut self, name: &str) -> ParcelableResult<ParcelType<BotFunction>> {
|
||||||
|
match name {
|
||||||
|
"buttons" => Ok(self.buttons.resolve()?),
|
||||||
|
"state" => Ok(self.state.resolve()?),
|
||||||
|
"handler" => Ok(self.handler.resolve()?),
|
||||||
|
field => Err(ParcelableError::FieldError(format!(
|
||||||
|
"tried to get field {field}, but this field does not exists or private"
|
||||||
|
))),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug)]
|
#[derive(Serialize, Deserialize, Debug)]
|
||||||
pub struct BotDialog {
|
pub struct BotDialog {
|
||||||
pub commands: HashMap<String, BotMessage>,
|
pub commands: HashMap<String, BotMessage>,
|
||||||
stateful_msg_handlers: HashMap<String, BotMessage>,
|
stateful_msg_handlers: HashMap<String, BotMessage>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Parcelable<BotFunction> for BotDialog {
|
||||||
|
fn get_field(&mut self, name: &str) -> Result<ParcelType<BotFunction>, ParcelableError> {
|
||||||
|
match name {
|
||||||
|
"commands" => Ok(ParcelType::Parcelable(&mut self.commands)),
|
||||||
|
"stateful_msg_handlersommands" => {
|
||||||
|
Ok(ParcelType::Parcelable(&mut self.stateful_msg_handlers))
|
||||||
|
}
|
||||||
|
field => Err(ParcelableError::FieldError(format!(
|
||||||
|
"tried to get field {field}, but this field does not exists or private"
|
||||||
|
))),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug)]
|
#[derive(Serialize, Deserialize, Debug)]
|
||||||
pub struct RunnerConfig {
|
pub struct RunnerConfig {
|
||||||
config: BotConfig,
|
config: BotConfig,
|
||||||
pub dialog: BotDialog,
|
pub dialog: BotDialog,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Parcelable<BotFunction> for RunnerConfig {
|
||||||
|
fn get_field(&mut self, name: &str) -> Result<ParcelType<BotFunction>, ParcelableError> {
|
||||||
|
match name {
|
||||||
|
"dialog" => Ok(ParcelType::Parcelable(&mut self.dialog)),
|
||||||
|
field => Err(ParcelableError::FieldError(format!(
|
||||||
|
"tried to get field {field}, but this field does not exists or private"
|
||||||
|
))),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub struct Runner {
|
pub struct Runner {
|
||||||
context: Context,
|
context: Context,
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user