Skip to content
This repository has been archived by the owner on Oct 21, 2023. It is now read-only.

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
LaoLittle committed Nov 13, 2022
1 parent b6f64f7 commit e033127
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "atri_bot"
version = "0.3.0"
version = "0.3.1"
edition = "2021"
authors = ["LaoLittle"]
description = "A simple bot"
Expand Down
32 changes: 32 additions & 0 deletions src/plugin/ffi/env.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
use std::path::PathBuf;
use atri_ffi::RustString;
use tracing::error;
use crate::plugin::cast_ref;
use crate::service::plugin_manager::PluginManager;

pub extern "C" fn env_get_workspace(handle: usize, manager: *const ()) -> RustString {
let manager: &PluginManager = cast_ref(manager);
manager.find_plugin(handle)
.map(|p| {
let name = p.name();
let mut path = std::env::current_dir()
.ok()
.and_then(|p| p.to_str().map(|str| {
let mut p = String::from(str);
p.push('/');
p
}))
.unwrap_or_else(String::new);

path.push_str("workspaces/");
path.push_str(name);

if let Err(e) = std::fs::create_dir_all(&path) {
error!("为{}创建Workspace失败: {}", p, e);
}

path
})
.unwrap_or_else(String::new)
.into()
}
7 changes: 6 additions & 1 deletion src/plugin/ffi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ mod listener;
mod log;
mod member;
mod message;
mod env;

use crate::plugin::ffi::client::{
client_find_friend, client_find_group, client_get_friends, client_get_groups, client_get_id,
Expand Down Expand Up @@ -36,10 +37,11 @@ use crate::plugin::ffi::message::{image_get_id, image_get_url};
use crate::PluginManager;
use atri_ffi::future::FFIFuture;
use atri_ffi::Managed;
use crate::plugin::ffi::env::env_get_workspace;

pub extern "C" fn plugin_get_function(sig: u16) -> *const () {
extern "C" fn not_impl() {
panic!("No such sig");
panic!("No such operation");
}

macro_rules! match_function {
Expand Down Expand Up @@ -116,6 +118,9 @@ pub extern "C" fn plugin_get_function(sig: u16) -> *const () {

// log
20000 => log,

// env
30000 => env_get_workspace,
}
}

Expand Down

0 comments on commit e033127

Please sign in to comment.