'////////////////////////////////////////////////////////////////////////
'// AUTO CLAN PRIVATE SCRIPT FOR 9.4
'// WRITTEN BY: Chriso
'// Automatically sets the clan to private when a flood is detected, 
'// returns clan to public after flood has finished.
'////////////////////////////////////////////////////////////////////////

'// Enter the password you want people to be able to whisper to the bot to
'// temporarily disable clan private in order to get in
Const Password = "PASSWORD"
'// If you want to clear the queue prior to sending /clan private or public
'// set this to True, this may be useful if your bot is moderator
Const ClearQueuePrior = False

'// Return Script Information
Sub Script(Name, Major, Minor, Build, Author, Commands, Description)
	Name = "Auto Clan Private Script"
	Major = 1
	Minor = 1
	Build = 0
	Author = "Chriso"
	Description = "Automatically sets the clan to private when a flood is detected, returns clan to public after 5 minutes."
End Sub

'// Initialize Timers in Disabled State
Sub Event_Load()
    AddTimer "AutoClanPrivate", "Public_Timer", 300000, False
    AddTimer "AutoClanPrivate", "Private_Timer", 15000, False
End Sub

'// Called when a channel appears to be no longer getting flooded
Sub Public_Timer()
    If GetBot.FloodDetected = False Then
	If ClearQueuePrior Then QueueClear
    	Send2 "/clan public"
    	StopTimer "AutoClanPrivate", "Public_Timer"
    End If
End Sub

'// Called when a channel is about to be closed again
Sub Private_Timer()
    If ClearQueuePrior Then QueueClear
    Send2 "/clan private"
    StopTimer "AutoClanPrivate", "Private_Timer"
End Sub

'// Called when a user whispers you
Sub Event_Whisper(CE)
    If CE.Message = Password Then
	If ClearQueuePrior Then QueueClear
	Send2 "/clan public"
	StartTimer "AutoClanPrivate", "Private_Timer"
    End If
End Sub

'// Called when a flood is detected
'// Value may be true (being flooded) or false (no longer being flooded)
Sub Event_FloodDetect(Value)
    '// Check if Chieftain
    If GetBot.Clan.Rank = 4 Then
        '// Check if you are in your channel
        If LCase(GetBot.Self.Channel) = LCase("clan " & GetBot.Clan.Tag) Then
            '// Check if the flood just began
    	    If Value = True Then
		If ClearQueuePrior Then QueueClear
		Send2 "/clan private"
		StartTimer "AutoClanPrivate", "Public_Timer"
    	    End If
        End If
    End If
End Sub