-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathShowRedeems_StreamlabsSystem.py
117 lines (98 loc) · 3.65 KB
/
ShowRedeems_StreamlabsSystem.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# -*- coding: utf-8 -*-
# ShowRedeems by luissanchezdev
# Show all rewards redeemed on Twitch using channel
# points directly on your Streamlabs Chatbot Console.
#
# Versions
# 1.0.1 - Fixed repeated messages when reloading script
# 1.0.0 - Release
import os
import sys
import clr
import time
import json
import codecs
import System
# Include the assembly with the name AnkhBotR2
clr.AddReference([asbly for asbly in System.AppDomain.CurrentDomain.GetAssemblies() if "AnkhBotR2" in str(asbly)][0])
import AnkhBotR2
# Twitch PubSub library and dependencies
lib_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), "Lib")
clr.AddReferenceToFileAndPath(os.path.join(lib_path, "Microsoft.Extensions.Logging.Abstractions.dll"))
clr.AddReferenceToFileAndPath(os.path.join(lib_path, "TwitchLib.Communication.dll"))
clr.AddReferenceToFileAndPath(os.path.join(lib_path, "TwitchLib.PubSub.dll"))
from TwitchLib.PubSub import *
from TwitchLib.PubSub.Events import *
# I wasn't able to use Parent.GetRequest :( so I used this instead
clr.AddReference("System.Net.Http")
from System.Net.Http import HttpClient
# Simple message box fordebugging
clr.AddReference("System.Windows.Forms")
from System.Windows.Forms.MessageBox import Show
msgbox = lambda obj: Show(str(obj))
# Script Information
Creator = "LuisSanchezDev"
Description = "Show all rewards redeemed on Twitch using channel points directly on your Streamlabs Chatbot Console"
ScriptName = "ShowRedeems"
Version = "1.0.1"
Website = "https://www.fiverr.com/luissanchezdev"
# Define Global Variables
path = os.path.dirname(os.path.realpath(__file__))
client = TwitchPubSub()
# Initialize Data (Only called on load)
def Init():
# Get OAuth token
# vmloc = AnkhBotR2.Managers.GlobalManager.Instance.VMLocator
oauth = GetOAuth()
# .Net Get request to get streamer's ID
auth = 'OAuth ' + oauth.replace("oauth:", "")
httpclient = HttpClient()
httpclient.DefaultRequestHeaders.Add("Authorization", auth)
t = httpclient.GetStringAsync("https://id.twitch.tv/oauth2/validate")
data = ""
try:
t.Wait()
data = t.Result
except:
msgbox("There was an error while authenticating\nPlease reload the scripts to try again\n\n" + str(t.Exception))
return
casterid = json.loads(data)['user_id']
# Register the client to listen to reward redeems
client.OnPubSubServiceConnected += OnPubSubConnected
client.OnRewardRedeemed += OnRewardRedeemed
client.ListenToRewards(casterid)
client.Connect()
# Execute Data / Process messages
def Execute(data):
pass
# Tick method (Gets called during every iteration even when there is no incoming data)
def Tick():
pass
# Unload (Called when a user reloads their scripts or closes the bot / cleanup stuff)
def Unload():
client.OnPubSubServiceConnected -= OnPubSubConnected
client.OnRewardRedeemed -= OnRewardRedeemed
client.Disconnect()
del client
def GetOAuth():
vmloc = AnkhBotR2.Managers.GlobalManager.Instance.VMLocator
return vmloc.StreamerLogin.Token
# On PubSub client connection
def OnPubSubConnected(s, e):
client.SendTopics()
# On reward redeemed
def OnRewardRedeemed(s, e):
message = "👉 " + e.DisplayName + " redeemed " + e.RewardTitle
message += " - " + e.RewardPrompt
_print(message)
if e.Message:
_print("📧 Message: " + e.Message)
# Prints a message to the Console
def _print(msg):
g_manager = AnkhBotR2.Managers.GlobalManager.Instance
handler = g_manager.SystemHandler
handler.StreamerClient.PrintServerMessage(msg)
#public void PrintMessage(string user = "", string message = "", IncTwitchMessage ircMessage = null)
handler.StreamerClient.WriteTextToUI()
def donate():
os.startfile("https://streamlabs.com/luissanchezdev/tip")