mirror of
https://codeberg.org/steam-vent/chat.git
synced 2026-11-30 12:40:52 +01:00
steam-vent-chat 0.5.0
This commit is contained in:
parent
5710d6858e
commit
b31706e11a
5 changed files with 994 additions and 726 deletions
1655
Cargo.lock
generated
1655
Cargo.lock
generated
File diff suppressed because it is too large
Load diff
18
Cargo.toml
18
Cargo.toml
|
|
@ -1,19 +1,21 @@
|
||||||
[package]
|
[package]
|
||||||
name = "steam-vent-chat"
|
name = "steam-vent-chat"
|
||||||
version = "0.4.0"
|
version = "0.5.0"
|
||||||
authors = ["Robin Appelman <robin@icewind.nl>"]
|
authors = ["Robin Appelman <robin@icewind.nl>"]
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
description = "Steam chat client library"
|
description = "Steam chat client library"
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
repository = "https://codeberg.org/steam-vent/chat"
|
repository = "https://codeberg.org/steam-vent/chat"
|
||||||
rust-version = "1.85.0"
|
rust-version = "1.88.0"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
steam-vent = "0.4.0"
|
steam-vent-proto = "0.5.2"
|
||||||
steamid-ng = "2.0.0"
|
steam-vent = "0.5.0"
|
||||||
tokio-stream = "0.1.17"
|
steamid-ng = "3.0.0"
|
||||||
|
tokio-stream = "0.1.18"
|
||||||
|
thiserror = "2.0.18"
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
tokio = { version = "1.47.1", features = ["macros", "rt-multi-thread"] }
|
tokio = { version = "1.52.3", features = ["macros", "rt-multi-thread"] }
|
||||||
tracing-subscriber = "0.3.20"
|
tracing-subscriber = "0.3.23"
|
||||||
clap = { version = "4.5.47", features = ["derive"] }
|
clap = { version = "4.6.1", features = ["derive"] }
|
||||||
|
|
|
||||||
34
flake.lock
generated
34
flake.lock
generated
|
|
@ -2,11 +2,11 @@
|
||||||
"nodes": {
|
"nodes": {
|
||||||
"crane": {
|
"crane": {
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1742394900,
|
"lastModified": 1780099841,
|
||||||
"narHash": "sha256-vVOAp9ahvnU+fQoKd4SEXB2JG2wbENkpqcwlkIXgUC0=",
|
"narHash": "sha256-EVZd2RsbpreRUDSi9rBwPY+ZxoyMaiEBbZxxhljbaS4=",
|
||||||
"owner": "ipetkov",
|
"owner": "ipetkov",
|
||||||
"repo": "crane",
|
"repo": "crane",
|
||||||
"rev": "70947c1908108c0c551ddfd73d4f750ff2ea67cd",
|
"rev": "0532eb17955225173906d671fb36306bdeb1e2dc",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
|
|
@ -22,11 +22,11 @@
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1747659009,
|
"lastModified": 1781309392,
|
||||||
"narHash": "sha256-3FFAthqh4rWKTClF+WgM+9CmMDlnfWcPdd3hGBFVNHc=",
|
"narHash": "sha256-3+oF2x5kf5RVYPbOGxdMIZgM90x/l7N60qK6GEMAw/4=",
|
||||||
"owner": "nix-community",
|
"owner": "nix-community",
|
||||||
"repo": "flakelight",
|
"repo": "flakelight",
|
||||||
"rev": "93d72adbe0b022791b0faadfb31cb6e98c37f0ad",
|
"rev": "ca76eecaa21c2b256c17e5883c3168d6a034510a",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
|
|
@ -44,11 +44,11 @@
|
||||||
"rust-overlay": "rust-overlay"
|
"rust-overlay": "rust-overlay"
|
||||||
},
|
},
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1748035164,
|
"lastModified": 1780231986,
|
||||||
"narHash": "sha256-PMWOFLi3oU/Eb+y4a0MlHS0IcUZ+UFCoGmA1Q7DnoW4=",
|
"narHash": "sha256-OyafczPtzE0Xa2zl3j/KvV2+ZVYGhYQHt0MOVWtDXlY=",
|
||||||
"ref": "refs/heads/main",
|
"ref": "refs/heads/main",
|
||||||
"rev": "e6d5d797b3d2c738309152f2545518b2b117f72b",
|
"rev": "f5cbda29b945df03256bf63c22fa4cd5fa429e67",
|
||||||
"revCount": 48,
|
"revCount": 72,
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://codeberg.org/icewind/mill-scale.git"
|
"url": "https://codeberg.org/icewind/mill-scale.git"
|
||||||
},
|
},
|
||||||
|
|
@ -59,16 +59,16 @@
|
||||||
},
|
},
|
||||||
"nixpkgs": {
|
"nixpkgs": {
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1750259320,
|
"lastModified": 1780902259,
|
||||||
"narHash": "sha256-H8J4H2XCIMEJ5g6fZ179QfQvsc2dUqhqfBjC8RAHNRY=",
|
"narHash": "sha256-q8yYEC5f1mFlQO9RGna4LTc9QrcvWunX6FYp83munkQ=",
|
||||||
"owner": "NixOS",
|
"owner": "NixOS",
|
||||||
"repo": "nixpkgs",
|
"repo": "nixpkgs",
|
||||||
"rev": "9ba04bda9249d5d5e5238303c9755de5a49a79c5",
|
"rev": "bd0ff2d3eac24699c3664d5966b9ef36f388e2ca",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
"id": "nixpkgs",
|
"id": "nixpkgs",
|
||||||
"ref": "nixos-25.05",
|
"ref": "nixos-26.05",
|
||||||
"type": "indirect"
|
"type": "indirect"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
@ -88,11 +88,11 @@
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1742697269,
|
"lastModified": 1780197589,
|
||||||
"narHash": "sha256-Lpp0XyAtIl1oGJzNmTiTGLhTkcUjwSkEb0gOiNzYFGM=",
|
"narHash": "sha256-FVCr2Ij/jKf59a4LW481eeOF6rJRreOBrVgW/aUBTrw=",
|
||||||
"owner": "oxalica",
|
"owner": "oxalica",
|
||||||
"repo": "rust-overlay",
|
"repo": "rust-overlay",
|
||||||
"rev": "01973c84732f9275c50c5f075dd1f54cc04b3316",
|
"rev": "21632e942d89bf1cce4e5a63d7e58a215a0cbfcc",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
inputs = {
|
inputs = {
|
||||||
nixpkgs.url = "nixpkgs/nixos-25.05";
|
nixpkgs.url = "nixpkgs/nixos-26.05";
|
||||||
flakelight = {
|
flakelight = {
|
||||||
url = "github:nix-community/flakelight";
|
url = "github:nix-community/flakelight";
|
||||||
inputs.nixpkgs.follows = "nixpkgs";
|
inputs.nixpkgs.follows = "nixpkgs";
|
||||||
|
|
@ -11,7 +11,5 @@
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
outputs = {mill-scale, ...}:
|
outputs = {mill-scale, ...}:
|
||||||
mill-scale ./. {
|
mill-scale ./. {};
|
||||||
extraFiles = ["system.pem"];
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
75
src/lib.rs
75
src/lib.rs
|
|
@ -1,6 +1,9 @@
|
||||||
use steam_vent::proto::steammessages_friendmessages_steamclient::{CFriendMessages_IncomingMessage_Notification, CFriendMessages_SendMessage_Request};
|
|
||||||
use steam_vent::{Connection, ConnectionTrait, NetworkError};
|
use steam_vent::{Connection, ConnectionTrait, NetworkError};
|
||||||
|
use steam_vent_proto::steammessages_friendmessages_steamclient::{
|
||||||
|
CFriendMessages_IncomingMessage_Notification, CFriendMessages_SendMessage_Request,
|
||||||
|
};
|
||||||
use steamid_ng::SteamID;
|
use steamid_ng::SteamID;
|
||||||
|
use thiserror::Error;
|
||||||
use tokio_stream::{Stream, StreamExt};
|
use tokio_stream::{Stream, StreamExt};
|
||||||
|
|
||||||
/// High level wrapper around steam-vent's [`Connection`] for implementing a chat client
|
/// High level wrapper around steam-vent's [`Connection`] for implementing a chat client
|
||||||
|
|
@ -20,13 +23,17 @@ impl ChatClient {
|
||||||
.on_notification::<CFriendMessages_IncomingMessage_Notification>()
|
.on_notification::<CFriendMessages_IncomingMessage_Notification>()
|
||||||
.filter_map(|notification| {
|
.filter_map(|notification| {
|
||||||
notification
|
notification
|
||||||
.map(|notification| ChatEvent::try_from(notification).ok())
|
.map(|notification| parse_chat_event(notification).ok().flatten())
|
||||||
.transpose()
|
.transpose()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Send a chat message to a user
|
/// Send a chat message to a user
|
||||||
pub async fn send_message(&self, target: SteamID, message: String) -> Result<MessageResult, NetworkError> {
|
pub async fn send_message(
|
||||||
|
&self,
|
||||||
|
target: SteamID,
|
||||||
|
message: String,
|
||||||
|
) -> Result<MessageResult, NetworkError> {
|
||||||
let req = CFriendMessages_SendMessage_Request {
|
let req = CFriendMessages_SendMessage_Request {
|
||||||
steamid: Some(target.into()),
|
steamid: Some(target.into()),
|
||||||
message: Some(message),
|
message: Some(message),
|
||||||
|
|
@ -53,35 +60,39 @@ pub enum ChatEvent {
|
||||||
Typing(TypingEvent),
|
Typing(TypingEvent),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TryFrom<CFriendMessages_IncomingMessage_Notification> for ChatEvent {
|
#[derive(Debug, Error)]
|
||||||
type Error = ();
|
pub enum InvalidChatEvent {
|
||||||
|
#[error("Invalid steam id {0}")]
|
||||||
fn try_from(
|
InvalidSteamId(u64),
|
||||||
notification: CFriendMessages_IncomingMessage_Notification,
|
|
||||||
) -> Result<Self, Self::Error> {
|
|
||||||
let source = SteamID::try_from(notification.steamid_friend()).unwrap_or_default();
|
|
||||||
let message_type =
|
|
||||||
MessageType::try_from(notification.chat_entry_type()).unwrap_or_default();
|
|
||||||
Ok(match message_type {
|
|
||||||
MessageType::Chat if notification.local_echo() => ChatEvent::Message(MessageEvent {
|
|
||||||
source,
|
|
||||||
server_timestamp: notification.rtime32_server_timestamp() as u64,
|
|
||||||
message: notification.message.unwrap_or_default(),
|
|
||||||
message_no_bbcode: notification.message_no_bbcode,
|
|
||||||
}),
|
|
||||||
MessageType::Chat if notification.local_echo() => ChatEvent::EchoMessage(MessageEvent {
|
|
||||||
source,
|
|
||||||
server_timestamp: notification.rtime32_server_timestamp() as u64,
|
|
||||||
message: notification.message.unwrap_or_default(),
|
|
||||||
message_no_bbcode: notification.message_no_bbcode,
|
|
||||||
}),
|
|
||||||
MessageType::Typing => ChatEvent::Typing(TypingEvent {
|
|
||||||
source,
|
|
||||||
server_timestamp: notification.rtime32_server_timestamp() as u64,
|
|
||||||
}),
|
|
||||||
_ => return Err(()),
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn parse_chat_event(
|
||||||
|
notification: CFriendMessages_IncomingMessage_Notification,
|
||||||
|
) -> Result<Option<ChatEvent>, InvalidChatEvent> {
|
||||||
|
let source = SteamID::try_from(notification.steamid_friend())
|
||||||
|
.map_err(|_| InvalidChatEvent::InvalidSteamId(notification.steamid_friend()))?;
|
||||||
|
let message_type = MessageType::try_from(notification.chat_entry_type()).unwrap_or_default();
|
||||||
|
Ok(match message_type {
|
||||||
|
MessageType::Chat if notification.local_echo() => Some(ChatEvent::Message(MessageEvent {
|
||||||
|
source,
|
||||||
|
server_timestamp: notification.rtime32_server_timestamp() as u64,
|
||||||
|
message: notification.message.unwrap_or_default(),
|
||||||
|
message_no_bbcode: notification.message_no_bbcode,
|
||||||
|
})),
|
||||||
|
MessageType::Chat if notification.local_echo() => {
|
||||||
|
Some(ChatEvent::EchoMessage(MessageEvent {
|
||||||
|
source,
|
||||||
|
server_timestamp: notification.rtime32_server_timestamp() as u64,
|
||||||
|
message: notification.message.unwrap_or_default(),
|
||||||
|
message_no_bbcode: notification.message_no_bbcode,
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
MessageType::Typing => Some(ChatEvent::Typing(TypingEvent {
|
||||||
|
source,
|
||||||
|
server_timestamp: notification.rtime32_server_timestamp() as u64,
|
||||||
|
})),
|
||||||
|
_ => None,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Incoming chat message
|
/// Incoming chat message
|
||||||
|
|
@ -107,7 +118,7 @@ pub struct TypingEvent {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[repr(i32)]
|
#[repr(i32)]
|
||||||
#[derive(Default)]
|
#[derive(Default, Debug)]
|
||||||
enum MessageType {
|
enum MessageType {
|
||||||
#[default]
|
#[default]
|
||||||
Invalid,
|
Invalid,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue