Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion basalt-server-lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ rust-version.workspace = true
[features]
doc-gen = []
webhooks = ["dep:reqwest"]
scripting = ["dep:rustyscript"]
scripting = ["dep:rustyscript", "dep:deno_core"]
full = ["webhooks", "scripting"]
default = ["full", "doc-gen"]

Expand Down Expand Up @@ -42,6 +42,7 @@ rustyscript = { git = "https://github.com/rscarson/rustyscript.git", branch = "m
"http",
], optional = true }
reqwest = { version = "0.11.0", features = ["json"], optional = true }
deno_core = { version = "0.340.0", optional = true }

[dev-dependencies]
async-tempfile = "0.6.0"
Expand Down
45 changes: 44 additions & 1 deletion basalt-server-lib/src/server/hooks/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,57 @@
}

mod evaluator {
use crate::server::{hooks::events::ServerEvent, AppState};
use crate::{
repositories::{self, users::Username},
server::{hooks::events::ServerEvent, AppState},
services::ws::{self, Broadcast, WebSocketSend},

Check warning on line 54 in basalt-server-lib/src/server/hooks/handlers.rs

View workflow job for this annotation

GitHub Actions / clippy

[clippy] basalt-server-lib/src/server/hooks/handlers.rs#L54

warning: unused imports: `Broadcast` and `WebSocketSend` --> basalt-server-lib/src/server/hooks/handlers.rs:54:30 | 54 | services::ws::{self, Broadcast, WebSocketSend}, | ^^^^^^^^^ ^^^^^^^^^^^^^ | = note: `#[warn(unused_imports)]` on by default
Raw output
basalt-server-lib/src/server/hooks/handlers.rs:54:30:w:warning: unused imports: `Broadcast` and `WebSocketSend`
  --> basalt-server-lib/src/server/hooks/handlers.rs:54:30
   |
54 |         services::ws::{self, Broadcast, WebSocketSend},
   |                              ^^^^^^^^^  ^^^^^^^^^^^^^
   |
   = note: `#[warn(unused_imports)]` on by default


__END__

Check warning on line 54 in basalt-server-lib/src/server/hooks/handlers.rs

View workflow job for this annotation

GitHub Actions / clippy

[clippy] basalt-server-lib/src/server/hooks/handlers.rs#L54

warning: unused imports: `Broadcast` and `WebSocketSend` --> basalt-server-lib/src/server/hooks/handlers.rs:54:30 | 54 | services::ws::{self, Broadcast, WebSocketSend}, | ^^^^^^^^^ ^^^^^^^^^^^^^ | = note: `#[warn(unused_imports)]` on by default
Raw output
basalt-server-lib/src/server/hooks/handlers.rs:54:30:w:warning: unused imports: `Broadcast` and `WebSocketSend`
  --> basalt-server-lib/src/server/hooks/handlers.rs:54:30
   |
54 |         services::ws::{self, Broadcast, WebSocketSend},
   |                              ^^^^^^^^^  ^^^^^^^^^^^^^
   |
   = note: `#[warn(unused_imports)]` on by default


__END__
utils,
};

use anyhow::Context;
use deno_core::OpState;
use rustyscript::{json_args, Module, Runtime, RuntimeOptions};
use std::{path::PathBuf, sync::Arc, time::Duration};
use tokio::sync::oneshot;
use tracing::debug;

#[deno_core::op2(async)]

Check failure on line 65 in basalt-server-lib/src/server/hooks/handlers.rs

View workflow job for this annotation

GitHub Actions / clippy

[clippy] basalt-server-lib/src/server/hooks/handlers.rs#L65

error[E0521]: borrowed data escapes outside of associated function --> basalt-server-lib/src/server/hooks/handlers.rs:65:5 | 65 | #[deno_core::op2(async)] | ^^^^^^^^^^^^^^^^^^^^^^^^ | | | `info` is a reference that is only valid in the associated function body | `info` escapes the associated function body here | lifetime `'s` defined here | argument requires that `'s` must outlive `'static` | = note: this error originates in the attribute macro `deno_core::op2` (in Nightly builds, run with -Z macro-backtrace for more info)
Raw output
basalt-server-lib/src/server/hooks/handlers.rs:65:5:e:error[E0521]: borrowed data escapes outside of associated function
  --> basalt-server-lib/src/server/hooks/handlers.rs:65:5
   |
65 |     #[deno_core::op2(async)]
   |     ^^^^^^^^^^^^^^^^^^^^^^^^
   |     |
   |     `info` is a reference that is only valid in the associated function body
   |     `info` escapes the associated function body here
   |     lifetime `'s` defined here
   |     argument requires that `'s` must outlive `'static`
   |
   = note: this error originates in the attribute macro `deno_core::op2` (in Nightly builds, run with -Z macro-backtrace for more info)


__END__

Check failure on line 65 in basalt-server-lib/src/server/hooks/handlers.rs

View workflow job for this annotation

GitHub Actions / clippy

[clippy] basalt-server-lib/src/server/hooks/handlers.rs#L65

error[E0716]: temporary value dropped while borrowed --> basalt-server-lib/src/server/hooks/handlers.rs:65:5 | 65 | #[deno_core::op2(async)] | ^^^^^^^^^^^^^^^^^^^^^^^- | | | | | temporary value is freed at the end of this statement | creates a temporary value which is freed while still in use | argument requires that borrow lasts for `'static` | = note: this error originates in the attribute macro `deno_core::op2` (in Nightly builds, run with -Z macro-backtrace for more info)
Raw output
basalt-server-lib/src/server/hooks/handlers.rs:65:5:e:error[E0716]: temporary value dropped while borrowed
  --> basalt-server-lib/src/server/hooks/handlers.rs:65:5
   |
65 |     #[deno_core::op2(async)]
   |     ^^^^^^^^^^^^^^^^^^^^^^^-
   |     |                      |
   |     |                      temporary value is freed at the end of this statement
   |     creates a temporary value which is freed while still in use
   |     argument requires that borrow lasts for `'static`
   |
   = note: this error originates in the attribute macro `deno_core::op2` (in Nightly builds, run with -Z macro-backtrace for more info)


__END__

Check failure on line 65 in basalt-server-lib/src/server/hooks/handlers.rs

View workflow job for this annotation

GitHub Actions / clippy

[clippy] basalt-server-lib/src/server/hooks/handlers.rs#L65

error[E0521]: borrowed data escapes outside of associated function --> basalt-server-lib/src/server/hooks/handlers.rs:65:5 | 65 | #[deno_core::op2(async)] | ^^^^^^^^^^^^^^^^^^^^^^^^ | | | `info` is a reference that is only valid in the associated function body | `info` escapes the associated function body here | lifetime `'s` defined here | argument requires that `'s` must outlive `'static` | = note: this error originates in the attribute macro `deno_core::op2` (in Nightly builds, run with -Z macro-backtrace for more info)
Raw output
basalt-server-lib/src/server/hooks/handlers.rs:65:5:e:error[E0521]: borrowed data escapes outside of associated function
  --> basalt-server-lib/src/server/hooks/handlers.rs:65:5
   |
65 |     #[deno_core::op2(async)]
   |     ^^^^^^^^^^^^^^^^^^^^^^^^
   |     |
   |     `info` is a reference that is only valid in the associated function body
   |     `info` escapes the associated function body here
   |     lifetime `'s` defined here
   |     argument requires that `'s` must outlive `'static`
   |
   = note: this error originates in the attribute macro `deno_core::op2` (in Nightly builds, run with -Z macro-backtrace for more info)


__END__

Check failure on line 65 in basalt-server-lib/src/server/hooks/handlers.rs

View workflow job for this annotation

GitHub Actions / clippy

[clippy] basalt-server-lib/src/server/hooks/handlers.rs#L65

error[E0716]: temporary value dropped while borrowed --> basalt-server-lib/src/server/hooks/handlers.rs:65:5 | 65 | #[deno_core::op2(async)] | ^^^^^^^^^^^^^^^^^^^^^^^- | | | | | temporary value is freed at the end of this statement | creates a temporary value which is freed while still in use | argument requires that borrow lasts for `'static` | = note: this error originates in the attribute macro `deno_core::op2` (in Nightly builds, run with -Z macro-backtrace for more info)
Raw output
basalt-server-lib/src/server/hooks/handlers.rs:65:5:e:error[E0716]: temporary value dropped while borrowed
  --> basalt-server-lib/src/server/hooks/handlers.rs:65:5
   |
65 |     #[deno_core::op2(async)]
   |     ^^^^^^^^^^^^^^^^^^^^^^^-
   |     |                      |
   |     |                      temporary value is freed at the end of this statement
   |     creates a temporary value which is freed while still in use
   |     argument requires that borrow lasts for `'static`
   |
   = note: this error originates in the attribute macro `deno_core::op2` (in Nightly builds, run with -Z macro-backtrace for more info)


__END__
async fn op_announcement(op_state: &OpState, #[string] msg: String) -> bool {
let state = op_state.borrow::<Arc<AppState>>().clone();
let sql = state.db.read().await;

let new = repositories::announcements::create_announcement(
&sql.db,
&Username("SYSTEM".to_owned()),
&msg,
)
.await;
drop(sql);
let result = match new {
Ok(new) => {
state.websocket.broadcast(ws::WebSocketSend::Broadcast {
broadcast: ws::Broadcast::NewAnnouncement(new.clone()),
});
if let Err(err) = (ServerEvent::OnAnnouncement {
announcer: Username("SYSTEM".into()),
announcement: msg,
time: utils::utc_now(),
}
.dispatch(state.clone()))
{
tracing::error!("Error dispatching announcement event: {:?}", err);
}
true
}
Err(err) => {
tracing::error!("Error getting announcements: {:?}", err);
false
}
};
drop(state);
result
}

pub fn evaluate(event: ServerEvent, path: &PathBuf) -> anyhow::Result<()> {
let main_module = Module::load(path).context("Failed to load provided module")?;
let entrypoint = event.get_fn_name();
Expand Down
Loading