Skip to content

Commit

Permalink
Merge pull request #27 from camalot/topic/duplicated-notifications
Browse files Browse the repository at this point in the history
Topic/duplicated notifications
  • Loading branch information
camalot authored Aug 22, 2019
2 parents 101fdcd + b75b765 commit e76eaa2
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 14 deletions.
8 changes: 4 additions & 4 deletions script/Client.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ jQuery(document).ready(function () {
}

$("#video-container video")
.on("error", function (e) { console.error(`Error: ${e}`); })
.on("canplay", function () { return videoLoaded(); })
.on("ended", function () { return videoEnded(); })
.css("max-width", `${vwidth}px`)
.css("min-width", `${vwidth}px`);

Expand Down Expand Up @@ -181,10 +184,7 @@ function connectWebsocket() {
.prop("muted", true)
.attr("src", webfile)
.empty()
.append(`<source src="${webfile}" type="video/mp4" />`)
.on("error", function(e) { console.error(`Error: ${e}`); })
.on("canplay", function () { return videoLoaded(); })
.on("ended", function () { return videoEnded(); });
.append(`<source src="${webfile}" type="video/mp4" />`);
break;
case "EVENT_MEDAL_VIDEO_WAIT":
console.log(eventName);
Expand Down
35 changes: 26 additions & 9 deletions script/Medal_StreamlabsSystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
LastClipTriggerUser = None
ClipWatcher = None
ProcessManager = None
Initialized = False

TriggerCooldownTime = None
TriggerCount = 0
Expand Down Expand Up @@ -83,6 +84,7 @@ def __init__(self, settingsfile=None):
self.OnlyTriggerOffCommand = False
self.TriggerCooldown = 60
self.RequiredTriggerCount = 1
self.NotifyChatOfClips = True

with codecs.open(settingsfile, encoding="utf-8-sig", mode="r") as f:
fileSettings = json.load(f, encoding="utf-8")
Expand Down Expand Up @@ -141,8 +143,8 @@ def OnClipReady(sender, eventArgs):
triggerUser = Parent.GetChannelName()
if LastClipTriggerUser is not None:
triggerUser = LastClipTriggerUser

Parent.SendTwitchMessage(triggerUser + ", clip processing completed. Video will play shortly.")
if ScriptSettings.NotifyChatOfClips:
Parent.SendTwitchMessage(triggerUser + ", clip processing completed. Video will play shortly.")
Parent.Log(ScriptName, "Event: ClipReady: " + eventArgs.ClipId)

PlayVideoById(eventArgs.ClipId)
Expand Down Expand Up @@ -176,7 +178,8 @@ def OnClipStarted(sender, eventArgs):
triggerUser = LastClipTriggerUser
# Add a cooldown on the command since a clip is currently processing.
Parent.AddCooldown(ScriptName, ScriptSettings.Command, ScriptSettings.Cooldown)
Parent.SendTwitchMessage(triggerUser + " has triggered a medal.tv clip. Clip is processing...")
if ScriptSettings.NotifyChatOfClips:
Parent.SendTwitchMessage(triggerUser + " has triggered a medal.tv clip. Clip is processing...")
Parent.Log(ScriptName, "Event: ClipStarted: " + eventArgs.ClipId)
return

Expand Down Expand Up @@ -209,11 +212,17 @@ def OnMonitorPause(sender, eventArgs):
#---------------------------
def Init():
""" Initialize script or startup or reload. """
Parent.Log(ScriptName, "Initialize")
# Globals
global ScriptSettings
global ClipWatcher
global ProcessManager
global Initialized

if Initialized:
Parent.Log(ScriptName, "Skip Initialization. Already Initialized.")
return

Parent.Log(ScriptName, "Initialize")
# Load saved settings and validate values
ScriptSettings = Settings(SettingsFile)
if(ScriptSettings.VideoPath == ""):
Expand All @@ -235,6 +244,7 @@ def Init():
ClipWatcher.MonitorPause += OnMonitorPause
ClipWatcher.Start()
StartHttpd(webDirectory, ScriptSettings.WebPort)
Initialized = True
return

#---------------------------
Expand Down Expand Up @@ -263,8 +273,6 @@ def Execute(data):
if data.User in TriggerList:
Parent.Log(ScriptName, "User already triggered the command. Skipping.")
return


TriggerList.append(data.User)
TriggerCount += 1
# only add normal cooldown if TriggerCount >= RequiredTriggerCount
Expand All @@ -283,10 +291,12 @@ def Execute(data):
if TriggerCount == 1:
Parent.Log(ScriptName, "init clip trigger.")
TriggerCooldownTime = datetime.datetime.now() + datetime.timedelta(seconds=ScriptSettings.TriggerCooldown)
Parent.SendTwitchMessage(data.User + " has initialized a medal.tv clip. Need " + str(triggerDiff) + " more to generate the clip.")
if ScriptSettings.NotifyChatOfClips:
Parent.SendTwitchMessage(data.User + " has initialized a medal.tv clip. Need " + str(triggerDiff) + " more to generate the clip.")
else:
Parent.Log(ScriptName, "Additional trigger of clip generation.")
Parent.SendTwitchMessage(data.User + " triggered a medal.tv clip. Need " + str(triggerDiff) + " more to generate the clip.")
if ScriptSettings.NotifyChatOfClips:
Parent.SendTwitchMessage(data.User + " triggered a medal.tv clip. Need " + str(triggerDiff) + " more to generate the clip.")
return

#---------------------------
Expand All @@ -302,27 +312,33 @@ def Parse(parseString, userid, username, targetid, targetname, message):
# [Optional] Unload (Called when a user reloads their scripts or closes the bot / cleanup stuff)
#---------------------------
def Unload():
global Initialized
global ClipWatcher
Parent.Log(ScriptName, "Unload")
Parent.Log(ScriptName, "Kill mohttpd Process")
stop = ProcessManager.Stop("mohttpd")
Parent.Log(ScriptName, stop)
Parent.Log(ScriptName, "Killed mohttpd Process")

if ClipWatcher is not None:
Parent.Log(ScriptName, "Clear ClipWatcher Events")
ClipWatcher.ClipReady -= OnClipReady
ClipWatcher.ClipStarted -= OnClipStarted
ClipWatcher.MonitorStart -= OnMonitorStart
ClipWatcher.MonitorStop -= OnMonitorStop
ClipWatcher.MonitorPause -= OnMonitorPause
ClipWatcher.Stop()
ClipWatcher = None

Initialized = False
# End of Unload
return

#---------------------------
# [Optional] ScriptToggled (Notifies you when a user disables your script or enables it)
#---------------------------
def ScriptToggled(state):
Parent.Log(ScriptName, "State Changed: " + str(state))
if state:
Init()
else:
Expand Down Expand Up @@ -351,7 +367,8 @@ def Tick():
TriggerCount = 0
TriggerList = []
Parent.Log(ScriptName, "Reset clip trigger due to cooldown exceeded")
Parent.SendTwitchMessage("Medal.tv clip generation did not get the required triggers of " + str(ScriptSettings.RequiredTriggerCount) + " to generate the clip.")
if ScriptSettings.NotifyChatOfClips:
Parent.SendTwitchMessage("Medal.tv clip generation did not get the required triggers of " + str(ScriptSettings.RequiredTriggerCount) + " to generate the clip.")
return

# ---------------------------------------
Expand Down
8 changes: 7 additions & 1 deletion script/UI_Config.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,13 @@
"tooltip": "Video Width (pixels) Scaled automatically.",
"group": "General"
},

"NotifyChatOfClips": {
"type": "checkbox",
"label": "Notify Chat About Clip Status",
"value": true,
"tooltip": "Put a message in chat about new clip being created and when completed",
"group": "General"
},
"Username": {
"type": "textbox",
"label": "Medal Username",
Expand Down

0 comments on commit e76eaa2

Please sign in to comment.