steam-vent-chat 0.5.0

This commit is contained in:
Robin Appelman 2026-06-13 18:32:51 +02:00
commit b31706e11a
5 changed files with 994 additions and 726 deletions

1655
Cargo.lock generated

File diff suppressed because it is too large Load diff

View file

@ -1,19 +1,21 @@
[package]
name = "steam-vent-chat"
version = "0.4.0"
version = "0.5.0"
authors = ["Robin Appelman <robin@icewind.nl>"]
edition = "2024"
description = "Steam chat client library"
license = "MIT"
repository = "https://codeberg.org/steam-vent/chat"
rust-version = "1.85.0"
rust-version = "1.88.0"
[dependencies]
steam-vent = "0.4.0"
steamid-ng = "2.0.0"
tokio-stream = "0.1.17"
steam-vent-proto = "0.5.2"
steam-vent = "0.5.0"
steamid-ng = "3.0.0"
tokio-stream = "0.1.18"
thiserror = "2.0.18"
[dev-dependencies]
tokio = { version = "1.47.1", features = ["macros", "rt-multi-thread"] }
tracing-subscriber = "0.3.20"
clap = { version = "4.5.47", features = ["derive"] }
tokio = { version = "1.52.3", features = ["macros", "rt-multi-thread"] }
tracing-subscriber = "0.3.23"
clap = { version = "4.6.1", features = ["derive"] }

34
flake.lock generated
View file

@ -2,11 +2,11 @@
"nodes": {
"crane": {
"locked": {
"lastModified": 1742394900,
"narHash": "sha256-vVOAp9ahvnU+fQoKd4SEXB2JG2wbENkpqcwlkIXgUC0=",
"lastModified": 1780099841,
"narHash": "sha256-EVZd2RsbpreRUDSi9rBwPY+ZxoyMaiEBbZxxhljbaS4=",
"owner": "ipetkov",
"repo": "crane",
"rev": "70947c1908108c0c551ddfd73d4f750ff2ea67cd",
"rev": "0532eb17955225173906d671fb36306bdeb1e2dc",
"type": "github"
},
"original": {
@ -22,11 +22,11 @@
]
},
"locked": {
"lastModified": 1747659009,
"narHash": "sha256-3FFAthqh4rWKTClF+WgM+9CmMDlnfWcPdd3hGBFVNHc=",
"lastModified": 1781309392,
"narHash": "sha256-3+oF2x5kf5RVYPbOGxdMIZgM90x/l7N60qK6GEMAw/4=",
"owner": "nix-community",
"repo": "flakelight",
"rev": "93d72adbe0b022791b0faadfb31cb6e98c37f0ad",
"rev": "ca76eecaa21c2b256c17e5883c3168d6a034510a",
"type": "github"
},
"original": {
@ -44,11 +44,11 @@
"rust-overlay": "rust-overlay"
},
"locked": {
"lastModified": 1748035164,
"narHash": "sha256-PMWOFLi3oU/Eb+y4a0MlHS0IcUZ+UFCoGmA1Q7DnoW4=",
"lastModified": 1780231986,
"narHash": "sha256-OyafczPtzE0Xa2zl3j/KvV2+ZVYGhYQHt0MOVWtDXlY=",
"ref": "refs/heads/main",
"rev": "e6d5d797b3d2c738309152f2545518b2b117f72b",
"revCount": 48,
"rev": "f5cbda29b945df03256bf63c22fa4cd5fa429e67",
"revCount": 72,
"type": "git",
"url": "https://codeberg.org/icewind/mill-scale.git"
},
@ -59,16 +59,16 @@
},
"nixpkgs": {
"locked": {
"lastModified": 1750259320,
"narHash": "sha256-H8J4H2XCIMEJ5g6fZ179QfQvsc2dUqhqfBjC8RAHNRY=",
"lastModified": 1780902259,
"narHash": "sha256-q8yYEC5f1mFlQO9RGna4LTc9QrcvWunX6FYp83munkQ=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "9ba04bda9249d5d5e5238303c9755de5a49a79c5",
"rev": "bd0ff2d3eac24699c3664d5966b9ef36f388e2ca",
"type": "github"
},
"original": {
"id": "nixpkgs",
"ref": "nixos-25.05",
"ref": "nixos-26.05",
"type": "indirect"
}
},
@ -88,11 +88,11 @@
]
},
"locked": {
"lastModified": 1742697269,
"narHash": "sha256-Lpp0XyAtIl1oGJzNmTiTGLhTkcUjwSkEb0gOiNzYFGM=",
"lastModified": 1780197589,
"narHash": "sha256-FVCr2Ij/jKf59a4LW481eeOF6rJRreOBrVgW/aUBTrw=",
"owner": "oxalica",
"repo": "rust-overlay",
"rev": "01973c84732f9275c50c5f075dd1f54cc04b3316",
"rev": "21632e942d89bf1cce4e5a63d7e58a215a0cbfcc",
"type": "github"
},
"original": {

View file

@ -1,6 +1,6 @@
{
inputs = {
nixpkgs.url = "nixpkgs/nixos-25.05";
nixpkgs.url = "nixpkgs/nixos-26.05";
flakelight = {
url = "github:nix-community/flakelight";
inputs.nixpkgs.follows = "nixpkgs";
@ -11,7 +11,5 @@
};
};
outputs = {mill-scale, ...}:
mill-scale ./. {
extraFiles = ["system.pem"];
};
mill-scale ./. {};
}

View file

@ -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_proto::steammessages_friendmessages_steamclient::{
CFriendMessages_IncomingMessage_Notification, CFriendMessages_SendMessage_Request,
};
use steamid_ng::SteamID;
use thiserror::Error;
use tokio_stream::{Stream, StreamExt};
/// High level wrapper around steam-vent's [`Connection`] for implementing a chat client
@ -20,13 +23,17 @@ impl ChatClient {
.on_notification::<CFriendMessages_IncomingMessage_Notification>()
.filter_map(|notification| {
notification
.map(|notification| ChatEvent::try_from(notification).ok())
.map(|notification| parse_chat_event(notification).ok().flatten())
.transpose()
})
}
/// 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 {
steamid: Some(target.into()),
message: Some(message),
@ -53,35 +60,39 @@ pub enum ChatEvent {
Typing(TypingEvent),
}
impl TryFrom<CFriendMessages_IncomingMessage_Notification> for ChatEvent {
type Error = ();
#[derive(Debug, Error)]
pub enum InvalidChatEvent {
#[error("Invalid steam id {0}")]
InvalidSteamId(u64),
}
fn try_from(
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 {
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::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(()),
})
}
}))
}
MessageType::Typing => Some(ChatEvent::Typing(TypingEvent {
source,
server_timestamp: notification.rtime32_server_timestamp() as u64,
})),
_ => None,
})
}
/// Incoming chat message
@ -107,7 +118,7 @@ pub struct TypingEvent {
}
#[repr(i32)]
#[derive(Default)]
#[derive(Default, Debug)]
enum MessageType {
#[default]
Invalid,
@ -149,4 +160,4 @@ pub struct MessageResult {
/// Chat message with bbcode added
pub modified_message: Option<String>,
pub server_timestamp: u64,
}
}