Sample Modules - OrfeasZ/GrooveCaster GitHub Wiki

Sample Modules

Queue Size

This module registers a new command (queueSize), which displays the number of upcoming songs in the broadcast queue.

This command is only available to users with special guest permissions.

from GS.Lib.Events import ChatMessageEvent

def OnQueueSize(p_Event, p_Data):
    s_SpecialGuest = BroadcastManager.GetGuestForUserID(p_Event.UserID)

    if not BroadcastManager.CanUseCommands(s_SpecialGuest):
        ChatManager.SendChatMessage("Sorry %s, but you don't have permission to use this feature." % p_Event.UserName)
        return

    s_Index = QueueManager.GetPlayingSongIndex()
    s_SongCount = len(QueueManager.GetCurrentQueue()) - s_Index - 1

    ChatManager.SendChatMessage("There are %d upcoming songs in the queue." % s_SongCount)


ChatManager.RegisterCommand('queueSize', ': Displays the number of upcoming songs in the queue.', Action[ChatMessageEvent, object](OnQueueSize))

def OnUnload():
    ChatManager.RemoveCommand('queueSize')

Dynamic Description

This module dynamically updates the description of the broadcast in order to include live details about the broadcast.

More precisely, if the description contains the string {upcoming}, this module will replace it with a string containing the number of upcoming songs.

from GS.Lib.Events import SharkEvent, SongPlayingEvent
from GS.Lib.Enums import ClientEvent

def OnSongPlaying(p_Event):
    s_Description = BroadcastManager.GetBroadcastDescription()

    s_Index = QueueManager.GetPlayingSongIndex()
    s_SongCount = len(QueueManager.GetCurrentQueue()) - s_Index - 1

    s_UpcomingSongs = "Upcoming Songs: %d" % s_SongCount

    if s_SongCount == 1:
        s_UpcomingSongs = "Upcoming Song: %d" % s_SongCount

    s_Description = s_Description.replace("{upcoming}", s_UpcomingSongs) 

    BroadcastManager.SetDescription(s_Description)


SharpShark.RegisterEventHandler(ClientEvent.SongPlaying, Action[SharkEvent](OnSongPlaying))
SharpShark.RegisterEventHandler(ClientEvent.QueueUpdated, Action[SharkEvent](OnSongPlaying))
OnSongPlaying(None)

def OnUnload():
    SharpShark.RemoveEventHandler(ClientEvent.SongPlaying,  Action[SharkEvent](OnSongPlaying))
    SharpShark.RemoveEventHandler(ClientEvent.QueueUpdated,  Action[SharkEvent](OnSongPlaying))

Chat Announcer

This module announces a message to the broadcast chat every 30 seconds.

def Announce(p_Timer):
	ChatManager.SendChatMessage('Welcome to my awesome broadcast! I hope you enjoy your stay.')

s_AnnouncementTimer = Timer.SetInterval(Action[Timer](Announce), 30000.0)
s_AnnouncementTimer.Start()

def OnUnload():
    s_AnnouncementTimer.Cancel()

Suggestion Manager

This module automatically approves song suggestions that have gathered 3 or more upvotes.

It should be noted that every upvote is actually a suggestion for the same song, meaning that the initial suggestion also counts as an upvote.

from GS.Lib.Events import SharkEvent, SongSuggestionEvent
from GS.Lib.Enums import ClientEvent

def OnSuggestion(p_Event):
    s_Event = Convert(p_Event, SongSuggestionEvent)
    
    s_Suggestion = SuggestionManager.Suggestions[s_Event.SongID]

    s_Upvotes = (len(s_Suggestion.OtherSuggesters) + 1)

    #print 'Song %s has %d upvotes' % (s_Suggestion.SongName, s_Upvotes)

    if s_Upvotes >= 3:
    	SuggestionManager.ApproveSuggestion(s_Suggestion)


SharpShark.RegisterEventHandler(ClientEvent.SongSuggestion, Action[SharkEvent](OnSuggestion))

def OnUnload():
    SharpShark.RemoveEventHandler(ClientEvent.SongSuggestion, Action[SharkEvent](OnSuggestion))