#include <String.au3>
#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GuiButton.au3>
#include <IE.au3>
;##########################################
;# Chatten mit C6CHB und B.E.S.U.C.H.E.R. #
;# Durch die XMl-API                      #
;# DE<>EN mit Sprache und Text!           #
;# campweb @ autoit.de                    #
;##########################################
InetGet("http://down.redio.de/sil.bmp", @tempdir&"\sil.bmp")
InetGet("http://down.redio.de/talk.bmp", @tempdir&"\talk.bmp")
HotKeySet("{ENTER}", "_Send")
$msgb = MsgBox(4, "", "Haben Sie das deutsche Sprackpaket Steffi (RSSolo4german) von Nuance installiert?")
If $msgb = 7 Then
	MsgBox(0, "", "Sie benötigen das deutsche Sprachpaket. Es wird sich gleich ein Link öffnen, bitte laden Sie das Archiv herunter und installieren Sie den Inhalt! Danach starten Sie das Programm neu!")
	_IECreate("http://people.fh-landshut.de/~hpk/Sprache/RSSolo4German.zip", 0, 0, 0)
	Exit
Else
	$BESUCHER = "f4e61812be375c3f"
	$C6CHB    = "fd302c6a9e34021d"
	SoundSetWaveVolume(100)
	Local $o_speech = ObjCreate ("SAPI.SpVoice")
	$voiceEN = $o_speech.GetVoices("", "Language=409").Item(0)
	$voiceDE = $o_speech.GetVoices("", "Language=407").Item(0)
	GUICreate("Chatten mit C6CHB und B.E.S.U.C.H.E.R. - campweb", 748, 444, 338, 146)
	$cBot = GUICtrlCreateCombo("", 8, 8, 601, 25)
	GUICtrlSetData(-1, "C6CHB (English) (Text + Voice Output)|B.E.S.U.C.H.E.R. (Deutsch) (Text + Voice Output)", "B.E.S.U.C.H.E.R. (Deutsch) (Text + Voice Output)")
	$Input = GUICtrlCreateInput("Deine Gedanken / Your thoughts...", 8, 40, 545, 21)
	Global $Send = GUICtrlCreateButton("Send", 560, 40, 51, 21, 0)
	$Output = GUICtrlCreateEdit("", 8, 72, 601, 361, BitOR($ES_AUTOVSCROLL,$ES_WANTRETURN,$WS_VSCROLL))
	$Lips = GUICtrlCreatePic(@tempdir&"\sil.bmp", 618, (444/2)-(50/2), 125, 50)
	GUISetState(@SW_SHOW)
	While 1
		$nMsg = GUIGetMsg()
		Switch $nMsg
			Case $GUI_EVENT_CLOSE
				Exit
			Case $Send
				If GUICtrlRead($input) <> "" Then
					GUICtrlSetState($cBot, $GUI_DISABLE)
					GUICtrlSetState($Input, $GUI_DISABLE)
					GUICtrlSetState($Send, $GUI_DISABLE)
					GUICtrlSetState($Output, $GUI_DISABLE)
					If GUICtrlRead($cBot) = "C6CHB (English) (Text + Voice Output)" Then $BotID = $C6CHB
					If GUICtrlRead($cBot) = "B.E.S.U.C.H.E.R. (Deutsch) (Text + Voice Output)" Then $BotID = $BESUCHER
					$Message = GUICtrlRead($Input)
					SetError(0,0,0)
					InetGet("http://www.pandorabots.com/pandora/talk-xml?botid="&$BotID&"&input="&$Message, @tempdir&"\bot.txt")
					$File = FileOpen(@tempdir&"\bot.txt")
					$sFile = FileRead($File)
					$sBetween = _stringbetween($sFile, "<that>", "</that>")
					If IsArray($sBetween) Then
						$sBetween[0] = StringReplace($sBetween[0], "&amp;", "")
						$sBetween[0] = StringReplace($sBetween[0], "&quot;", '"')
						$sBetween[0] = StringReplace($sBetween[0], "growmonster", GUICtrlRead($cBot))
						$sBetween[0] = StringReplace($sBetween[0], "&lt;botmaster&gt;&lt;/botmaster&gt;", 'campweb')
						GUICtrlSetImage($Lips, @tempdir&"\talk.bmp")
						GUICtrlSetData($Output, "Human: "&$Message&@CRLF&GUICtrlRead($cBot)&": "&$sBetween[0]&@CRLF&GUICtrlRead($Output))
						FileClose($File)
						GUICtrlSetData($Input, "")
						GUICtrlSetState($cBot, $GUI_ENABLE)
						GUICtrlSetState($Input, $GUI_ENABLE)
						GUICtrlSetState($Send, $GUI_ENABLE)
						GUICtrlSetState($Output, $GUI_ENABLE)
						If $BotID = $C6CHB And IsObj($voiceEN) Then
							$o_speech.Voice = $voiceEN
						ElseIf $BotID = $BESUCHER And IsObj($voiceDE) Then
							$o_speech.Voice = $voiceDE
						EndIf
						$o_speech.Speak ($sBetween[0], 8)
						FileDelete(@tempdir&"\bot.txt")
						GUICtrlSetImage($Lips, @tempdir&"\sil.bmp")
					Else
						$sBetween = "Server Error"
						$sBetween = StringReplace($sBetween, "&amp;", "")
						$sBetween = StringReplace($sBetween, "&quot;", '"')
						$sBetween = StringReplace($sBetween, "growmonster", GUICtrlRead($cBot))
						$sBetween = StringReplace($sBetween, "&lt;botmaster&gt;&lt;/botmaster&gt;", 'campweb')
						GUICtrlSetImage($Lips, @tempdir&"\talk.bmp")
						GUICtrlSetData($Output, "Human: "&$Message&@CRLF&GUICtrlRead($cBot)&": "&$sBetween&@CRLF&GUICtrlRead($Output))
						FileClose($File)
						GUICtrlSetData($Input, "")
						GUICtrlSetState($cBot, $GUI_ENABLE)
						GUICtrlSetState($Input, $GUI_ENABLE)
						GUICtrlSetState($Send, $GUI_ENABLE)
						GUICtrlSetState($Output, $GUI_ENABLE)
						If $BotID = $C6CHB And IsObj($voiceEN) Then
							$o_speech.Voice = $voiceEN
						ElseIf $BotID = $BESUCHER And IsObj($voiceDE) Then
							$o_speech.Voice = $voiceDE
						EndIf
						$o_speech.Speak ($sBetween, 8)
						FileDelete(@tempdir&"\bot.txt")
						GUICtrlSetImage($Lips, @tempdir&"\sil.bmp")
					EndIf
					
				EndIf
		EndSwitch
	WEnd
EndIf
Func _Send()
	_GUICtrlButton_Click($Send)
EndFunc