#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Icon=Skype.ico
#AutoIt3Wrapper_UseUpx=n
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#cs ----------------------------------------------------------------------------
	testing alert new messages.
#ce ----------------------------------------------------------------------------
#include <Array.au3>
#include <File.au3>





;// Create a Skype4COM object:
$oSkype = ObjCreate("Skype4COM.Skype")
$oSkypeEvent = ObjEvent($oSkype, "Skype_")
$oError = ObjEvent("AutoIt.Error", "MyErrFunc")
;// Start the skype client:
If Not $oSkype.Client.IsRunning Then
	$oSkype.Client.Start()
EndIf

$CurrentUser = IniRead(@ScriptDir & "\-s.CFG","User","User","NOT::HERE")
if $CurrentUser= "NOT::HERE" Then
	MsgBox(2,"WARNUNG","Bitte wähle einen User ( -s.CFG)")
	sleep(5000)
	Exit
	EndIf
;// Verify that a user is signed in and online before continuing
While 1
	If $oSkype.CurrentUserStatus = $oSkype.Convert.TextToUserStatus("ONLINE") Then
		ExitLoop
	Else
		$oSkype.ChangeUserStatus($oSkype.Convert.TextToUserStatus("ONLINE"))
	EndIf
	Sleep(1000)
WEnd
;// The AttachmentStatus event handler monitors attachment status and automatically attempts to reattach to the API following loss of connection:
Func Skype_AttachmentStatus($aStatus)
	If @OSVersion = "WIN_XP" Or "WIN_2000" Then
		TrayTip("Script", "Attachment status " & $oSkype.Convert.AttachmentStatusToText($aStatus), 10000)
	Else

		ToolTip("Attachment status " & $oSkype.Convert.AttachmentStatusToText($aStatus), 1500, 900, "Meldung [Skype] : ....", 1, 7)
	EndIf
	If $aStatus = $oSkype.Convert.TextToAttachmentStatus("AVAILABLE") Then
		$oSkype.Attach()
	EndIf
EndFunc   ;==>Skype_AttachmentStatus


;// messagebox Message received from "user"
Func Skype_MessageStatus($aMsg, $aStatus)
	If ($aStatus = $oSkype.Convert.TextToChatMessageStatus("RECEIVED")) And _
			$aMsg.Type = $oSkype.Convert.TextToChatMessageType("SAID") Then
;~     MsgBox(0,"","Message " & $aMsg.Id & " " & $aMsg.FromHandle & " : " & $aMsg.Body)
		If $aMsg.FromHandle = $CurrentUser Then
;~ 		MsgBox(2,"","Nachricht : " & $aMsg.Body)
			$split_Message = StringSplit($aMsg.Body, " ")









			If $split_Message[1] = "Shutdown" Then
				If UBound($split_Message) - 1 < 2 Then
					_ErrorLogNotEnoughArguments($CurrentUser)
				ElseIf $split_Message[2] < 1 Then
					_ErrorLogWrongSyntax($CurrentUser)
				Else
					Shutdown($split_Message[2])
				EndIf;
			EndIf;











			If $split_Message[1] = "Start" Then
				If UBound($split_Message) - 1 < 2 Then
					_ErrorLogNotEnoughArguments($CurrentUser)
				ElseIf $split_Message[2] = "-s" Then
					If UBound($split_Message) - 1 < 3 Then
						_ErrorLogNotEnoughArguments($CurrentUser)
					Else
						$read_config = IniRead(@ScriptDir & "\-s.CFG", "data", $split_Message[3], "ERROR::NOT HERE")
						If $read_config = "ERROR::NOT HERE" Then
							_ErrorLogConfigORDataNotFound($CurrentUser)
						Else
							Run($read_config)
						EndIf
					EndIf
				Else
					_ErrorLogWrongSyntax("alexepvp")
				EndIf
			Else
				Run($split_Message[2])
			EndIf










			If $split_Message[1] = "Config" Then
				If UBound($split_Message) - 1 < 4 Then
					_ErrorLogNotEnoughArguments($CurrentUser)

					ElseIf $split_Message[2] = "-d" Then
						DirCreate(@ScriptDir & "\Backup_Config-s")
						FileCopy(@ScriptDir & "\-s.CFG", @ScriptDir & "\Backup_Config-s", 1)
						Sleep(500)
						IniDelete(@ScriptDir & "\-s.CFG", "data")
					ElseIf $split_Message[2] = "-a" Then
						IniWrite(@ScriptDir & "\-s.CFG", "data", $split_Message[3], $split_Message[4])
					Else
						_ErrorLogWrongSyntax($CurrentUser)

				EndIf
			EndIf












			If $split_Message[1] = "Create" Then
				If UBound($split_Message) - 1 < 4 Then
					_ErrorLogNotEnoughArguments($CurrentUser)
				Else
					If $split_Message[2] = "-f" Then
						_FileCreate($split_Message[3] & "\" & $split_Message[4])
					ElseIf $split_Message[2] = "-d" Then
						DirCreate($split_Message[3] & "\" & $split_Message[4])
					Else
						_ErrorLogWrongSyntax($CurrentUser)
					EndIf
				EndIf
			EndIf













		EndIf;

	EndIf;
EndFunc   ;==>Skype_MessageStatus

While 1
	Sleep(1000)
WEnd




Func _ErrorLogNotEnoughArguments($User)
	$oSkype.Client.Focus
	$oSkype.Client.OpenMessageDialog($User, "[CHATBOT] : Error , not enough arguments")
	Sleep(100)
	Send("{ENTER}")
	Sleep(200)
	$oSkype.Client.Minimize
EndFunc   ;==>_ErrorLogNotEnoughArguments

Func _ErrorLogConfigORDataNotFound($User)
	$oSkype.Client.Focus
	$oSkype.Client.OpenMessageDialog($User, "[CHATBOT] : Error , could not find Config or data")
	Sleep(100)
	Send("{ENTER}")
	Sleep(200)
	$oSkype.Client.Minimize
EndFunc   ;==>_ErrorLogConfigORDataNotFound

Func _ErrorLogWrongSyntax($User)
	$oSkype.Client.Focus
	$oSkype.Client.OpenMessageDialog($User, "[CHATBOT] : Error , wrong Syntax")
	Sleep(100)
	Send("{ENTER}")
	Sleep(200)
	$oSkype.Client.Minimize
EndFunc   ;==>_ErrorLogWrongSyntax








