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 Jan 21, 2023
1 parent ec3281e commit 4acead0
Show file tree
Hide file tree
Showing 8 changed files with 70 additions and 23 deletions.
30 changes: 15 additions & 15 deletions Cargo.lock

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

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "atri_bot"
version = "0.8.6"
version = "0.8.7"
edition = "2021"
authors = ["LaoLittle"]
description = "A simple bot"
Expand Down Expand Up @@ -56,7 +56,7 @@ features = [

[dependencies.ricq]
git = "https://github.com/AtriKawaii/ricq.git"
version = "0.1.19"
#version = "0.1.19"

#[dependencies.ricq-guild]
#version = "0.1.0"
Expand All @@ -65,9 +65,9 @@ version = "0.1.19"
version = "0.8.0"

[profile.release]
codegen-units = 1
lto = true
strip = true
codegen-units = 1

[build-dependencies]
serde = { version = "1.0.150", features = ["derive"] }
Expand Down
6 changes: 5 additions & 1 deletion src/contact/friend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ impl Friend {
Err(AtriError::NotSupported)
}

pub async fn upload_image(&self, image: Vec<u8>) -> AtriResult<Image> {
pub async fn _upload_image(&self, image: &[u8]) -> AtriResult<Image> {
let f = self
.client()
.request_client()
Expand All @@ -88,6 +88,10 @@ impl Friend {
Ok(Image::Friend(f))
}

pub async fn upload_image<B: AsRef<[u8]>>(&self, image: B) -> AtriResult<Image> {
self._upload_image(image.as_ref()).await
}

async fn _recall_message(&self, receipt: MessageReceipt) -> AtriResult<()> {
self.client()
.request_client()
Expand Down
6 changes: 3 additions & 3 deletions src/contact/group.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ impl Group {
}
*/

async fn _upload_image(&self, image: Vec<u8>) -> AtriResult<Image> {
async fn _upload_image(&self, image: &[u8]) -> AtriResult<Image> {
self.client()
.request_client()
.upload_group_image(self.id(), image)
Expand All @@ -168,8 +168,8 @@ impl Group {
}

#[inline]
pub async fn upload_image<I: Into<Vec<u8>>>(&self, image: I) -> AtriResult<Image> {
self._upload_image(image.into()).await
pub async fn upload_image<B: AsRef<[u8]>>(&self, image: B) -> AtriResult<Image> {
self._upload_image(image.as_ref()).await
}

async fn _recall_message(&self, receipt: MessageReceipt) -> AtriResult<()> {
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ impl AtriGlobalStatus {
pub fn new() -> Self {
let listener_runtime = runtime::Builder::new_multi_thread()
.worker_threads(8)
.thread_name("Global-Listener-Executor")
.thread_name("GlobalListenerExecutor")
.enable_all()
.build()
.unwrap();
Expand Down
17 changes: 17 additions & 0 deletions src/plugin/ffi/friend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use atri_ffi::ffi::ForFFI;
use atri_ffi::future::FFIFuture;
use atri_ffi::message::{FFIMessageChain, FFIMessageReceipt};
use atri_ffi::{ManagedCloneable, RustStr, RustVec};
use std::slice;

pub extern "C" fn friend_get_id(friend: *const ()) -> i64 {
let f: &Friend = cast_ref(friend);
Expand Down Expand Up @@ -86,3 +87,19 @@ pub extern "C" fn friend_upload_image_blocking(
FFIResult::from(result)
})
}

pub extern "C" fn friend_upload_image_ex(
friend: *const (),
ptr: *const u8,
size: usize,
) -> FFIFuture<FFIResult<ManagedCloneable>> {
let slice = unsafe { slice::from_raw_parts(ptr, size) };
FFIFuture::from(async {
let f: &Friend = cast_ref(friend);
let result = f
.upload_image(slice)
.await
.map(ManagedCloneable::from_value);
FFIResult::from(result)
})
}
18 changes: 18 additions & 0 deletions src/plugin/ffi/group.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use atri_ffi::message::forward::FFIForwardNode;
use atri_ffi::message::{FFIMessageChain, FFIMessageReceipt};
use atri_ffi::{ManagedCloneable, RustStr, RustVec};
use message::MessageChain;
use std::slice;

pub extern "C" fn group_get_id(group: *const ()) -> i64 {
let group: &Group = cast_ref(group);
Expand Down Expand Up @@ -200,3 +201,20 @@ pub extern "C" fn group_invite_blocking(
let group: &Group = cast_ref(group);
future_block_on(manager, async move { group.invite(id).await.into() })
}

pub extern "C" fn group_upload_image_ex(
group: *const (),
ptr: *const u8,
size: usize,
) -> FFIFuture<FFIResult<ManagedCloneable>> {
let slice = unsafe { slice::from_raw_parts(ptr, size) };
FFIFuture::from(async {
let group: &Group = cast_ref(group);
let result = group
.upload_image(slice)
.await
.map(ManagedCloneable::from_value);

FFIResult::from(result)
})
}
8 changes: 8 additions & 0 deletions src/plugin/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
mod ffi;

use crate::plugin::ffi::friend::friend_upload_image_ex;
use crate::plugin::ffi::group::group_upload_image_ex;
use crate::plugin::ffi::rt::{plugin_manager_block_on, plugin_manager_spawn};
use crate::plugin::ffi::string::{c_str_cvt, rust_str_cvt, rust_string_drop};
use ffi::client::{
Expand Down Expand Up @@ -103,6 +105,9 @@ pub extern "C" fn plugin_get_function(sig: u16) -> *const () {
460 => group_send_forward_message_blocking,
461 => group_invite_blocking,

// extension
480 => group_upload_image_ex,

// friend
500 => friend_get_id,
501 => friend_get_nickname,
Expand All @@ -114,6 +119,9 @@ pub extern "C" fn plugin_get_function(sig: u16) -> *const () {
553 => friend_send_message_blocking,
554 => friend_upload_image_blocking,

// extension
580 => friend_upload_image_ex,

// named member
600 => named_member_get_id,
601 => named_member_get_nickname,
Expand Down

0 comments on commit 4acead0

Please sign in to comment.