HackmudChatClient 1.0.0

dotnet add package HackmudChatClient --version 1.0.0                
NuGet\Install-Package HackmudChatClient -Version 1.0.0                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="HackmudChatClient" Version="1.0.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add HackmudChatClient --version 1.0.0                
#r "nuget: HackmudChatClient, 1.0.0"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install HackmudChatClient as a Cake Addin
#addin nuget:?package=HackmudChatClient&version=1.0.0

// Install HackmudChatClient as a Cake Tool
#tool nuget:?package=HackmudChatClient&version=1.0.0                

Hackmud Chat Client

A chat client that uses the hackmud api to receive chats and send chats in game

usage

// this is to store messages
static readonly List<UserChatsModel> processedChats = [];
static async Task Main( string[] args ) {
    // Tokens get stored in the environment.
    var token = Environment.GetEnvironmentVariable( "HackmudChatClientApiToken", EnvironmentVariableTarget.User );

    var client = new HackmudChat();
    // set chat poll frequency.
    var client = new HackmudChat(700);
    // set chat poll frequency and account data poll frequency
    var client = new HackmudChat(700,5000);
    // ^ + set default user.
    var client = new HackmudChat(700,5000,"<user>");

    // subscribe to events.
    client.OnTokenError += new HackmudChat.TokenError( Client_TokenErrorReceived );
    client.OnChatsReceived += new HackmudChat.ChatsReceived( Client_OnChatsReceived );
    client.OnChatsError += new HackmudChat.ChatsError( Client_ChatsErrorReceived );
    client.OnAccountDataReceived += new HackmudChat.AccountDataReceived( Client_AccountDataReceived );
    client.OnAccountDataError += new HackmudChat.AccountDataError( Client_AccountDataErrorReceived );

    // you can check if anything comes back. token is stored base64 as it is an object.
    if ( string.IsNullOrEmpty(token) ) {
        Console.WriteLine("type pass:");
        var pass = Console.ReadLine();
        while (pass == null || string.IsNullOrEmpty(pass.Trim())) {
            Console.WriteLine( "type pass:" );
            pass = Console.ReadLine();
        }

        await client.CreateToken( pass );
    }

    // inits the timers.
    client.Init();
    // inits the timers and sets default user
    client.Init("<username>");

    // other things you can do
    await client.SendChatMessage( "0000", "hello" );
    await client.SendChatMessage( "<user>", "0000", "hello" );

    //
    await client.SendTellMessage( "<toUser>", "hello" );
    await client.SendTellMessage( "<fromUser>", "<toUser>", "hello" );


    // keep application alive.
    Thread.Sleep( -1 );
}


private static void Client_TokenErrorReceived( object sender, string message ) {
    Console.WriteLine( message );
}

private static void Client_OnChatsReceived( object sender, List<UserChatsModel> e ) {
    foreach (var chat in e) {
        if ( processedChats.FirstOrDefault( c => c.Id.Equals( chat.Id ) ) == null ) {
            processedChats.Add( chat );
            Console.WriteLine( $"id: {chat.Id} -- from: {chat.FromUser} -- join?{chat.IsJoin} -- leave?{chat.IsLeave} -- message:{chat.Message}" );
        }
    }
}

private static void Client_ChatsErrorReceived( object sender, string message ) {
    Console.WriteLine( message );
}
private static void Client_AccountDataReceived( object sender, List<AccountDataModel> data ) {
    throw new NotImplementedException();
}

private static void Client_AccountDataErrorReceived( object sender, string message ) {
    Console.WriteLine( message );
}

Returned objects

The hackmud api has some interesting return objects.<br/> this api client will give things back in a more Flat way and easy to use with linq

public class AccountDataModel
{
    public required string User { get; set; }
    public List<ChannelDataModel>? Channels { get; set; }
}

public class ApiToken
{
    public required string Token { get; set; }
    public DateTime TokenCreated { get; set; } = DateTime.Now;
}

public class ChannelDataModel
{
    public required string Channel { get; set; }
    public List<string>? Users { get; set; }
}

public class HackmudTimeStamp
{
    public long UnixTimeStamp { get; set; } = DateTimeOffset.Now.ToUnixTimeMilliseconds();
    public DateTime DateTime => DateTimeOffset.FromUnixTimeMilliseconds(UnixTimeStamp).DateTime;
    public double HackmudTime => Math.Floor( UnixTimeStamp / 1000d );
}

public class UserChatsModel
{
    public required string Id { get; set; }
    public required string ChannelUser { get; set; }
    public DateTime Time { get; set; }
    public required string FromUser { get; set; }
    public required string Message { get; set; }
    public bool IsJoin { get; set; }
    public bool IsLeave { get; set; }
    public bool IsTell { get; set; }
}

public class Response
{
    [JsonPropertyName("ok")]
    public bool Ok { get; set; }
}
Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net8.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.0 108 7/7/2024