'////////////////////////////////////////////////////////////////////////
'// MIMIC SCRIPT FOR 9.4
'// WRITTEN BY: Chriso
'// This script will allow you to copy exactly what a user says or emotes.
'// This was designed to annoy others or advertise something.
'////////////////////////////////////////////////////////////////////////

Dim Mimic
Dim Target

'// Return Script Information
Sub Script(Name, Major, Minor, Build, Author, Commands, Description)
	Name = "Mimicker"
	Major = 1
	Minor = 1
	Build = 0
	Author = "Chriso"
	Commands = "cmdmimic, mimic, setmimic"
	Description = "Copy exactly what a user says or emotes."
End Sub

'// Called when the script is loaded for a particular bot
Sub Event_Load()
	CreateCommand "cmdmimic", "Mimic", "Command_CmdMimic", "", "mode", "Change the status of command mimicking - on/off/? - if this is off messages beginning with the current trigger will not be mimicked", 0, True
    	CreateCommand "mimic", "Mimic", "Command_Mimic", "", "mode", "Change the status of mimicking - on/off/?", 0, True
	CreateCommand "setmimic", "Mimic", "Command_SetMimic", "", "user", "Change the target user for the bot to mimic", 0, True
	
	CmdMimic = ReadSetting("Mimic","CmdMimic") = "Y"
	Mimic = ReadSetting("Mimic","Mimic") = "Y"
	Target = ReadSetting("Mimic","Target")
End Sub

'// Callback for "mimic" Command
Sub Command_Mimic(CS)
    Select Case LCase(CS.Message)
	Case "on"
		WriteSetting "Mimic", "Mimic", "Y"
		Mimic = True
	Case "off"
		WriteSetting "Mimic", "Mimic", "N"
		Mimic = False
	Case "?"
	Case Else
		Exit Sub
	End Select
	If CBool(Mimic) Then
		CS.Reply "Mimic is currently on."
	Else
		CS.Reply "Mimic is currently off."
	End If
End Sub

'// Callback for "cmdmimic" Command
Sub Command_CmdMimic(CS)
    Select Case LCase(CS.Message)
	Case "on"
		WriteSetting "Mimic", "CmdMimic", "Y"
		CmdMimic = True
	Case "off"
		WriteSetting "Mimic", "CmdMimic", "N"
		CmdMimic = False
	Case "?"
	Case Else
		Exit Sub
	End Select
	If CBool(CmdMimic) Then
		CS.Reply "Command mimic is currently on."
	Else
		CS.Reply "Command mimic is currently off."
	End If
End Sub

'// Callback for "setmimic" Command
Sub Command_SetMimic(CS)
    Target = CS.Message
	WriteSetting "Mimic", "Target", Target
	CS.Reply "Mimic is currently targeting: " & Target & "."
End Sub

'// Called when a user speaks
Sub Event_UserTalk(CE)
	If Not CBool(Mimic) Then Exit Sub
	Dim A, B, C
	A = LCase(GetBot.GetAccount(Target))
	B = LCase(GetBot.GetAccount(CE.Username))
	C = LCase(GetBot.Config.Trigger)
	If A = B Then
		If LCase(Left(CE.Message, Len(C))) = C Then
			If CBool(CmdMimic) Then
				Send2 CE.Message
			End If
		Else
			Send2 CE.Message
		End If
	End If
End Sub

'// Called when a user emotes
Sub Event_UserEmote(CE)
	If Not CBool(Mimic) Then Exit Sub
	Dim A, B, C
	A = LCase(GetBot.GetAccount(Target))
	B = LCase(GetBot.GetAccount(CE.Username))
	If A = B Then
		Send2 "/me " & CE.Message
	End If
End Sub