{"id":16754922,"url":"https://github.com/mrlotu/swifthooks","last_synced_at":"2025-04-10T16:21:47.027Z","repository":{"id":179981544,"uuid":"181151067","full_name":"MrLotU/SwiftHooks","owner":"MrLotU","description":"Event driven programming in Swift","archived":false,"fork":false,"pushed_at":"2020-10-04T12:24:17.000Z","size":462,"stargazers_count":19,"open_issues_count":0,"forks_count":3,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-24T14:09:47.246Z","etag":null,"topics":["event-driven-programming","events","framework","swift","swifthooks"],"latest_commit_sha":null,"homepage":"https://mrlotu.github.io/SwiftHooks/","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/MrLotU.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":["MrLotU"]}},"created_at":"2019-04-13T09:49:09.000Z","updated_at":"2024-12-22T10:28:23.000Z","dependencies_parsed_at":"2024-05-05T08:46:15.835Z","dependency_job_id":null,"html_url":"https://github.com/MrLotU/SwiftHooks","commit_stats":null,"previous_names":["mrlotu/swifthooks"],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MrLotU%2FSwiftHooks","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MrLotU%2FSwiftHooks/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MrLotU%2FSwiftHooks/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MrLotU%2FSwiftHooks/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/MrLotU","download_url":"https://codeload.github.com/MrLotU/SwiftHooks/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248252661,"owners_count":21072699,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["event-driven-programming","events","framework","swift","swifthooks"],"created_at":"2024-10-13T03:06:23.087Z","updated_at":"2025-04-10T16:21:47.020Z","avatar_url":"https://github.com/MrLotU.png","language":"Swift","funding_links":["https://github.com/sponsors/MrLotU"],"categories":[],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\n    \u003cimg src=\"https://user-images.githubusercontent.com/18392003/80610769-08499e00-8a3a-11ea-830e-ad1ab4552164.png\"\n    width=80%\n    alt=\"SwiftHooks\"\u003e\n\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\n    \u003ca href=\"LICENSE\"\u003e\n        \u003cimg src=\"https://img.shields.io/badge/license-MIT-brightgreen.svg\" alt=\"MIT License\"\u003e\n    \u003c/a\u003e\n    \u003ca href=\"https://github.com/MrLotU/SwiftHooks/actions\"\u003e\n        \u003cimg src=\"https://github.com/MrLotU/SwiftHooks/workflows/test/badge.svg\" alt=\"Continuous Integration\"\u003e\n    \u003c/a\u003e\n    \u003ca href=\"https://swift.org\"\u003e\n        \u003cimg src=\"https://img.shields.io/badge/swift-5.2-brightgreen.svg\" alt=\"Swift 5.2\"\u003e\n    \u003c/a\u003e\n    \u003ca href=\"https://twitter.com/LotUDev\"\u003e\n        \u003cimg src=\"https://img.shields.io/badge/twitter-LotUDev-5AA9E7.svg\" alt=\"Twitter\"\u003e\n    \u003c/a\u003e\n\u003c/p\u003e\n\n\u003cbr\u003e\n\nSwiftHooks 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.\n\nSwiftHooks is built on a couple of core concepts/types:\n- Hooks: A `Hook` within SwiftHooks is a backend implementation emitting events. For example [Discord](https://github.com/MrLotU/SwiftHooksDiscord), Slack or GitHub\n- 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.\n- Plugins: A `Plugin` contains `Commands` and `Listeners`, usually grouped by purpose and can be registered to the main `SwiftHooks` class.\n- Commands: A `Command` is a specific function to be executed on specific message events. For example `/ping`.\n- Listeners: A `Listener` defines a callback for certain events. For example `messageCreate` or `messageUpdate`.\n\n---\n\nHooks are simple in architecture. They need the ability to:\n- Boot and connect to their specific backend.\n- Have listeners attached to them.\n- Emit events back to the main `SwiftHooks` instance.\n\nThe 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.\n\n# Installation\n\nSwiftHooks is available through SPM. To include it in your project add the following dependency to your `Package.swift`:\n\n```swift\n    .package(url: \"https://github.com/MrLotU/SwiftHooks.git\", from: \"1.0.0-alpha\")\n```\n# Usage\n\nFor a full example see the [Example repository](https://github.com/MrLotU/SwiftHooksExample).\n\nTo get started create an instance of `SwiftHooks`.\n```swift\nlet swiftHooks = SwiftHooks()\n```\n\nAfter that, attach your first hook:\n```swift\nswiftHooks.hook(DiscordHook.self, DiscordHookOptions(token: \"discord_token\"))\n```\n\nThis will set up your system to connect to Discord, and stream events to your program.\n\nTo add listeners and commands, create a pluign:\n```swift\nclass MyPlugin: Plugin {\n    \n    var commands: some Commands {\n        Group {\n            Command(\"echo\")\n                .arg(String?.self, named: \"content\")\n                .execute { (hooks, event, content) in\n                    event.message.reply(content ?? \"No content provided\")    \n            }\n\n            Command(\"ping\")\n                .execute { (hooks, event) in\n                    event.message.reply(\"Pong!\")    \n            }\n        }\n    }\n\n    var listeners: some EventListeners {\n        Listeners {\n            Listener(Discord.guildCreate) { event, guild in\n                print(\"\"\"\n                    Succesfully loaded \\(guild.name).\n                    It has \\(guild.members.count) members and \\(guild.channels.count) channels.\n                    \"\"\")\n            }\n\n            GlobalListener(Global.messageCreate) { event, message in\n                print(\"Message: \\(message.content)\")\n            }\n        }\n    }\n}\n```\n\nFor a more complex Plugin example check the [Example repository](https://github.com/MrLotU/SwiftHooksExample).\n\nAfter your plugin is created, register it to the system and run.\n```swift\ntry swiftHooks.register(MyPlugin())\n\ntry swiftHooks.run()\n```\nCalling `swiftHooks.run()` will block the main thread and run forever.\n\n# Contributing\n\nAll contributions are most welcome!\n\nIf you think of some cool new feature that should be included, please [create an issue](https://github.com/MrLotU/SwiftHooks/issues/new/choose). Or, if you want to implement it yourself, [fork this repo](https://github.com/MrLotU/SwiftHooks/fork) and submit a PR!\n\nIf you find a bug or have issues, please [create an issue](https://github.com/MrLotU/SwiftHooks/issues/new/choose) explaining your problems, and include as much information as possible, so it's easier to reproduce \u0026 investigate (Framework, OS and Swift version, terminal output, etc.)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmrlotu%2Fswifthooks","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmrlotu%2Fswifthooks","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmrlotu%2Fswifthooks/lists"}