Art was right but it looks like it needs updated.
Rem Type=Plugin
Rem Name=GRETTA Media Functions
Rem Author=VR - jasondude7116
Rem Host=Assistant
'This sub setups the plug-ins option panel in Hal's options dialog
Sub OptionsPanel()
'------------------
' Define the Help
'------------------
lblPlugin(0).Caption = "GRETTA will be able to play your favourite songs. Click below for more info"
lblPlugin(0).Move 120, 120, 3300, 1000
lblPlugin(0).WordWrap = True
lblPlugin(0).Visible = True
cmdPlugin(0).Move 320, 650, 2100, 375
cmdPlugin(0).Caption = "Help on this plugin"
cmdPlugin(0).Visible = True
'------------------
' Define the Musical Mood listbox
'------------------
lblPlugin(1).Caption = "GRETTA Media Mood level"
lblPlugin(1).Move 320, 1300, 4000, 1000
lblPlugin(1).WordWrap = True
lblPlugin(1).Visible = True
cboPlugin(0).Move 320, 1600, 1800
cboPlugin(0).AddItem "Very high"
cboPlugin(0).AddItem "High"
cboPlugin(0).AddItem "Average"
cboPlugin(0).AddItem "Low"
cboPlugin(0).AddItem "Very Low"
cboPlugin(0).Visible = True
cmdPlugin(1).Caption = "Apply Changes"
cmdPlugin(1).Move 320, 2100, 1600, 375
cmdPlugin(1).Visible = True
'------------------
' Update the listbox with the current value stored in the table
'------------------
If HalBrain.CheckTableExistence("vrParameter") = True Then
vrMusicMood = HalBrain.TopicSearch("MUSIC", "vrParameter")
If vrMusicMood = "" Then vrMusicMood = 1
Select Case vrMusicMood
Case 50
cboPlugin(0).Text = "Very high"
Case 40
cboPlugin(0).Text = "High"
Case 30
cboPlugin(0).Text = "Average"
Case 20
cboPlugin(0).Text = "Low"
Case 10
cboPlugin(0).Text = "Very Low"
End Select
End If
End Sub
Sub cmdPlugin_Click(Index)
Dim vrTempQuery()
Dim vrMusic, vrMusicMood
Select Case Index
Case 0
HalMenu.HalCommand "<RUNPROG>vrMP3Help.html</RUNPROG>"
Case 1
'------------------
' Convert the listbox in a value
'------------------
Select Case cboPlugin(0).Text
Case "Very high"
vrMusicMood = 50
Case "High"
vrMusicMood = 40
Case "Average"
vrMusicMood = 30
Case "Low"
vrMusicMood = 20
Case "Very Low"
vrMusicMood = 10
End Select
'------------------
' If the Parameter table does not exist, I create it
'------------------
HalBrain.ReadOnlyMode = False
vrTableName = "vrParameter"
If HalBrain.CheckTableExistence(vrTableName) = False Then
'Create table if it doesn't exist
HalBrain.CreateTable vrTableName, "TopicSearch", "miscData"
End If
'------------------
' Search if it contains the MusicMood parameter
'------------------
vrMusic = "MUSIC"
If HalBrain.TopicSearch(vrMusic, vrTableName) = "" Then
'------------------
'Creates the record storing the new value
'------------------
HalBrain.AddToTable vrTableName, "TopicSearch", vrMusic, vrMusicMood
Else
'------------------
'Updates the record storing the new value
'------------------
HalBrain.RunQuery "UPDATE " & vrTableName & " SET topic = " & vrMusicMood & " WHERE searchString = " & """" & vrMusic & """", vrTempQuery
End If
End Select
End Sub
Rem PLUGIN: PLUGINAREA5
If OriginalSentence <> "" Then
'The comment above tells Ultra Hal Assistant to insert the following code
'on-the-fly into the main brain code in the section referenced.
'------------------
' Check if the user asked for reorganizing the MP3 table
'------------------
vrMp3 = False
If InStr(UserSentence, " INDEX ") <> 0 And InStr(UserSentence, " MP3 ") <> 0 Then vrMP3 = True
If vrMP3 = True Then
'------------------
' If the MP3 table does not exist, I create it
'------------------
HalBrain.ReadOnlyMode = False
vrTableName = "vrMp3"
If HalBrain.CheckTableExistence(vrTableName) = False Then
' Create table if it doesn't exist
' It must be of type Brain, to allow partial text search
HalBrain.CreateTable vrTableName, "Brain", "miscData"
Else
' The 260 parameter is 256 + 4 = Yes/No with Default = No
vrAnswer = MsgBox("Shall I delete the existing index and recreate it from scratch?", 260, "MP3 Reindexing")
If vrAnswer = 6 Then
HalBrain.RunQuery "DELETE FROM " & vrTableName, vrTempQuery
End If
End If
'------------------
' Ask which is the main MP3 folder
'------------------
vrMp3Folder = InputBox("Which main folder to you want to reindex?", "MP3 Reindexing", "D:\MP3")
'------------------
' Read the main MP3 folder
'------------------
Set vrFso = CreateObject("Scripting.FileSystemObject")
If vrFso.FolderExists(vrMp3Folder) Then
GetResponse = "I have indexed all the MP3 files in the specified folder and subfolders. "
HalBrain.ReadOnlyMode = False
vrCurrentFolder = vrMp3Folder
Call ReadFolder(vrCurrentFolder, vrMp3Folder)
Else
GetResponse = "The folder " & vrMp3Folder & " does not exist on your computer. "
End If
HalBrain.ReadOnlyMode = True
End If
'------------------
' Check if the user asked for playing a song
'------------------
vrMp3 = False
vrToPlay = ""
vrNameToPlay = ""
vrToPlay = UCase(HalBrain.SearchPattern(UserSentence, "PLAY * SONG *", 2))
If vrToPlay <> "" Then
vrToPlay = " " & vrToPlay & " "
vrToPlay = Replace(vrToPlay," ","xx",1,-1,vbTextCompare)
If HalBrain.CheckTableExistence("vrMp3") = False Then
GetResponse = "I don't find any MP3 index in my brain. "
Else
vrNameToPlay = HalBrain.QABrain(vrToPlay, "vrMp3", 0)
If vrNameToPlay <> "" Then
GetResponse = "Listen to this song; maybe it's the one you were talking about. "
'HalCommands = HalCommands & "<RUNPROG>" & vrNameToPlay & "</RUNPROG>"
Set objFSO = CreateObject("Scripting.FileSystemObject")
If objFSO.FileExists(vrNameToPlay) Then
Set objWSHShell = CreateObject("WScript.Shell")
objWSHShell.Run """" & vrNameToPlay & """"
End If
Else
GetResponse = "I'm sorry, it seems that song is not located in the library."
End If
End If
HalBrain.ReadOnlyMode = True
End If
'------------------
' From time to time, Hal will play a song, according to some word you say
' For example, you say: "I am going to California"
' Hal will play "Hotel California" by Eagles
'------------------
'------------------
' check the current music mood factor
'------------------
vrMusicMood = HalBrain.TopicSearch("MUSIC", "vrParameter")
If vrMusicMood = "" Then vrMusicMood = 0
vrMusicMood = CInt(vrMusicMood)
vrKeywords = ""
If vrMusicMood > 0 Then
MediaintHighNumber = 300
MediaintLowNumber = 1
Randomize
MediaintNumber = Int((MediaintHighNumber - MediaintLowNumber + 1) * Rnd + MediaintLowNumber)
vrNameToPlay = ""
If vrNameToPlay = "" Then
vrKeywords = WN.FindFirstNoun(UserSentence, True)
vrKeywords = Trim(Ucase(vrKeywords))
If vrKeywords <> "" Then
vrKeywords = " " & vrKeywords & " "
vrKeywords = Replace(vrKeywords,", "," , ",1,-1,vbTextCompare)
vrKeywords = Replace(vrKeywords," ","xx",1,-1,vbTextCompare)
vrKeywordList = Split(vrKeywords, ",")
For i = Lbound(vrKeywordList) To Ubound(vrKeywordList)
vrNameToPlay = HalBrain.QABrain(vrKeywordList(i), "vrMp3", 0)
Exit For
Next
End If
End If
If vrNameToPlay = "" Then
vrKeywords = WN.FindFirstNoun(UserSentence, False)
vrKeywords = Trim(Ucase(vrKeywords))
If vrKeywords <> "" Then
vrKeywords = " " & vrKeywords & " "
vrKeywords = Replace(vrKeywords,", "," , ",1,-1,vbTextCompare)
vrKeywords = Replace(vrKeywords," ","xx",1,-1,vbTextCompare)
vrKeywordList = Split(vrKeywords, ",")
For i = Lbound(vrKeywordList) To Ubound(vrKeywordList)
vrNameToPlay = HalBrain.QABrain(vrKeywordList(i), "vrMp3", 0)
Exit For
Next
End If
End If
If vrNameToPlay = "" Then
vrKeywords = HalBrain.RemoveExtraSpaces(HalBrain.ExtractKeywords(" " & UserSentence & " "))
vrKeywords = Trim(Ucase(vrKeywords))
If vrKeywords <> "" Then
vrKeywords = " " & vrKeywords & " "
vrKeywords = Replace(vrKeywords,", "," , ",1,-1,vbTextCompare)
vrKeywords = Replace(vrKeywords," ","xx",1,-1,vbTextCompare)
vrKeywordList = Split(vrKeywords, ",")
For i = Lbound(vrKeywordList) To Ubound(vrKeywordList)
vrNameToPlay = HalBrain.QABrain(vrKeywordList(i), "vrMp3", 0)
Next
End If
End If
If vrNameToPlay = "" Then
vrKeywords = WN.FindFirstNoun(UserSentence, True)
vrKeywords = Trim(Ucase(vrKeywords))
If vrKeywords <> "" Then
vrKeywords = CurrentSubject
vrKeywords = "xx" & vrKeywords & "xx"
vrKeywords = Replace(vrKeywords,", ","xx,xx",1,-1,vbTextCompare)
vrKeywordList = Split(vrKeywords, ",")
For i = Lbound(vrKeywordList) To Ubound(vrKeywordList)
vrNameToPlay = HalBrain.QABrain(vrKeywordList(i), "vrMp3", 0)
Exit For
Next
End If
End If
If vrNameToPlay <> "" Then
If MediaintNumber < vrMusicMood Then
Set objFSO = CreateObject("Scripting.FileSystemObject")
If objFSO.FileExists(vrNameToPlay) Then
Set objWSHShell = CreateObject("WScript.Shell")
objWSHShell.Run """" & vrNameToPlay & """"
End If
End If
End If
End If
End If
Rem PLUGIN: FUNCTIONS
'The preceding comment is actually a plug-in directive for
'the Ultra Hal host application. It allows for code snippets
'to be inserted here on-the-fly based on user configuration.
Function ReadFolder(vrCurrentFolder, vrMp3Folder)
Set vrFso = CreateObject("Scripting.FileSystemObject")
Set vrFolder = vrFso.GetFolder(vrCurrentFolder)
'------------------
' Read all the files in the current folder
'------------------
Set vrFiles = vrFolder.Files
For Each vrFile in vrFiles
'------------------
' It's an MP3 file; I add it to the table
'------------------
If UCase(Right(vrFile, 3)) = "MP3" Then
vrSong = Ucase(vrFile)
vrSong = Replace(vrSong, ".MP3", "")
vrLen = Len(vrSong)
vrPos = InStrRev(vrSong, "\")
vrRight = vrLen - vrPos
vrSong = LTrim(Right(vrSong, vrRight))
vrSong = " " & vrSong & " "
vrSong = Replace(vrSong," ","xx",1,-1,vbTextCompare)
HalBrain.AddToTable "vrMp3", "Brain", vrSong, vrFile
End If
Next
'------------------
' Read all the subfolders in the current folder
'------------------
Set vrSubFolders = vrFolder.SubFolders
For Each vrFolderObject in vrSubFolders
'------------------
' Pay attetion here: This is recursive! We must be sure that it will get to an end
' Since we are reading directories on a hard disk, the number of recursions
' should never be infinite. However, a very big number of subfolders and files
' might lead to memory problems or to performances bottlenecks.
' I've tested it on a folder containing about 100 subfolders and 3.000 files,
' and got acceptable performances (less than 5 minutes)
'------------------
Call ReadFolder(vrFolderObject, vrMp3Folder)
Next
End Function