Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: shuttle-serenity initial commit poc #429

Merged
merged 7 commits into from
Oct 25, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
refactor: cargo fmt
  • Loading branch information
chesedo committed Oct 25, 2022
commit d6738f31612e0d369bcc8e6fb80e1a9661a6a7f7
17 changes: 8 additions & 9 deletions plugins/serenity/runtime/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use std::fs::File;
use std::io::{Read, Write};
use std::os::unix::prelude::RawFd;
use std::path::Path;
use std::sync::Arc;
use std::os::unix::prelude::RawFd;

use async_trait::async_trait;

Expand Down Expand Up @@ -53,7 +53,7 @@ impl BotBuilder {
let mut buf = Vec::new();
self.src.unwrap().read_to_end(&mut buf).unwrap();
let module = Module::new(&self.engine, buf).unwrap();

for export in module.exports() {
println!("export: {}", export.name());
}
Expand All @@ -64,7 +64,7 @@ impl BotBuilder {
linker: self.linker,
};
Bot {
inner: Arc::new(Mutex::new(inner))
inner: Arc::new(Mutex::new(inner)),
}
}
}
Expand All @@ -78,7 +78,7 @@ impl BotInner {
pub async fn message(&mut self, new_message: &str) -> Option<String> {
let (mut host, client) = UnixStream::pair().unwrap();
let client = WasiUnixStream::from_cap_std(client);

self.store
.data_mut()
.insert_file(3, Box::new(client), FileCaps::all());
Expand All @@ -87,7 +87,8 @@ impl BotInner {
host.write(&[0]).unwrap();

println!("calling inner EventHandler message");
self.linker.get(&mut self.store, "bot", "__SHUTTLE_EventHandler_message")
self.linker
.get(&mut self.store, "bot", "__SHUTTLE_EventHandler_message")
.unwrap()
.into_func()
.unwrap()
Expand All @@ -108,7 +109,7 @@ impl BotInner {
}

pub struct Bot {
inner: Arc<Mutex<BotInner>>
inner: Arc<Mutex<BotInner>>,
}

impl Bot {
Expand All @@ -117,9 +118,7 @@ impl Bot {
}

pub fn new<P: AsRef<Path>>(src: P) -> Self {
Self::builder()
.src(src)
.build()
Self::builder().src(src).build()
}

pub async fn into_client(self, token: &str, intents: GatewayIntents) -> Client {
Expand Down
3 changes: 1 addition & 2 deletions plugins/serenity/wasm/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::os::wasi::prelude::*;
use std::fs::File;
use std::io::{Read, Write};
use std::os::wasi::prelude::*;

pub fn handle_message(message: &str) -> Option<String> {
if message == "!hello" {
Expand Down Expand Up @@ -34,5 +34,4 @@ pub extern "C" fn __SHUTTLE_EventHandler_message(fd: RawFd) {
if let Some(resp) = handle_message(msg.as_str()) {
f.write_all(resp.as_bytes()).unwrap();
}

}