All Projects → MrLotU → SwiftHooks

MrLotU / SwiftHooks

Licence: MIT license
Event driven programming in Swift

Programming Languages

swift
15916 projects

Projects that are alternatives of or similar to SwiftHooks

Php Sse
A simple and efficient library implemented HTML5's server-sent events by PHP, is used to real-time push events from server to client, and easier than Websocket, instead of AJAX request.
Stars: ✭ 237 (+1294.12%)
Mutual labels:  events
chronosjs
JS Channels (Events / Commands / Reqest-Response / Courier) Mechanism
Stars: ✭ 35 (+105.88%)
Mutual labels:  events
event-horizon
Custom global event firing/subscribing in GameMaker: Studio 2
Stars: ✭ 16 (-5.88%)
Mutual labels:  events
Cqrs Clean Eventual Consistency
CQRS, using Clean Architecture, multiple databases and Eventual Consistency
Stars: ✭ 247 (+1352.94%)
Mutual labels:  events
laravel-attribute-observer
Observe (and react to) attribute changes made on Eloquent models.
Stars: ✭ 59 (+247.06%)
Mutual labels:  events
easyappointments-integrations
📅 Various platform integration packages of Easy!Appointments
Stars: ✭ 29 (+70.59%)
Mutual labels:  events
Vue Events
Simple event handling for Vue.js
Stars: ✭ 234 (+1276.47%)
Mutual labels:  events
ng2-events
Supercharge your Angular2+ event handling
Stars: ✭ 17 (+0%)
Mutual labels:  events
Tech-Conferences
Overview of upcoming and past tech conferences
Stars: ✭ 42 (+147.06%)
Mutual labels:  events
Wortuhr ESP8266
Wortuhr mit ESP8266 WeMos D1 mini und NeoPixel WS2812B LEDs mit mp3 Sounds, Animationen, Transitions, Events und Spiele
Stars: ✭ 33 (+94.12%)
Mutual labels:  events
micro-typed-events
The smallest, most convenient typesafe TS event emitter you'll ever need
Stars: ✭ 39 (+129.41%)
Mutual labels:  events
penn-clubs
Official React-based website for Penn Labs' club directory and events listings.
Stars: ✭ 41 (+141.18%)
Mutual labels:  events
tiny-typed-emitter
Fully type-checked NodeJS EventEmitter
Stars: ✭ 96 (+464.71%)
Mutual labels:  events
Watermill
Building event-driven applications the easy way in Go.
Stars: ✭ 3,504 (+20511.76%)
Mutual labels:  events
UnityEventAggregator
Simple event aggregation for Unity3D.
Stars: ✭ 30 (+76.47%)
Mutual labels:  events
Cphalcon7
Dao7 - Web framework for PHP7.x,项目接洽 QQ 176013762
Stars: ✭ 237 (+1294.12%)
Mutual labels:  events
ZSFakeTouch
Simulate touch events for iOS 模拟点击
Stars: ✭ 104 (+511.76%)
Mutual labels:  events
EasyEventEditor
Drop in replacement for the default Unity event editor drawer that allows listener reordering
Stars: ✭ 103 (+505.88%)
Mutual labels:  events
evon
Fast and versatile event dispatcher code generator for Golang
Stars: ✭ 15 (-11.76%)
Mutual labels:  events
vcenter-connector
Extend vCenter with OpenFaaS
Stars: ✭ 29 (+70.59%)
Mutual labels:  events

SwiftHooks

MIT License Continuous Integration Swift 5.2 Twitter


SwiftHooks is a modular event-driven programming framework for Swift, that allows you to listen for both generic and specific events, with a builtin command system. All with a SwiftUI inspired API design.

SwiftHooks is built on a couple of core concepts/types:

  • Hooks: A Hook within SwiftHooks is a backend implementation emitting events. For example Discord, Slack or GitHub
  • SwiftHooks: This is the main class that acts as a traffic control and connection hub of sorts. Hooks and Plugins are both connected to the main SwiftHooks class.
  • Plugins: A Plugin contains Commands and Listeners, usually grouped by purpose and can be registered to the main SwiftHooks class.
  • Commands: A Command is a specific function to be executed on specific message events. For example /ping.
  • Listeners: A Listener defines a callback for certain events. For example messageCreate or messageUpdate.

Hooks are simple in architecture. They need the ability to:

  • Boot and connect to their specific backend.
  • Have listeners attached to them.
  • Emit events back to the main SwiftHooks instance.

The emitting back to SwiftHooks is important for so called "Global" events. Global events are generic events that can be emitted by multiple backends. A great example of this is messageCreate, supported by Discord, Slack, GitHub and loads more. This allows you to create one listener that acts on multiple platforms.

Installation

SwiftHooks is available through SPM. To include it in your project add the following dependency to your Package.swift:

    .package(url: "https://github.com/MrLotU/SwiftHooks.git", from: "1.0.0-alpha")

Usage

For a full example see the Example repository.

To get started create an instance of SwiftHooks.

let swiftHooks = SwiftHooks()

After that, attach your first hook:

swiftHooks.hook(DiscordHook.self, DiscordHookOptions(token: "discord_token"))

This will set up your system to connect to Discord, and stream events to your program.

To add listeners and commands, create a pluign:

class MyPlugin: Plugin {
    
    var commands: some Commands {
        Group {
            Command("echo")
                .arg(String?.self, named: "content")
                .execute { (hooks, event, content) in
                    event.message.reply(content ?? "No content provided")    
            }

            Command("ping")
                .execute { (hooks, event) in
                    event.message.reply("Pong!")    
            }
        }
    }

    var listeners: some EventListeners {
        Listeners {
            Listener(Discord.guildCreate) { event, guild in
                print("""
                    Succesfully loaded \(guild.name).
                    It has \(guild.members.count) members and \(guild.channels.count) channels.
                    """)
            }

            GlobalListener(Global.messageCreate) { event, message in
                print("Message: \(message.content)")
            }
        }
    }
}

For a more complex Plugin example check the Example repository.

After your plugin is created, register it to the system and run.

try swiftHooks.register(MyPlugin())

try swiftHooks.run()

Calling swiftHooks.run() will block the main thread and run forever.

Contributing

All contributions are most welcome!

If you think of some cool new feature that should be included, please create an issue. Or, if you want to implement it yourself, fork this repo and submit a PR!

If you find a bug or have issues, please create an issue explaining your problems, and include as much information as possible, so it's easier to reproduce & investigate (Framework, OS and Swift version, terminal output, etc.)

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].