├── .gitattributes ├── .github └── workflows │ ├── check-buildstatus.yml │ ├── preview-release.yml │ └── release.yml ├── .gitignore ├── LICENSE.txt ├── README.md ├── TwitchLib.EventSub.Websockets.Example.NetStandard ├── Program.cs ├── TwitchLib.EventSub.Websockets.Example.NetStandard.csproj ├── WebsocketHostedService.cs ├── WebsocketHostedServiceWithoutDI.cs └── appsettings.json ├── TwitchLib.EventSub.Websockets.Example ├── Program.cs ├── Properties │ └── launchSettings.json ├── TwitchLib.EventSub.Websockets.Example.csproj ├── WebsocketHostedService.cs ├── appsettings.Development.json └── appsettings.json ├── TwitchLib.EventSub.Websockets.sln └── TwitchLib.EventSub.Websockets ├── Client └── WebsocketClient.cs ├── Core ├── EventArgs │ ├── Channel │ │ ├── ChannelAdBreakBeginArgs.cs │ │ ├── ChannelBanArgs.cs │ │ ├── ChannelCharityCampaignDonateArgs.cs │ │ ├── ChannelCharityCampaignProgressArgs.cs │ │ ├── ChannelCharityCampaignStartArgs.cs │ │ ├── ChannelCharityCampaignStopArgs.cs │ │ ├── ChannelChatClearArgs.cs │ │ ├── ChannelChatClearUserMessagesArgs.cs │ │ ├── ChannelChatMessageArgs.cs │ │ ├── ChannelChatMessageDeleteArgs.cs │ │ ├── ChannelChatNotificationArgs.cs │ │ ├── ChannelCheerArgs.cs │ │ ├── ChannelFollowArgs.cs │ │ ├── ChannelGoalBeginArgs.cs │ │ ├── ChannelGoalEndArgs.cs │ │ ├── ChannelGoalProgressArgs.cs │ │ ├── ChannelGuestStarGuestUpdateArgs.cs │ │ ├── ChannelGuestStarSessionBeginArgs.cs │ │ ├── ChannelGuestStarSessionEndArgs.cs │ │ ├── ChannelGuestStarSettingsUpdateArgs.cs │ │ ├── ChannelGuestStarSlotUpdateArgs.cs │ │ ├── ChannelHypeTrainBeginArgs.cs │ │ ├── ChannelHypeTrainEndArgs.cs │ │ ├── ChannelHypeTrainProgressArgs.cs │ │ ├── ChannelModeratorArgs.cs │ │ ├── ChannelPointsAutomaticRewardRedemptionArgs.cs │ │ ├── ChannelPointsCustomRewardArgs.cs │ │ ├── ChannelPointsCustomRewardRedemptionArgs.cs │ │ ├── ChannelPollBeginArgs.cs │ │ ├── ChannelPollEndArgs.cs │ │ ├── ChannelPollProgressArgs.cs │ │ ├── ChannelPredictionBeginArgs.cs │ │ ├── ChannelPredictionEndArgs.cs │ │ ├── ChannelPredictionLockArgs.cs │ │ ├── ChannelPredictionProgressArgs.cs │ │ ├── ChannelRaidArgs.cs │ │ ├── ChannelSharedChatSessionBeginArgs.cs │ │ ├── ChannelSharedChatSessionEndArgs.cs │ │ ├── ChannelSharedChatSessionUpdateArgs.cs │ │ ├── ChannelShieldModeBeginArgs.cs │ │ ├── ChannelShieldModeEndArgs.cs │ │ ├── ChannelShoutoutCreateArgs.cs │ │ ├── ChannelShoutoutReceiveArgs.cs │ │ ├── ChannelSubscribeArgs.cs │ │ ├── ChannelSubscriptionEndArgs.cs │ │ ├── ChannelSubscriptionGiftArgs.cs │ │ ├── ChannelSubscriptionMessageArgs.cs │ │ ├── ChannelSuspiciousUserMessageArgs.cs │ │ ├── ChannelSuspiciousUserUpdateArgs.cs │ │ ├── ChannelUnbanArgs.cs │ │ ├── ChannelUnbanRequestCreateArgs.cs │ │ ├── ChannelUnbanRequestResolveArgs.cs │ │ ├── ChannelUpdateArgs.cs │ │ ├── ChannelVipArgs.cs │ │ ├── ChannelWarningAcknowledgeArgs.cs │ │ └── ChannelWarningSendArgs.cs │ ├── DataReceivedArgs.cs │ ├── ErrorOccuredArgs.cs │ ├── RevocationArgs.cs │ ├── Stream │ │ ├── StreamOfflineArgs.cs │ │ └── StreamOnlineArgs.cs │ ├── TwitchLibEventSubEventArgs.cs │ ├── User │ │ ├── UserUpdateArgs.cs │ │ └── UserWhisperMessageArgs.cs │ ├── WebsocketConnectedArgs.cs │ └── WebsocketDisconnectedArgs.cs ├── Handler │ └── INotificationHandler.cs └── Models │ ├── EventSubMetadata.cs │ ├── EventSubNotification.cs │ ├── EventSubNotificationPayload.cs │ ├── EventSubTransport.cs │ ├── EventSubWebsocketSessionInfo.cs │ ├── EventSubWebsocketSessionInfoMessage.cs │ └── EventSubWebsocketSessionInfoPayload.cs ├── EventSubWebsocketClient.cs ├── Extensions ├── LogExtensions.cs └── ServiceCollectionExtensions.cs ├── Handler ├── Channel │ ├── Ads │ │ └── AdBreakBeginHandler.cs │ ├── ChannelPoints │ │ ├── CustomReward │ │ │ ├── ChannelPointsCustomRewardAddHandler.cs │ │ │ ├── ChannelPointsCustomRewardRemoveHandler.cs │ │ │ └── ChannelPointsCustomRewardUpdateHandler.cs │ │ └── Redemptions │ │ │ ├── ChannelPointsAutomaticRewardRedemptionAddHandler.cs │ │ │ ├── ChannelPointsCustomRewardRedemptionAddHandler.cs │ │ │ └── ChannelPointsCustomRewardRedemptionUpdate.cs │ ├── ChannelUpdateHandler.cs │ ├── Charity │ │ ├── ChannelCharityCampaignDonateHandler.cs │ │ ├── ChannelCharityCampaignProgressHandler.cs │ │ ├── ChannelCharityCampaignStartHandler.cs │ │ └── ChannelCharityCampaignStopHandler.cs │ ├── Chat │ │ ├── ChannelChatClearHandler.cs │ │ ├── ChannelChatClearUserMessagesHandler.cs │ │ ├── ChatMessageDeleteHandler.cs │ │ └── ChatNotificationHandler.cs │ ├── ChatMessageHandler.cs │ ├── Cheers │ │ └── ChannelCheerHandler.cs │ ├── Follows │ │ └── ChannelFollowHandler.cs │ ├── Goals │ │ ├── ChannelGoalBeginHandler.cs │ │ ├── ChannelGoalEndHandler.cs │ │ └── ChannelGoalProgressHandler.cs │ ├── GuestStar │ │ ├── ChannelGuestStarGuestUpdateHandler.cs │ │ ├── ChannelGuestStarSessionBeginHandler.cs │ │ ├── ChannelGuestStarSessionEndHandler.cs │ │ ├── ChannelGuestStarSettingsUpdateHandler.cs │ │ └── ChannelGuestStarSlotUpdateHandler.cs │ ├── HypeTrains │ │ ├── ChannelHypeTrainBeginHandler.cs │ │ ├── ChannelHypeTrainEndHandler.cs │ │ └── ChannelHypeTrainProgressHandler.cs │ ├── Moderation │ │ ├── ChannelBanHandler.cs │ │ ├── ChannelUnbanHandler.cs │ │ ├── ChannelUnbanRequestCreateHandler.cs │ │ └── ChannelUnbanRequestResolveHandler.cs │ ├── Moderators │ │ ├── ChannelModeratorAddHandler.cs │ │ └── ChannelModeratorRemoveHandler.cs │ ├── Polls │ │ ├── ChannelPollBeginHandler.cs │ │ ├── ChannelPollEndHandler.cs │ │ └── ChannelPollProgressHandler.cs │ ├── Predictions │ │ ├── ChannelPredictionBeginHandler.cs │ │ ├── ChannelPredictionEndHandler.cs │ │ ├── ChannelPredictionLockHandler.cs │ │ └── ChannelPredictionProgressHandler.cs │ ├── Raids │ │ └── ChannelRaidHandler.cs │ ├── SharedChat │ │ ├── ChannelSharedChatSessionBeginHandler.cs │ │ ├── ChannelSharedChatSessionEndHandler.cs │ │ └── ChannelSharedChatSessionUpdateHandler.cs │ ├── ShieldMode │ │ ├── ChannelShieldModeBeginHandler.cs │ │ └── ChannelShieldModeEndHandler.cs │ ├── Shoutouts │ │ ├── ChannelShoutoutCreateHandler.cs │ │ └── ChannelShoutoutReceiveHandler.cs │ ├── Subscription │ │ ├── ChannelSubscribeHandler.cs │ │ ├── ChannelSubscriptionEndHandler.cs │ │ ├── ChannelSubscriptionGiftHandler.cs │ │ └── ChannelSubscriptionMessageHandler.cs │ ├── SuspiciousUser │ │ ├── ChannelSuspiciousUserMessageHandler.cs │ │ └── ChannelSuspiciousUserUpdateHandler.cs │ ├── Vips │ │ ├── ChannelVipAddHandler.cs │ │ └── ChannelVipRemoveHandler.cs │ └── Warning │ │ ├── ChannelWarningAcknowledgeHandler.cs │ │ └── ChannelWarningSendHandler.cs ├── RevocationHandler.cs ├── Stream │ ├── StreamOfflineHandler.cs │ └── StreamOnlineHandler.cs └── User │ ├── UserUpdateHandler.cs │ └── UserWhisperMessageHandler.cs └── TwitchLib.EventSub.Websockets.csproj /.gitattributes: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Set default behavior to automatically normalize line endings. 3 | ############################################################################### 4 | * text=auto 5 | 6 | ############################################################################### 7 | # Set default behavior for command prompt diff. 8 | # 9 | # This is need for earlier builds of msysgit that does not have it on by 10 | # default for csharp files. 11 | # Note: This is only used by command line 12 | ############################################################################### 13 | #*.cs diff=csharp 14 | 15 | ############################################################################### 16 | # Set the merge driver for project and solution files 17 | # 18 | # Merging from the command prompt will add diff markers to the files if there 19 | # are conflicts (Merging from VS is not affected by the settings below, in VS 20 | # the diff markers are never inserted). Diff markers may cause the following 21 | # file extensions to fail to load in VS. An alternative would be to treat 22 | # these files as binary and thus will always conflict and require user 23 | # intervention with every merge. To do so, just uncomment the entries below 24 | ############################################################################### 25 | #*.sln merge=binary 26 | #*.csproj merge=binary 27 | #*.vbproj merge=binary 28 | #*.vcxproj merge=binary 29 | #*.vcproj merge=binary 30 | #*.dbproj merge=binary 31 | #*.fsproj merge=binary 32 | #*.lsproj merge=binary 33 | #*.wixproj merge=binary 34 | #*.modelproj merge=binary 35 | #*.sqlproj merge=binary 36 | #*.wwaproj merge=binary 37 | 38 | ############################################################################### 39 | # behavior for image files 40 | # 41 | # image files are treated as binary by default. 42 | ############################################################################### 43 | #*.jpg binary 44 | #*.png binary 45 | #*.gif binary 46 | 47 | ############################################################################### 48 | # diff behavior for common document formats 49 | # 50 | # Convert binary document formats to text before diffing them. This feature 51 | # is only available from the command line. Turn it on by uncommenting the 52 | # entries below. 53 | ############################################################################### 54 | #*.doc diff=astextplain 55 | #*.DOC diff=astextplain 56 | #*.docx diff=astextplain 57 | #*.DOCX diff=astextplain 58 | #*.dot diff=astextplain 59 | #*.DOT diff=astextplain 60 | #*.pdf diff=astextplain 61 | #*.PDF diff=astextplain 62 | #*.rtf diff=astextplain 63 | #*.RTF diff=astextplain 64 | -------------------------------------------------------------------------------- /.github/workflows/check-buildstatus.yml: -------------------------------------------------------------------------------- 1 | name: Check TwitchLib.EventSub.Websockets PR Build Status 2 | 3 | on: 4 | pull_request: 5 | branches: [ dev, main ] 6 | 7 | jobs: 8 | check-buildstatus: 9 | 10 | runs-on: ubuntu-latest 11 | 12 | steps: 13 | - uses: actions/checkout@v4 14 | - name: Setup .NET 15 | uses: actions/setup-dotnet@v3 16 | with: 17 | dotnet-version: 8.0.x 18 | - name: Restore dependencies 19 | run: dotnet restore 20 | - name: Build TwitchLib.EventSub.Websockets 21 | run: dotnet build --no-restore 22 | -------------------------------------------------------------------------------- /.github/workflows/preview-release.yml: -------------------------------------------------------------------------------- 1 | name: Release Preview Nuget Package 2 | 3 | on: 4 | push: 5 | branches: [ dev ] 6 | 7 | jobs: 8 | release-preview: 9 | if: "! contains(toJSON(github.event.commits.*.message), '[skip-ci]')" 10 | runs-on: ubuntu-latest 11 | 12 | steps: 13 | - uses: actions/checkout@v4 14 | - uses: benjlevesque/short-sha@v3.0 15 | id: short-sha 16 | - name: Setup .NET 17 | uses: actions/setup-dotnet@v3 18 | with: 19 | dotnet-version: 8.0.x 20 | - name: Restore dependencies 21 | run: dotnet restore 22 | - name: Build TwitchLib.EventSub.Websockets 23 | run: dotnet build -c Release --no-restore 24 | - name: Pack TwitchLib.EventSub.Websockets 25 | run: dotnet pack ./TwitchLib.EventSub.Websockets/TwitchLib.EventSub.Websockets.csproj -v normal -c Release -o nugets --no-build --version-suffix "preview.${{ github.run_number }}.${{ steps.short-sha.outputs.sha }}" 26 | - name: Push to Nuget 27 | run: dotnet nuget push "./nugets/*.nupkg" -k ${{ secrets.API_NUGET_TOKEN }} -s https://api.nuget.org/v3/index.json 28 | -------------------------------------------------------------------------------- /.github/workflows/release.yml: -------------------------------------------------------------------------------- 1 | name: Release Nuget Package 2 | 3 | on: 4 | push: 5 | branches: [ main ] 6 | 7 | jobs: 8 | release: 9 | if: "contains(toJSON(github.event.commits.*.message), '[Release]')" 10 | runs-on: ubuntu-latest 11 | 12 | steps: 13 | - uses: actions/checkout@v4 14 | - name: Setup .NET 15 | uses: actions/setup-dotnet@v3 16 | with: 17 | dotnet-version: 8.0.x 18 | - name: Restore dependencies 19 | run: dotnet restore 20 | - name: Build TwitchLib.EventSub.Websockets 21 | run: dotnet build -c Release --no-restore 22 | - name: Pack TwitchLib.EventSub.Websockets 23 | run: dotnet pack ./TwitchLib.EventSub.Websockets/TwitchLib.EventSub.Websockets.csproj -v normal -c Release -o nugets --no-build 24 | - name: Push to Nuget 25 | run: dotnet nuget push "./nugets/*.nupkg" -k ${{ secrets.API_NUGET_TOKEN }} -s https://api.nuget.org/v3/index.json 26 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | ## 4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore 5 | 6 | # User-specific files 7 | *.rsuser 8 | *.suo 9 | *.user 10 | *.userosscache 11 | *.sln.docstates 12 | 13 | # User-specific files (MonoDevelop/Xamarin Studio) 14 | *.userprefs 15 | 16 | # Mono auto generated files 17 | mono_crash.* 18 | 19 | # Build results 20 | [Dd]ebug/ 21 | [Dd]ebugPublic/ 22 | [Rr]elease/ 23 | [Rr]eleases/ 24 | x64/ 25 | x86/ 26 | [Ww][Ii][Nn]32/ 27 | [Aa][Rr][Mm]/ 28 | [Aa][Rr][Mm]64/ 29 | bld/ 30 | [Bb]in/ 31 | [Oo]bj/ 32 | [Oo]ut/ 33 | [Ll]og/ 34 | [Ll]ogs/ 35 | 36 | # Visual Studio 2015/2017 cache/options directory 37 | .vs/ 38 | # Uncomment if you have tasks that create the project's static files in wwwroot 39 | #wwwroot/ 40 | 41 | # Visual Studio 2017 auto generated files 42 | Generated\ Files/ 43 | 44 | # MSTest test Results 45 | [Tt]est[Rr]esult*/ 46 | [Bb]uild[Ll]og.* 47 | 48 | # NUnit 49 | *.VisualState.xml 50 | TestResult.xml 51 | nunit-*.xml 52 | 53 | # Build Results of an ATL Project 54 | [Dd]ebugPS/ 55 | [Rr]eleasePS/ 56 | dlldata.c 57 | 58 | # Benchmark Results 59 | BenchmarkDotNet.Artifacts/ 60 | 61 | # .NET Core 62 | project.lock.json 63 | project.fragment.lock.json 64 | artifacts/ 65 | 66 | # ASP.NET Scaffolding 67 | ScaffoldingReadMe.txt 68 | 69 | # StyleCop 70 | StyleCopReport.xml 71 | 72 | # Files built by Visual Studio 73 | *_i.c 74 | *_p.c 75 | *_h.h 76 | *.ilk 77 | *.meta 78 | *.obj 79 | *.iobj 80 | *.pch 81 | *.pdb 82 | *.ipdb 83 | *.pgc 84 | *.pgd 85 | *.rsp 86 | *.sbr 87 | *.tlb 88 | *.tli 89 | *.tlh 90 | *.tmp 91 | *.tmp_proj 92 | *_wpftmp.csproj 93 | *.log 94 | *.vspscc 95 | *.vssscc 96 | .builds 97 | *.pidb 98 | *.svclog 99 | *.scc 100 | 101 | # Chutzpah Test files 102 | _Chutzpah* 103 | 104 | # Visual C++ cache files 105 | ipch/ 106 | *.aps 107 | *.ncb 108 | *.opendb 109 | *.opensdf 110 | *.sdf 111 | *.cachefile 112 | *.VC.db 113 | *.VC.VC.opendb 114 | 115 | # Visual Studio profiler 116 | *.psess 117 | *.vsp 118 | *.vspx 119 | *.sap 120 | 121 | # Visual Studio Trace Files 122 | *.e2e 123 | 124 | # TFS 2012 Local Workspace 125 | $tf/ 126 | 127 | # Guidance Automation Toolkit 128 | *.gpState 129 | 130 | # ReSharper is a .NET coding add-in 131 | _ReSharper*/ 132 | *.[Rr]e[Ss]harper 133 | *.DotSettings.user 134 | 135 | # TeamCity is a build add-in 136 | _TeamCity* 137 | 138 | # DotCover is a Code Coverage Tool 139 | *.dotCover 140 | 141 | # AxoCover is a Code Coverage Tool 142 | .axoCover/* 143 | !.axoCover/settings.json 144 | 145 | # Coverlet is a free, cross platform Code Coverage Tool 146 | coverage*.json 147 | coverage*.xml 148 | coverage*.info 149 | 150 | # Visual Studio code coverage results 151 | *.coverage 152 | *.coveragexml 153 | 154 | # NCrunch 155 | _NCrunch_* 156 | .*crunch*.local.xml 157 | nCrunchTemp_* 158 | 159 | # MightyMoose 160 | *.mm.* 161 | AutoTest.Net/ 162 | 163 | # Web workbench (sass) 164 | .sass-cache/ 165 | 166 | # Installshield output folder 167 | [Ee]xpress/ 168 | 169 | # DocProject is a documentation generator add-in 170 | DocProject/buildhelp/ 171 | DocProject/Help/*.HxT 172 | DocProject/Help/*.HxC 173 | DocProject/Help/*.hhc 174 | DocProject/Help/*.hhk 175 | DocProject/Help/*.hhp 176 | DocProject/Help/Html2 177 | DocProject/Help/html 178 | 179 | # Click-Once directory 180 | publish/ 181 | 182 | # Publish Web Output 183 | *.[Pp]ublish.xml 184 | *.azurePubxml 185 | # Note: Comment the next line if you want to checkin your web deploy settings, 186 | # but database connection strings (with potential passwords) will be unencrypted 187 | *.pubxml 188 | *.publishproj 189 | 190 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 191 | # checkin your Azure Web App publish settings, but sensitive information contained 192 | # in these scripts will be unencrypted 193 | PublishScripts/ 194 | 195 | # NuGet Packages 196 | *.nupkg 197 | # NuGet Symbol Packages 198 | *.snupkg 199 | # The packages folder can be ignored because of Package Restore 200 | **/[Pp]ackages/* 201 | # except build/, which is used as an MSBuild target. 202 | !**/[Pp]ackages/build/ 203 | # Uncomment if necessary however generally it will be regenerated when needed 204 | #!**/[Pp]ackages/repositories.config 205 | # NuGet v3's project.json files produces more ignorable files 206 | *.nuget.props 207 | *.nuget.targets 208 | 209 | # Microsoft Azure Build Output 210 | csx/ 211 | *.build.csdef 212 | 213 | # Microsoft Azure Emulator 214 | ecf/ 215 | rcf/ 216 | 217 | # Windows Store app package directories and files 218 | AppPackages/ 219 | BundleArtifacts/ 220 | Package.StoreAssociation.xml 221 | _pkginfo.txt 222 | *.appx 223 | *.appxbundle 224 | *.appxupload 225 | 226 | # Visual Studio cache files 227 | # files ending in .cache can be ignored 228 | *.[Cc]ache 229 | # but keep track of directories ending in .cache 230 | !?*.[Cc]ache/ 231 | 232 | # Others 233 | ClientBin/ 234 | ~$* 235 | *~ 236 | *.dbmdl 237 | *.dbproj.schemaview 238 | *.jfm 239 | *.pfx 240 | *.publishsettings 241 | orleans.codegen.cs 242 | 243 | # Including strong name files can present a security risk 244 | # (https://github.com/github/gitignore/pull/2483#issue-259490424) 245 | #*.snk 246 | 247 | # Since there are multiple workflows, uncomment next line to ignore bower_components 248 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 249 | #bower_components/ 250 | 251 | # RIA/Silverlight projects 252 | Generated_Code/ 253 | 254 | # Backup & report files from converting an old project file 255 | # to a newer Visual Studio version. Backup files are not needed, 256 | # because we have git ;-) 257 | _UpgradeReport_Files/ 258 | Backup*/ 259 | UpgradeLog*.XML 260 | UpgradeLog*.htm 261 | ServiceFabricBackup/ 262 | *.rptproj.bak 263 | 264 | # SQL Server files 265 | *.mdf 266 | *.ldf 267 | *.ndf 268 | 269 | # Business Intelligence projects 270 | *.rdl.data 271 | *.bim.layout 272 | *.bim_*.settings 273 | *.rptproj.rsuser 274 | *- [Bb]ackup.rdl 275 | *- [Bb]ackup ([0-9]).rdl 276 | *- [Bb]ackup ([0-9][0-9]).rdl 277 | 278 | # Microsoft Fakes 279 | FakesAssemblies/ 280 | 281 | # GhostDoc plugin setting file 282 | *.GhostDoc.xml 283 | 284 | # Node.js Tools for Visual Studio 285 | .ntvs_analysis.dat 286 | node_modules/ 287 | 288 | # Visual Studio 6 build log 289 | *.plg 290 | 291 | # Visual Studio 6 workspace options file 292 | *.opt 293 | 294 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 295 | *.vbw 296 | 297 | # Visual Studio LightSwitch build output 298 | **/*.HTMLClient/GeneratedArtifacts 299 | **/*.DesktopClient/GeneratedArtifacts 300 | **/*.DesktopClient/ModelManifest.xml 301 | **/*.Server/GeneratedArtifacts 302 | **/*.Server/ModelManifest.xml 303 | _Pvt_Extensions 304 | 305 | # Paket dependency manager 306 | .paket/paket.exe 307 | paket-files/ 308 | 309 | # FAKE - F# Make 310 | .fake/ 311 | 312 | # CodeRush personal settings 313 | .cr/personal 314 | 315 | # Python Tools for Visual Studio (PTVS) 316 | __pycache__/ 317 | *.pyc 318 | 319 | # Cake - Uncomment if you are using it 320 | # tools/** 321 | # !tools/packages.config 322 | 323 | # Tabs Studio 324 | *.tss 325 | 326 | # Telerik's JustMock configuration file 327 | *.jmconfig 328 | 329 | # BizTalk build output 330 | *.btp.cs 331 | *.btm.cs 332 | *.odx.cs 333 | *.xsd.cs 334 | 335 | # OpenCover UI analysis results 336 | OpenCover/ 337 | 338 | # Azure Stream Analytics local run output 339 | ASALocalRun/ 340 | 341 | # MSBuild Binary and Structured Log 342 | *.binlog 343 | 344 | # NVidia Nsight GPU debugger configuration file 345 | *.nvuser 346 | 347 | # MFractors (Xamarin productivity tool) working folder 348 | .mfractor/ 349 | 350 | # Local History for Visual Studio 351 | .localhistory/ 352 | 353 | # BeatPulse healthcheck temp database 354 | healthchecksdb 355 | 356 | # Backup folder for Package Reference Convert tool in Visual Studio 2017 357 | MigrationBackup/ 358 | 359 | # Ionide (cross platform F# VS Code tools) working folder 360 | .ionide/ 361 | 362 | # Fody - auto-generated XML schema 363 | FodyWeavers.xsd -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) [year] [fullname] 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # TwitchLib.EventSub.Websockets 2 | TwitchLib component to connect to Twitch's EventSub service via Websockets also known as EventSockets 3 | 4 | ## Disclaimer 5 | EventSub via Websockets is still in open beta. 6 | You can use it in production but Twitch may introduce breaking changes without prior notice. 7 | The same goes for this implementation until it reaches Version 1.0.0 8 | 9 | ## Resources 10 | If you need help on how to setup Dependency Injection in your Console or WPF Application you can have a look at these guides: 11 | - Console: https://dfederm.com/building-a-console-app-with-.net-generic-host/ 12 | - WPF: https://laurentkempe.com/2019/09/03/WPF-and-dotnet-Generic-Host-with-dotnet-Core-3-0/ 13 | 14 | You can also find a console app example for .NET 8 and for .NET Framework 4.8 in the repo. 15 | 16 | ## Installation 17 | 18 | | NuGet | | [![TwitchLib.EventSub.Websockets][1]][2] | 19 | | :--------------- | ----: | :--------------------------------------------------------------------------- | 20 | | Package Manager | `PM>` | `Install-Package TwitchLib.EventSub.Websockets -Version 0.6.0` | 21 | | .NET CLI | `>` | `dotnet add package TwitchLib.EventSub.Websockets --version 0.6.0` | 22 | | PackageReference | | `` | 23 | | Paket CLI | `>` | `paket add TwitchLib.EventSub.Websockets --version 0.6.0` | 24 | 25 | [1]: https://img.shields.io/nuget/v/TwitchLib.EventSub.Websockets.svg?label=TwitchLib.EventSub.Websockets 26 | [2]: https://www.nuget.org/packages/TwitchLib.EventSub.Websockets 27 | 28 | ## Setup 29 | 30 | Step 1: Create a new project (Console, WPF, ASP.NET) 31 | 32 | Step 2: Install the TwitchLib.EventSub.Websockets nuget package. (See above on how to do that) 33 | 34 | Step 3: Step 3: Add necessary services and config to the DI Container 35 | 36 | ```csharp 37 | services.AddTwitchLibEventSubWebsockets(); 38 | services.AddHostedService(); 39 | ``` 40 | (The location of where to put this and the naming of variables might differ depending on what kind of project and general setup you have) 41 | 42 | Step 4: Create the HostedService we just added to the DI container and connect to EventSub and listen to Events 43 | 44 | ```csharp 45 | using System.Net.Http.Headers; 46 | using System.Text; 47 | using System.Text.Json; 48 | using TwitchLib.Api; 49 | using TwitchLib.Api.Core.Enums; 50 | using TwitchLib.EventSub.Websockets.Core.EventArgs; 51 | using TwitchLib.EventSub.Websockets.Core.EventArgs.Channel; 52 | 53 | namespace TwitchLib.EventSub.Websockets.Test 54 | { 55 | public class WebsocketHostedService : IHostedService 56 | { 57 | private readonly ILogger _logger; 58 | private readonly EventSubWebsocketClient _eventSubWebsocketClient; 59 | private readonly TwitchApi _twitchApi = new(); 60 | private string _userId; 61 | 62 | public WebsocketHostedService(ILogger logger, EventSubWebsocketClient eventSubWebsocketClient) 63 | { 64 | _logger = logger ?? throw new ArgumentNullException(nameof(logger)); 65 | 66 | _eventSubWebsocketClient = eventSubWebsocketClient ?? throw new ArgumentNullException(nameof(eventSubWebsocketClient)); 67 | _eventSubWebsocketClient.WebsocketConnected += OnWebsocketConnected; 68 | _eventSubWebsocketClient.WebsocketDisconnected += OnWebsocketDisconnected; 69 | _eventSubWebsocketClient.WebsocketReconnected += OnWebsocketReconnected; 70 | _eventSubWebsocketClient.ErrorOccurred += OnErrorOccurred; 71 | 72 | _eventSubWebsocketClient.ChannelFollow += OnChannelFollow; 73 | // Get ClientId and ClientSecret by register an Application here: https://dev.twitch.tv/console/apps 74 | // https://dev.twitch.tv/docs/authentication/register-app/ 75 | _twitchApi.Settings.ClientId = "YOUR_APP_CLIENT_ID"; 76 | // Get Application Token with Client credentials grant flow. 77 | // https://dev.twitch.tv/docs/authentication/getting-tokens-oauth/#client-credentials-grant-flow 78 | _twitchApi.Settings.AccessToken = "YOUR_APPLICATION_ACCESS_TOKEN"; 79 | 80 | // You need the UserID for the User/Channel you want to get Events from. 81 | // You can use await _api.Helix.Users.GetUsersAsync() for that. 82 | _userId = "USER_ID"; 83 | } 84 | 85 | public async Task StartAsync(CancellationToken cancellationToken) 86 | { 87 | await _eventSubWebsocketClient.ConnectAsync(); 88 | } 89 | 90 | public async Task StopAsync(CancellationToken cancellationToken) 91 | { 92 | await _eventSubWebsocketClient.DisconnectAsync(); 93 | } 94 | 95 | private async Task OnWebsocketConnected(object sender, WebsocketConnectedArgs e) 96 | { 97 | _logger.LogInformation($"Websocket {_eventSubWebsocketClient.SessionId} connected!"); 98 | 99 | if (!e.IsRequestedReconnect) 100 | { 101 | // subscribe to topics 102 | // create condition Dictionary 103 | // You need BOTH broadcaster and moderator values or EventSub returns an Error! 104 | var condition = new Dictionary { { "broadcaster_user_id", _userId }, {"moderator_user_id", _userId} }; 105 | // Create and send EventSubscription 106 | await _twitchApi.Helix.EventSub.CreateEventSubSubscriptionAsync("channel.follow", "2", condition, EventSubTransportMethod.Websocket, 107 | _eventSubWebsocketClient.SessionId, accessToken: "BROADCASTER_ACCESS_TOKEN_WITH_SCOPES"); 108 | // If you want to get Events for special Events you need to additionally add the AccessToken of the ChannelOwner to the request. 109 | // https://dev.twitch.tv/docs/eventsub/eventsub-subscription-types/ 110 | } 111 | } 112 | 113 | private async Task OnWebsocketDisconnected(object sender, EventArgs e) 114 | { 115 | _logger.LogError($"Websocket {_eventSubWebsocketClient.SessionId} disconnected!"); 116 | 117 | // Don't do this in production. You should implement a better reconnect strategy with exponential backoff 118 | while (!await _eventSubWebsocketClient.ReconnectAsync()) 119 | { 120 | _logger.LogError("Websocket reconnect failed!"); 121 | await Task.Delay(1000); 122 | } 123 | } 124 | 125 | private async Task OnWebsocketReconnected(object sender, EventArgs e) 126 | { 127 | _logger.LogWarning($"Websocket {_eventSubWebsocketClient.SessionId} reconnected"); 128 | } 129 | 130 | private async Task OnErrorOccurred(object sender, ErrorOccuredArgs e) 131 | { 132 | _logger.LogError($"Websocket {_eventSubWebsocketClient.SessionId} - Error occurred!"); 133 | } 134 | 135 | private async Task OnChannelFollow(object sender, ChannelFollowArgs e) 136 | { 137 | var eventData = e.Notification.Payload.Event; 138 | _logger.LogInformation($"{eventData.UserName} followed {eventData.BroadcasterUserName} at {eventData.FollowedAt}"); 139 | } 140 | } 141 | } 142 | ``` 143 | 144 | Alternatively you can also just clone the examples: 145 | - .NET Framework 4.8 -> https://github.com/TwitchLib/TwitchLib.EventSub.Websockets/tree/main/TwitchLib.EventSub.Websockets.Example.NetStandard 146 | - .NET 8 -> https://github.com/TwitchLib/TwitchLib.EventSub.Websockets/tree/main/TwitchLib.EventSub.Websockets.Example 147 | -------------------------------------------------------------------------------- /TwitchLib.EventSub.Websockets.Example.NetStandard/Program.cs: -------------------------------------------------------------------------------- 1 | using System.IO; 2 | using Microsoft.Extensions.Configuration; 3 | using Microsoft.Extensions.DependencyInjection; 4 | using Microsoft.Extensions.Hosting; 5 | using TwitchLib.EventSub.Websockets.Extensions; 6 | 7 | namespace TwitchLib.EventSub.Websockets.Example.NetStandard 8 | { 9 | internal class Program 10 | { 11 | private static void Main(string[] args) 12 | { 13 | CreateHostBuilder(args).Build().Run(); 14 | } 15 | 16 | private static IHostBuilder CreateHostBuilder(string[] args) => 17 | Host.CreateDefaultBuilder(args) 18 | .ConfigureAppConfiguration(configure => 19 | { 20 | configure.AddJsonFile(Path.Combine(Directory.GetCurrentDirectory(), "appsettings.json")); 21 | }) 22 | .ConfigureServices((hostContext, services) => 23 | { 24 | services.AddLogging(); 25 | services.AddTwitchLibEventSubWebsockets(); 26 | 27 | services.AddHostedService(); 28 | }); 29 | } 30 | } -------------------------------------------------------------------------------- /TwitchLib.EventSub.Websockets.Example.NetStandard/TwitchLib.EventSub.Websockets.Example.NetStandard.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Exe 5 | netframework4.8 6 | disable 7 | disable 8 | latest 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | Always 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /TwitchLib.EventSub.Websockets.Example.NetStandard/WebsocketHostedService.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.Extensions.Configuration; 2 | using Microsoft.Extensions.Hosting; 3 | using Microsoft.Extensions.Logging; 4 | using System; 5 | using System.Threading; 6 | using System.Threading.Tasks; 7 | using TwitchLib.Api; 8 | using TwitchLib.EventSub.Websockets.Core.EventArgs; 9 | using TwitchLib.EventSub.Websockets.Core.EventArgs.Channel; 10 | 11 | namespace TwitchLib.EventSub.Websockets.Example.NetStandard 12 | { 13 | public class WebsocketHostedService : IHostedService 14 | { 15 | private readonly IConfiguration _configuration; 16 | private readonly ILogger _logger; 17 | private readonly EventSubWebsocketClient _eventSubWebsocketClient; 18 | private readonly TwitchAPI _twitchApi = new(); 19 | private string _userId; 20 | 21 | public WebsocketHostedService(IConfiguration configuration ,ILogger logger, EventSubWebsocketClient eventSubWebsocketClient) 22 | { 23 | _configuration = configuration; 24 | _logger = logger ?? throw new ArgumentNullException(nameof(logger)); 25 | 26 | _eventSubWebsocketClient = eventSubWebsocketClient ?? throw new ArgumentNullException(nameof(eventSubWebsocketClient)); 27 | _eventSubWebsocketClient.WebsocketConnected += OnWebsocketConnected; 28 | _eventSubWebsocketClient.WebsocketDisconnected += OnWebsocketDisconnected; 29 | _eventSubWebsocketClient.WebsocketReconnected += OnWebsocketReconnected; 30 | _eventSubWebsocketClient.ErrorOccurred += OnErrorOccurred; 31 | 32 | _eventSubWebsocketClient.ChannelFollow += OnChannelFollow; 33 | 34 | // Get ClientId and ClientSecret by register an Application here: https://dev.twitch.tv/console/apps 35 | // https://dev.twitch.tv/docs/authentication/register-app/ 36 | _twitchApi.Settings.ClientId = "YOUR_APP_CLIENT_ID"; 37 | // Get Application Token with Client credentials grant flow. 38 | // https://dev.twitch.tv/docs/authentication/getting-tokens-oauth/#client-credentials-grant-flow 39 | _twitchApi.Settings.AccessToken = "YOUR_APPLICATION_ACCESS_TOKEN"; 40 | 41 | // You need the UserID for the User/Channel you want to get Events from. 42 | // You can use await _api.Helix.Users.GetUsersAsync() for that. 43 | _userId = "USER_ID"; 44 | } 45 | 46 | private async Task OnErrorOccurred(object sender, ErrorOccuredArgs e) 47 | { 48 | _logger.LogError($"Websocket {_eventSubWebsocketClient.SessionId} - Error occurred!"); 49 | } 50 | 51 | private async Task OnChannelFollow(object sender, ChannelFollowArgs e) 52 | { 53 | var eventData = e.Notification.Payload.Event; 54 | _logger.LogInformation($"{eventData.UserName} followed {eventData.BroadcasterUserName} at {eventData.FollowedAt}"); 55 | } 56 | 57 | public async Task StartAsync(CancellationToken cancellationToken) 58 | { 59 | await _eventSubWebsocketClient.ConnectAsync(); 60 | } 61 | 62 | public async Task StopAsync(CancellationToken cancellationToken) 63 | { 64 | await _eventSubWebsocketClient.DisconnectAsync(); 65 | } 66 | 67 | private async Task OnWebsocketConnected(object sender, WebsocketConnectedArgs e) 68 | { 69 | _logger.LogInformation($"Websocket {_eventSubWebsocketClient.SessionId} connected!"); 70 | 71 | if (!e.IsRequestedReconnect) 72 | { 73 | // subscribe to topics 74 | } 75 | } 76 | 77 | private async Task OnWebsocketDisconnected(object sender, EventArgs e) 78 | { 79 | _logger.LogError($"Websocket {_eventSubWebsocketClient.SessionId} disconnected!"); 80 | 81 | // Don't do this in production. You should implement a better reconnect strategy 82 | while (!await _eventSubWebsocketClient.ReconnectAsync()) 83 | { 84 | _logger.LogError("Websocket reconnect failed!"); 85 | await Task.Delay(1000); 86 | } 87 | } 88 | 89 | private async Task OnWebsocketReconnected(object sender, EventArgs e) 90 | { 91 | _logger.LogWarning($"Websocket {_eventSubWebsocketClient.SessionId} reconnected"); 92 | } 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /TwitchLib.EventSub.Websockets.Example.NetStandard/WebsocketHostedServiceWithoutDI.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Threading; 3 | using System.Threading.Tasks; 4 | using Microsoft.Extensions.Hosting; 5 | using Microsoft.Extensions.Logging; 6 | using TwitchLib.Api; 7 | using TwitchLib.EventSub.Websockets.Core.EventArgs; 8 | using TwitchLib.EventSub.Websockets.Core.EventArgs.Channel; 9 | 10 | namespace TwitchLib.EventSub.Websockets.Example.NetStandard 11 | { 12 | public class WebsocketHostedServiceWithoutDI : IHostedService 13 | { 14 | private readonly ILogger _logger; 15 | private readonly EventSubWebsocketClient _eventSubWebsocketClient; 16 | private readonly TwitchAPI _twitchApi = new(); 17 | private string _userId; 18 | 19 | public WebsocketHostedServiceWithoutDI(ILogger logger, ILoggerFactory loggerFactory) 20 | { 21 | _logger = logger; 22 | _eventSubWebsocketClient = new EventSubWebsocketClient(loggerFactory); 23 | 24 | _eventSubWebsocketClient.WebsocketConnected += OnWebsocketConnected; 25 | _eventSubWebsocketClient.WebsocketDisconnected += OnWebsocketDisconnected; 26 | _eventSubWebsocketClient.WebsocketReconnected += OnWebsocketReconnected; 27 | _eventSubWebsocketClient.ErrorOccurred += OnErrorOccurred; 28 | 29 | _eventSubWebsocketClient.ChannelFollow += OnChannelFollow; 30 | } 31 | 32 | public async Task StartAsync(CancellationToken cancellationToken) 33 | { 34 | await _eventSubWebsocketClient.ConnectAsync(); 35 | } 36 | 37 | public async Task StopAsync(CancellationToken cancellationToken) 38 | { 39 | await _eventSubWebsocketClient.DisconnectAsync(); 40 | } 41 | 42 | private async Task OnErrorOccurred(object sender, ErrorOccuredArgs e) 43 | { 44 | _logger.LogError($"Websocket {_eventSubWebsocketClient.SessionId} - Error occurred!"); 45 | } 46 | 47 | private async Task OnChannelFollow(object sender, ChannelFollowArgs e) 48 | { 49 | var eventData = e.Notification.Payload.Event; 50 | _logger.LogInformation($"{eventData.UserName} followed {eventData.BroadcasterUserName} at {eventData.FollowedAt}"); 51 | } 52 | 53 | private async Task OnWebsocketConnected(object sender, WebsocketConnectedArgs e) 54 | { 55 | _logger.LogInformation($"Websocket {_eventSubWebsocketClient.SessionId} connected!"); 56 | 57 | if (!e.IsRequestedReconnect) 58 | { 59 | // subscribe to topics 60 | // Get ClientId and ClientSecret by register an Application here: https://dev.twitch.tv/console/apps 61 | // https://dev.twitch.tv/docs/authentication/register-app/ 62 | _twitchApi.Settings.ClientId = "YOUR_APP_CLIENT_ID"; 63 | // Get Application Token with Client credentials grant flow. 64 | // https://dev.twitch.tv/docs/authentication/getting-tokens-oauth/#client-credentials-grant-flow 65 | _twitchApi.Settings.AccessToken = "YOUR_APPLICATION_ACCESS_TOKEN"; 66 | 67 | // You need the UserID for the User/Channel you want to get Events from. 68 | // You can use await _api.Helix.Users.GetUsersAsync() for that. 69 | _userId = "USER_ID"; 70 | } 71 | } 72 | 73 | private async Task OnWebsocketDisconnected(object sender, EventArgs e) 74 | { 75 | _logger.LogError($"Websocket {_eventSubWebsocketClient.SessionId} disconnected!"); 76 | 77 | // Don't do this in production. You should implement a better reconnect strategy 78 | while (!await _eventSubWebsocketClient.ReconnectAsync()) 79 | { 80 | _logger.LogError("Websocket reconnect failed!"); 81 | await Task.Delay(1000); 82 | } 83 | } 84 | 85 | private async Task OnWebsocketReconnected(object sender, EventArgs e) 86 | { 87 | _logger.LogWarning($"Websocket {_eventSubWebsocketClient.SessionId} reconnected"); 88 | } 89 | } 90 | } -------------------------------------------------------------------------------- /TwitchLib.EventSub.Websockets.Example.NetStandard/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | 3 | } 4 | -------------------------------------------------------------------------------- /TwitchLib.EventSub.Websockets.Example/Program.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.Extensions.DependencyInjection; 2 | using Microsoft.Extensions.Hosting; 3 | using TwitchLib.EventSub.Websockets.Example; 4 | using TwitchLib.EventSub.Websockets.Extensions; 5 | 6 | var builder = Host.CreateApplicationBuilder(args); 7 | 8 | //Add services to the container. 9 | builder.Services.AddLogging(); 10 | builder.Services.AddTwitchLibEventSubWebsockets(); 11 | builder.Services.AddHostedService(); 12 | 13 | var app = builder.Build(); 14 | 15 | app.Run(); 16 | 17 | -------------------------------------------------------------------------------- /TwitchLib.EventSub.Websockets.Example/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "profiles": { 3 | "TwitchLib.EventSub.Websockets.Test": { 4 | "commandName": "Project", 5 | "dotnetRunMessages": "true", 6 | "environmentVariables": { 7 | "DOTNET_ENVIRONMENT": "Development" 8 | } 9 | } 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /TwitchLib.EventSub.Websockets.Example/TwitchLib.EventSub.Websockets.Example.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net8.0 5 | disable 6 | disable 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /TwitchLib.EventSub.Websockets.Example/WebsocketHostedService.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.Extensions.Hosting; 2 | using Microsoft.Extensions.Logging; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Threading; 6 | using System.Threading.Tasks; 7 | using TwitchLib.Api; 8 | using TwitchLib.Api.Core.Enums; 9 | using TwitchLib.EventSub.Websockets.Core.EventArgs; 10 | using TwitchLib.EventSub.Websockets.Core.EventArgs.Channel; 11 | 12 | namespace TwitchLib.EventSub.Websockets.Example 13 | { 14 | public class WebsocketHostedService : IHostedService 15 | { 16 | private readonly ILogger _logger; 17 | private readonly EventSubWebsocketClient _eventSubWebsocketClient; 18 | private readonly TwitchAPI _twitchApi = new(); 19 | private string _userId; 20 | 21 | public WebsocketHostedService(ILogger logger, EventSubWebsocketClient eventSubWebsocketClient) 22 | { 23 | _logger = logger ?? throw new ArgumentNullException(nameof(logger)); 24 | 25 | _eventSubWebsocketClient = eventSubWebsocketClient ?? throw new ArgumentNullException(nameof(eventSubWebsocketClient)); 26 | _eventSubWebsocketClient.WebsocketConnected += OnWebsocketConnected; 27 | _eventSubWebsocketClient.WebsocketDisconnected += OnWebsocketDisconnected; 28 | _eventSubWebsocketClient.WebsocketReconnected += OnWebsocketReconnected; 29 | _eventSubWebsocketClient.ErrorOccurred += OnErrorOccurred; 30 | 31 | _eventSubWebsocketClient.ChannelFollow += OnChannelFollow; 32 | 33 | // Get ClientId and ClientSecret by register an Application here: https://dev.twitch.tv/console/apps 34 | // https://dev.twitch.tv/docs/authentication/register-app/ 35 | _twitchApi.Settings.ClientId = "YOUR_APP_CLIENT_ID"; 36 | // Get Application Token with Client credentials grant flow. 37 | // https://dev.twitch.tv/docs/authentication/getting-tokens-oauth/#client-credentials-grant-flow 38 | _twitchApi.Settings.AccessToken = "YOUR_APPLICATION_ACCESS_TOKEN"; 39 | 40 | // You need the UserID for the User/Channel you want to get Events from. 41 | // You can use await _api.Helix.Users.GetUsersAsync() for that. 42 | _userId = "USER_ID"; 43 | } 44 | 45 | private async Task OnErrorOccurred(object sender, ErrorOccuredArgs e) 46 | { 47 | _logger.LogError($"Websocket {_eventSubWebsocketClient.SessionId} - Error occurred!"); 48 | } 49 | 50 | private async Task OnChannelFollow(object sender, ChannelFollowArgs e) 51 | { 52 | var eventData = e.Notification.Payload.Event; 53 | _logger.LogInformation($"{eventData.UserName} followed {eventData.BroadcasterUserName} at {eventData.FollowedAt}"); 54 | } 55 | 56 | public async Task StartAsync(CancellationToken cancellationToken) 57 | { 58 | await _eventSubWebsocketClient.ConnectAsync(); 59 | } 60 | 61 | public async Task StopAsync(CancellationToken cancellationToken) 62 | { 63 | await _eventSubWebsocketClient.DisconnectAsync(); 64 | } 65 | 66 | private async Task OnWebsocketConnected(object sender, WebsocketConnectedArgs e) 67 | { 68 | _logger.LogInformation($"Websocket {_eventSubWebsocketClient.SessionId} connected!"); 69 | 70 | if (!e.IsRequestedReconnect) 71 | { 72 | // subscribe to topics 73 | // create condition Dictionary 74 | // You need BOTH broadcaster and moderator values or EventSub returns an Error! 75 | var condition = new Dictionary { { "broadcaster_user_id", _userId }, {"moderator_user_id", _userId} }; 76 | // Create and send EventSubscription 77 | await _twitchApi.Helix.EventSub.CreateEventSubSubscriptionAsync("channel.follow", "2", condition, EventSubTransportMethod.Websocket, 78 | _eventSubWebsocketClient.SessionId, accessToken: "BROADCASTER_ACCESS_TOKEN_WITH_SCOPES"); 79 | // If you want to get Events for special Events you need to additionally add the AccessToken of the ChannelOwner to the request. 80 | // https://dev.twitch.tv/docs/eventsub/eventsub-subscription-types/ 81 | } 82 | } 83 | 84 | private async Task OnWebsocketDisconnected(object sender, EventArgs e) 85 | { 86 | _logger.LogError($"Websocket {_eventSubWebsocketClient.SessionId} disconnected!"); 87 | 88 | // Don't do this in production. You should implement a better reconnect strategy 89 | while (!await _eventSubWebsocketClient.ReconnectAsync()) 90 | { 91 | _logger.LogError("Websocket reconnect failed!"); 92 | await Task.Delay(1000); 93 | } 94 | } 95 | 96 | private async Task OnWebsocketReconnected(object sender, EventArgs e) 97 | { 98 | _logger.LogWarning($"Websocket {_eventSubWebsocketClient.SessionId} reconnected"); 99 | } 100 | } 101 | } 102 | -------------------------------------------------------------------------------- /TwitchLib.EventSub.Websockets.Example/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft": "Warning", 6 | "Microsoft.Hosting.Lifetime": "Information" 7 | } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /TwitchLib.EventSub.Websockets.Example/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | 3 | } 4 | -------------------------------------------------------------------------------- /TwitchLib.EventSub.Websockets.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 17 4 | VisualStudioVersion = 17.4.33020.496 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TwitchLib.EventSub.Websockets", "TwitchLib.EventSub.Websockets\TwitchLib.EventSub.Websockets.csproj", "{20D03DA8-D1D1-4499-B960-E85E8B7446F0}" 7 | EndProject 8 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TwitchLib.EventSub.Websockets.Example", "TwitchLib.EventSub.Websockets.Example\TwitchLib.EventSub.Websockets.Example.csproj", "{24842EDD-7841-4EEC-98DE-08E9ACBBFCBD}" 9 | EndProject 10 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TwitchLib.EventSub.Websockets.Example.NetStandard", "TwitchLib.EventSub.Websockets.Example.NetStandard\TwitchLib.EventSub.Websockets.Example.NetStandard.csproj", "{0168680F-D8C2-44E6-8666-6724FCED8398}" 11 | EndProject 12 | Global 13 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 14 | Debug|Any CPU = Debug|Any CPU 15 | Release|Any CPU = Release|Any CPU 16 | EndGlobalSection 17 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 18 | {20D03DA8-D1D1-4499-B960-E85E8B7446F0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 19 | {20D03DA8-D1D1-4499-B960-E85E8B7446F0}.Debug|Any CPU.Build.0 = Debug|Any CPU 20 | {20D03DA8-D1D1-4499-B960-E85E8B7446F0}.Release|Any CPU.ActiveCfg = Release|Any CPU 21 | {20D03DA8-D1D1-4499-B960-E85E8B7446F0}.Release|Any CPU.Build.0 = Release|Any CPU 22 | {24842EDD-7841-4EEC-98DE-08E9ACBBFCBD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 23 | {24842EDD-7841-4EEC-98DE-08E9ACBBFCBD}.Debug|Any CPU.Build.0 = Debug|Any CPU 24 | {24842EDD-7841-4EEC-98DE-08E9ACBBFCBD}.Release|Any CPU.ActiveCfg = Release|Any CPU 25 | {24842EDD-7841-4EEC-98DE-08E9ACBBFCBD}.Release|Any CPU.Build.0 = Release|Any CPU 26 | {0168680F-D8C2-44E6-8666-6724FCED8398}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 27 | {0168680F-D8C2-44E6-8666-6724FCED8398}.Debug|Any CPU.Build.0 = Debug|Any CPU 28 | {0168680F-D8C2-44E6-8666-6724FCED8398}.Release|Any CPU.ActiveCfg = Release|Any CPU 29 | {0168680F-D8C2-44E6-8666-6724FCED8398}.Release|Any CPU.Build.0 = Release|Any CPU 30 | EndGlobalSection 31 | GlobalSection(SolutionProperties) = preSolution 32 | HideSolutionNode = FALSE 33 | EndGlobalSection 34 | GlobalSection(ExtensibilityGlobals) = postSolution 35 | SolutionGuid = {90746E40-9F6E-4707-B859-5F213566FB99} 36 | EndGlobalSection 37 | EndGlobal 38 | -------------------------------------------------------------------------------- /TwitchLib.EventSub.Websockets/Client/WebsocketClient.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.Extensions.Logging; 2 | using System; 3 | using System.IO; 4 | using System.Net.WebSockets; 5 | using System.Text; 6 | using System.Threading; 7 | using System.Threading.Tasks; 8 | using TwitchLib.EventSub.Core; 9 | using TwitchLib.EventSub.Websockets.Core.EventArgs; 10 | using TwitchLib.EventSub.Websockets.Extensions; 11 | 12 | #if NET6_0_OR_GREATER 13 | using System.Buffers; 14 | #endif 15 | 16 | namespace TwitchLib.EventSub.Websockets.Client 17 | { 18 | /// 19 | /// Websocket client to connect to variable websocket servers 20 | /// 21 | public class WebsocketClient : IDisposable 22 | { 23 | /// 24 | /// Determines if the Client is still connected based on WebsocketState 25 | /// 26 | public bool IsConnected => _webSocket.State == WebSocketState.Open; 27 | /// 28 | /// Determines if the Client has encountered an unrecoverable issue based on WebsocketState 29 | /// 30 | public bool IsFaulted => _webSocket.CloseStatus != WebSocketCloseStatus.Empty && _webSocket.CloseStatus != WebSocketCloseStatus.NormalClosure; 31 | 32 | internal event AsyncEventHandler? OnDataReceived; 33 | internal event AsyncEventHandler? OnErrorOccurred; 34 | 35 | private ClientWebSocket _webSocket; 36 | private readonly ILogger? _logger; 37 | 38 | /// 39 | /// Constructor to create a new Websocket client with a logger 40 | /// 41 | /// Logger used by the websocket client to print various state info 42 | public WebsocketClient(ILogger? logger = null) 43 | { 44 | _webSocket = new ClientWebSocket(); 45 | _logger = logger; 46 | } 47 | 48 | /// 49 | /// Connects the websocket client to a given Websocket Server 50 | /// 51 | /// Websocket Server URL to connect to 52 | /// true: if the connection is already open or was successful false: if the connection failed to be established 53 | public async Task ConnectAsync(Uri url) 54 | { 55 | try 56 | { 57 | if (_webSocket.State is WebSocketState.Open or WebSocketState.Connecting) 58 | return true; 59 | if (_webSocket.State is WebSocketState.Closed) //after a socken is closed it cannot be reopened 60 | _webSocket = new(); 61 | 62 | await _webSocket.ConnectAsync(url, CancellationToken.None); 63 | 64 | #pragma warning disable 4014 65 | Task.Run(async () => await ProcessDataAsync()); 66 | #pragma warning restore 4014 67 | 68 | return IsConnected; 69 | } 70 | catch (Exception ex) 71 | { 72 | OnErrorOccurred?.Invoke(this, new ErrorOccuredArgs { Exception = ex }); 73 | return false; 74 | } 75 | } 76 | 77 | /// 78 | /// Disconnect the Websocket client from its currently connected server 79 | /// 80 | /// true: if the disconnect was successful without errors false: if the client encountered an issue during the disconnect 81 | public async Task DisconnectAsync() 82 | { 83 | try 84 | { 85 | if (_webSocket.State is WebSocketState.Open or WebSocketState.Connecting) 86 | await _webSocket.CloseAsync(WebSocketCloseStatus.NormalClosure, string.Empty, CancellationToken.None); 87 | 88 | return true; 89 | } 90 | catch (Exception ex) 91 | { 92 | OnErrorOccurred?.Invoke(this, new ErrorOccuredArgs { Exception = ex }); 93 | return false; 94 | } 95 | } 96 | 97 | /// 98 | /// Background operation to process incoming data via the websocket 99 | /// 100 | /// Task representing the background operation 101 | /// 102 | private async Task ProcessDataAsync() 103 | { 104 | const int bufferLength = 4096; 105 | #if NETSTANDARD2_0 106 | var buffer = new ArraySegment(new byte[bufferLength]); 107 | #else 108 | var buffer = new Memory(new byte[bufferLength]); 109 | #endif 110 | var store = new byte[4096]; 111 | var payloadSize = 0; 112 | 113 | while (IsConnected) 114 | { 115 | try 116 | { 117 | #if NETSTANDARD2_0 118 | WebSocketReceiveResult receiveResult; 119 | #else 120 | ValueWebSocketReceiveResult receiveResult; 121 | #endif 122 | do 123 | { 124 | receiveResult = await _webSocket.ReceiveAsync(buffer, CancellationToken.None); 125 | 126 | if (payloadSize + receiveResult.Count >= store.Length) 127 | { 128 | var newStoreLength = store.Length + Math.Max(bufferLength, receiveResult.Count); 129 | var newStore = new byte[newStoreLength]; 130 | store.AsSpan().CopyTo(newStore); 131 | store = newStore; 132 | } 133 | 134 | buffer 135 | #if NETSTANDARD2_0 136 | .Array.AsSpan(0, receiveResult.Count) 137 | #else 138 | .Span.Slice(0, receiveResult.Count) 139 | #endif 140 | .CopyTo(store.AsSpan(payloadSize)); 141 | 142 | payloadSize += receiveResult.Count; 143 | } while (!receiveResult.EndOfMessage); 144 | 145 | switch (receiveResult.MessageType) 146 | { 147 | case WebSocketMessageType.Text: 148 | if (payloadSize == 0) 149 | continue; 150 | 151 | OnDataReceived?.Invoke(this, new DataReceivedArgs { Bytes = store.AsSpan(0, payloadSize).ToArray() }); 152 | payloadSize = 0; 153 | break; 154 | case WebSocketMessageType.Binary: 155 | break; 156 | case WebSocketMessageType.Close: 157 | _logger?.LogWebsocketClosed((WebSocketCloseStatus)_webSocket.CloseStatus!, _webSocket.CloseStatusDescription!); 158 | break; 159 | default: 160 | throw new ArgumentOutOfRangeException(); 161 | } 162 | } 163 | catch (Exception ex) 164 | { 165 | OnErrorOccurred?.Invoke(this, new ErrorOccuredArgs { Exception = ex }); 166 | break; 167 | } 168 | } 169 | } 170 | 171 | /// 172 | /// Cleanup of any unused resources as per IDisposable guidelines 173 | /// 174 | public void Dispose() 175 | { 176 | GC.SuppressFinalize(this); 177 | _webSocket.Dispose(); 178 | } 179 | } 180 | } -------------------------------------------------------------------------------- /TwitchLib.EventSub.Websockets/Core/EventArgs/Channel/ChannelAdBreakBeginArgs.cs: -------------------------------------------------------------------------------- 1 | using TwitchLib.EventSub.Core.SubscriptionTypes.Channel; 2 | using TwitchLib.EventSub.Websockets.Core.Models; 3 | namespace TwitchLib.EventSub.Websockets.Core.EventArgs.Channel 4 | { 5 | public class ChannelAdBreakBeginArgs : TwitchLibEventSubEventArgs> 6 | { 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /TwitchLib.EventSub.Websockets/Core/EventArgs/Channel/ChannelBanArgs.cs: -------------------------------------------------------------------------------- 1 | using TwitchLib.EventSub.Core.SubscriptionTypes.Channel; 2 | using TwitchLib.EventSub.Websockets.Core.Models; 3 | 4 | namespace TwitchLib.EventSub.Websockets.Core.EventArgs.Channel 5 | { 6 | public class ChannelBanArgs : TwitchLibEventSubEventArgs> 7 | { } 8 | } -------------------------------------------------------------------------------- /TwitchLib.EventSub.Websockets/Core/EventArgs/Channel/ChannelCharityCampaignDonateArgs.cs: -------------------------------------------------------------------------------- 1 | using TwitchLib.EventSub.Core.SubscriptionTypes.Channel; 2 | using TwitchLib.EventSub.Websockets.Core.Models; 3 | 4 | namespace TwitchLib.EventSub.Websockets.Core.EventArgs.Channel 5 | { 6 | public class ChannelCharityCampaignDonateArgs : TwitchLibEventSubEventArgs> 7 | { 8 | 9 | } 10 | } -------------------------------------------------------------------------------- /TwitchLib.EventSub.Websockets/Core/EventArgs/Channel/ChannelCharityCampaignProgressArgs.cs: -------------------------------------------------------------------------------- 1 | using TwitchLib.EventSub.Core.SubscriptionTypes.Channel; 2 | using TwitchLib.EventSub.Websockets.Core.Models; 3 | 4 | namespace TwitchLib.EventSub.Websockets.Core.EventArgs.Channel 5 | { 6 | public class ChannelCharityCampaignProgressArgs : TwitchLibEventSubEventArgs> 7 | { 8 | 9 | } 10 | } -------------------------------------------------------------------------------- /TwitchLib.EventSub.Websockets/Core/EventArgs/Channel/ChannelCharityCampaignStartArgs.cs: -------------------------------------------------------------------------------- 1 | using TwitchLib.EventSub.Core.SubscriptionTypes.Channel; 2 | using TwitchLib.EventSub.Websockets.Core.Models; 3 | 4 | namespace TwitchLib.EventSub.Websockets.Core.EventArgs.Channel 5 | { 6 | public class ChannelCharityCampaignStartArgs : TwitchLibEventSubEventArgs> 7 | { } 8 | } 9 | 10 | -------------------------------------------------------------------------------- /TwitchLib.EventSub.Websockets/Core/EventArgs/Channel/ChannelCharityCampaignStopArgs.cs: -------------------------------------------------------------------------------- 1 | using TwitchLib.EventSub.Core.SubscriptionTypes.Channel; 2 | using TwitchLib.EventSub.Websockets.Core.Models; 3 | 4 | namespace TwitchLib.EventSub.Websockets.Core.EventArgs.Channel 5 | { 6 | public class ChannelCharityCampaignStopArgs : TwitchLibEventSubEventArgs> 7 | { } 8 | } -------------------------------------------------------------------------------- /TwitchLib.EventSub.Websockets/Core/EventArgs/Channel/ChannelChatClearArgs.cs: -------------------------------------------------------------------------------- 1 | using TwitchLib.EventSub.Core.SubscriptionTypes.Channel; 2 | using TwitchLib.EventSub.Websockets.Core.Models; 3 | 4 | namespace TwitchLib.EventSub.Websockets.Core.EventArgs.Channel; 5 | 6 | public class ChannelChatClearArgs : TwitchLibEventSubEventArgs> 7 | { } 8 | -------------------------------------------------------------------------------- /TwitchLib.EventSub.Websockets/Core/EventArgs/Channel/ChannelChatClearUserMessagesArgs.cs: -------------------------------------------------------------------------------- 1 | using TwitchLib.EventSub.Core.SubscriptionTypes.Channel; 2 | using TwitchLib.EventSub.Websockets.Core.Models; 3 | 4 | namespace TwitchLib.EventSub.Websockets.Core.EventArgs.Channel; 5 | 6 | public class ChannelChatClearUserMessagesArgs : TwitchLibEventSubEventArgs> 7 | { } 8 | -------------------------------------------------------------------------------- /TwitchLib.EventSub.Websockets/Core/EventArgs/Channel/ChannelChatMessageArgs.cs: -------------------------------------------------------------------------------- 1 | using TwitchLib.EventSub.Core.SubscriptionTypes.Channel; 2 | using TwitchLib.EventSub.Websockets.Core.Models; 3 | 4 | namespace TwitchLib.EventSub.Websockets.Core.EventArgs.Channel 5 | { 6 | public class ChannelChatMessageArgs : TwitchLibEventSubEventArgs> 7 | { 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /TwitchLib.EventSub.Websockets/Core/EventArgs/Channel/ChannelChatMessageDeleteArgs.cs: -------------------------------------------------------------------------------- 1 | using TwitchLib.EventSub.Core.SubscriptionTypes.Channel; 2 | using TwitchLib.EventSub.Websockets.Core.Models; 3 | namespace TwitchLib.EventSub.Websockets.Core.EventArgs.Channel 4 | { 5 | public class ChannelChatMessageDeleteArgs : TwitchLibEventSubEventArgs> 6 | { 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /TwitchLib.EventSub.Websockets/Core/EventArgs/Channel/ChannelChatNotificationArgs.cs: -------------------------------------------------------------------------------- 1 | using TwitchLib.EventSub.Core.SubscriptionTypes.Channel; 2 | using TwitchLib.EventSub.Websockets.Core.Models; 3 | namespace TwitchLib.EventSub.Websockets.Core.EventArgs.Channel 4 | { 5 | public class ChannelChatNotificationArgs : TwitchLibEventSubEventArgs> 6 | { 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /TwitchLib.EventSub.Websockets/Core/EventArgs/Channel/ChannelCheerArgs.cs: -------------------------------------------------------------------------------- 1 | using TwitchLib.EventSub.Core.SubscriptionTypes.Channel; 2 | using TwitchLib.EventSub.Websockets.Core.Models; 3 | 4 | namespace TwitchLib.EventSub.Websockets.Core.EventArgs.Channel 5 | { 6 | public class ChannelCheerArgs : TwitchLibEventSubEventArgs> 7 | { } 8 | } -------------------------------------------------------------------------------- /TwitchLib.EventSub.Websockets/Core/EventArgs/Channel/ChannelFollowArgs.cs: -------------------------------------------------------------------------------- 1 | using TwitchLib.EventSub.Core.SubscriptionTypes.Channel; 2 | using TwitchLib.EventSub.Websockets.Core.Models; 3 | 4 | namespace TwitchLib.EventSub.Websockets.Core.EventArgs.Channel 5 | { 6 | public class ChannelFollowArgs : TwitchLibEventSubEventArgs> 7 | { } 8 | } -------------------------------------------------------------------------------- /TwitchLib.EventSub.Websockets/Core/EventArgs/Channel/ChannelGoalBeginArgs.cs: -------------------------------------------------------------------------------- 1 | using TwitchLib.EventSub.Core.SubscriptionTypes.Channel; 2 | using TwitchLib.EventSub.Websockets.Core.Models; 3 | 4 | namespace TwitchLib.EventSub.Websockets.Core.EventArgs.Channel 5 | { 6 | public class ChannelGoalBeginArgs : TwitchLibEventSubEventArgs> 7 | { } 8 | } -------------------------------------------------------------------------------- /TwitchLib.EventSub.Websockets/Core/EventArgs/Channel/ChannelGoalEndArgs.cs: -------------------------------------------------------------------------------- 1 | using TwitchLib.EventSub.Core.SubscriptionTypes.Channel; 2 | using TwitchLib.EventSub.Websockets.Core.Models; 3 | 4 | namespace TwitchLib.EventSub.Websockets.Core.EventArgs.Channel 5 | { 6 | public class ChannelGoalEndArgs : TwitchLibEventSubEventArgs> 7 | { } 8 | } -------------------------------------------------------------------------------- /TwitchLib.EventSub.Websockets/Core/EventArgs/Channel/ChannelGoalProgressArgs.cs: -------------------------------------------------------------------------------- 1 | using TwitchLib.EventSub.Core.SubscriptionTypes.Channel; 2 | using TwitchLib.EventSub.Websockets.Core.Models; 3 | 4 | namespace TwitchLib.EventSub.Websockets.Core.EventArgs.Channel 5 | { 6 | public class ChannelGoalProgressArgs : TwitchLibEventSubEventArgs> 7 | { } 8 | } -------------------------------------------------------------------------------- /TwitchLib.EventSub.Websockets/Core/EventArgs/Channel/ChannelGuestStarGuestUpdateArgs.cs: -------------------------------------------------------------------------------- 1 | using TwitchLib.EventSub.Core.SubscriptionTypes.Channel; 2 | using TwitchLib.EventSub.Websockets.Core.Models; 3 | 4 | namespace TwitchLib.EventSub.Websockets.Core.EventArgs.Channel 5 | { 6 | public class ChannelGuestStarGuestUpdateArgs : TwitchLibEventSubEventArgs> 7 | { } 8 | } -------------------------------------------------------------------------------- /TwitchLib.EventSub.Websockets/Core/EventArgs/Channel/ChannelGuestStarSessionBeginArgs.cs: -------------------------------------------------------------------------------- 1 | using TwitchLib.EventSub.Core.SubscriptionTypes.Channel; 2 | using TwitchLib.EventSub.Websockets.Core.Models; 3 | 4 | namespace TwitchLib.EventSub.Websockets.Core.EventArgs.Channel 5 | { 6 | public class ChannelGuestStarSessionBeginArgs : TwitchLibEventSubEventArgs> 7 | { } 8 | } -------------------------------------------------------------------------------- /TwitchLib.EventSub.Websockets/Core/EventArgs/Channel/ChannelGuestStarSessionEndArgs.cs: -------------------------------------------------------------------------------- 1 | using TwitchLib.EventSub.Core.SubscriptionTypes.Channel; 2 | using TwitchLib.EventSub.Websockets.Core.Models; 3 | 4 | namespace TwitchLib.EventSub.Websockets.Core.EventArgs.Channel 5 | { 6 | public class ChannelGuestStarSessionEndArgs : TwitchLibEventSubEventArgs> 7 | { } 8 | } -------------------------------------------------------------------------------- /TwitchLib.EventSub.Websockets/Core/EventArgs/Channel/ChannelGuestStarSettingsUpdateArgs.cs: -------------------------------------------------------------------------------- 1 | using TwitchLib.EventSub.Core.SubscriptionTypes.Channel; 2 | using TwitchLib.EventSub.Websockets.Core.Models; 3 | 4 | namespace TwitchLib.EventSub.Websockets.Core.EventArgs.Channel 5 | { 6 | public class ChannelGuestStarSettingsUpdateArgs : TwitchLibEventSubEventArgs> 7 | { } 8 | } -------------------------------------------------------------------------------- /TwitchLib.EventSub.Websockets/Core/EventArgs/Channel/ChannelGuestStarSlotUpdateArgs.cs: -------------------------------------------------------------------------------- 1 | using TwitchLib.EventSub.Core.SubscriptionTypes.Channel; 2 | using TwitchLib.EventSub.Websockets.Core.Models; 3 | 4 | namespace TwitchLib.EventSub.Websockets.Core.EventArgs.Channel 5 | { 6 | public class ChannelGuestStarSlotUpdateArgs : TwitchLibEventSubEventArgs> 7 | { } 8 | } -------------------------------------------------------------------------------- /TwitchLib.EventSub.Websockets/Core/EventArgs/Channel/ChannelHypeTrainBeginArgs.cs: -------------------------------------------------------------------------------- 1 | using TwitchLib.EventSub.Core.SubscriptionTypes.Channel; 2 | using TwitchLib.EventSub.Websockets.Core.Models; 3 | 4 | namespace TwitchLib.EventSub.Websockets.Core.EventArgs.Channel 5 | { 6 | public class ChannelHypeTrainBeginArgs : TwitchLibEventSubEventArgs> 7 | { } 8 | } -------------------------------------------------------------------------------- /TwitchLib.EventSub.Websockets/Core/EventArgs/Channel/ChannelHypeTrainEndArgs.cs: -------------------------------------------------------------------------------- 1 | using TwitchLib.EventSub.Core.SubscriptionTypes.Channel; 2 | using TwitchLib.EventSub.Websockets.Core.Models; 3 | 4 | namespace TwitchLib.EventSub.Websockets.Core.EventArgs.Channel 5 | { 6 | public class ChannelHypeTrainEndArgs : TwitchLibEventSubEventArgs> 7 | { } 8 | } -------------------------------------------------------------------------------- /TwitchLib.EventSub.Websockets/Core/EventArgs/Channel/ChannelHypeTrainProgressArgs.cs: -------------------------------------------------------------------------------- 1 | using TwitchLib.EventSub.Core.SubscriptionTypes.Channel; 2 | using TwitchLib.EventSub.Websockets.Core.Models; 3 | 4 | namespace TwitchLib.EventSub.Websockets.Core.EventArgs.Channel 5 | { 6 | public class ChannelHypeTrainProgressArgs : TwitchLibEventSubEventArgs> 7 | { } 8 | } -------------------------------------------------------------------------------- /TwitchLib.EventSub.Websockets/Core/EventArgs/Channel/ChannelModeratorArgs.cs: -------------------------------------------------------------------------------- 1 | using TwitchLib.EventSub.Core.SubscriptionTypes.Channel; 2 | using TwitchLib.EventSub.Websockets.Core.Models; 3 | 4 | namespace TwitchLib.EventSub.Websockets.Core.EventArgs.Channel 5 | { 6 | public class ChannelModeratorArgs : TwitchLibEventSubEventArgs> 7 | { } 8 | } -------------------------------------------------------------------------------- /TwitchLib.EventSub.Websockets/Core/EventArgs/Channel/ChannelPointsAutomaticRewardRedemptionArgs.cs: -------------------------------------------------------------------------------- 1 | using TwitchLib.EventSub.Core.SubscriptionTypes.Channel; 2 | using TwitchLib.EventSub.Websockets.Core.Models; 3 | 4 | namespace TwitchLib.EventSub.Websockets.Core.EventArgs.Channel; 5 | 6 | public class ChannelPointsAutomaticRewardRedemptionArgs : TwitchLibEventSubEventArgs> 7 | { 8 | } 9 | -------------------------------------------------------------------------------- /TwitchLib.EventSub.Websockets/Core/EventArgs/Channel/ChannelPointsCustomRewardArgs.cs: -------------------------------------------------------------------------------- 1 | using TwitchLib.EventSub.Core.SubscriptionTypes.Channel; 2 | using TwitchLib.EventSub.Websockets.Core.Models; 3 | 4 | namespace TwitchLib.EventSub.Websockets.Core.EventArgs.Channel 5 | { 6 | public class ChannelPointsCustomRewardArgs : TwitchLibEventSubEventArgs> 7 | { } 8 | } -------------------------------------------------------------------------------- /TwitchLib.EventSub.Websockets/Core/EventArgs/Channel/ChannelPointsCustomRewardRedemptionArgs.cs: -------------------------------------------------------------------------------- 1 | using TwitchLib.EventSub.Core.SubscriptionTypes.Channel; 2 | using TwitchLib.EventSub.Websockets.Core.Models; 3 | 4 | namespace TwitchLib.EventSub.Websockets.Core.EventArgs.Channel 5 | { 6 | public class ChannelPointsCustomRewardRedemptionArgs : TwitchLibEventSubEventArgs> 7 | { } 8 | } -------------------------------------------------------------------------------- /TwitchLib.EventSub.Websockets/Core/EventArgs/Channel/ChannelPollBeginArgs.cs: -------------------------------------------------------------------------------- 1 | using TwitchLib.EventSub.Core.SubscriptionTypes.Channel; 2 | using TwitchLib.EventSub.Websockets.Core.Models; 3 | 4 | namespace TwitchLib.EventSub.Websockets.Core.EventArgs.Channel 5 | { 6 | public class ChannelPollBeginArgs : TwitchLibEventSubEventArgs> 7 | { } 8 | } -------------------------------------------------------------------------------- /TwitchLib.EventSub.Websockets/Core/EventArgs/Channel/ChannelPollEndArgs.cs: -------------------------------------------------------------------------------- 1 | using TwitchLib.EventSub.Core.SubscriptionTypes.Channel; 2 | using TwitchLib.EventSub.Websockets.Core.Models; 3 | 4 | namespace TwitchLib.EventSub.Websockets.Core.EventArgs.Channel 5 | { 6 | public class ChannelPollEndArgs : TwitchLibEventSubEventArgs> 7 | { } 8 | } -------------------------------------------------------------------------------- /TwitchLib.EventSub.Websockets/Core/EventArgs/Channel/ChannelPollProgressArgs.cs: -------------------------------------------------------------------------------- 1 | using TwitchLib.EventSub.Core.SubscriptionTypes.Channel; 2 | using TwitchLib.EventSub.Websockets.Core.Models; 3 | 4 | namespace TwitchLib.EventSub.Websockets.Core.EventArgs.Channel 5 | { 6 | public class ChannelPollProgressArgs : TwitchLibEventSubEventArgs> 7 | { } 8 | } -------------------------------------------------------------------------------- /TwitchLib.EventSub.Websockets/Core/EventArgs/Channel/ChannelPredictionBeginArgs.cs: -------------------------------------------------------------------------------- 1 | using TwitchLib.EventSub.Core.SubscriptionTypes.Channel; 2 | using TwitchLib.EventSub.Websockets.Core.Models; 3 | 4 | namespace TwitchLib.EventSub.Websockets.Core.EventArgs.Channel 5 | { 6 | public class ChannelPredictionBeginArgs : TwitchLibEventSubEventArgs> 7 | { } 8 | } -------------------------------------------------------------------------------- /TwitchLib.EventSub.Websockets/Core/EventArgs/Channel/ChannelPredictionEndArgs.cs: -------------------------------------------------------------------------------- 1 | using TwitchLib.EventSub.Core.SubscriptionTypes.Channel; 2 | using TwitchLib.EventSub.Websockets.Core.Models; 3 | 4 | namespace TwitchLib.EventSub.Websockets.Core.EventArgs.Channel 5 | { 6 | public class ChannelPredictionEndArgs : TwitchLibEventSubEventArgs> 7 | { } 8 | } -------------------------------------------------------------------------------- /TwitchLib.EventSub.Websockets/Core/EventArgs/Channel/ChannelPredictionLockArgs.cs: -------------------------------------------------------------------------------- 1 | using TwitchLib.EventSub.Core.SubscriptionTypes.Channel; 2 | using TwitchLib.EventSub.Websockets.Core.Models; 3 | 4 | namespace TwitchLib.EventSub.Websockets.Core.EventArgs.Channel 5 | { 6 | public class ChannelPredictionLockArgs : TwitchLibEventSubEventArgs> 7 | { } 8 | } -------------------------------------------------------------------------------- /TwitchLib.EventSub.Websockets/Core/EventArgs/Channel/ChannelPredictionProgressArgs.cs: -------------------------------------------------------------------------------- 1 | using TwitchLib.EventSub.Core.SubscriptionTypes.Channel; 2 | using TwitchLib.EventSub.Websockets.Core.Models; 3 | 4 | namespace TwitchLib.EventSub.Websockets.Core.EventArgs.Channel 5 | { 6 | public class ChannelPredictionProgressArgs : TwitchLibEventSubEventArgs> 7 | { } 8 | } -------------------------------------------------------------------------------- /TwitchLib.EventSub.Websockets/Core/EventArgs/Channel/ChannelRaidArgs.cs: -------------------------------------------------------------------------------- 1 | using TwitchLib.EventSub.Core.SubscriptionTypes.Channel; 2 | using TwitchLib.EventSub.Websockets.Core.Models; 3 | 4 | namespace TwitchLib.EventSub.Websockets.Core.EventArgs.Channel 5 | { 6 | public class ChannelRaidArgs : TwitchLibEventSubEventArgs> 7 | { } 8 | } -------------------------------------------------------------------------------- /TwitchLib.EventSub.Websockets/Core/EventArgs/Channel/ChannelSharedChatSessionBeginArgs.cs: -------------------------------------------------------------------------------- 1 | using TwitchLib.EventSub.Core.SubscriptionTypes.Channel; 2 | using TwitchLib.EventSub.Websockets.Core.Models; 3 | 4 | namespace TwitchLib.EventSub.Websockets.Core.EventArgs.Channel 5 | { 6 | public class ChannelSharedChatSessionBeginArgs : TwitchLibEventSubEventArgs> 7 | { } 8 | } -------------------------------------------------------------------------------- /TwitchLib.EventSub.Websockets/Core/EventArgs/Channel/ChannelSharedChatSessionEndArgs.cs: -------------------------------------------------------------------------------- 1 | using TwitchLib.EventSub.Core.SubscriptionTypes.Channel; 2 | using TwitchLib.EventSub.Websockets.Core.Models; 3 | 4 | namespace TwitchLib.EventSub.Websockets.Core.EventArgs.Channel 5 | { 6 | public class ChannelSharedChatSessionEndArgs : TwitchLibEventSubEventArgs> 7 | { } 8 | } -------------------------------------------------------------------------------- /TwitchLib.EventSub.Websockets/Core/EventArgs/Channel/ChannelSharedChatSessionUpdateArgs.cs: -------------------------------------------------------------------------------- 1 | using TwitchLib.EventSub.Core.SubscriptionTypes.Channel; 2 | using TwitchLib.EventSub.Websockets.Core.Models; 3 | 4 | namespace TwitchLib.EventSub.Websockets.Core.EventArgs.Channel 5 | { 6 | public class ChannelSharedChatSessionUpdateArgs : TwitchLibEventSubEventArgs> 7 | { } 8 | } -------------------------------------------------------------------------------- /TwitchLib.EventSub.Websockets/Core/EventArgs/Channel/ChannelShieldModeBeginArgs.cs: -------------------------------------------------------------------------------- 1 | using TwitchLib.EventSub.Core.SubscriptionTypes.Channel; 2 | using TwitchLib.EventSub.Websockets.Core.Models; 3 | 4 | namespace TwitchLib.EventSub.Websockets.Core.EventArgs.Channel 5 | { 6 | public class ChannelShieldModeBeginArgs : TwitchLibEventSubEventArgs> 7 | { } 8 | } -------------------------------------------------------------------------------- /TwitchLib.EventSub.Websockets/Core/EventArgs/Channel/ChannelShieldModeEndArgs.cs: -------------------------------------------------------------------------------- 1 | using TwitchLib.EventSub.Core.SubscriptionTypes.Channel; 2 | using TwitchLib.EventSub.Websockets.Core.Models; 3 | 4 | namespace TwitchLib.EventSub.Websockets.Core.EventArgs.Channel 5 | { 6 | public class ChannelShieldModeEndArgs : TwitchLibEventSubEventArgs> 7 | { } 8 | } -------------------------------------------------------------------------------- /TwitchLib.EventSub.Websockets/Core/EventArgs/Channel/ChannelShoutoutCreateArgs.cs: -------------------------------------------------------------------------------- 1 | using TwitchLib.EventSub.Core.SubscriptionTypes.Channel; 2 | using TwitchLib.EventSub.Websockets.Core.Models; 3 | 4 | namespace TwitchLib.EventSub.Websockets.Core.EventArgs.Channel 5 | { 6 | public class ChannelShoutoutCreateArgs : TwitchLibEventSubEventArgs> 7 | { } 8 | } -------------------------------------------------------------------------------- /TwitchLib.EventSub.Websockets/Core/EventArgs/Channel/ChannelShoutoutReceiveArgs.cs: -------------------------------------------------------------------------------- 1 | using TwitchLib.EventSub.Core.SubscriptionTypes.Channel; 2 | using TwitchLib.EventSub.Websockets.Core.Models; 3 | 4 | namespace TwitchLib.EventSub.Websockets.Core.EventArgs.Channel 5 | { 6 | public class ChannelShoutoutReceiveArgs : TwitchLibEventSubEventArgs> 7 | { } 8 | } -------------------------------------------------------------------------------- /TwitchLib.EventSub.Websockets/Core/EventArgs/Channel/ChannelSubscribeArgs.cs: -------------------------------------------------------------------------------- 1 | using TwitchLib.EventSub.Core.SubscriptionTypes.Channel; 2 | using TwitchLib.EventSub.Websockets.Core.Models; 3 | 4 | namespace TwitchLib.EventSub.Websockets.Core.EventArgs.Channel 5 | { 6 | public class ChannelSubscribeArgs : TwitchLibEventSubEventArgs> 7 | { } 8 | } -------------------------------------------------------------------------------- /TwitchLib.EventSub.Websockets/Core/EventArgs/Channel/ChannelSubscriptionEndArgs.cs: -------------------------------------------------------------------------------- 1 | using TwitchLib.EventSub.Core.SubscriptionTypes.Channel; 2 | using TwitchLib.EventSub.Websockets.Core.Models; 3 | 4 | namespace TwitchLib.EventSub.Websockets.Core.EventArgs.Channel 5 | { 6 | public class ChannelSubscriptionEndArgs : TwitchLibEventSubEventArgs> 7 | { } 8 | } -------------------------------------------------------------------------------- /TwitchLib.EventSub.Websockets/Core/EventArgs/Channel/ChannelSubscriptionGiftArgs.cs: -------------------------------------------------------------------------------- 1 | using TwitchLib.EventSub.Core.SubscriptionTypes.Channel; 2 | using TwitchLib.EventSub.Websockets.Core.Models; 3 | 4 | namespace TwitchLib.EventSub.Websockets.Core.EventArgs.Channel 5 | { 6 | public class ChannelSubscriptionGiftArgs : TwitchLibEventSubEventArgs> 7 | { } 8 | } -------------------------------------------------------------------------------- /TwitchLib.EventSub.Websockets/Core/EventArgs/Channel/ChannelSubscriptionMessageArgs.cs: -------------------------------------------------------------------------------- 1 | using TwitchLib.EventSub.Core.SubscriptionTypes.Channel; 2 | using TwitchLib.EventSub.Websockets.Core.Models; 3 | 4 | namespace TwitchLib.EventSub.Websockets.Core.EventArgs.Channel 5 | { 6 | public class ChannelSubscriptionMessageArgs : TwitchLibEventSubEventArgs> 7 | { } 8 | } -------------------------------------------------------------------------------- /TwitchLib.EventSub.Websockets/Core/EventArgs/Channel/ChannelSuspiciousUserMessageArgs.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using TwitchLib.EventSub.Core.SubscriptionTypes.Channel; 5 | using TwitchLib.EventSub.Websockets.Core.Models; 6 | 7 | namespace TwitchLib.EventSub.Websockets.Core.EventArgs.Channel 8 | { 9 | public class ChannelSuspiciousUserMessageArgs : TwitchLibEventSubEventArgs> 10 | { 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /TwitchLib.EventSub.Websockets/Core/EventArgs/Channel/ChannelSuspiciousUserUpdateArgs.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using TwitchLib.EventSub.Core.SubscriptionTypes.Channel; 5 | using TwitchLib.EventSub.Websockets.Core.Models; 6 | 7 | namespace TwitchLib.EventSub.Websockets.Core.EventArgs.Channel 8 | { 9 | public sealed class ChannelSuspiciousUserUpdateArgs : TwitchLibEventSubEventArgs> 10 | { 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /TwitchLib.EventSub.Websockets/Core/EventArgs/Channel/ChannelUnbanArgs.cs: -------------------------------------------------------------------------------- 1 | using TwitchLib.EventSub.Core.SubscriptionTypes.Channel; 2 | using TwitchLib.EventSub.Websockets.Core.Models; 3 | 4 | namespace TwitchLib.EventSub.Websockets.Core.EventArgs.Channel 5 | { 6 | public class ChannelUnbanArgs : TwitchLibEventSubEventArgs> 7 | { } 8 | } -------------------------------------------------------------------------------- /TwitchLib.EventSub.Websockets/Core/EventArgs/Channel/ChannelUnbanRequestCreateArgs.cs: -------------------------------------------------------------------------------- 1 | using TwitchLib.EventSub.Core.SubscriptionTypes.Channel; 2 | using TwitchLib.EventSub.Websockets.Core.Models; 3 | 4 | namespace TwitchLib.EventSub.Websockets.Core.EventArgs.Channel 5 | { 6 | public class ChannelUnbanRequestCreateArgs : TwitchLibEventSubEventArgs> 7 | { } 8 | } 9 | -------------------------------------------------------------------------------- /TwitchLib.EventSub.Websockets/Core/EventArgs/Channel/ChannelUnbanRequestResolveArgs.cs: -------------------------------------------------------------------------------- 1 | using TwitchLib.EventSub.Core.SubscriptionTypes.Channel; 2 | using TwitchLib.EventSub.Websockets.Core.Models; 3 | 4 | namespace TwitchLib.EventSub.Websockets.Core.EventArgs.Channel 5 | { 6 | public class ChannelUnbanRequestResolveArgs : TwitchLibEventSubEventArgs> 7 | { } 8 | } 9 | -------------------------------------------------------------------------------- /TwitchLib.EventSub.Websockets/Core/EventArgs/Channel/ChannelUpdateArgs.cs: -------------------------------------------------------------------------------- 1 | using TwitchLib.EventSub.Core.SubscriptionTypes.Channel; 2 | using TwitchLib.EventSub.Websockets.Core.Models; 3 | 4 | namespace TwitchLib.EventSub.Websockets.Core.EventArgs.Channel 5 | { 6 | public class ChannelUpdateArgs : TwitchLibEventSubEventArgs> 7 | { } 8 | } -------------------------------------------------------------------------------- /TwitchLib.EventSub.Websockets/Core/EventArgs/Channel/ChannelVipArgs.cs: -------------------------------------------------------------------------------- 1 | using TwitchLib.EventSub.Core.SubscriptionTypes.Channel; 2 | using TwitchLib.EventSub.Websockets.Core.Models; 3 | 4 | namespace TwitchLib.EventSub.Websockets.Core.EventArgs.Channel 5 | { 6 | public class ChannelVipArgs : TwitchLibEventSubEventArgs> 7 | { } 8 | } -------------------------------------------------------------------------------- /TwitchLib.EventSub.Websockets/Core/EventArgs/Channel/ChannelWarningAcknowledgeArgs.cs: -------------------------------------------------------------------------------- 1 | using TwitchLib.EventSub.Core.SubscriptionTypes.Channel; 2 | using TwitchLib.EventSub.Websockets.Core.Models; 3 | 4 | namespace TwitchLib.EventSub.Websockets.Core.EventArgs.Channel 5 | { 6 | public class ChannelWarningAcknowledgeArgs : TwitchLibEventSubEventArgs> 7 | { } 8 | } -------------------------------------------------------------------------------- /TwitchLib.EventSub.Websockets/Core/EventArgs/Channel/ChannelWarningSendArgs.cs: -------------------------------------------------------------------------------- 1 | using TwitchLib.EventSub.Core.SubscriptionTypes.Channel; 2 | using TwitchLib.EventSub.Websockets.Core.Models; 3 | 4 | namespace TwitchLib.EventSub.Websockets.Core.EventArgs.Channel 5 | { 6 | public class ChannelWarningSendArgs : TwitchLibEventSubEventArgs> 7 | { } 8 | } -------------------------------------------------------------------------------- /TwitchLib.EventSub.Websockets/Core/EventArgs/DataReceivedArgs.cs: -------------------------------------------------------------------------------- 1 | namespace TwitchLib.EventSub.Websockets.Core.EventArgs; 2 | 3 | internal class DataReceivedArgs : System.EventArgs 4 | { 5 | public byte[] Bytes { get; internal set; } 6 | } 7 | -------------------------------------------------------------------------------- /TwitchLib.EventSub.Websockets/Core/EventArgs/ErrorOccuredArgs.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace TwitchLib.EventSub.Websockets.Core.EventArgs 4 | { 5 | public class ErrorOccuredArgs : System.EventArgs 6 | { 7 | public Exception Exception { get; internal set; } 8 | public string Message { get; internal set; } 9 | } 10 | } -------------------------------------------------------------------------------- /TwitchLib.EventSub.Websockets/Core/EventArgs/RevocationArgs.cs: -------------------------------------------------------------------------------- 1 | using TwitchLib.EventSub.Websockets.Core.Models; 2 | 3 | namespace TwitchLib.EventSub.Websockets.Core.EventArgs 4 | { 5 | public class RevocationArgs : TwitchLibEventSubEventArgs> 6 | { } 7 | } -------------------------------------------------------------------------------- /TwitchLib.EventSub.Websockets/Core/EventArgs/Stream/StreamOfflineArgs.cs: -------------------------------------------------------------------------------- 1 | using TwitchLib.EventSub.Core.SubscriptionTypes.Stream; 2 | using TwitchLib.EventSub.Websockets.Core.Models; 3 | 4 | namespace TwitchLib.EventSub.Websockets.Core.EventArgs.Stream 5 | { 6 | public class StreamOfflineArgs : TwitchLibEventSubEventArgs> 7 | { } 8 | } -------------------------------------------------------------------------------- /TwitchLib.EventSub.Websockets/Core/EventArgs/Stream/StreamOnlineArgs.cs: -------------------------------------------------------------------------------- 1 | using TwitchLib.EventSub.Core.SubscriptionTypes.Stream; 2 | using TwitchLib.EventSub.Websockets.Core.Models; 3 | 4 | namespace TwitchLib.EventSub.Websockets.Core.EventArgs.Stream 5 | { 6 | public class StreamOnlineArgs : TwitchLibEventSubEventArgs> 7 | { } 8 | } -------------------------------------------------------------------------------- /TwitchLib.EventSub.Websockets/Core/EventArgs/TwitchLibEventSubEventArgs.cs: -------------------------------------------------------------------------------- 1 | namespace TwitchLib.EventSub.Websockets.Core.EventArgs 2 | { 3 | public abstract class TwitchLibEventSubEventArgs : System.EventArgs where T: new() 4 | { 5 | public T Notification { get; set; } = new T(); 6 | } 7 | } -------------------------------------------------------------------------------- /TwitchLib.EventSub.Websockets/Core/EventArgs/User/UserUpdateArgs.cs: -------------------------------------------------------------------------------- 1 | using TwitchLib.EventSub.Core.SubscriptionTypes.User; 2 | using TwitchLib.EventSub.Websockets.Core.Models; 3 | 4 | namespace TwitchLib.EventSub.Websockets.Core.EventArgs.User 5 | { 6 | public class UserUpdateArgs : TwitchLibEventSubEventArgs> 7 | { } 8 | } -------------------------------------------------------------------------------- /TwitchLib.EventSub.Websockets/Core/EventArgs/User/UserWhisperMessageArgs.cs: -------------------------------------------------------------------------------- 1 | using TwitchLib.EventSub.Core.SubscriptionTypes.User; 2 | using TwitchLib.EventSub.Websockets.Core.Models; 3 | 4 | namespace TwitchLib.EventSub.Websockets.Core.EventArgs.User 5 | { 6 | public class UserWhisperMessageArgs : TwitchLibEventSubEventArgs> 7 | { } 8 | } -------------------------------------------------------------------------------- /TwitchLib.EventSub.Websockets/Core/EventArgs/WebsocketConnectedArgs.cs: -------------------------------------------------------------------------------- 1 | namespace TwitchLib.EventSub.Websockets.Core.EventArgs 2 | { 3 | public class WebsocketConnectedArgs : System.EventArgs 4 | { 5 | public bool IsRequestedReconnect { get; set; } 6 | } 7 | } -------------------------------------------------------------------------------- /TwitchLib.EventSub.Websockets/Core/EventArgs/WebsocketDisconnectedArgs.cs: -------------------------------------------------------------------------------- 1 | using System.Net.WebSockets; 2 | 3 | namespace TwitchLib.EventSub.Websockets.Core.EventArgs 4 | { 5 | public class WebsocketDisconnectedArgs : System.EventArgs 6 | { 7 | public WebSocketCloseStatus CloseStatus { get; set; } 8 | public string CloseStatusDescription { get; set; } 9 | } 10 | } -------------------------------------------------------------------------------- /TwitchLib.EventSub.Websockets/Core/Handler/INotificationHandler.cs: -------------------------------------------------------------------------------- 1 | using System.Text.Json; 2 | 3 | namespace TwitchLib.EventSub.Websockets.Core.Handler 4 | { 5 | /// 6 | /// Interface describing a NotificationHandler for Twitch EventSub notifications 7 | /// 8 | public interface INotificationHandler 9 | { 10 | /// 11 | /// Type of subscription the handler handles 12 | /// 13 | string SubscriptionType { get; } 14 | 15 | /// 16 | /// Handles incoming notifications that the Handler is designed to handle as described by the SubscriptionType property of the Handler 17 | /// 18 | /// EventSubWebsocketClient that received the notification 19 | /// Message as json string received by the EventSubWebsocketClient 20 | /// Options to configure the JsonSerializer 21 | void Handle(EventSubWebsocketClient client, string jsonString, JsonSerializerOptions serializerOptions); 22 | } 23 | } -------------------------------------------------------------------------------- /TwitchLib.EventSub.Websockets/Core/Models/EventSubMetadata.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace TwitchLib.EventSub.Websockets.Core.Models; 4 | 5 | public class EventSubMetadata 6 | { 7 | /// 8 | /// An ID that uniquely identifies message. 9 | /// 10 | public string MessageId { get; set; } 11 | 12 | /// 13 | /// The type of notification. 14 | /// 15 | public string MessageType { get; set; } 16 | 17 | /// 18 | /// The UTC date and time that Twitch sent the notification. 19 | /// 20 | public DateTime MessageTimestamp { get; set; } 21 | 22 | /// 23 | /// The subscription type. 24 | /// 25 | public string? SubscriptionType { get; set; } 26 | 27 | /// 28 | /// The subscription version. 29 | /// 30 | public string? SubscriptionVersion { get; set; } 31 | } -------------------------------------------------------------------------------- /TwitchLib.EventSub.Websockets/Core/Models/EventSubNotification.cs: -------------------------------------------------------------------------------- 1 | namespace TwitchLib.EventSub.Websockets.Core.Models 2 | { 3 | public class EventSubNotification 4 | { 5 | public EventSubMetadata Metadata { get; set; } 6 | public EventSubNotificationPayload Payload { get; set; } 7 | } 8 | } -------------------------------------------------------------------------------- /TwitchLib.EventSub.Websockets/Core/Models/EventSubNotificationPayload.cs: -------------------------------------------------------------------------------- 1 | namespace TwitchLib.EventSub.Websockets.Core.Models 2 | { 3 | public class EventSubNotificationPayload 4 | { 5 | public EventSubTransport Transport { get; set; } 6 | 7 | /// 8 | /// The event’s data. 9 | /// 10 | public T Event { get; set; } 11 | } 12 | } -------------------------------------------------------------------------------- /TwitchLib.EventSub.Websockets/Core/Models/EventSubTransport.cs: -------------------------------------------------------------------------------- 1 | namespace TwitchLib.EventSub.Websockets.Core.Models 2 | { 3 | public class EventSubTransport 4 | { 5 | public string Method { get; set; } 6 | public string WebsocketId { get; set; } 7 | } 8 | } -------------------------------------------------------------------------------- /TwitchLib.EventSub.Websockets/Core/Models/EventSubWebsocketSessionInfo.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace TwitchLib.EventSub.Websockets.Core.Models; 4 | 5 | public class EventSubWebsocketSessionInfo 6 | { 7 | /// 8 | /// An ID that uniquely identifies this WebSocket connection. 9 | /// 10 | public string Id { get; set; } 11 | 12 | /// 13 | /// The connection’s status. 14 | /// 15 | public string Status { get; set; } 16 | public string DisconnectReason { get; set; } 17 | 18 | /// 19 | /// The maximum number of seconds that you should expect silence before receiving a keepalive message. 20 | /// 21 | public int? KeepaliveTimeoutSeconds { get; set; } 22 | 23 | /// 24 | /// The URL to reconnect to. 25 | /// 26 | public string? ReconnectUrl { get; set; } 27 | 28 | /// 29 | /// The UTC date and time when the connection was created. 30 | /// 31 | public DateTime ConnectedAt { get; set; } 32 | public DateTime? DisconnectedAt { get; set; } 33 | public DateTime? ReconnectingAt { get; set; } 34 | } -------------------------------------------------------------------------------- /TwitchLib.EventSub.Websockets/Core/Models/EventSubWebsocketSessionInfoMessage.cs: -------------------------------------------------------------------------------- 1 | namespace TwitchLib.EventSub.Websockets.Core.Models 2 | { 3 | public class EventSubWebsocketSessionInfoMessage 4 | { 5 | public EventSubMetadata Metadata { get; set; } 6 | public EventSubWebsocketSessionInfoPayload Payload { get; set; } 7 | } 8 | } -------------------------------------------------------------------------------- /TwitchLib.EventSub.Websockets/Core/Models/EventSubWebsocketSessionInfoPayload.cs: -------------------------------------------------------------------------------- 1 | namespace TwitchLib.EventSub.Websockets.Core.Models 2 | { 3 | public class EventSubWebsocketSessionInfoPayload 4 | { 5 | public EventSubWebsocketSessionInfo Session { get; set; } 6 | } 7 | } -------------------------------------------------------------------------------- /TwitchLib.EventSub.Websockets/Extensions/LogExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Net.WebSockets; 3 | using System.Text; 4 | using Microsoft.Extensions.Logging; 5 | using TwitchLib.EventSub.Websockets.Client; 6 | 7 | namespace TwitchLib.EventSub.Websockets.Extensions 8 | { 9 | internal static partial class LogExtensions 10 | { 11 | const LogLevel LogMessageLogLevel = LogLevel.Debug; 12 | 13 | [LoggerMessage(LogLevel.Error, "Exeption was throw when raising '{eventName}' event.")] 14 | public static partial void LogRaiseEventExeption(this ILogger logger, string eventName, Exception ex); 15 | 16 | [LoggerMessage(LogMessageLogLevel, "{message}")] 17 | public static partial void LogMessage(this ILogger logger, string message); 18 | 19 | [LoggerMessage(LogLevel.Critical, "Websocket {sessionId} disconnected at {disconnectedAt}. Reason: {disconnectReason}")] 20 | public static partial void LogForceDisconnected(this ILogger logger, string sessionId, DateTime? disconnectedAt, string disconnectReason); 21 | 22 | [LoggerMessage(LogLevel.Warning, "Websocket reconnect for SessionId {sessionId} requested!")] 23 | public static partial void LogReconnectRequested(this ILogger logger, string sessionId); 24 | 25 | [LoggerMessage(LogLevel.Error, "Websocket reconnect for SessionId {sessionId} failed!")] 26 | public static partial void LogReconnectFailed(this ILogger logger, string sessionId); 27 | 28 | [LoggerMessage(LogLevel.Warning, "Found unknown message type: {messageType}")] 29 | public static partial void LogUnknownMessageType(this ILogger logger, string messageType); 30 | 31 | [LoggerMessage(LogLevel.Critical, "{closeStatus} - {closeStatusDescription}")] 32 | public static partial void LogWebsocketClosed(this ILogger logger, WebSocketCloseStatus closeStatus, string closeStatusDescription); 33 | 34 | public static void LogMessage(this ILogger logger, byte[] message) 35 | { 36 | if (logger.IsEnabled(LogMessageLogLevel)) 37 | { 38 | __LogMessageCallback(logger, Encoding.UTF8.GetString(message), null); 39 | } 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /TwitchLib.EventSub.Websockets/Extensions/ServiceCollectionExtensions.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.Extensions.DependencyInjection; 2 | using Microsoft.Extensions.DependencyInjection.Extensions; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using Microsoft.Extensions.Logging; 7 | using TwitchLib.EventSub.Websockets.Client; 8 | using TwitchLib.EventSub.Websockets.Core.Handler; 9 | 10 | namespace TwitchLib.EventSub.Websockets.Extensions 11 | { 12 | /// 13 | /// Static class containing extension methods for the IServiceCollection of the DI Container 14 | /// 15 | public static class ServiceCollectionExtensions 16 | { 17 | /// 18 | /// 19 | /// 20 | /// ServiceCollection of the DI Container 21 | /// Array of types in which assemblies to search for NotificationHandlers 22 | /// the IServiceCollection to enable further fluent additions to it 23 | private static IServiceCollection AddNotificationHandlers(this IServiceCollection services, params Type[] scanMarkers) 24 | { 25 | foreach (var marker in scanMarkers) 26 | { 27 | var types = marker 28 | .Assembly.DefinedTypes 29 | .Where(x => typeof(INotificationHandler).IsAssignableFrom(x) && !x.IsInterface && !x.IsAbstract) 30 | .ToList(); 31 | 32 | foreach (var type in types) 33 | services.AddSingleton(typeof(INotificationHandler), type); 34 | } 35 | 36 | return services; 37 | } 38 | 39 | /// 40 | /// Add TwitchLib EventSub Websockets and its needed parts to the DI container 41 | /// 42 | /// ServiceCollection of the DI Container 43 | /// the IServiceCollection to enable further fluent additions to it 44 | public static IServiceCollection AddTwitchLibEventSubWebsockets(this IServiceCollection services) 45 | { 46 | services.TryAddTransient(); 47 | services.TryAddSingleton(x => new EventSubWebsocketClient(x.GetRequiredService>(), x.GetRequiredService>(), x.GetRequiredService(), x.GetRequiredService())); 48 | services.AddNotificationHandlers(typeof(INotificationHandler)); 49 | return services; 50 | } 51 | } 52 | } -------------------------------------------------------------------------------- /TwitchLib.EventSub.Websockets/Handler/Channel/Ads/AdBreakBeginHandler.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Text.Json; 3 | using TwitchLib.EventSub.Core.SubscriptionTypes.Channel; 4 | using TwitchLib.EventSub.Websockets.Core.EventArgs; 5 | using TwitchLib.EventSub.Websockets.Core.EventArgs.Channel; 6 | using TwitchLib.EventSub.Websockets.Core.Handler; 7 | using TwitchLib.EventSub.Websockets.Core.Models; 8 | 9 | namespace TwitchLib.EventSub.Websockets.Handler.Channel.Ads 10 | { 11 | /// 12 | /// Handler for 'channel.ad_break.begin' notifications 13 | /// 14 | public class AdBreakBeginHandler : INotificationHandler 15 | { 16 | /// 17 | public string SubscriptionType => "channel.ad_break.begin"; 18 | 19 | /// 20 | public void Handle(EventSubWebsocketClient client, string jsonString, JsonSerializerOptions serializerOptions) 21 | { 22 | try 23 | { 24 | var data = JsonSerializer.Deserialize>(jsonString.AsSpan(), serializerOptions); 25 | if (data is null) 26 | throw new InvalidOperationException("Parsed JSON cannot be null!"); 27 | client.RaiseEvent("ChannelAdBreakBegin", new ChannelAdBreakBeginArgs { Notification = data }); 28 | } 29 | catch (Exception ex) 30 | { 31 | client.RaiseEvent("ErrorOccurred", new ErrorOccuredArgs { Exception = ex, Message = $"Error encountered while trying to handle {SubscriptionType} notification! Raw Json: {jsonString}" }); 32 | } 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /TwitchLib.EventSub.Websockets/Handler/Channel/ChannelPoints/CustomReward/ChannelPointsCustomRewardAddHandler.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Text.Json; 3 | using TwitchLib.EventSub.Core.SubscriptionTypes.Channel; 4 | using TwitchLib.EventSub.Websockets.Core.EventArgs; 5 | using TwitchLib.EventSub.Websockets.Core.EventArgs.Channel; 6 | using TwitchLib.EventSub.Websockets.Core.Handler; 7 | using TwitchLib.EventSub.Websockets.Core.Models; 8 | 9 | namespace TwitchLib.EventSub.Websockets.Handler.Channel.ChannelPoints.CustomReward 10 | { 11 | /// 12 | /// Handler for 'channel.channel_points_custom_reward.add' notifications 13 | /// 14 | public class ChannelPointsCustomRewardAddHandler : INotificationHandler 15 | { 16 | /// 17 | public string SubscriptionType => "channel.channel_points_custom_reward.add"; 18 | 19 | /// 20 | public void Handle(EventSubWebsocketClient client, string jsonString, JsonSerializerOptions serializerOptions) 21 | { 22 | try 23 | { 24 | var data = JsonSerializer.Deserialize>(jsonString.AsSpan(), serializerOptions); 25 | 26 | if (data is null) 27 | throw new InvalidOperationException("Parsed JSON cannot be null!"); 28 | 29 | client.RaiseEvent("ChannelPointsCustomRewardAdd", new ChannelPointsCustomRewardArgs { Notification = data }); 30 | } 31 | catch (Exception ex) 32 | { 33 | client.RaiseEvent("ErrorOccurred", new ErrorOccuredArgs { Exception = ex, Message = $"Error encountered while trying to handle {SubscriptionType} notification! Raw Json: {jsonString}" }); 34 | } 35 | } 36 | } 37 | } -------------------------------------------------------------------------------- /TwitchLib.EventSub.Websockets/Handler/Channel/ChannelPoints/CustomReward/ChannelPointsCustomRewardRemoveHandler.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Text.Json; 3 | using TwitchLib.EventSub.Core.SubscriptionTypes.Channel; 4 | using TwitchLib.EventSub.Websockets.Core.EventArgs; 5 | using TwitchLib.EventSub.Websockets.Core.EventArgs.Channel; 6 | using TwitchLib.EventSub.Websockets.Core.Handler; 7 | using TwitchLib.EventSub.Websockets.Core.Models; 8 | 9 | namespace TwitchLib.EventSub.Websockets.Handler.Channel.ChannelPoints.CustomReward 10 | { 11 | /// 12 | /// Handler for 'channel.channel_points_custom_reward.remove' notifications 13 | /// 14 | public class ChannelPointsCustomRewardRemoveHandler : INotificationHandler 15 | { 16 | /// 17 | public string SubscriptionType => "channel.channel_points_custom_reward.remove"; 18 | 19 | /// 20 | public void Handle(EventSubWebsocketClient client, string jsonString, JsonSerializerOptions serializerOptions) 21 | { 22 | try 23 | { 24 | var data = JsonSerializer.Deserialize>(jsonString.AsSpan(), serializerOptions); 25 | 26 | if (data is null) 27 | throw new InvalidOperationException("Parsed JSON cannot be null!"); 28 | 29 | client.RaiseEvent("ChannelPointsCustomRewardRemove", new ChannelPointsCustomRewardArgs { Notification = data }); 30 | } 31 | catch (Exception ex) 32 | { 33 | client.RaiseEvent("ErrorOccurred", new ErrorOccuredArgs { Exception = ex, Message = $"Error encountered while trying to handle {SubscriptionType} notification! Raw Json: {jsonString}" }); 34 | } 35 | } 36 | } 37 | } -------------------------------------------------------------------------------- /TwitchLib.EventSub.Websockets/Handler/Channel/ChannelPoints/CustomReward/ChannelPointsCustomRewardUpdateHandler.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Text.Json; 3 | using TwitchLib.EventSub.Core.SubscriptionTypes.Channel; 4 | using TwitchLib.EventSub.Websockets.Core.EventArgs; 5 | using TwitchLib.EventSub.Websockets.Core.EventArgs.Channel; 6 | using TwitchLib.EventSub.Websockets.Core.Handler; 7 | using TwitchLib.EventSub.Websockets.Core.Models; 8 | 9 | namespace TwitchLib.EventSub.Websockets.Handler.Channel.ChannelPoints.CustomReward 10 | { 11 | /// 12 | /// Handler for 'channel.channel_points_custom_reward.update' notifications 13 | /// 14 | public class ChannelPointsCustomRewardUpdateHandler : INotificationHandler 15 | { 16 | /// 17 | public string SubscriptionType => "channel.channel_points_custom_reward.update"; 18 | 19 | /// 20 | public void Handle(EventSubWebsocketClient client, string jsonString, JsonSerializerOptions serializerOptions) 21 | { 22 | try 23 | { 24 | var data = JsonSerializer.Deserialize>(jsonString.AsSpan(), serializerOptions); 25 | 26 | if (data is null) 27 | throw new InvalidOperationException("Parsed JSON cannot be null!"); 28 | 29 | client.RaiseEvent("ChannelPointsCustomRewardUpdate", new ChannelPointsCustomRewardArgs { Notification = data }); 30 | } 31 | catch (Exception ex) 32 | { 33 | client.RaiseEvent("ErrorOccurred", new ErrorOccuredArgs { Exception = ex, Message = $"Error encountered while trying to handle {SubscriptionType} notification! Raw Json: {jsonString}" }); 34 | } 35 | } 36 | } 37 | } -------------------------------------------------------------------------------- /TwitchLib.EventSub.Websockets/Handler/Channel/ChannelPoints/Redemptions/ChannelPointsAutomaticRewardRedemptionAddHandler.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Text.Json; 3 | using TwitchLib.EventSub.Core.SubscriptionTypes.Channel; 4 | using TwitchLib.EventSub.Websockets.Core.EventArgs; 5 | using TwitchLib.EventSub.Websockets.Core.EventArgs.Channel; 6 | using TwitchLib.EventSub.Websockets.Core.Handler; 7 | using TwitchLib.EventSub.Websockets.Core.Models; 8 | 9 | namespace TwitchLib.EventSub.Websockets.Handler.Channel.ChannelPoints.Redemptions; 10 | /// 11 | /// Handler for 'channel.channel_points_automatic_reward_redemption.add' notifications 12 | /// 13 | public class ChannelPointsAutomaticRewardRedemptionAddHandler : INotificationHandler 14 | { 15 | /// 16 | public string SubscriptionType => "channel.channel_points_automatic_reward_redemption.add"; 17 | 18 | /// 19 | public void Handle(EventSubWebsocketClient client, string jsonString, JsonSerializerOptions serializerOptions) 20 | { 21 | try 22 | { 23 | var data = JsonSerializer.Deserialize>(jsonString.AsSpan(), serializerOptions); 24 | 25 | if (data is null) 26 | throw new InvalidOperationException("Parsed JSON cannot be null!"); 27 | 28 | client.RaiseEvent("ChannelPointsAutomaticRewardRedemptionAdd", new ChannelPointsAutomaticRewardRedemptionArgs { Notification = data }); 29 | } 30 | catch (Exception ex) 31 | { 32 | client.RaiseEvent("ErrorOccurred", new ErrorOccuredArgs { Exception = ex, Message = $"Error encountered while trying to handle {SubscriptionType} notification! Raw Json: {jsonString}" }); 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /TwitchLib.EventSub.Websockets/Handler/Channel/ChannelPoints/Redemptions/ChannelPointsCustomRewardRedemptionAddHandler.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Text.Json; 3 | using TwitchLib.EventSub.Core.SubscriptionTypes.Channel; 4 | using TwitchLib.EventSub.Websockets.Core.EventArgs; 5 | using TwitchLib.EventSub.Websockets.Core.EventArgs.Channel; 6 | using TwitchLib.EventSub.Websockets.Core.Handler; 7 | using TwitchLib.EventSub.Websockets.Core.Models; 8 | 9 | namespace TwitchLib.EventSub.Websockets.Handler.Channel.ChannelPoints.Redemptions 10 | { 11 | /// 12 | /// Handler for 'channel.channel_points_custom_reward_redemption.add' notifications 13 | /// 14 | public class ChannelPointsCustomRewardRedemptionAddHandler : INotificationHandler 15 | { 16 | /// 17 | public string SubscriptionType => "channel.channel_points_custom_reward_redemption.add"; 18 | 19 | /// 20 | public void Handle(EventSubWebsocketClient client, string jsonString, JsonSerializerOptions serializerOptions) 21 | { 22 | try 23 | { 24 | var data = JsonSerializer.Deserialize>(jsonString.AsSpan(), serializerOptions); 25 | 26 | if (data is null) 27 | throw new InvalidOperationException("Parsed JSON cannot be null!"); 28 | 29 | client.RaiseEvent("ChannelPointsCustomRewardRedemptionAdd", new ChannelPointsCustomRewardRedemptionArgs { Notification = data }); 30 | } 31 | catch (Exception ex) 32 | { 33 | client.RaiseEvent("ErrorOccurred", new ErrorOccuredArgs { Exception = ex, Message = $"Error encountered while trying to handle {SubscriptionType} notification! Raw Json: {jsonString}" }); 34 | } 35 | } 36 | } 37 | } -------------------------------------------------------------------------------- /TwitchLib.EventSub.Websockets/Handler/Channel/ChannelPoints/Redemptions/ChannelPointsCustomRewardRedemptionUpdate.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Text.Json; 3 | using TwitchLib.EventSub.Core.SubscriptionTypes.Channel; 4 | using TwitchLib.EventSub.Websockets.Core.EventArgs; 5 | using TwitchLib.EventSub.Websockets.Core.EventArgs.Channel; 6 | using TwitchLib.EventSub.Websockets.Core.Handler; 7 | using TwitchLib.EventSub.Websockets.Core.Models; 8 | 9 | namespace TwitchLib.EventSub.Websockets.Handler.Channel.ChannelPoints.Redemptions 10 | { 11 | /// 12 | /// Handler for 'channel.channel_points_custom_reward_redemption.update' notifications 13 | /// 14 | public class ChannelPointsCustomRewardRedemptionUpdate : INotificationHandler 15 | { 16 | /// 17 | public string SubscriptionType => "channel.channel_points_custom_reward_redemption.update"; 18 | 19 | /// 20 | public void Handle(EventSubWebsocketClient client, string jsonString, JsonSerializerOptions serializerOptions) 21 | { 22 | try 23 | { 24 | var data = JsonSerializer.Deserialize>(jsonString.AsSpan(), serializerOptions); 25 | 26 | if (data is null) 27 | throw new InvalidOperationException("Parsed JSON cannot be null!"); 28 | 29 | client.RaiseEvent("ChannelPointsCustomRewardRedemptionUpdate", new ChannelPointsCustomRewardRedemptionArgs { Notification = data }); 30 | } 31 | catch (Exception ex) 32 | { 33 | client.RaiseEvent("ErrorOccurred", new ErrorOccuredArgs { Exception = ex, Message = $"Error encountered while trying to handle {SubscriptionType} notification! Raw Json: {jsonString}" }); 34 | } 35 | } 36 | } 37 | } -------------------------------------------------------------------------------- /TwitchLib.EventSub.Websockets/Handler/Channel/ChannelUpdateHandler.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Text.Json; 3 | using TwitchLib.EventSub.Core.SubscriptionTypes.Channel; 4 | using TwitchLib.EventSub.Websockets.Core.EventArgs; 5 | using TwitchLib.EventSub.Websockets.Core.EventArgs.Channel; 6 | using TwitchLib.EventSub.Websockets.Core.Handler; 7 | using TwitchLib.EventSub.Websockets.Core.Models; 8 | 9 | namespace TwitchLib.EventSub.Websockets.Handler.Channel 10 | { 11 | /// 12 | /// Handler for 'channel.update' notifications 13 | /// 14 | public class ChannelUpdateHandler : INotificationHandler 15 | { 16 | /// 17 | public string SubscriptionType => "channel.update"; 18 | 19 | /// 20 | public void Handle(EventSubWebsocketClient client, string jsonString, JsonSerializerOptions serializerOptions) 21 | { 22 | try 23 | { 24 | var data = JsonSerializer.Deserialize>(jsonString.AsSpan(), serializerOptions); 25 | 26 | if (data is null) 27 | throw new InvalidOperationException("Parsed JSON cannot be null!"); 28 | 29 | client.RaiseEvent("ChannelUpdate", new ChannelUpdateArgs { Notification = data }); 30 | } 31 | catch (Exception ex) 32 | { 33 | client.RaiseEvent("ErrorOccurred", new ErrorOccuredArgs { Exception = ex, Message = $"Error encountered while trying to handle {SubscriptionType} notification! Raw Json: {jsonString}" }); 34 | } 35 | } 36 | } 37 | } -------------------------------------------------------------------------------- /TwitchLib.EventSub.Websockets/Handler/Channel/Charity/ChannelCharityCampaignDonateHandler.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Text.Json; 3 | using TwitchLib.EventSub.Core.SubscriptionTypes.Channel; 4 | using TwitchLib.EventSub.Websockets.Core.EventArgs; 5 | using TwitchLib.EventSub.Websockets.Core.EventArgs.Channel; 6 | using TwitchLib.EventSub.Websockets.Core.Handler; 7 | using TwitchLib.EventSub.Websockets.Core.Models; 8 | 9 | namespace TwitchLib.EventSub.Websockets.Handler.Channel.Charity 10 | { 11 | /// 12 | /// Handler for 'channel.charity_campaign.donate' notifications 13 | /// 14 | public class ChannelCharityCampaignDonateHandler : INotificationHandler 15 | { 16 | /// 17 | public string SubscriptionType => "channel.charity_campaign.donate"; 18 | 19 | /// 20 | public void Handle(EventSubWebsocketClient client, string jsonString, JsonSerializerOptions serializerOptions) 21 | { 22 | try 23 | { 24 | var data = JsonSerializer.Deserialize>(jsonString.AsSpan(), serializerOptions); 25 | 26 | if (data is null) 27 | throw new InvalidOperationException("Parsed JSON cannot be null!"); 28 | 29 | client.RaiseEvent("ChannelCharityCampaignDonate", new ChannelCharityCampaignDonateArgs { Notification = data }); 30 | } 31 | catch (Exception ex) 32 | { 33 | client.RaiseEvent("ErrorOccurred", new ErrorOccuredArgs { Exception = ex, Message = $"Error encountered while trying to handle {SubscriptionType} notification! Raw Json: {jsonString}" }); 34 | } 35 | } 36 | } 37 | } -------------------------------------------------------------------------------- /TwitchLib.EventSub.Websockets/Handler/Channel/Charity/ChannelCharityCampaignProgressHandler.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Text.Json; 3 | using TwitchLib.EventSub.Core.SubscriptionTypes.Channel; 4 | using TwitchLib.EventSub.Websockets.Core.EventArgs; 5 | using TwitchLib.EventSub.Websockets.Core.EventArgs.Channel; 6 | using TwitchLib.EventSub.Websockets.Core.Handler; 7 | using TwitchLib.EventSub.Websockets.Core.Models; 8 | 9 | namespace TwitchLib.EventSub.Websockets.Handler.Channel.Charity 10 | { 11 | /// 12 | /// Handler for 'channel.charity_campaign.progress' notifications 13 | /// 14 | public class ChannelCharityCampaignProgressHandler : INotificationHandler 15 | { 16 | /// 17 | public string SubscriptionType => "channel.charity_campaign.progress"; 18 | 19 | /// 20 | public void Handle(EventSubWebsocketClient client, string jsonString, JsonSerializerOptions serializerOptions) 21 | { 22 | try 23 | { 24 | var data = JsonSerializer.Deserialize>(jsonString.AsSpan(), serializerOptions); 25 | 26 | if (data is null) 27 | throw new InvalidOperationException("Parsed JSON cannot be null!"); 28 | 29 | client.RaiseEvent("ChannelCharityCampaignProgress", new ChannelCharityCampaignProgressArgs { Notification = data }); 30 | } 31 | catch (Exception ex) 32 | { 33 | client.RaiseEvent("ErrorOccurred", new ErrorOccuredArgs { Exception = ex, Message = $"Error encountered while trying to handle {SubscriptionType} notification! Raw Json: {jsonString}" }); 34 | } 35 | } 36 | } 37 | } -------------------------------------------------------------------------------- /TwitchLib.EventSub.Websockets/Handler/Channel/Charity/ChannelCharityCampaignStartHandler.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Text.Json; 3 | using TwitchLib.EventSub.Core.SubscriptionTypes.Channel; 4 | using TwitchLib.EventSub.Websockets.Core.EventArgs; 5 | using TwitchLib.EventSub.Websockets.Core.EventArgs.Channel; 6 | using TwitchLib.EventSub.Websockets.Core.Handler; 7 | using TwitchLib.EventSub.Websockets.Core.Models; 8 | 9 | namespace TwitchLib.EventSub.Websockets.Handler.Channel.Charity 10 | { 11 | /// 12 | /// Handler for 'channel.charity_campaign.start' notifications 13 | /// 14 | public class ChannelCharityCampaignStartHandler : INotificationHandler 15 | { 16 | /// 17 | public string SubscriptionType => "channel.charity_campaign.start"; 18 | 19 | /// 20 | public void Handle(EventSubWebsocketClient client, string jsonString, JsonSerializerOptions serializerOptions) 21 | { 22 | try 23 | { 24 | var data = JsonSerializer.Deserialize>(jsonString.AsSpan(), serializerOptions); 25 | 26 | if (data is null) 27 | throw new InvalidOperationException("Parsed JSON cannot be null!"); 28 | 29 | client.RaiseEvent("ChannelCharityCampaignStart", new ChannelCharityCampaignStartArgs { Notification = data }); 30 | } 31 | catch (Exception ex) 32 | { 33 | client.RaiseEvent("ErrorOccurred", new ErrorOccuredArgs { Exception = ex, Message = $"Error encountered while trying to handle {SubscriptionType} notification! Raw Json: {jsonString}" }); 34 | } 35 | } 36 | } 37 | } -------------------------------------------------------------------------------- /TwitchLib.EventSub.Websockets/Handler/Channel/Charity/ChannelCharityCampaignStopHandler.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Text.Json; 3 | using TwitchLib.EventSub.Core.SubscriptionTypes.Channel; 4 | using TwitchLib.EventSub.Websockets.Core.EventArgs; 5 | using TwitchLib.EventSub.Websockets.Core.EventArgs.Channel; 6 | using TwitchLib.EventSub.Websockets.Core.Handler; 7 | using TwitchLib.EventSub.Websockets.Core.Models; 8 | 9 | namespace TwitchLib.EventSub.Websockets.Handler.Channel.Charity 10 | { 11 | /// 12 | /// Handler for 'channel.charity_campaign.stop' notifications 13 | /// 14 | public class ChannelCharityCampaignStopHandler : INotificationHandler 15 | { 16 | /// 17 | public string SubscriptionType => "channel.charity_campaign.stop"; 18 | 19 | /// 20 | public void Handle(EventSubWebsocketClient client, string jsonString, JsonSerializerOptions serializerOptions) 21 | { 22 | try 23 | { 24 | var data = JsonSerializer.Deserialize>(jsonString.AsSpan(), serializerOptions); 25 | 26 | if (data is null) 27 | throw new InvalidOperationException("Parsed JSON cannot be null!"); 28 | 29 | client.RaiseEvent("ChannelCharityCampaignStop", new ChannelCharityCampaignStopArgs { Notification = data }); 30 | } 31 | catch (Exception ex) 32 | { 33 | client.RaiseEvent("ErrorOccurred", new ErrorOccuredArgs { Exception = ex, Message = $"Error encountered while trying to handle {SubscriptionType} notification! Raw Json: {jsonString}" }); 34 | } 35 | } 36 | } 37 | } -------------------------------------------------------------------------------- /TwitchLib.EventSub.Websockets/Handler/Channel/Chat/ChannelChatClearHandler.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Text.Json; 3 | using TwitchLib.EventSub.Core.SubscriptionTypes.Channel; 4 | using TwitchLib.EventSub.Websockets.Core.EventArgs; 5 | using TwitchLib.EventSub.Websockets.Core.EventArgs.Channel; 6 | using TwitchLib.EventSub.Websockets.Core.Handler; 7 | using TwitchLib.EventSub.Websockets.Core.Models; 8 | 9 | namespace TwitchLib.EventSub.Websockets.Handler.Channel.Chat; 10 | 11 | /// 12 | /// Handler for 'channel.chat.clear' notifications 13 | /// 14 | public class ChannelChatClearHandler : INotificationHandler 15 | { 16 | /// 17 | public string SubscriptionType => "channel.chat.clear"; 18 | 19 | /// 20 | public void Handle(EventSubWebsocketClient client, string jsonString, JsonSerializerOptions serializerOptions) 21 | { 22 | try 23 | { 24 | var data = JsonSerializer.Deserialize>(jsonString.AsSpan(), serializerOptions); 25 | 26 | if (data is null) 27 | throw new InvalidOperationException("Parsed JSON cannot be null!"); 28 | 29 | client.RaiseEvent("ChannelChatClear", new ChannelChatClearArgs { Notification = data }); 30 | } 31 | catch (Exception ex) 32 | { 33 | client.RaiseEvent("ErrorOccurred", new ErrorOccuredArgs { Exception = ex, Message = $"Error encountered while trying to handle {SubscriptionType} notification! Raw Json: {jsonString}" }); 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /TwitchLib.EventSub.Websockets/Handler/Channel/Chat/ChannelChatClearUserMessagesHandler.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Text.Json; 3 | using TwitchLib.EventSub.Core.SubscriptionTypes.Channel; 4 | using TwitchLib.EventSub.Websockets.Core.EventArgs; 5 | using TwitchLib.EventSub.Websockets.Core.EventArgs.Channel; 6 | using TwitchLib.EventSub.Websockets.Core.Handler; 7 | using TwitchLib.EventSub.Websockets.Core.Models; 8 | 9 | namespace TwitchLib.EventSub.Websockets.Handler.Channel.Chat; 10 | 11 | /// 12 | /// Handler for 'channel.chat.clear_user_messages' notifications 13 | /// 14 | public class ChannelChatClearUserMessagesHandler : INotificationHandler 15 | { 16 | /// 17 | public string SubscriptionType => "channel.chat.clear_user_messages"; 18 | 19 | /// 20 | public void Handle(EventSubWebsocketClient client, string jsonString, JsonSerializerOptions serializerOptions) 21 | { 22 | try 23 | { 24 | var data = JsonSerializer.Deserialize>(jsonString.AsSpan(), serializerOptions); 25 | 26 | if (data is null) 27 | throw new InvalidOperationException("Parsed JSON cannot be null!"); 28 | 29 | client.RaiseEvent("ChannelChatClearUserMessages", new ChannelChatClearUserMessagesArgs { Notification = data }); 30 | } 31 | catch (Exception ex) 32 | { 33 | client.RaiseEvent("ErrorOccurred", new ErrorOccuredArgs { Exception = ex, Message = $"Error encountered while trying to handle {SubscriptionType} notification! Raw Json: {jsonString}" }); 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /TwitchLib.EventSub.Websockets/Handler/Channel/Chat/ChatMessageDeleteHandler.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Text.Json; 3 | using TwitchLib.EventSub.Core.SubscriptionTypes.Channel; 4 | using TwitchLib.EventSub.Websockets.Core.EventArgs; 5 | using TwitchLib.EventSub.Websockets.Core.EventArgs.Channel; 6 | using TwitchLib.EventSub.Websockets.Core.Handler; 7 | using TwitchLib.EventSub.Websockets.Core.Models; 8 | 9 | namespace TwitchLib.EventSub.Websockets.Handler.Channel.Chat 10 | { 11 | /// 12 | /// Handler for 'channel.chat.message_delete' notifications 13 | /// 14 | public class ChatMessageDeleteHandler : INotificationHandler 15 | { 16 | /// 17 | public string SubscriptionType => "channel.chat.message_delete"; 18 | 19 | /// 20 | public void Handle(EventSubWebsocketClient client, string jsonString, JsonSerializerOptions serializerOptions) 21 | { 22 | try 23 | { 24 | var data = JsonSerializer.Deserialize>(jsonString.AsSpan(), serializerOptions); 25 | if (data is null) 26 | throw new InvalidOperationException("Parsed JSON cannot be null!"); 27 | client.RaiseEvent("ChannelChatMessageDelete", new ChannelChatMessageDeleteArgs { Notification = data }); 28 | } 29 | catch (Exception ex) 30 | { 31 | client.RaiseEvent("ErrorOccurred", new ErrorOccuredArgs { Exception = ex, Message = $"Error encountered while trying to handle {SubscriptionType} notification! Raw Json: {jsonString}" }); 32 | } 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /TwitchLib.EventSub.Websockets/Handler/Channel/Chat/ChatNotificationHandler.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Text.Json; 3 | using TwitchLib.EventSub.Core.SubscriptionTypes.Channel; 4 | using TwitchLib.EventSub.Websockets.Core.EventArgs; 5 | using TwitchLib.EventSub.Websockets.Core.EventArgs.Channel; 6 | using TwitchLib.EventSub.Websockets.Core.Handler; 7 | using TwitchLib.EventSub.Websockets.Core.Models; 8 | 9 | namespace TwitchLib.EventSub.Websockets.Handler.Channel.Chat 10 | { 11 | /// 12 | /// Handler for 'channel.chat.notification' notifications 13 | /// 14 | public class ChatNotificationHandler : INotificationHandler 15 | { 16 | /// 17 | public string SubscriptionType => "channel.chat.notification"; 18 | 19 | /// 20 | public void Handle(EventSubWebsocketClient client, string jsonString, JsonSerializerOptions serializerOptions) 21 | { 22 | try 23 | { 24 | var data = JsonSerializer.Deserialize>(jsonString.AsSpan(), serializerOptions); 25 | if (data is null) 26 | throw new InvalidOperationException("Parsed JSON cannot be null!"); 27 | client.RaiseEvent("ChannelChatNotification", new ChannelChatNotificationArgs { Notification = data }); 28 | } 29 | catch (Exception ex) 30 | { 31 | client.RaiseEvent("ErrorOccurred", new ErrorOccuredArgs { Exception = ex, Message = $"Error encountered while trying to handle {SubscriptionType} notification! Raw Json: {jsonString}" }); 32 | } 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /TwitchLib.EventSub.Websockets/Handler/Channel/ChatMessageHandler.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Text.Json; 3 | using TwitchLib.EventSub.Core.SubscriptionTypes.Channel; 4 | using TwitchLib.EventSub.Websockets.Core.EventArgs; 5 | using TwitchLib.EventSub.Websockets.Core.EventArgs.Channel; 6 | using TwitchLib.EventSub.Websockets.Core.Handler; 7 | using TwitchLib.EventSub.Websockets.Core.Models; 8 | 9 | namespace TwitchLib.EventSub.Websockets.Handler.Channel 10 | { 11 | /// 12 | /// Handler for 'channel.chat.nessage' notifications 13 | /// 14 | public class ChatMessageHandler : INotificationHandler 15 | { 16 | /// 17 | public string SubscriptionType => "channel.chat.message"; 18 | 19 | /// 20 | public void Handle(EventSubWebsocketClient client, string jsonString, JsonSerializerOptions serializerOptions) 21 | { 22 | try 23 | { 24 | var data = JsonSerializer.Deserialize>(jsonString.AsSpan(), serializerOptions); 25 | if (data is null) 26 | throw new InvalidOperationException("Parsed JSON cannot be null!"); 27 | client.RaiseEvent("ChannelChatMessage", new ChannelChatMessageArgs { Notification = data }); 28 | } 29 | catch (Exception ex) 30 | { 31 | client.RaiseEvent("ErrorOccurred", new ErrorOccuredArgs { Exception = ex, Message = $"Error encountered while trying to handle {SubscriptionType} notification! Raw Json: {jsonString}" }); 32 | } 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /TwitchLib.EventSub.Websockets/Handler/Channel/Cheers/ChannelCheerHandler.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Text.Json; 3 | using TwitchLib.EventSub.Core.SubscriptionTypes.Channel; 4 | using TwitchLib.EventSub.Websockets.Core.EventArgs; 5 | using TwitchLib.EventSub.Websockets.Core.EventArgs.Channel; 6 | using TwitchLib.EventSub.Websockets.Core.Handler; 7 | using TwitchLib.EventSub.Websockets.Core.Models; 8 | 9 | namespace TwitchLib.EventSub.Websockets.Handler.Channel.Cheers 10 | { 11 | /// 12 | /// Handler for 'channel.cheer' notifications 13 | /// 14 | public class ChannelCheerHandler : INotificationHandler 15 | { 16 | /// 17 | public string SubscriptionType => "channel.cheer"; 18 | 19 | /// 20 | public void Handle(EventSubWebsocketClient client, string jsonString, JsonSerializerOptions serializerOptions) 21 | { 22 | try 23 | { 24 | var data = JsonSerializer.Deserialize>(jsonString.AsSpan(), serializerOptions); 25 | 26 | if (data is null) 27 | throw new InvalidOperationException("Parsed JSON cannot be null!"); 28 | 29 | client.RaiseEvent("ChannelCheer", new ChannelCheerArgs { Notification = data }); 30 | } 31 | catch (Exception ex) 32 | { 33 | client.RaiseEvent("ErrorOccurred", new ErrorOccuredArgs { Exception = ex, Message = $"Error encountered while trying to handle {SubscriptionType} notification! Raw Json: {jsonString}" }); 34 | } 35 | } 36 | } 37 | } -------------------------------------------------------------------------------- /TwitchLib.EventSub.Websockets/Handler/Channel/Follows/ChannelFollowHandler.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Text.Json; 3 | using TwitchLib.EventSub.Core.SubscriptionTypes.Channel; 4 | using TwitchLib.EventSub.Websockets.Core.EventArgs; 5 | using TwitchLib.EventSub.Websockets.Core.EventArgs.Channel; 6 | using TwitchLib.EventSub.Websockets.Core.Handler; 7 | using TwitchLib.EventSub.Websockets.Core.Models; 8 | 9 | namespace TwitchLib.EventSub.Websockets.Handler.Channel.Follows 10 | { 11 | /// 12 | /// Handler for 'channel.follow' notifications 13 | /// 14 | public class ChannelFollowHandler : INotificationHandler 15 | { 16 | /// 17 | public string SubscriptionType => "channel.follow"; 18 | 19 | /// 20 | public void Handle(EventSubWebsocketClient client, string jsonString, JsonSerializerOptions serializerOptions) 21 | { 22 | try 23 | { 24 | var data = JsonSerializer.Deserialize>(jsonString.AsSpan(), serializerOptions); 25 | 26 | if (data is null) 27 | throw new InvalidOperationException("Parsed JSON cannot be null!"); 28 | 29 | client.RaiseEvent("ChannelFollow", new ChannelFollowArgs { Notification = data }); 30 | } 31 | catch (Exception ex) 32 | { 33 | client.RaiseEvent("ErrorOccurred", new ErrorOccuredArgs { Exception = ex, Message = $"Error encountered while trying to handle channel.follow notification! Raw Json: {jsonString}" }); 34 | } 35 | } 36 | } 37 | } -------------------------------------------------------------------------------- /TwitchLib.EventSub.Websockets/Handler/Channel/Goals/ChannelGoalBeginHandler.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Text.Json; 3 | using TwitchLib.EventSub.Core.SubscriptionTypes.Channel; 4 | using TwitchLib.EventSub.Websockets.Core.EventArgs; 5 | using TwitchLib.EventSub.Websockets.Core.EventArgs.Channel; 6 | using TwitchLib.EventSub.Websockets.Core.Handler; 7 | using TwitchLib.EventSub.Websockets.Core.Models; 8 | 9 | namespace TwitchLib.EventSub.Websockets.Handler.Channel.Goals 10 | { 11 | /// 12 | /// Handler for 'channel.goal.begin' notifications 13 | /// 14 | public class ChannelGoalBeginHandler : INotificationHandler 15 | { 16 | /// 17 | public string SubscriptionType => "channel.goal.begin"; 18 | 19 | /// 20 | public void Handle(EventSubWebsocketClient client, string jsonString, JsonSerializerOptions serializerOptions) 21 | { 22 | try 23 | { 24 | var data = JsonSerializer.Deserialize>(jsonString.AsSpan(), serializerOptions); 25 | 26 | if (data is null) 27 | throw new InvalidOperationException("Parsed JSON cannot be null!"); 28 | 29 | client.RaiseEvent("ChannelGoalBegin", new ChannelGoalBeginArgs { Notification = data }); 30 | } 31 | catch (Exception ex) 32 | { 33 | client.RaiseEvent("ErrorOccurred", new ErrorOccuredArgs { Exception = ex, Message = $"Error encountered while trying to handle {SubscriptionType} notification! Raw Json: {jsonString}" }); 34 | } 35 | } 36 | } 37 | } -------------------------------------------------------------------------------- /TwitchLib.EventSub.Websockets/Handler/Channel/Goals/ChannelGoalEndHandler.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Text.Json; 3 | using TwitchLib.EventSub.Core.SubscriptionTypes.Channel; 4 | using TwitchLib.EventSub.Websockets.Core.EventArgs; 5 | using TwitchLib.EventSub.Websockets.Core.EventArgs.Channel; 6 | using TwitchLib.EventSub.Websockets.Core.Handler; 7 | using TwitchLib.EventSub.Websockets.Core.Models; 8 | 9 | namespace TwitchLib.EventSub.Websockets.Handler.Channel.Goals 10 | { 11 | /// 12 | /// Handler for 'channel.goal.end' notifications 13 | /// 14 | public class ChannelGoalEndHandler : INotificationHandler 15 | { 16 | /// 17 | public string SubscriptionType => "channel.goal.end"; 18 | 19 | /// 20 | public void Handle(EventSubWebsocketClient client, string jsonString, JsonSerializerOptions serializerOptions) 21 | { 22 | try 23 | { 24 | var data = JsonSerializer.Deserialize>(jsonString.AsSpan(), serializerOptions); 25 | 26 | if (data is null) 27 | throw new InvalidOperationException("Parsed JSON cannot be null!"); 28 | 29 | client.RaiseEvent("ChannelGoalEnd", new ChannelGoalEndArgs { Notification = data }); 30 | } 31 | catch (Exception ex) 32 | { 33 | client.RaiseEvent("ErrorOccurred", new ErrorOccuredArgs { Exception = ex, Message = $"Error encountered while trying to handle {SubscriptionType} notification! Raw Json: {jsonString}" }); 34 | } 35 | } 36 | } 37 | } -------------------------------------------------------------------------------- /TwitchLib.EventSub.Websockets/Handler/Channel/Goals/ChannelGoalProgressHandler.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Text.Json; 3 | using TwitchLib.EventSub.Core.SubscriptionTypes.Channel; 4 | using TwitchLib.EventSub.Websockets.Core.EventArgs; 5 | using TwitchLib.EventSub.Websockets.Core.EventArgs.Channel; 6 | using TwitchLib.EventSub.Websockets.Core.Handler; 7 | using TwitchLib.EventSub.Websockets.Core.Models; 8 | 9 | namespace TwitchLib.EventSub.Websockets.Handler.Channel.Goals 10 | { 11 | /// 12 | /// Handler for 'channel.goal.progress' notifications 13 | /// 14 | public class ChannelGoalProgressHandler : INotificationHandler 15 | { 16 | /// 17 | public string SubscriptionType => "channel.goal.progress"; 18 | 19 | /// 20 | public void Handle(EventSubWebsocketClient client, string jsonString, JsonSerializerOptions serializerOptions) 21 | { 22 | try 23 | { 24 | var data = JsonSerializer.Deserialize>(jsonString.AsSpan(), serializerOptions); 25 | 26 | if (data is null) 27 | throw new InvalidOperationException("Parsed JSON cannot be null!"); 28 | 29 | client.RaiseEvent("ChannelGoalProgress", new ChannelGoalProgressArgs { Notification = data }); 30 | } 31 | catch (Exception ex) 32 | { 33 | client.RaiseEvent("ErrorOccurred", new ErrorOccuredArgs { Exception = ex, Message = $"Error encountered while trying to handle {SubscriptionType} notification! Raw Json: {jsonString}" }); 34 | } 35 | } 36 | } 37 | } -------------------------------------------------------------------------------- /TwitchLib.EventSub.Websockets/Handler/Channel/GuestStar/ChannelGuestStarGuestUpdateHandler.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Text.Json; 3 | using TwitchLib.EventSub.Core.SubscriptionTypes.Channel; 4 | using TwitchLib.EventSub.Websockets.Core.EventArgs; 5 | using TwitchLib.EventSub.Websockets.Core.EventArgs.Channel; 6 | using TwitchLib.EventSub.Websockets.Core.Handler; 7 | using TwitchLib.EventSub.Websockets.Core.Models; 8 | 9 | namespace TwitchLib.EventSub.Websockets.Handler.Channel.GuestStar 10 | { 11 | /// 12 | /// Handler for 'channel.guest_star_guest.update' notifications 13 | /// 14 | public class ChannelGuestStarGuestUpdateHandler : INotificationHandler 15 | { 16 | /// 17 | public string SubscriptionType => "channel.guest_star_guest.update"; 18 | 19 | /// 20 | public void Handle(EventSubWebsocketClient client, string jsonString, JsonSerializerOptions serializerOptions) 21 | { 22 | try 23 | { 24 | var data = JsonSerializer.Deserialize>(jsonString.AsSpan(), serializerOptions); 25 | 26 | if (data is null) 27 | throw new InvalidOperationException("Parsed JSON cannot be null!"); 28 | 29 | client.RaiseEvent("ChannelGuestStarGuestUpdate", new ChannelGuestStarGuestUpdateArgs { Notification = data }); 30 | } 31 | catch (Exception ex) 32 | { 33 | client.RaiseEvent("ErrorOccurred", new ErrorOccuredArgs { Exception = ex, Message = $"Error encountered while trying to handle channel.guest_star_guest.update notification! Raw Json: {jsonString}" }); 34 | } 35 | } 36 | } 37 | } -------------------------------------------------------------------------------- /TwitchLib.EventSub.Websockets/Handler/Channel/GuestStar/ChannelGuestStarSessionBeginHandler.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Text.Json; 3 | using TwitchLib.EventSub.Core.SubscriptionTypes.Channel; 4 | using TwitchLib.EventSub.Websockets.Core.EventArgs; 5 | using TwitchLib.EventSub.Websockets.Core.EventArgs.Channel; 6 | using TwitchLib.EventSub.Websockets.Core.Handler; 7 | using TwitchLib.EventSub.Websockets.Core.Models; 8 | 9 | namespace TwitchLib.EventSub.Websockets.Handler.Channel.GuestStar 10 | { 11 | /// 12 | /// Handler for 'channel.guest_star_session.begin' notifications 13 | /// 14 | public class ChannelGuestStarSessionBeginHandler : INotificationHandler 15 | { 16 | /// 17 | public string SubscriptionType => "channel.guest_star_session.begin"; 18 | 19 | /// 20 | public void Handle(EventSubWebsocketClient client, string jsonString, JsonSerializerOptions serializerOptions) 21 | { 22 | try 23 | { 24 | var data = JsonSerializer.Deserialize>(jsonString.AsSpan(), serializerOptions); 25 | 26 | if (data is null) 27 | throw new InvalidOperationException("Parsed JSON cannot be null!"); 28 | 29 | client.RaiseEvent("ChannelGuestStarSessionBegin", new ChannelGuestStarSessionBeginArgs { Notification = data }); 30 | } 31 | catch (Exception ex) 32 | { 33 | client.RaiseEvent("ErrorOccurred", new ErrorOccuredArgs { Exception = ex, Message = $"Error encountered while trying to handle channel.guest_star_session.begin notification! Raw Json: {jsonString}" }); 34 | } 35 | } 36 | } 37 | } -------------------------------------------------------------------------------- /TwitchLib.EventSub.Websockets/Handler/Channel/GuestStar/ChannelGuestStarSessionEndHandler.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Text.Json; 3 | using TwitchLib.EventSub.Core.SubscriptionTypes.Channel; 4 | using TwitchLib.EventSub.Websockets.Core.EventArgs; 5 | using TwitchLib.EventSub.Websockets.Core.EventArgs.Channel; 6 | using TwitchLib.EventSub.Websockets.Core.Handler; 7 | using TwitchLib.EventSub.Websockets.Core.Models; 8 | 9 | namespace TwitchLib.EventSub.Websockets.Handler.Channel.GuestStar 10 | { 11 | /// 12 | /// Handler for 'channel.guest_star_session.end' notifications 13 | /// 14 | public class ChannelGuestStarSessionEndHandler : INotificationHandler 15 | { 16 | /// 17 | public string SubscriptionType => "channel.guest_star_session.end"; 18 | 19 | /// 20 | public void Handle(EventSubWebsocketClient client, string jsonString, JsonSerializerOptions serializerOptions) 21 | { 22 | try 23 | { 24 | var data = JsonSerializer.Deserialize>(jsonString.AsSpan(), serializerOptions); 25 | 26 | if (data is null) 27 | throw new InvalidOperationException("Parsed JSON cannot be null!"); 28 | 29 | client.RaiseEvent("ChannelGuestStarSessionEnd", new ChannelGuestStarSessionEndArgs { Notification = data }); 30 | } 31 | catch (Exception ex) 32 | { 33 | client.RaiseEvent("ErrorOccurred", new ErrorOccuredArgs { Exception = ex, Message = $"Error encountered while trying to handle channel.guest_star_session.end notification! Raw Json: {jsonString}" }); 34 | } 35 | } 36 | } 37 | } -------------------------------------------------------------------------------- /TwitchLib.EventSub.Websockets/Handler/Channel/GuestStar/ChannelGuestStarSettingsUpdateHandler.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Text.Json; 3 | using TwitchLib.EventSub.Core.SubscriptionTypes.Channel; 4 | using TwitchLib.EventSub.Websockets.Core.EventArgs; 5 | using TwitchLib.EventSub.Websockets.Core.EventArgs.Channel; 6 | using TwitchLib.EventSub.Websockets.Core.Handler; 7 | using TwitchLib.EventSub.Websockets.Core.Models; 8 | 9 | namespace TwitchLib.EventSub.Websockets.Handler.Channel.GuestStar 10 | { 11 | /// 12 | /// Handler for 'channel.guest_star_slot.update' notifications 13 | /// 14 | public class ChannelGuestStarSettingsUpdateHandler : INotificationHandler 15 | { 16 | /// 17 | public string SubscriptionType => "channel.guest_star_settings.update"; 18 | 19 | /// 20 | public void Handle(EventSubWebsocketClient client, string jsonString, JsonSerializerOptions serializerOptions) 21 | { 22 | try 23 | { 24 | var data = JsonSerializer.Deserialize>(jsonString.AsSpan(), serializerOptions); 25 | 26 | if (data is null) 27 | throw new InvalidOperationException("Parsed JSON cannot be null!"); 28 | 29 | client.RaiseEvent("ChannelGuestStarSettingsUpdate", new ChannelGuestStarSettingsUpdateArgs { Notification = data }); 30 | } 31 | catch (Exception ex) 32 | { 33 | client.RaiseEvent("ErrorOccurred", new ErrorOccuredArgs { Exception = ex, Message = $"Error encountered while trying to handle channel.guest_star_settings.update notification! Raw Json: {jsonString}" }); 34 | } 35 | } 36 | } 37 | } -------------------------------------------------------------------------------- /TwitchLib.EventSub.Websockets/Handler/Channel/GuestStar/ChannelGuestStarSlotUpdateHandler.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Text.Json; 3 | using TwitchLib.EventSub.Core.SubscriptionTypes.Channel; 4 | using TwitchLib.EventSub.Websockets.Core.EventArgs; 5 | using TwitchLib.EventSub.Websockets.Core.EventArgs.Channel; 6 | using TwitchLib.EventSub.Websockets.Core.Handler; 7 | using TwitchLib.EventSub.Websockets.Core.Models; 8 | 9 | namespace TwitchLib.EventSub.Websockets.Handler.Channel.GuestStar 10 | { 11 | /// 12 | /// Handler for 'channel.guest_star_slot.update' notifications 13 | /// 14 | public class ChannelGuestStarSlotUpdateHandler : INotificationHandler 15 | { 16 | /// 17 | public string SubscriptionType => "channel.guest_star_slot.update"; 18 | 19 | /// 20 | public void Handle(EventSubWebsocketClient client, string jsonString, JsonSerializerOptions serializerOptions) 21 | { 22 | try 23 | { 24 | var data = JsonSerializer.Deserialize>(jsonString.AsSpan(), serializerOptions); 25 | 26 | if (data is null) 27 | throw new InvalidOperationException("Parsed JSON cannot be null!"); 28 | 29 | client.RaiseEvent("ChannelGuestStarSlotUpdate", new ChannelGuestStarSlotUpdateArgs { Notification = data }); 30 | } 31 | catch (Exception ex) 32 | { 33 | client.RaiseEvent("ErrorOccurred", new ErrorOccuredArgs { Exception = ex, Message = $"Error encountered while trying to handle channel.guest_star_slot.update notification! Raw Json: {jsonString}" }); 34 | } 35 | } 36 | } 37 | } -------------------------------------------------------------------------------- /TwitchLib.EventSub.Websockets/Handler/Channel/HypeTrains/ChannelHypeTrainBeginHandler.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Text.Json; 3 | using TwitchLib.EventSub.Core.SubscriptionTypes.Channel; 4 | using TwitchLib.EventSub.Websockets.Core.EventArgs; 5 | using TwitchLib.EventSub.Websockets.Core.EventArgs.Channel; 6 | using TwitchLib.EventSub.Websockets.Core.Handler; 7 | using TwitchLib.EventSub.Websockets.Core.Models; 8 | 9 | namespace TwitchLib.EventSub.Websockets.Handler.Channel.HypeTrains 10 | { 11 | /// 12 | /// Handler for 'channel.hype_train.begin' notifications 13 | /// 14 | public class ChannelHypeTrainBeginHandler : INotificationHandler 15 | { 16 | /// 17 | public string SubscriptionType => "channel.hype_train.begin"; 18 | 19 | /// 20 | public void Handle(EventSubWebsocketClient client, string jsonString, JsonSerializerOptions serializerOptions) 21 | { 22 | try 23 | { 24 | var data = JsonSerializer.Deserialize>(jsonString.AsSpan(), serializerOptions); 25 | 26 | if (data is null) 27 | throw new InvalidOperationException("Parsed JSON cannot be null!"); 28 | 29 | client.RaiseEvent("ChannelHypeTrainBegin", new ChannelHypeTrainBeginArgs { Notification = data }); 30 | } 31 | catch (Exception ex) 32 | { 33 | client.RaiseEvent("ErrorOccurred", new ErrorOccuredArgs { Exception = ex, Message = $"Error encountered while trying to handle {SubscriptionType} notification! Raw Json: {jsonString}" }); 34 | } 35 | } 36 | } 37 | } -------------------------------------------------------------------------------- /TwitchLib.EventSub.Websockets/Handler/Channel/HypeTrains/ChannelHypeTrainEndHandler.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Text.Json; 3 | using TwitchLib.EventSub.Core.SubscriptionTypes.Channel; 4 | using TwitchLib.EventSub.Websockets.Core.EventArgs; 5 | using TwitchLib.EventSub.Websockets.Core.EventArgs.Channel; 6 | using TwitchLib.EventSub.Websockets.Core.Handler; 7 | using TwitchLib.EventSub.Websockets.Core.Models; 8 | 9 | namespace TwitchLib.EventSub.Websockets.Handler.Channel.HypeTrains 10 | { 11 | /// 12 | /// Handler for 'channel.hype_train.end' notifications 13 | /// 14 | public class ChannelHypeTrainEndHandler : INotificationHandler 15 | { 16 | /// 17 | public string SubscriptionType => "channel.hype_train.end"; 18 | 19 | /// 20 | public void Handle(EventSubWebsocketClient client, string jsonString, JsonSerializerOptions serializerOptions) 21 | { 22 | try 23 | { 24 | var data = JsonSerializer.Deserialize>(jsonString.AsSpan(), serializerOptions); 25 | 26 | if (data is null) 27 | throw new InvalidOperationException("Parsed JSON cannot be null!"); 28 | 29 | client.RaiseEvent("ChannelHypeTrainEnd", new ChannelHypeTrainEndArgs { Notification = data }); 30 | } 31 | catch (Exception ex) 32 | { 33 | client.RaiseEvent("ErrorOccurred", new ErrorOccuredArgs { Exception = ex, Message = $"Error encountered while trying to handle {SubscriptionType} notification! Raw Json: {jsonString}" }); 34 | } 35 | } 36 | } 37 | } -------------------------------------------------------------------------------- /TwitchLib.EventSub.Websockets/Handler/Channel/HypeTrains/ChannelHypeTrainProgressHandler.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Text.Json; 3 | using TwitchLib.EventSub.Core.SubscriptionTypes.Channel; 4 | using TwitchLib.EventSub.Websockets.Core.EventArgs; 5 | using TwitchLib.EventSub.Websockets.Core.EventArgs.Channel; 6 | using TwitchLib.EventSub.Websockets.Core.Handler; 7 | using TwitchLib.EventSub.Websockets.Core.Models; 8 | 9 | namespace TwitchLib.EventSub.Websockets.Handler.Channel.HypeTrains 10 | { 11 | /// 12 | /// Handler for 'channel.hype_train.progress' notifications 13 | /// 14 | public class ChannelHypeTrainProgressHandler : INotificationHandler 15 | { 16 | /// 17 | public string SubscriptionType => "channel.hype_train.progress"; 18 | 19 | /// 20 | public void Handle(EventSubWebsocketClient client, string jsonString, JsonSerializerOptions serializerOptions) 21 | { 22 | try 23 | { 24 | var data = JsonSerializer.Deserialize>(jsonString.AsSpan(), serializerOptions); 25 | 26 | if (data is null) 27 | throw new InvalidOperationException("Parsed JSON cannot be null!"); 28 | 29 | client.RaiseEvent("ChannelHypeTrainProgress", new ChannelHypeTrainProgressArgs { Notification = data }); 30 | } 31 | catch (Exception ex) 32 | { 33 | client.RaiseEvent("ErrorOccurred", new ErrorOccuredArgs { Exception = ex, Message = $"Error encountered while trying to handle {SubscriptionType} notification! Raw Json: {jsonString}" }); 34 | } 35 | } 36 | } 37 | } -------------------------------------------------------------------------------- /TwitchLib.EventSub.Websockets/Handler/Channel/Moderation/ChannelBanHandler.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Text.Json; 3 | using TwitchLib.EventSub.Core.SubscriptionTypes.Channel; 4 | using TwitchLib.EventSub.Websockets.Core.EventArgs; 5 | using TwitchLib.EventSub.Websockets.Core.EventArgs.Channel; 6 | using TwitchLib.EventSub.Websockets.Core.Handler; 7 | using TwitchLib.EventSub.Websockets.Core.Models; 8 | 9 | namespace TwitchLib.EventSub.Websockets.Handler.Channel.Moderation 10 | { 11 | /// 12 | /// Handler for 'channel.ban' notifications 13 | /// 14 | public class ChannelBanHandler : INotificationHandler 15 | { 16 | /// 17 | public string SubscriptionType => "channel.ban"; 18 | 19 | /// 20 | public void Handle(EventSubWebsocketClient client, string jsonString, JsonSerializerOptions serializerOptions) 21 | { 22 | try 23 | { 24 | var data = JsonSerializer.Deserialize>(jsonString.AsSpan(), serializerOptions); 25 | 26 | if (data is null) 27 | throw new InvalidOperationException("Parsed JSON cannot be null!"); 28 | 29 | client.RaiseEvent("ChannelBan", new ChannelBanArgs { Notification = data }); 30 | } 31 | catch (Exception ex) 32 | { 33 | client.RaiseEvent("ErrorOccurred", new ErrorOccuredArgs { Exception = ex, Message = $"Error encountered while trying to handle {SubscriptionType} notification! Raw Json: {jsonString}" }); 34 | } 35 | } 36 | } 37 | } -------------------------------------------------------------------------------- /TwitchLib.EventSub.Websockets/Handler/Channel/Moderation/ChannelUnbanHandler.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Text.Json; 3 | using TwitchLib.EventSub.Core.SubscriptionTypes.Channel; 4 | using TwitchLib.EventSub.Websockets.Core.EventArgs; 5 | using TwitchLib.EventSub.Websockets.Core.EventArgs.Channel; 6 | using TwitchLib.EventSub.Websockets.Core.Handler; 7 | using TwitchLib.EventSub.Websockets.Core.Models; 8 | 9 | namespace TwitchLib.EventSub.Websockets.Handler.Channel.Moderation 10 | { 11 | /// 12 | /// Handler for 'channel.unban' notifications 13 | /// 14 | public class ChannelUnbanHandler : INotificationHandler 15 | { 16 | /// 17 | public string SubscriptionType => "channel.unban"; 18 | 19 | /// 20 | public void Handle(EventSubWebsocketClient client, string jsonString, JsonSerializerOptions serializerOptions) 21 | { 22 | try 23 | { 24 | var data = JsonSerializer.Deserialize>(jsonString.AsSpan(), serializerOptions); 25 | 26 | if (data is null) 27 | throw new InvalidOperationException("Parsed JSON cannot be null!"); 28 | 29 | client.RaiseEvent("ChannelUnban", new ChannelUnbanArgs { Notification = data }); 30 | } 31 | catch (Exception ex) 32 | { 33 | client.RaiseEvent("ErrorOccurred", new ErrorOccuredArgs { Exception = ex, Message = $"Error encountered while trying to handle {SubscriptionType} notification! Raw Json: {jsonString}" }); 34 | } 35 | } 36 | } 37 | } -------------------------------------------------------------------------------- /TwitchLib.EventSub.Websockets/Handler/Channel/Moderation/ChannelUnbanRequestCreateHandler.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Text.Json; 3 | using TwitchLib.EventSub.Core.SubscriptionTypes.Channel; 4 | using TwitchLib.EventSub.Websockets.Core.EventArgs; 5 | using TwitchLib.EventSub.Websockets.Core.EventArgs.Channel; 6 | using TwitchLib.EventSub.Websockets.Core.Handler; 7 | using TwitchLib.EventSub.Websockets.Core.Models; 8 | 9 | namespace TwitchLib.EventSub.Websockets.Handler.Channel.Moderation 10 | { 11 | /// 12 | /// Handler for 'channel.unban_request.create' notifications 13 | /// 14 | public class ChannelUnbanRequestCreateHandler : INotificationHandler 15 | { 16 | /// 17 | public string SubscriptionType => "channel.unban_request.create"; 18 | 19 | /// 20 | public void Handle(EventSubWebsocketClient client, string jsonString, JsonSerializerOptions serializerOptions) 21 | { 22 | try 23 | { 24 | var data = JsonSerializer.Deserialize>(jsonString.AsSpan(), serializerOptions); 25 | 26 | if (data is null) 27 | throw new InvalidOperationException("Parsed JSON cannot be null!"); 28 | 29 | client.RaiseEvent("ChannelUnbanRequestCreate", new ChannelUnbanRequestCreateArgs { Notification = data }); 30 | } 31 | catch (Exception ex) 32 | { 33 | client.RaiseEvent("ErrorOccurred", new ErrorOccuredArgs { Exception = ex, Message = $"Error encountered while trying to handle {SubscriptionType} notification! Raw Json: {jsonString}" }); 34 | } 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /TwitchLib.EventSub.Websockets/Handler/Channel/Moderation/ChannelUnbanRequestResolveHandler.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Text.Json; 3 | using TwitchLib.EventSub.Core.SubscriptionTypes.Channel; 4 | using TwitchLib.EventSub.Websockets.Core.EventArgs; 5 | using TwitchLib.EventSub.Websockets.Core.EventArgs.Channel; 6 | using TwitchLib.EventSub.Websockets.Core.Handler; 7 | using TwitchLib.EventSub.Websockets.Core.Models; 8 | 9 | namespace TwitchLib.EventSub.Websockets.Handler.Channel.Moderation 10 | { 11 | /// 12 | /// Handler for 'channel.unban_request.resolve' notifications 13 | /// 14 | public class ChannelUnbanRequestResolveHandler : INotificationHandler 15 | { 16 | /// 17 | public string SubscriptionType => "channel.unban_request.resolve"; 18 | 19 | /// 20 | public void Handle(EventSubWebsocketClient client, string jsonString, JsonSerializerOptions serializerOptions) 21 | { 22 | try 23 | { 24 | var data = JsonSerializer.Deserialize>(jsonString.AsSpan(), serializerOptions); 25 | 26 | if (data is null) 27 | throw new InvalidOperationException("Parsed JSON cannot be null!"); 28 | 29 | client.RaiseEvent("ChannelUnbanRequestResolve", new ChannelUnbanRequestResolveArgs { Notification = data }); 30 | } 31 | catch (Exception ex) 32 | { 33 | client.RaiseEvent("ErrorOccurred", new ErrorOccuredArgs { Exception = ex, Message = $"Error encountered while trying to handle {SubscriptionType} notification! Raw Json: {jsonString}" }); 34 | } 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /TwitchLib.EventSub.Websockets/Handler/Channel/Moderators/ChannelModeratorAddHandler.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Text.Json; 3 | using TwitchLib.EventSub.Core.SubscriptionTypes.Channel; 4 | using TwitchLib.EventSub.Websockets.Core.EventArgs; 5 | using TwitchLib.EventSub.Websockets.Core.EventArgs.Channel; 6 | using TwitchLib.EventSub.Websockets.Core.Handler; 7 | using TwitchLib.EventSub.Websockets.Core.Models; 8 | 9 | namespace TwitchLib.EventSub.Websockets.Handler.Channel.Moderators 10 | { 11 | /// 12 | /// Handler for 'channel.moderator.add' notifications 13 | /// 14 | public class ChannelModeratorAddHandler : INotificationHandler 15 | { 16 | /// 17 | public string SubscriptionType => "channel.moderator.add"; 18 | 19 | /// 20 | public void Handle(EventSubWebsocketClient client, string jsonString, JsonSerializerOptions serializerOptions) 21 | { 22 | try 23 | { 24 | var data = JsonSerializer.Deserialize>(jsonString.AsSpan(), serializerOptions); 25 | 26 | if (data is null) 27 | throw new InvalidOperationException("Parsed JSON cannot be null!"); 28 | 29 | client.RaiseEvent("ChannelModeratorAdd", new ChannelModeratorArgs { Notification = data }); 30 | } 31 | catch (Exception ex) 32 | { 33 | client.RaiseEvent("ErrorOccurred", new ErrorOccuredArgs { Exception = ex, Message = $"Error encountered while trying to handle {SubscriptionType} notification! Raw Json: {jsonString}" }); 34 | } 35 | } 36 | } 37 | } -------------------------------------------------------------------------------- /TwitchLib.EventSub.Websockets/Handler/Channel/Moderators/ChannelModeratorRemoveHandler.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Text.Json; 3 | using TwitchLib.EventSub.Core.SubscriptionTypes.Channel; 4 | using TwitchLib.EventSub.Websockets.Core.EventArgs; 5 | using TwitchLib.EventSub.Websockets.Core.EventArgs.Channel; 6 | using TwitchLib.EventSub.Websockets.Core.Handler; 7 | using TwitchLib.EventSub.Websockets.Core.Models; 8 | 9 | namespace TwitchLib.EventSub.Websockets.Handler.Channel.Moderators 10 | { 11 | /// 12 | /// Handler for 'channel.moderator.remove' notifications 13 | /// 14 | public class ChannelModeratorRemoveHandler : INotificationHandler 15 | { 16 | /// 17 | public string SubscriptionType => "channel.moderator.remove"; 18 | 19 | /// 20 | public void Handle(EventSubWebsocketClient client, string jsonString, JsonSerializerOptions serializerOptions) 21 | { 22 | try 23 | { 24 | var data = JsonSerializer.Deserialize>(jsonString.AsSpan(), serializerOptions); 25 | 26 | if (data is null) 27 | throw new InvalidOperationException("Parsed JSON cannot be null!"); 28 | 29 | client.RaiseEvent("ChannelModeratorRemove", new ChannelModeratorArgs { Notification = data }); 30 | } 31 | catch (Exception ex) 32 | { 33 | client.RaiseEvent("ErrorOccurred", new ErrorOccuredArgs { Exception = ex, Message = $"Error encountered while trying to handle {SubscriptionType} notification! Raw Json: {jsonString}" }); 34 | } 35 | } 36 | } 37 | } -------------------------------------------------------------------------------- /TwitchLib.EventSub.Websockets/Handler/Channel/Polls/ChannelPollBeginHandler.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Text.Json; 3 | using TwitchLib.EventSub.Core.SubscriptionTypes.Channel; 4 | using TwitchLib.EventSub.Websockets.Core.EventArgs; 5 | using TwitchLib.EventSub.Websockets.Core.EventArgs.Channel; 6 | using TwitchLib.EventSub.Websockets.Core.Handler; 7 | using TwitchLib.EventSub.Websockets.Core.Models; 8 | 9 | namespace TwitchLib.EventSub.Websockets.Handler.Channel.Polls 10 | { 11 | /// 12 | /// Handler for 'channel.poll.begin' notifications 13 | /// 14 | public class ChannelPollBeginHandler : INotificationHandler 15 | { 16 | /// 17 | public string SubscriptionType => "channel.poll.begin"; 18 | 19 | /// 20 | public void Handle(EventSubWebsocketClient client, string jsonString, JsonSerializerOptions serializerOptions) 21 | { 22 | try 23 | { 24 | var data = JsonSerializer.Deserialize>(jsonString.AsSpan(), serializerOptions); 25 | 26 | if (data is null) 27 | throw new InvalidOperationException("Parsed JSON cannot be null!"); 28 | 29 | client.RaiseEvent("ChannelPollBegin", new ChannelPollBeginArgs { Notification = data }); 30 | } 31 | catch (Exception ex) 32 | { 33 | client.RaiseEvent("ErrorOccurred", new ErrorOccuredArgs { Exception = ex, Message = $"Error encountered while trying to handle {SubscriptionType} notification! Raw Json: {jsonString}" }); 34 | } 35 | } 36 | } 37 | } -------------------------------------------------------------------------------- /TwitchLib.EventSub.Websockets/Handler/Channel/Polls/ChannelPollEndHandler.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Text.Json; 3 | using TwitchLib.EventSub.Core.SubscriptionTypes.Channel; 4 | using TwitchLib.EventSub.Websockets.Core.EventArgs; 5 | using TwitchLib.EventSub.Websockets.Core.EventArgs.Channel; 6 | using TwitchLib.EventSub.Websockets.Core.Handler; 7 | using TwitchLib.EventSub.Websockets.Core.Models; 8 | 9 | namespace TwitchLib.EventSub.Websockets.Handler.Channel.Polls 10 | { 11 | /// 12 | /// Handler for 'channel.poll.end' notifications 13 | /// 14 | public class ChannelPollEndHandler : INotificationHandler 15 | { 16 | /// 17 | public string SubscriptionType => "channel.poll.end"; 18 | 19 | /// 20 | public void Handle(EventSubWebsocketClient client, string jsonString, JsonSerializerOptions serializerOptions) 21 | { 22 | try 23 | { 24 | var data = JsonSerializer.Deserialize>(jsonString.AsSpan(), serializerOptions); 25 | 26 | if (data is null) 27 | throw new InvalidOperationException("Parsed JSON cannot be null!"); 28 | 29 | client.RaiseEvent("ChannelPollEnd", new ChannelPollEndArgs { Notification = data }); 30 | } 31 | catch (Exception ex) 32 | { 33 | client.RaiseEvent("ErrorOccurred", new ErrorOccuredArgs { Exception = ex, Message = $"Error encountered while trying to handle {SubscriptionType} notification! Raw Json: {jsonString}" }); 34 | } 35 | } 36 | } 37 | } -------------------------------------------------------------------------------- /TwitchLib.EventSub.Websockets/Handler/Channel/Polls/ChannelPollProgressHandler.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Text.Json; 3 | using TwitchLib.EventSub.Core.SubscriptionTypes.Channel; 4 | using TwitchLib.EventSub.Websockets.Core.EventArgs; 5 | using TwitchLib.EventSub.Websockets.Core.EventArgs.Channel; 6 | using TwitchLib.EventSub.Websockets.Core.Handler; 7 | using TwitchLib.EventSub.Websockets.Core.Models; 8 | 9 | namespace TwitchLib.EventSub.Websockets.Handler.Channel.Polls 10 | { 11 | /// 12 | /// Handler for 'channel.poll.progress' notifications 13 | /// 14 | public class ChannelPollProgressHandler : INotificationHandler 15 | { 16 | /// 17 | public string SubscriptionType => "channel.poll.progress"; 18 | 19 | /// 20 | public void Handle(EventSubWebsocketClient client, string jsonString, JsonSerializerOptions serializerOptions) 21 | { 22 | try 23 | { 24 | var data = JsonSerializer.Deserialize>(jsonString.AsSpan(), serializerOptions); 25 | 26 | if (data is null) 27 | throw new InvalidOperationException("Parsed JSON cannot be null!"); 28 | 29 | client.RaiseEvent("ChannelPollProgress", new ChannelPollProgressArgs { Notification = data }); 30 | } 31 | catch (Exception ex) 32 | { 33 | client.RaiseEvent("ErrorOccurred", new ErrorOccuredArgs { Exception = ex, Message = $"Error encountered while trying to handle {SubscriptionType} notification! Raw Json: {jsonString}" }); 34 | } 35 | } 36 | } 37 | } -------------------------------------------------------------------------------- /TwitchLib.EventSub.Websockets/Handler/Channel/Predictions/ChannelPredictionBeginHandler.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Text.Json; 3 | using TwitchLib.EventSub.Core.SubscriptionTypes.Channel; 4 | using TwitchLib.EventSub.Websockets.Core.EventArgs; 5 | using TwitchLib.EventSub.Websockets.Core.EventArgs.Channel; 6 | using TwitchLib.EventSub.Websockets.Core.Handler; 7 | using TwitchLib.EventSub.Websockets.Core.Models; 8 | 9 | namespace TwitchLib.EventSub.Websockets.Handler.Channel.Predictions 10 | { 11 | /// 12 | /// Handler for 'channel.prediction.begin' notifications 13 | /// 14 | public class ChannelPredictionBeginHandler : INotificationHandler 15 | { 16 | /// 17 | public string SubscriptionType => "channel.prediction.begin"; 18 | 19 | /// 20 | public void Handle(EventSubWebsocketClient client, string jsonString, JsonSerializerOptions serializerOptions) 21 | { 22 | try 23 | { 24 | var data = JsonSerializer.Deserialize>(jsonString.AsSpan(), serializerOptions); 25 | 26 | if (data is null) 27 | throw new InvalidOperationException("Parsed JSON cannot be null!"); 28 | 29 | client.RaiseEvent("ChannelPredictionBegin", new ChannelPredictionBeginArgs { Notification = data }); 30 | } 31 | catch (Exception ex) 32 | { 33 | client.RaiseEvent("ErrorOccurred", new ErrorOccuredArgs { Exception = ex, Message = $"Error encountered while trying to handle {SubscriptionType} notification! Raw Json: {jsonString}" }); 34 | } 35 | } 36 | } 37 | } -------------------------------------------------------------------------------- /TwitchLib.EventSub.Websockets/Handler/Channel/Predictions/ChannelPredictionEndHandler.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Text.Json; 3 | using TwitchLib.EventSub.Core.SubscriptionTypes.Channel; 4 | using TwitchLib.EventSub.Websockets.Core.EventArgs; 5 | using TwitchLib.EventSub.Websockets.Core.EventArgs.Channel; 6 | using TwitchLib.EventSub.Websockets.Core.Handler; 7 | using TwitchLib.EventSub.Websockets.Core.Models; 8 | 9 | namespace TwitchLib.EventSub.Websockets.Handler.Channel.Predictions 10 | { 11 | /// 12 | /// Handler for 'channel.prediction.end' notifications 13 | /// 14 | public class ChannelPredictionEndHandler : INotificationHandler 15 | { 16 | /// 17 | public string SubscriptionType => "channel.prediction.end"; 18 | 19 | /// 20 | public void Handle(EventSubWebsocketClient client, string jsonString, JsonSerializerOptions serializerOptions) 21 | { 22 | try 23 | { 24 | var data = JsonSerializer.Deserialize>(jsonString.AsSpan(), serializerOptions); 25 | 26 | if (data is null) 27 | throw new InvalidOperationException("Parsed JSON cannot be null!"); 28 | 29 | client.RaiseEvent("ChannelPredictionEnd", new ChannelPredictionEndArgs { Notification = data }); 30 | } 31 | catch (Exception ex) 32 | { 33 | client.RaiseEvent("ErrorOccurred", new ErrorOccuredArgs { Exception = ex, Message = $"Error encountered while trying to handle {SubscriptionType} notification! Raw Json: {jsonString}" }); 34 | } 35 | } 36 | } 37 | } -------------------------------------------------------------------------------- /TwitchLib.EventSub.Websockets/Handler/Channel/Predictions/ChannelPredictionLockHandler.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Text.Json; 3 | using TwitchLib.EventSub.Core.SubscriptionTypes.Channel; 4 | using TwitchLib.EventSub.Websockets.Core.EventArgs; 5 | using TwitchLib.EventSub.Websockets.Core.EventArgs.Channel; 6 | using TwitchLib.EventSub.Websockets.Core.Handler; 7 | using TwitchLib.EventSub.Websockets.Core.Models; 8 | 9 | namespace TwitchLib.EventSub.Websockets.Handler.Channel.Predictions 10 | { 11 | /// 12 | /// Handler for 'channel.prediction.lock' notifications 13 | /// 14 | public class ChannelPredictionLockBeginHandler : INotificationHandler 15 | { 16 | /// 17 | public string SubscriptionType => "channel.prediction.lock"; 18 | 19 | /// 20 | public void Handle(EventSubWebsocketClient client, string jsonString, JsonSerializerOptions serializerOptions) 21 | { 22 | try 23 | { 24 | var data = JsonSerializer.Deserialize>(jsonString.AsSpan(), serializerOptions); 25 | 26 | if (data is null) 27 | throw new InvalidOperationException("Parsed JSON cannot be null!"); 28 | 29 | client.RaiseEvent("ChannelPredictionLock", new ChannelPredictionLockArgs { Notification = data }); 30 | } 31 | catch (Exception ex) 32 | { 33 | client.RaiseEvent("ErrorOccurred", new ErrorOccuredArgs { Exception = ex, Message = $"Error encountered while trying to handle {SubscriptionType} notification! Raw Json: {jsonString}" }); 34 | } 35 | } 36 | } 37 | } -------------------------------------------------------------------------------- /TwitchLib.EventSub.Websockets/Handler/Channel/Predictions/ChannelPredictionProgressHandler.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Text.Json; 3 | using TwitchLib.EventSub.Core.SubscriptionTypes.Channel; 4 | using TwitchLib.EventSub.Websockets.Core.EventArgs; 5 | using TwitchLib.EventSub.Websockets.Core.EventArgs.Channel; 6 | using TwitchLib.EventSub.Websockets.Core.Handler; 7 | using TwitchLib.EventSub.Websockets.Core.Models; 8 | 9 | namespace TwitchLib.EventSub.Websockets.Handler.Channel.Predictions 10 | { 11 | /// 12 | /// Handler for 'channel.prediction.progress' notifications 13 | /// 14 | public class ChannelPredictionProgressHandler : INotificationHandler 15 | { 16 | /// 17 | public string SubscriptionType => "channel.prediction.progress"; 18 | 19 | /// 20 | public void Handle(EventSubWebsocketClient client, string jsonString, JsonSerializerOptions serializerOptions) 21 | { 22 | try 23 | { 24 | var data = JsonSerializer.Deserialize>(jsonString.AsSpan(), serializerOptions); 25 | 26 | if (data is null) 27 | throw new InvalidOperationException("Parsed JSON cannot be null!"); 28 | 29 | client.RaiseEvent("ChannelPredictionProgress", new ChannelPredictionProgressArgs { Notification = data }); 30 | } 31 | catch (Exception ex) 32 | { 33 | client.RaiseEvent("ErrorOccurred", new ErrorOccuredArgs { Exception = ex, Message = $"Error encountered while trying to handle {SubscriptionType} notification! Raw Json: {jsonString}" }); 34 | } 35 | } 36 | } 37 | } -------------------------------------------------------------------------------- /TwitchLib.EventSub.Websockets/Handler/Channel/Raids/ChannelRaidHandler.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Text.Json; 3 | using TwitchLib.EventSub.Core.SubscriptionTypes.Channel; 4 | using TwitchLib.EventSub.Websockets.Core.EventArgs; 5 | using TwitchLib.EventSub.Websockets.Core.EventArgs.Channel; 6 | using TwitchLib.EventSub.Websockets.Core.Handler; 7 | using TwitchLib.EventSub.Websockets.Core.Models; 8 | 9 | namespace TwitchLib.EventSub.Websockets.Handler.Channel.Raids 10 | { 11 | /// 12 | /// Handler for 'channel.raid' notifications 13 | /// 14 | public class ChannelRaidHandler : INotificationHandler 15 | { 16 | /// 17 | public string SubscriptionType => "channel.raid"; 18 | 19 | /// 20 | public void Handle(EventSubWebsocketClient client, string jsonString, JsonSerializerOptions serializerOptions) 21 | { 22 | try 23 | { 24 | var data = JsonSerializer.Deserialize>(jsonString.AsSpan(), serializerOptions); 25 | 26 | if (data is null) 27 | throw new InvalidOperationException("Parsed JSON cannot be null!"); 28 | 29 | client.RaiseEvent("ChannelRaid", new ChannelRaidArgs { Notification = data }); 30 | } 31 | catch (Exception ex) 32 | { 33 | client.RaiseEvent("ErrorOccurred", new ErrorOccuredArgs { Exception = ex, Message = $"Error encountered while trying to handle {SubscriptionType} notification! Raw Json: {jsonString}" }); 34 | } 35 | } 36 | } 37 | } -------------------------------------------------------------------------------- /TwitchLib.EventSub.Websockets/Handler/Channel/SharedChat/ChannelSharedChatSessionBeginHandler.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Text.Json; 3 | using TwitchLib.EventSub.Core.SubscriptionTypes.Channel; 4 | using TwitchLib.EventSub.Websockets.Core.EventArgs; 5 | using TwitchLib.EventSub.Websockets.Core.EventArgs.Channel; 6 | using TwitchLib.EventSub.Websockets.Core.Handler; 7 | using TwitchLib.EventSub.Websockets.Core.Models; 8 | 9 | namespace TwitchLib.EventSub.Websockets.Handler.Channel.SharedChat 10 | { 11 | /// 12 | /// Handler for 'channel.shared_chat.begin' notifications 13 | /// 14 | public class ChannelSharedChatSessionBeginHandler : INotificationHandler 15 | { 16 | /// 17 | public string SubscriptionType => "channel.shared_chat.begin"; 18 | 19 | /// 20 | public void Handle(EventSubWebsocketClient client, string jsonString, JsonSerializerOptions serializerOptions) 21 | { 22 | try 23 | { 24 | var data = JsonSerializer.Deserialize>(jsonString.AsSpan(), serializerOptions); 25 | 26 | if (data is null) 27 | throw new InvalidOperationException("Parsed JSON cannot be null!"); 28 | 29 | client.RaiseEvent("ChannelSharedChatSessionBegin", new ChannelSharedChatSessionBeginArgs { Notification = data }); 30 | } 31 | catch (Exception ex) 32 | { 33 | client.RaiseEvent("ErrorOccurred", new ErrorOccuredArgs { Exception = ex, Message = $"Error encountered while trying to handle channel.shared_chat.begin notification! Raw Json: {jsonString}" }); 34 | } 35 | } 36 | } 37 | } -------------------------------------------------------------------------------- /TwitchLib.EventSub.Websockets/Handler/Channel/SharedChat/ChannelSharedChatSessionEndHandler.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Text.Json; 3 | using TwitchLib.EventSub.Core.SubscriptionTypes.Channel; 4 | using TwitchLib.EventSub.Websockets.Core.EventArgs; 5 | using TwitchLib.EventSub.Websockets.Core.EventArgs.Channel; 6 | using TwitchLib.EventSub.Websockets.Core.Handler; 7 | using TwitchLib.EventSub.Websockets.Core.Models; 8 | 9 | namespace TwitchLib.EventSub.Websockets.Handler.Channel.SharedChat 10 | { 11 | /// 12 | /// Handler for 'channel.shared_chat.end' notifications 13 | /// 14 | public class ChannelSharedChatSessionEndHandler : INotificationHandler 15 | { 16 | /// 17 | public string SubscriptionType => "channel.shared_chat.end"; 18 | 19 | /// 20 | public void Handle(EventSubWebsocketClient client, string jsonString, JsonSerializerOptions serializerOptions) 21 | { 22 | try 23 | { 24 | var data = JsonSerializer.Deserialize>(jsonString.AsSpan(), serializerOptions); 25 | 26 | if (data is null) 27 | throw new InvalidOperationException("Parsed JSON cannot be null!"); 28 | 29 | client.RaiseEvent("ChannelSharedChatSessionEnd", new ChannelSharedChatSessionEndArgs { Notification = data }); 30 | } 31 | catch (Exception ex) 32 | { 33 | client.RaiseEvent("ErrorOccurred", new ErrorOccuredArgs { Exception = ex, Message = $"Error encountered while trying to handle channel.shared_chat.end notification! Raw Json: {jsonString}" }); 34 | } 35 | } 36 | } 37 | } -------------------------------------------------------------------------------- /TwitchLib.EventSub.Websockets/Handler/Channel/SharedChat/ChannelSharedChatSessionUpdateHandler.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Text.Json; 3 | using TwitchLib.EventSub.Core.SubscriptionTypes.Channel; 4 | using TwitchLib.EventSub.Websockets.Core.EventArgs; 5 | using TwitchLib.EventSub.Websockets.Core.EventArgs.Channel; 6 | using TwitchLib.EventSub.Websockets.Core.Handler; 7 | using TwitchLib.EventSub.Websockets.Core.Models; 8 | 9 | namespace TwitchLib.EventSub.Websockets.Handler.Channel.SharedChat 10 | { 11 | /// 12 | /// Handler for 'channel.shared_chat.update' notifications 13 | /// 14 | public class ChannelSharedChatSessionUpdateHandler : INotificationHandler 15 | { 16 | /// 17 | public string SubscriptionType => "channel.shared_chat.update"; 18 | 19 | /// 20 | public void Handle(EventSubWebsocketClient client, string jsonString, JsonSerializerOptions serializerOptions) 21 | { 22 | try 23 | { 24 | var data = JsonSerializer.Deserialize>(jsonString.AsSpan(), serializerOptions); 25 | 26 | if (data is null) 27 | throw new InvalidOperationException("Parsed JSON cannot be null!"); 28 | 29 | client.RaiseEvent("ChannelSharedChatSessionUpdate", new ChannelSharedChatSessionUpdateArgs { Notification = data }); 30 | } 31 | catch (Exception ex) 32 | { 33 | client.RaiseEvent("ErrorOccurred", new ErrorOccuredArgs { Exception = ex, Message = $"Error encountered while trying to handle channel.shared_chat.update notification! Raw Json: {jsonString}" }); 34 | } 35 | } 36 | } 37 | } -------------------------------------------------------------------------------- /TwitchLib.EventSub.Websockets/Handler/Channel/ShieldMode/ChannelShieldModeBeginHandler.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Text.Json; 3 | using TwitchLib.EventSub.Core.SubscriptionTypes.Channel; 4 | using TwitchLib.EventSub.Websockets.Core.EventArgs; 5 | using TwitchLib.EventSub.Websockets.Core.EventArgs.Channel; 6 | using TwitchLib.EventSub.Websockets.Core.Handler; 7 | using TwitchLib.EventSub.Websockets.Core.Models; 8 | 9 | namespace TwitchLib.EventSub.Websockets.Handler.Channel.ShieldMode 10 | { 11 | /// 12 | /// Handler for 'channel.shield_mode.begin' notifications 13 | /// 14 | public class ChannelShieldModeBeginHandler : INotificationHandler 15 | { 16 | /// 17 | public string SubscriptionType => "channel.shield_mode.begin"; 18 | 19 | /// 20 | public void Handle(EventSubWebsocketClient client, string jsonString, JsonSerializerOptions serializerOptions) 21 | { 22 | try 23 | { 24 | var data = JsonSerializer.Deserialize>(jsonString.AsSpan(), serializerOptions); 25 | 26 | if (data is null) 27 | throw new InvalidOperationException("Parsed JSON cannot be null!"); 28 | 29 | client.RaiseEvent("ChannelShieldModeBegin", new ChannelShieldModeBeginArgs { Notification = data }); 30 | } 31 | catch (Exception ex) 32 | { 33 | client.RaiseEvent("ErrorOccurred", new ErrorOccuredArgs { Exception = ex, Message = $"Error encountered while trying to handle {SubscriptionType} notification! Raw Json: {jsonString}" }); 34 | } 35 | } 36 | } 37 | } -------------------------------------------------------------------------------- /TwitchLib.EventSub.Websockets/Handler/Channel/ShieldMode/ChannelShieldModeEndHandler.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Text.Json; 3 | using TwitchLib.EventSub.Core.SubscriptionTypes.Channel; 4 | using TwitchLib.EventSub.Websockets.Core.EventArgs; 5 | using TwitchLib.EventSub.Websockets.Core.EventArgs.Channel; 6 | using TwitchLib.EventSub.Websockets.Core.Handler; 7 | using TwitchLib.EventSub.Websockets.Core.Models; 8 | 9 | namespace TwitchLib.EventSub.Websockets.Handler.Channel.ShieldMode 10 | { 11 | /// 12 | /// Handler for 'channel.shield_mode.end' notifications 13 | /// 14 | public class ChannelShieldModeEndHandler : INotificationHandler 15 | { 16 | /// 17 | public string SubscriptionType => "channel.shield_mode.end"; 18 | 19 | /// 20 | public void Handle(EventSubWebsocketClient client, string jsonString, JsonSerializerOptions serializerOptions) 21 | { 22 | try 23 | { 24 | var data = JsonSerializer.Deserialize>(jsonString.AsSpan(), serializerOptions); 25 | 26 | if (data is null) 27 | throw new InvalidOperationException("Parsed JSON cannot be null!"); 28 | 29 | client.RaiseEvent("ChannelShieldModeEnd", new ChannelShieldModeEndArgs { Notification = data }); 30 | } 31 | catch (Exception ex) 32 | { 33 | client.RaiseEvent("ErrorOccurred", new ErrorOccuredArgs { Exception = ex, Message = $"Error encountered while trying to handle {SubscriptionType} notification! Raw Json: {jsonString}" }); 34 | } 35 | } 36 | } 37 | } -------------------------------------------------------------------------------- /TwitchLib.EventSub.Websockets/Handler/Channel/Shoutouts/ChannelShoutoutCreateHandler.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Text.Json; 3 | using TwitchLib.EventSub.Core.SubscriptionTypes.Channel; 4 | using TwitchLib.EventSub.Websockets.Core.EventArgs; 5 | using TwitchLib.EventSub.Websockets.Core.EventArgs.Channel; 6 | using TwitchLib.EventSub.Websockets.Core.Handler; 7 | using TwitchLib.EventSub.Websockets.Core.Models; 8 | 9 | namespace TwitchLib.EventSub.Websockets.Handler.Channel.Shoutouts 10 | { 11 | /// 12 | /// Handler for 'channel.shoutout.create' notifications 13 | /// 14 | public class ChannelShoutoutCreateHandler : INotificationHandler 15 | { 16 | /// 17 | public string SubscriptionType => "channel.shoutout.create"; 18 | 19 | /// 20 | public void Handle(EventSubWebsocketClient client, string jsonString, JsonSerializerOptions serializerOptions) 21 | { 22 | try 23 | { 24 | var data = JsonSerializer.Deserialize>(jsonString.AsSpan(), serializerOptions); 25 | 26 | if (data is null) 27 | throw new InvalidOperationException("Parsed JSON cannot be null!"); 28 | 29 | client.RaiseEvent("ChannelShoutoutCreate", new ChannelShoutoutCreateArgs { Notification = data }); 30 | } 31 | catch (Exception ex) 32 | { 33 | client.RaiseEvent("ErrorOccurred", new ErrorOccuredArgs { Exception = ex, Message = $"Error encountered while trying to handle {SubscriptionType} notification! Raw Json: {jsonString}" }); 34 | } 35 | } 36 | } 37 | } -------------------------------------------------------------------------------- /TwitchLib.EventSub.Websockets/Handler/Channel/Shoutouts/ChannelShoutoutReceiveHandler.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Text.Json; 3 | using TwitchLib.EventSub.Core.SubscriptionTypes.Channel; 4 | using TwitchLib.EventSub.Websockets.Core.EventArgs; 5 | using TwitchLib.EventSub.Websockets.Core.EventArgs.Channel; 6 | using TwitchLib.EventSub.Websockets.Core.Handler; 7 | using TwitchLib.EventSub.Websockets.Core.Models; 8 | 9 | namespace TwitchLib.EventSub.Websockets.Handler.Channel.Shoutouts 10 | { 11 | /// 12 | /// Handler for 'channel.shoutout.receive' notifications 13 | /// 14 | public class ChannelShoutoutReceiveHandler : INotificationHandler 15 | { 16 | /// 17 | public string SubscriptionType => "channel.shoutout.receive"; 18 | 19 | public void Handle(EventSubWebsocketClient client, string jsonString, JsonSerializerOptions serializerOptions) 20 | { 21 | try 22 | { 23 | var data = JsonSerializer.Deserialize>(jsonString.AsSpan(), serializerOptions); 24 | 25 | if (data is null) 26 | throw new InvalidOperationException("Parsed JSON cannot be null!"); 27 | 28 | client.RaiseEvent("ChannelShoutoutReceive", new ChannelShoutoutReceiveArgs { Notification = data }); 29 | } 30 | catch (Exception ex) 31 | { 32 | client.RaiseEvent("ErrorOccurred", new ErrorOccuredArgs { Exception = ex, Message = $"Error encountered while trying to handle {SubscriptionType} notification! Raw Json: {jsonString}" }); 33 | } 34 | } 35 | } 36 | } -------------------------------------------------------------------------------- /TwitchLib.EventSub.Websockets/Handler/Channel/Subscription/ChannelSubscribeHandler.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Text.Json; 3 | using TwitchLib.EventSub.Core.SubscriptionTypes.Channel; 4 | using TwitchLib.EventSub.Websockets.Core.EventArgs; 5 | using TwitchLib.EventSub.Websockets.Core.EventArgs.Channel; 6 | using TwitchLib.EventSub.Websockets.Core.Handler; 7 | using TwitchLib.EventSub.Websockets.Core.Models; 8 | 9 | namespace TwitchLib.EventSub.Websockets.Handler.Channel.Subscription 10 | { 11 | /// 12 | /// Handler for 'channel.subscribe' notifications 13 | /// 14 | public class ChannelSubscribeHandler : INotificationHandler 15 | { 16 | /// 17 | public string SubscriptionType => "channel.subscribe"; 18 | 19 | /// 20 | public void Handle(EventSubWebsocketClient client, string jsonString, JsonSerializerOptions serializerOptions) 21 | { 22 | try 23 | { 24 | var data = JsonSerializer.Deserialize>(jsonString.AsSpan(), serializerOptions); 25 | 26 | if (data is null) 27 | throw new InvalidOperationException("Parsed JSON cannot be null!"); 28 | 29 | client.RaiseEvent("ChannelSubscribe", new ChannelSubscribeArgs { Notification = data }); 30 | } 31 | catch (Exception ex) 32 | { 33 | client.RaiseEvent("ErrorOccurred", new ErrorOccuredArgs { Exception = ex, Message = $"Error encountered while trying to handle {SubscriptionType} notification! Raw Json: {jsonString}" }); 34 | } 35 | } 36 | } 37 | } -------------------------------------------------------------------------------- /TwitchLib.EventSub.Websockets/Handler/Channel/Subscription/ChannelSubscriptionEndHandler.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Text.Json; 3 | using TwitchLib.EventSub.Core.SubscriptionTypes.Channel; 4 | using TwitchLib.EventSub.Websockets.Core.EventArgs; 5 | using TwitchLib.EventSub.Websockets.Core.EventArgs.Channel; 6 | using TwitchLib.EventSub.Websockets.Core.Handler; 7 | using TwitchLib.EventSub.Websockets.Core.Models; 8 | 9 | namespace TwitchLib.EventSub.Websockets.Handler.Channel.Subscription 10 | { 11 | /// 12 | /// Handler for 'channel.subscription.end' notifications 13 | /// 14 | public class ChannelSubscriptionEndHandler : INotificationHandler 15 | { 16 | /// 17 | public string SubscriptionType => "channel.subscription.end"; 18 | 19 | /// 20 | public void Handle(EventSubWebsocketClient client, string jsonString, JsonSerializerOptions serializerOptions) 21 | { 22 | try 23 | { 24 | var data = JsonSerializer.Deserialize>(jsonString.AsSpan(), serializerOptions); 25 | 26 | if (data is null) 27 | throw new InvalidOperationException("Parsed JSON cannot be null!"); 28 | 29 | client.RaiseEvent("ChannelSubscriptionEnd", new ChannelSubscriptionEndArgs { Notification = data }); 30 | } 31 | catch (Exception ex) 32 | { 33 | client.RaiseEvent("ErrorOccurred", new ErrorOccuredArgs { Exception = ex, Message = $"Error encountered while trying to handle {SubscriptionType} notification! Raw Json: {jsonString}" }); 34 | } 35 | } 36 | } 37 | } -------------------------------------------------------------------------------- /TwitchLib.EventSub.Websockets/Handler/Channel/Subscription/ChannelSubscriptionGiftHandler.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Text.Json; 3 | using TwitchLib.EventSub.Core.SubscriptionTypes.Channel; 4 | using TwitchLib.EventSub.Websockets.Core.EventArgs; 5 | using TwitchLib.EventSub.Websockets.Core.EventArgs.Channel; 6 | using TwitchLib.EventSub.Websockets.Core.Handler; 7 | using TwitchLib.EventSub.Websockets.Core.Models; 8 | 9 | namespace TwitchLib.EventSub.Websockets.Handler.Channel.Subscription 10 | { 11 | /// 12 | /// Handler for 'channel.subscription.gift' notifications 13 | /// 14 | public class ChannelSubscriptionGiftHandler : INotificationHandler 15 | { 16 | /// 17 | public string SubscriptionType => "channel.subscription.gift"; 18 | 19 | /// 20 | public void Handle(EventSubWebsocketClient client, string jsonString, JsonSerializerOptions serializerOptions) 21 | { 22 | try 23 | { 24 | var data = JsonSerializer.Deserialize>(jsonString.AsSpan(), serializerOptions); 25 | 26 | if (data is null) 27 | throw new InvalidOperationException("Parsed JSON cannot be null!"); 28 | 29 | client.RaiseEvent("ChannelSubscriptionGift", new ChannelSubscriptionGiftArgs { Notification = data }); 30 | } 31 | catch (Exception ex) 32 | { 33 | client.RaiseEvent("ErrorOccurred", new ErrorOccuredArgs { Exception = ex, Message = $"Error encountered while trying to handle {SubscriptionType} notification! Raw Json: {jsonString}" }); 34 | } 35 | } 36 | } 37 | } -------------------------------------------------------------------------------- /TwitchLib.EventSub.Websockets/Handler/Channel/Subscription/ChannelSubscriptionMessageHandler.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Text.Json; 3 | using TwitchLib.EventSub.Core.SubscriptionTypes.Channel; 4 | using TwitchLib.EventSub.Websockets.Core.EventArgs; 5 | using TwitchLib.EventSub.Websockets.Core.EventArgs.Channel; 6 | using TwitchLib.EventSub.Websockets.Core.Handler; 7 | using TwitchLib.EventSub.Websockets.Core.Models; 8 | 9 | namespace TwitchLib.EventSub.Websockets.Handler.Channel.Subscription 10 | { 11 | /// 12 | /// Handler for 'channel.subscription.message' notifications 13 | /// 14 | public class ChannelSubscriptionMessageHandler : INotificationHandler 15 | { 16 | /// 17 | public string SubscriptionType => "channel.subscription.message"; 18 | 19 | /// 20 | public void Handle(EventSubWebsocketClient client, string jsonString, JsonSerializerOptions serializerOptions) 21 | { 22 | try 23 | { 24 | var data = JsonSerializer.Deserialize>(jsonString.AsSpan(), serializerOptions); 25 | 26 | if (data is null) 27 | throw new InvalidOperationException("Parsed JSON cannot be null!"); 28 | 29 | client.RaiseEvent("ChannelSubscriptionMessage", new ChannelSubscriptionMessageArgs { Notification = data }); 30 | } 31 | catch (Exception ex) 32 | { 33 | client.RaiseEvent("ErrorOccurred", new ErrorOccuredArgs { Exception = ex, Message = $"Error encountered while trying to handle {SubscriptionType} notification! Raw Json: {jsonString}" }); 34 | } 35 | } 36 | } 37 | } -------------------------------------------------------------------------------- /TwitchLib.EventSub.Websockets/Handler/Channel/SuspiciousUser/ChannelSuspiciousUserMessageHandler.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using System.Text.Json; 5 | using TwitchLib.EventSub.Core.SubscriptionTypes.Channel; 6 | using TwitchLib.EventSub.Websockets.Core.EventArgs; 7 | using TwitchLib.EventSub.Websockets.Core.EventArgs.Channel; 8 | using TwitchLib.EventSub.Websockets.Core.Handler; 9 | using TwitchLib.EventSub.Websockets.Core.Models; 10 | 11 | namespace TwitchLib.EventSub.Websockets.Handler.Channel.SuspiciousUser 12 | { 13 | /// 14 | /// Handler for 'channel.suspicious_user.message' notifications 15 | /// 16 | public class ChannelSuspiciousUserMessageHandler : INotificationHandler 17 | { 18 | /// 19 | public string SubscriptionType => "channel.suspicious_user.message"; 20 | 21 | /// 22 | public void Handle(EventSubWebsocketClient client, string jsonString, JsonSerializerOptions serializerOptions) 23 | { 24 | try 25 | { 26 | var data = JsonSerializer.Deserialize>(jsonString.AsSpan(), serializerOptions); 27 | 28 | if (data is null) 29 | throw new InvalidOperationException("Parsed JSON cannot be null!"); 30 | 31 | client.RaiseEvent("ChannelSuspiciousUserMessage", new ChannelSuspiciousUserMessageArgs { Notification = data }); 32 | } 33 | catch (Exception ex) 34 | { 35 | client.RaiseEvent("ErrorOccurred", new ErrorOccuredArgs { Exception = ex, Message = $"Error encountered while trying to handle {SubscriptionType} notification! Raw Json: {jsonString}" }); 36 | } 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /TwitchLib.EventSub.Websockets/Handler/Channel/SuspiciousUser/ChannelSuspiciousUserUpdateHandler.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using System.Text.Json; 5 | using TwitchLib.EventSub.Core.SubscriptionTypes.Channel; 6 | using TwitchLib.EventSub.Websockets.Core.EventArgs; 7 | using TwitchLib.EventSub.Websockets.Core.EventArgs.Channel; 8 | using TwitchLib.EventSub.Websockets.Core.Handler; 9 | using TwitchLib.EventSub.Websockets.Core.Models; 10 | 11 | namespace TwitchLib.EventSub.Websockets.Handler.Channel.SuspiciousUser 12 | { 13 | /// 14 | /// Handler for 'channel.suspicious_user.update' notifications 15 | /// 16 | public class ChannelSuspiciousUserUpdateHandler : INotificationHandler 17 | { 18 | /// 19 | public string SubscriptionType => "channel.suspicious_user.update"; 20 | 21 | /// 22 | public void Handle(EventSubWebsocketClient client, string jsonString, JsonSerializerOptions serializerOptions) 23 | { 24 | try 25 | { 26 | var data = JsonSerializer.Deserialize>(jsonString.AsSpan(), serializerOptions); 27 | 28 | if (data is null) 29 | throw new InvalidOperationException("Parsed JSON cannot be null!"); 30 | 31 | client.RaiseEvent("ChannelSuspiciousUserUpdate", new ChannelSuspiciousUserUpdateArgs { Notification = data }); 32 | } 33 | catch (Exception ex) 34 | { 35 | client.RaiseEvent("ErrorOccurred", new ErrorOccuredArgs { Exception = ex, Message = $"Error encountered while trying to handle {SubscriptionType} notification! Raw Json: {jsonString}" }); 36 | } 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /TwitchLib.EventSub.Websockets/Handler/Channel/Vips/ChannelVipAddHandler.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Text.Json; 3 | using TwitchLib.EventSub.Core.SubscriptionTypes.Channel; 4 | using TwitchLib.EventSub.Websockets.Core.EventArgs; 5 | using TwitchLib.EventSub.Websockets.Core.EventArgs.Channel; 6 | using TwitchLib.EventSub.Websockets.Core.Handler; 7 | using TwitchLib.EventSub.Websockets.Core.Models; 8 | 9 | namespace TwitchLib.EventSub.Websockets.Handler.Channel.Vips 10 | { 11 | /// 12 | /// Handler for 'channel.vip.add' notifications 13 | /// 14 | public class ChannelVipAddHandler : INotificationHandler 15 | { 16 | /// 17 | public string SubscriptionType => "channel.vip.add"; 18 | 19 | /// 20 | public void Handle(EventSubWebsocketClient client, string jsonString, JsonSerializerOptions serializerOptions) 21 | { 22 | try 23 | { 24 | var data = JsonSerializer.Deserialize>(jsonString.AsSpan(), serializerOptions); 25 | 26 | if (data is null) 27 | throw new InvalidOperationException("Parsed JSON cannot be null!"); 28 | 29 | client.RaiseEvent("ChannelVipAdd", new ChannelVipArgs { Notification = data }); 30 | } 31 | catch (Exception ex) 32 | { 33 | client.RaiseEvent("ErrorOccurred", new ErrorOccuredArgs { Exception = ex, Message = $"Error encountered while trying to handle {SubscriptionType} notification! Raw Json: {jsonString}" }); 34 | } 35 | } 36 | } 37 | } -------------------------------------------------------------------------------- /TwitchLib.EventSub.Websockets/Handler/Channel/Vips/ChannelVipRemoveHandler.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Text.Json; 3 | using TwitchLib.EventSub.Core.SubscriptionTypes.Channel; 4 | using TwitchLib.EventSub.Websockets.Core.EventArgs; 5 | using TwitchLib.EventSub.Websockets.Core.EventArgs.Channel; 6 | using TwitchLib.EventSub.Websockets.Core.Handler; 7 | using TwitchLib.EventSub.Websockets.Core.Models; 8 | 9 | namespace TwitchLib.EventSub.Websockets.Handler.Channel.Vips 10 | { 11 | /// 12 | /// Handler for 'channel.vip.remove' notifications 13 | /// 14 | public class ChannelVipRemoveHandler : INotificationHandler 15 | { 16 | /// 17 | public string SubscriptionType => "channel.vip.remove"; 18 | 19 | /// 20 | public void Handle(EventSubWebsocketClient client, string jsonString, JsonSerializerOptions serializerOptions) 21 | { 22 | try 23 | { 24 | var data = JsonSerializer.Deserialize>(jsonString.AsSpan(), serializerOptions); 25 | 26 | if (data is null) 27 | throw new InvalidOperationException("Parsed JSON cannot be null!"); 28 | 29 | client.RaiseEvent("ChannelVipRemove", new ChannelVipArgs { Notification = data }); 30 | } 31 | catch (Exception ex) 32 | { 33 | client.RaiseEvent("ErrorOccurred", new ErrorOccuredArgs { Exception = ex, Message = $"Error encountered while trying to handle {SubscriptionType} notification! Raw Json: {jsonString}" }); 34 | } 35 | } 36 | } 37 | } -------------------------------------------------------------------------------- /TwitchLib.EventSub.Websockets/Handler/Channel/Warning/ChannelWarningAcknowledgeHandler.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Text.Json; 3 | using TwitchLib.EventSub.Core.SubscriptionTypes.Channel; 4 | using TwitchLib.EventSub.Websockets.Core.EventArgs; 5 | using TwitchLib.EventSub.Websockets.Core.EventArgs.Channel; 6 | using TwitchLib.EventSub.Websockets.Core.Handler; 7 | using TwitchLib.EventSub.Websockets.Core.Models; 8 | 9 | namespace TwitchLib.EventSub.Websockets.Handler.Channel.Warning 10 | { 11 | /// 12 | /// Handler for 'channel.warning.acknowledge' notifications 13 | /// 14 | public class ChannelWarningAcknowledgeHandler : INotificationHandler 15 | { 16 | /// 17 | public string SubscriptionType => "channel.warning.acknowledge"; 18 | 19 | /// 20 | public void Handle(EventSubWebsocketClient client, string jsonString, JsonSerializerOptions serializerOptions) 21 | { 22 | try 23 | { 24 | var data = JsonSerializer.Deserialize>(jsonString.AsSpan(), serializerOptions); 25 | 26 | if (data is null) 27 | throw new InvalidOperationException("Parsed JSON cannot be null!"); 28 | 29 | client.RaiseEvent("ChannelWarningAcknowledge", new ChannelWarningAcknowledgeArgs { Notification = data }); 30 | } 31 | catch (Exception ex) 32 | { 33 | client.RaiseEvent("ErrorOccurred", new ErrorOccuredArgs { Exception = ex, Message = $"Error encountered while trying to handle {SubscriptionType} notification! Raw Json: {jsonString}" }); 34 | } 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /TwitchLib.EventSub.Websockets/Handler/Channel/Warning/ChannelWarningSendHandler.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Text.Json; 3 | using TwitchLib.EventSub.Core.SubscriptionTypes.Channel; 4 | using TwitchLib.EventSub.Websockets.Core.EventArgs; 5 | using TwitchLib.EventSub.Websockets.Core.EventArgs.Channel; 6 | using TwitchLib.EventSub.Websockets.Core.Handler; 7 | using TwitchLib.EventSub.Websockets.Core.Models; 8 | 9 | namespace TwitchLib.EventSub.Websockets.Handler.Channel.Warning 10 | { 11 | /// 12 | /// Handler for 'channel.warning.send' notifications 13 | /// 14 | public class ChannelWarningSendHandler : INotificationHandler 15 | { 16 | /// 17 | public string SubscriptionType => "channel.warning.send"; 18 | 19 | /// 20 | public void Handle(EventSubWebsocketClient client, string jsonString, JsonSerializerOptions serializerOptions) 21 | { 22 | try 23 | { 24 | var data = JsonSerializer.Deserialize>(jsonString.AsSpan(), serializerOptions); 25 | 26 | if (data is null) 27 | throw new InvalidOperationException("Parsed JSON cannot be null!"); 28 | 29 | client.RaiseEvent("ChannelWarningSend", new ChannelWarningSendArgs { Notification = data }); 30 | } 31 | catch (Exception ex) 32 | { 33 | client.RaiseEvent("ErrorOccurred", new ErrorOccuredArgs { Exception = ex, Message = $"Error encountered while trying to handle {SubscriptionType} notification! Raw Json: {jsonString}" }); 34 | } 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /TwitchLib.EventSub.Websockets/Handler/RevocationHandler.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Text.Json; 3 | using TwitchLib.EventSub.Websockets.Core.EventArgs; 4 | using TwitchLib.EventSub.Websockets.Core.Handler; 5 | using TwitchLib.EventSub.Websockets.Core.Models; 6 | 7 | namespace TwitchLib.EventSub.Websockets.Handler 8 | { 9 | /// 10 | /// Handler for 'revocation' notifications 11 | /// 12 | public class RevocationHandler : INotificationHandler 13 | { 14 | /// 15 | public string SubscriptionType => "revocation"; 16 | 17 | /// 18 | public void Handle(EventSubWebsocketClient client, string jsonString, JsonSerializerOptions serializerOptions) 19 | { 20 | var data = JsonSerializer.Deserialize>(jsonString.AsSpan(), serializerOptions); 21 | 22 | if (data is null) 23 | throw new InvalidOperationException("Parsed JSON cannot be null!"); 24 | 25 | client.RaiseEvent("Revocation", new RevocationArgs { Notification = data }); 26 | } 27 | } 28 | } -------------------------------------------------------------------------------- /TwitchLib.EventSub.Websockets/Handler/Stream/StreamOfflineHandler.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Text.Json; 3 | using TwitchLib.EventSub.Core.SubscriptionTypes.Stream; 4 | using TwitchLib.EventSub.Websockets.Core.EventArgs; 5 | using TwitchLib.EventSub.Websockets.Core.EventArgs.Stream; 6 | using TwitchLib.EventSub.Websockets.Core.Handler; 7 | using TwitchLib.EventSub.Websockets.Core.Models; 8 | 9 | namespace TwitchLib.EventSub.Websockets.Handler.Stream 10 | { 11 | /// 12 | /// Handler for 'stream.offline' notifications 13 | /// 14 | public class StreamOfflineHandler : INotificationHandler 15 | { 16 | /// 17 | public string SubscriptionType => "stream.offline"; 18 | 19 | /// 20 | public void Handle(EventSubWebsocketClient client, string jsonString, JsonSerializerOptions serializerOptions) 21 | { 22 | try 23 | { 24 | var data = JsonSerializer.Deserialize>(jsonString.AsSpan(), serializerOptions); 25 | 26 | if (data is null) 27 | throw new InvalidOperationException("Parsed JSON cannot be null!"); 28 | 29 | client.RaiseEvent("StreamOffline", new StreamOfflineArgs { Notification = data }); 30 | } 31 | catch (Exception ex) 32 | { 33 | client.RaiseEvent("ErrorOccurred", new ErrorOccuredArgs { Exception = ex, Message = $"Error encountered while trying to handle {SubscriptionType} notification! Raw Json: {jsonString}" }); 34 | } 35 | } 36 | } 37 | } -------------------------------------------------------------------------------- /TwitchLib.EventSub.Websockets/Handler/Stream/StreamOnlineHandler.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Text.Json; 3 | using TwitchLib.EventSub.Core.SubscriptionTypes.Stream; 4 | using TwitchLib.EventSub.Websockets.Core.EventArgs; 5 | using TwitchLib.EventSub.Websockets.Core.EventArgs.Stream; 6 | using TwitchLib.EventSub.Websockets.Core.Handler; 7 | using TwitchLib.EventSub.Websockets.Core.Models; 8 | 9 | namespace TwitchLib.EventSub.Websockets.Handler.Stream 10 | { 11 | /// 12 | /// Handler for 'stream.online' notifications 13 | /// 14 | public class StreamOnlineHandler : INotificationHandler 15 | { 16 | /// 17 | public string SubscriptionType => "stream.online"; 18 | 19 | /// 20 | public void Handle(EventSubWebsocketClient client, string jsonString, JsonSerializerOptions serializerOptions) 21 | { 22 | try 23 | { 24 | var data = JsonSerializer.Deserialize>(jsonString.AsSpan(), serializerOptions); 25 | 26 | if (data is null) 27 | throw new InvalidOperationException("Parsed JSON cannot be null!"); 28 | 29 | client.RaiseEvent("StreamOnline", new StreamOnlineArgs { Notification = data }); 30 | } 31 | catch (Exception ex) 32 | { 33 | client.RaiseEvent("ErrorOccurred", new ErrorOccuredArgs { Exception = ex, Message = $"Error encountered while trying to handle {SubscriptionType} notification! Raw Json: {jsonString}" }); 34 | } 35 | } 36 | } 37 | } -------------------------------------------------------------------------------- /TwitchLib.EventSub.Websockets/Handler/User/UserUpdateHandler.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Text.Json; 3 | using TwitchLib.EventSub.Core.SubscriptionTypes.User; 4 | using TwitchLib.EventSub.Websockets.Core.EventArgs; 5 | using TwitchLib.EventSub.Websockets.Core.EventArgs.User; 6 | using TwitchLib.EventSub.Websockets.Core.Handler; 7 | using TwitchLib.EventSub.Websockets.Core.Models; 8 | 9 | namespace TwitchLib.EventSub.Websockets.Handler.User 10 | { 11 | /// 12 | /// Handler for 'user.update' notifications 13 | /// 14 | public class UserUpdateHandler : INotificationHandler 15 | { 16 | /// 17 | public string SubscriptionType => "user.update"; 18 | 19 | /// 20 | public void Handle(EventSubWebsocketClient client, string jsonString, JsonSerializerOptions serializerOptions) 21 | { 22 | try 23 | { 24 | var data = JsonSerializer.Deserialize>(jsonString.AsSpan(), serializerOptions); 25 | 26 | if (data is null) 27 | throw new InvalidOperationException("Parsed JSON cannot be null!"); 28 | 29 | client.RaiseEvent("UserUpdate", new UserUpdateArgs { Notification = data }); 30 | } 31 | catch (Exception ex) 32 | { 33 | client.RaiseEvent("ErrorOccurred", new ErrorOccuredArgs { Exception = ex, Message = $"Error encountered while trying to handle {SubscriptionType} notification! Raw Json: {jsonString}" }); 34 | } 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /TwitchLib.EventSub.Websockets/Handler/User/UserWhisperMessageHandler.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Text.Json; 3 | using TwitchLib.EventSub.Core.SubscriptionTypes.User; 4 | using TwitchLib.EventSub.Websockets.Core.EventArgs; 5 | using TwitchLib.EventSub.Websockets.Core.EventArgs.User; 6 | using TwitchLib.EventSub.Websockets.Core.Handler; 7 | using TwitchLib.EventSub.Websockets.Core.Models; 8 | 9 | namespace TwitchLib.EventSub.Websockets.Handler.User; 10 | 11 | /// 12 | /// Handler for 'user.whisper.message' notifications 13 | /// 14 | public class UserWhisperMessageHandler : INotificationHandler 15 | { 16 | /// 17 | public string SubscriptionType => "user.whisper.message"; 18 | 19 | /// 20 | public void Handle(EventSubWebsocketClient client, string jsonString, JsonSerializerOptions serializerOptions) 21 | { 22 | try 23 | { 24 | var data = JsonSerializer.Deserialize>(jsonString.AsSpan(), serializerOptions); 25 | 26 | if (data is null) 27 | throw new InvalidOperationException("Parsed JSON cannot be null!"); 28 | 29 | client.RaiseEvent("UserWhisperMessage", new UserWhisperMessageArgs { Notification = data }); 30 | } 31 | catch (Exception ex) 32 | { 33 | client.RaiseEvent("ErrorOccurred", new ErrorOccuredArgs { Exception = ex, Message = $"Error encountered while trying to handle {SubscriptionType} notification! Raw Json: {jsonString}" }); 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /TwitchLib.EventSub.Websockets/TwitchLib.EventSub.Websockets.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | netstandard2.0;netstandard2.1;net6.0;net7.0;net8.0 5 | TwitchLib.EventSub.Websockets 6 | TwitchLib.EventSub.Websockets 7 | swiftyspiffy, Prom3theu5, Syzuna, LuckyNoS7evin 8 | 0.6.0 9 | $(VersionSuffix) 10 | 0.6.0 11 | 0.6.0 12 | EventSub Websockets (also known as EventSockets) Client Library 13 | https://cdn.syzuna-programs.de/images/twitchlib.png 14 | https://github.com/TwitchLib/TwitchLib.EventSub.Websockets 15 | https://github.com/TwitchLib/TwitchLib.EventSub.Websockets 16 | Git 17 | MIT 18 | Copyright 2023 19 | twitch library events eventsub websockets eventsockets c# csharp netstandard2.0 netstandard2.1 net6.0 net7.0 net8.0 20 | Updated dependencies, enabled nullable, added new events (ChannelChatClear, ChannelChatClearUserMessages, ChannelChatMessageDelete, ChannelChatNotification, ChannelVipAdd, ChannelVipRemove, ChannelPointsAutomaticRewardRedemptionAdd, ChannelSuspiciousUserMessage, ChannelSuspiciousUserUpdate, ChannelWarningAcknowledge, ChannelWarningSend, UserWhisperMessage, ChannelSharedChatSessionBegin, ChannelSharedChatSessionUpdate, ChannelSharedChatSessionEnd, ChannelUnbanRequestCreate, ChannelUnbanRequestResolve) 21 | en-US 22 | disable 23 | enable 24 | True 25 | latest-all 26 | True 27 | README.md 28 | latest 29 | 1701;1702;CA1003 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | --------------------------------------------------------------------------------