Too lazy to make propper edit but i changed the

polling system to a message one so we can have
more ways we can interract with plugins
(reload/ reset/ on click events)
This commit is contained in:
2024-06-26 04:00:44 +03:00
parent 9f53240807
commit 026a68364b
33 changed files with 694 additions and 271 deletions

View File

@@ -11,3 +11,4 @@ crate-type=["cdylib"]
chrono = "0.4.38"
dim_sdk = {path="../../sdk/rust/dim_sdk"}
lazy_static = "1.4.0"
log = "0.4.21"

View File

@@ -1,5 +1,5 @@
use std::fmt::Write;
use dim_sdk::{plugin_info, Context, DimPlugin};
use dim_sdk::{plugin_info, Context, DimPlugin, Message, Result};
use chrono::{NaiveDate, Local};
plugin_info!(
@@ -11,30 +11,32 @@ plugin_info!(
#[derive(Debug, Clone)]
struct Plug {
}
impl Plug {
pub fn new() -> Self {
Self {
}
}
ctx: Context
}
impl DimPlugin for Plug {
fn init(&mut self, _ctx: Context) {}
fn poll(&mut self, f: &mut dim_sdk::CBuffer) -> dim_sdk::Result<()> {
fn init(ctx: Context) -> Result<Self> {
Ok(Self {
ctx
})
}
fn on_message(&mut self, msg: Message) -> Result<()> {
self.ctx.buf.reset();
match msg.name.as_str() {
"poll" => {
let start_date = NaiveDate::from_ymd_opt(2024, 3, 8).expect("Invalid date");
let current_date = Local::now().date_naive();
let duration = current_date.signed_duration_since(start_date);
let start_date = NaiveDate::from_ymd_opt(2024, 3, 8).expect("Invalid date");
let current_date = Local::now().date_naive();
let duration = current_date.signed_duration_since(start_date);
write!(f, "{} days <3", duration.num_days())?;
write!(self.ctx, "{} days <3", duration.num_days())?;
}
_ => ()
}
Ok(())
}
fn pre_reload(&mut self) {}
fn post_reload(&mut self) {}
fn free(&mut self) {}
fn pre_reload(&mut self) -> Result<()> { Ok(()) }
fn post_reload(&mut self) -> Result<()> { Ok(()) }
fn free(&mut self) -> Result<()> { Ok(()) }
}