Git Product home page Git Product logo

hackchatsharp's Introduction

HackchatSharp

HackchatSharp is a C# library for hack.chat.

Required packages

  • WebSocketSharp
  • Newtonsoft.Json

Example

using System;
using System.Linq;
using HackchatSharp;

class Program
{
    static void Main(string[] _args)
    {
        var client = new HackClient();

        client.Prefix = "-";

        client.OnConnect += OnConnect;
        client.OnDisconnect += OnDisconnect;
        client.OnMessage += OnMessage;
        client.OnOnlineSet += OnOnlineSet;
        client.OnOnlineAdd += OnOnlineAdd;
        client.OnOnlineRemove += OnOnlineRemove;

        /**
         * Define a new command
         */
        client.Commands["ping"] = args =>
        {
            /**
             * args.Client
             * args.User
             * args.Message
             * args.Args
             * args.Parsed
             */

            args.User.Say("pong!");
        };

        client.Connect();
    }

    static void OnConnect(object sender, HackClient.HCConnectEventArgs e)
    {
        Console.WriteLine("Connected!");

        /**
         * Try to join a channel when connected
         * to WebSocket server
         */
        e.Client.Join("SharpBot", "NoStealingMyPassword", "programming");
    }

    static void OnDisconnect(object sender, HackClient.HCDisconnectEventArgs e)
    {
        Console.WriteLine("Disconnected!");
    }

    static void OnMessage(object sender, HackClient.HCMessageEventArgs e)
    {
        string text = $"{e.User}: {e.Message.Text}";

        if (e.User.Nick == null)
            text = $"{e.Message.Text}";

        Console.WriteLine(text);

        if (e.Message.Type == MessageTypes.Chat)
        {
            // ...
        }
        else if (e.Message.Type == MessageTypes.Info)
        {
            // ...
        }
        else if (e.Message.Type == MessageTypes.Warn)
        {
            // ...
        }
    }

    static void OnOnlineSet(object sender, HackClient.HCOnlineSetEventArgs e)
    {
        Console.WriteLine($"Users online: {String.Join(", ", e.Users.Select(user => user.ToString()))}");
    }

    static void OnOnlineAdd(object sender, HackClient.HCOnlineAddEventArgs e)
    {
        Console.WriteLine($"{e.User} joined");
    }

    static void OnOnlineRemove(object sender, HackClient.HCOnlineRemoveEventArgs e)
    {
        Console.WriteLine($"{e.User} left");
    }
}

hackchatsharp's People

Contributors

heapoverride avatar

Stargazers

 avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.