Coder Social home page Coder Social logo

twitchirc's Introduction

TwitchIRC

Build Status

A dependancy-free Swift package that takes of parsing and serializing Twitch IRC messages.

How To Parse

To parse Twitch messages, use IncomingMessage.parse(ircOutput:):

/// `websocketOutput` here represents the `String` Twitch sent you over IRC.
let twitchMessages: [(message: IncomingMessage?, text: String)] = IncomingMessage.parse(ircOutput: websocketOutput)

Then to use:

for (message, text) in twitchMessages {
    if let message = message {
        switch message {
        /// Switch over each case of the `IncomingMessage` and do whatever you want.
        }
    }
}

As an example, this will print any normal chat messages viewers send, in the channels you've joined:

for (message, _) in twitchMessages {
    if let message = message {
        switch message {
        case let .privateMessage(privateMessage):
            print("In channel \(privateMessage.channel), user \(privateMessage.displayName) sent a message: \(privateMessage.message)")
        default: break
        }
    }
}

How To Serialize

To serialize your messages to a proper text form, use OutgoingMessage.serialize():

let outgoingMessage: OutgoingMessage = ...
let serialized = outgoingMessage.serialize()
/// Now send `serialized` to Twitch over IRC.

As an example of serializing, this will send a normal chat message to channel mahdimmbm, saying Testing TwitchIRC :):

let outgoingMessage: OutgoingMessage = .privateMessage(to: "mahdimmbm", message: "Testing TwitchIRC :)")
let serialized = outgoingMessage.serialize()
/// Now send `serialized` to Twitch over IRC.

I don't see some info in some messages

TwitchIRC contains all info sent by Twitch. If you don't see something in message types, its probably deprecated.
Some of the deprecated keys are subscriber, mod or user-type. You need to instead use the badges for those 3 mentioned keys.
I'm personally actively looking for any non-parsed info using the parsingLeftOvers property that some message types have, and will update the package with the new info as soon as I catch them.

How To Add TwitchIRC To Your Project

To use the TwitchIRC library in a SwiftPM project, add the following line to the dependencies in your Package.swift file:

.package(url: "https://github.com/MahdiBM/TwitchIRC", from: "1.0.0"),

Include "TwitchIRC" as a dependency for your executable target:

.target(name: "<target>", dependencies: [
    .product(name: "TwitchIRC", package: "TwitchIRC"),
]),

Finally, add import TwitchIRC to your source code.

Warning

This package includes both official and unofficial info sent to you over IRC by Twitch.
Twitch only gurantees the official stuff, and using the unofficial info might result in code breakage in the future.
To see what's official and what's not, you can take a look at the official documentation.

Communication and Support

If you have any questions, TwitchDev Discord server will likely prove helpful to you. I'm available there @Mahdi BM#0517.

Feel free to make PRs or open Issues as well :)

twitchirc's People

Contributors

false avatar mahdibm 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.