Posted by: ArticWolve
« on: December 04, 2008, 08:53:11 PM »Fair enough. Anyways, will test soon as possible.....
'pw
'0.1
'&Phrase Warns:Vector:Warns people for saying specific words or phrases
'*
'*Type /r77 open pw for more information on this plugin. Go to %topic=281 also for more info.
'*
'*timeban.plug
'*Moderation Related
'// COMMANDS: (be sure to use your bot's trigger for these)
'// /pwall = Lists all warns. (in-bot only)"
'// COMMANDS ONLY AVAILABLE WITH FLAG A, M, OR O
'// pww <on/off> = sets whether the plugin will warn users or not
'// pwstatus = returns whether users will be warned or not
'// papprove = Approves a user to be added to the safelist
'// pdisapprove = Denies a user to be added to the safelist
'// psafelist = Shows a list of all users awaiting to be added to the safelist
'// 90 access or more
'// pwa = Changes max warn limit before punishing user
'// pwp = Changes the current punishment (see below)
'// pwspam = Toggles responses on or off
'// 70 access or more
'// addpwarn = Adds a phrase warn
'// delpwarn = Removes a phrase warn
'// 30 access or more
'// cpw = Whispers a username the warn count of another user
'// default action after warn limit has been reached (kick/ban)
'// Punishments:
'// kick = kicks a user for saying a phrase ban
'// ban = bans a user for saying a phrase ban
'// timeban = timebans a user for saying a phrase ban
'// exile = exiles the user if they say a phrase ban
'// ra = removes access if a user says a phrase ban
Private pwWarnAction
pwWarnAction = "kick"
'// Default minutes to time ban user if timeban is used
Dim pwNumMinutes
pwNumMinutes = 5
Const warnFile = "plugins\PhraseWarnUsers.txt"
'// Locks commands to prevent spam
Private pwCmdLocked
pwCmdLocked = False
'// holds the amount of time a user needs to wait before issuing another command
Dim pwSpamTime
pwSpamTime = 0
Dim flagAcc
flagAcc = Array("a", "m", "o")
'// default amount of warnings before taking action
Dim pwWarnLimit
pwWarnLimit = 3
'// Will the plugin warn users?
Private pwWarnEnabled
pwWarnEnabled = True
'// Will the plugin whisper users when they are warned?
Private pwWhisperMessage
pwWhisperMessage = True
Private preparePWString
Dim fso
Set fso = CreateObject("Scripting.FileSystemObject")
Dim dicPhraseWarns, dicWarnedUsers, dicReasons, dicWords, dicSafeList
Set dicPhraseWarns = CreateObject("Scripting.Dictionary")
set dicWarnedUsers = CreateObject("Scripting.Dictionary")
Set dicReasons = CreateObject("Scripting.Dictionary")
Set dicPhrases = CreateObject("Scripting.Dictionary")
Set dicPendSafeList = CreateObject("Scripting.Dictionary")
Sub pw_Event_Load()
AddChat vbGreen, "Vector's Phrase Warn plugin v" & psVersions.Item("pw") & " loaded."
If Getsetting("pw", "warnLimit") = "" Then
SetSetting "pw", "warnLimit", pwWarnLimit, "Number of warns before action is carried out", False
Else
pwWarnLimit = GetSetting("pw", "warnLimit")
End If
If Getsetting("pw", "warnEnabled") = "" Then
SetSetting "pw", "warnEnabled", pwWarnEnabled, "Determines whether users will be warned or not", False
Else
pwWarnEnabled = GetSetting("pw", "warnEnabled")
End If
If GetSetting("pw", "warnAction") = "" Then
SetSetting "pw", "warnAction", pwWarnAction, "Action to take when user reaches maximum warn level", False
Else
pwWarnAction = GetSetting("pw", "warnAction")
End If
If GetSetting("pw", "whisperMessage") = "" Then
SetSetting "pw", "whisperMessage", pwWhisperMessage, "Determines whether or not the bot whispers a user when they receive a warn", False
Else
pwWhisperMessage = GetSetting("pw", "whisperMessage")
End If
If GetSetting("pw", "Dummy") = "" Then
SetSetting "pw", "Dummy", True, "", False
Command BotVars.Username, "/set " & BotVars.Username & " 999", True
AddChat vbGreen, "[PW] Set up the dummy account for the timeban command."
End If
If GetSetting("pw", "PhraseWarns") Then
preparePWString = Lcase(GetSetting("pw", "PhraseWarns"))
splString = Split(preparePWString, ", ")
For i=0 to Ubound(splString)
dicPhraseWarns.Item(splString(i)) = 1
Next
End If
If fso.FileExists(warnFile) Then
Set initWarns = fso.OpenTextFile(warnFile, 1, True)
lines = Split(initWarns.ReadAll, vbNewLine)
For i=0 to Ubound(lines)
user = Split(lines(i), ":")(0)
warnCount = Split(lines(i), ":")(1)
reason = Split(lines(i), ":")(2)
dicWarnedUsers.Item(user) = warnCount
dicReasons.Item(user) = reason
Next
initWarns.Close
End If
End Sub
Sub pw_Event_PressedEnter(text)
If Lcase(text) = "/pwall" Then
If dicWarnedUsers.Count = 0 Then
AddChat vbCyan, "There are currently no users with any warns."
Exit Sub
End If
For each key in dicWarnedUsers.Keys
getWC = dicWarnedUsers.Item(key)
AddChat vbOrange, key & " has " & getWC & " warns. He/She was last warned for the word/phrase """ _
& dicPhrases.Item(key) & """."
Next
End If
Call pw_ProcessInput(BotVars.Username, text, 4)
End Sub
Sub pw_Event_WhisperFromUser(Username, Flags, Message)
Call pw_ProcessInput(Username, Message, 3)
End Sub
Sub pw_Event_UserTalk(Username, Flags, Message, Ping)
Call pw_ProcessInput(Username, Message, 1)
GetDBEntry Username, a, f
If InArray(flagAcc, f) Then Exit Sub
If Not pwWarnEnabled Then Exit Sub
countWords = Ubound(Split(Message))
If dicPhraseWarns.Exists(Message) Then
If dicWarned.Users.Item(Username) = pwWarnLimit Then
dicWarnedUsers.Remove(Username)
Select Case Lcase(pwWarnAction)
Case "kick", "ban"
AddQ "/" & pwWarnAction & " " & PsD2 & Username & " Phrase warn count reached"
Case "timeban"
Call timeban_Event_UserTalk(BotVars.Username, "", BotVars.Trigger & "timeban " & Username & " " & pwNumMinutes, 0)
Case "exile"
Command BotVars.Username, "/exile " & Username & " Phrase warn count reached", True
Case "ra"
GetDBEntry Username, a, f : If a <> -1 Then Command BotVars.Username, "/rem " & Username, True
Case Else
AddChat vbRed, "Invalid phrase warn punishment. Use ""ban"", ""kick"", ""exile"", ""timeban"", or ""ra""."
End Select
If IsSafelisted(Username) Then
Command BotVars.Username, "/safedel " & Username, True
dicPendSafeList.Item(Username) = 1
End If
Else
dicWarnedUsers.Item(Username) = dicWarnedUsers.Item(Username) + 1
If pwWhisperMessage Then AddQ "/w " & PsD2 & Username & " You have been warned for the phrase """ & Message & """. You have " & dicWarnedUsers.Item(Username) & " warns."
End If
ElseIf countWords > 0 Then
For Each key in dicPhraseWarns.Keys
If InStr(Lcase(Message), key) Then
If dicWarnedUsers.Users.Item(Username) = pwWarnLimit Then
dicWarnedUsers.Remove(Username)
Select Case Lcase(pwWarnAction)
Case "kick", "ban"
AddQ "/" & pwWarnAction & " " & PsD2 & Username & " Phrase warns activated"
Case "timeban"
Call timeban_Event_UserTalk(BotVars.Username, "", BotVars.Trigger & "timeban " & Username & " " & pwNumMinutes, 0)
Case "exile"
Command BotVars.Username, "/exile " & Username & " Phrase warn count reached", True
Case "ra"
GetDBEntry Username, a, f
If a <> -1 Then Command BotVars.Username, "/rem " & Username, True
Case Else
AddChat vbRed, "Invalid phrase warn punishment. Use ""ban"", ""kick"", ""exile"", ""timeban"", or ""ra""."
End Select
If IsSafelisted(Username) Then
Command BotVars.Username, "/safedel " & Username, True
dicPendSafeList.Item(Username) = 1
End If
Exit Sub
Else
dicWarnedUsers.Item(Username) = dicWarnedUsers.Item(Username) + 1
If pwWhisperMessage Then AddQ "/w " & PsD2 & Username & " You have been warned for the phrase """ & key & """. You have " & dicWarnedUsers.Item(Username) & " warns."
Exit Sub
End If
End If
Next
End If
End Sub
Sub pw_Event_ProcessInput(Username, Message, Origin)
If Left(Message, Len(BotVars.Trigger)) <> BotVars.Trigger And Left(Message, 1) <> "/" Then Exit Sub
If pwCmdLocked Then Exit Sub
If Len(Message) = Len(Botvars.Trigger) Then Exit Sub
GetDBEntry Username, a, f
If Origin = 4 Then
Cmd = Split(Mid(Lcase(Trim(Message)), 2), " ")
Else
Cmd = Split(Mid(Lcase(Trim(Message)), Len(BotVars.Trigger) + 1), " ")
End If
ucmd = Ubound(cmd)
Select Case cmd(0)
Case "pww"
If Not InArray(flagAcc, f) Then Exit Sub
If cmd(1) = "on" Then
pwWarnEnabled = True
DSP Origin, "Users will be warned if they say a flagged phrase.", Username, vbWhite
ElseIf cmd(1) = "off" Then
pwWarnEnabled = False
DSP Origin, "Users will be not warned if they say a flagged phrase.", Username, vbWhite
End If
Case "pwp"
If a < 90 Then Exit Sub
If ucmd < 0 Or ucmd > 1 Then Exit Sub
tempCheck = Array("kick", "ban", "exile", "timeban", "ra")
found = false
For i=0 to Ubound(tempCheck)
If Lcase(tempCheck(i)) = cmd(1) Then
found = True
End If
Next
If found Then
pwWarnAction = cmd(1)
DSP Origin, "Changed phrase warn punishment to " & cmd(1), Username, vbWhite
Else
DSP Origin, "Invalid punishment. Possible punishments: " & Join(tempCheck, ", ")
End If
Case "pwa"
If a < 90 Then Exit Sub
If ucmd = 0 Then Exit Sub
If Not IsNumeric(cmd(1)) Then
DSP Origin, "Amount must be an integer.", Username, vbWhite
Exit Sub
End If
pwWarnLimit = cmd(1)
DSP Origin, "Changed the maximum warn level to " & cmd(1)
Case "pwstatus"
If Not InArray(flagAcc, f) Then Exit Sub
If ucmd = 1 Then Exit Sub
DSP Origin, "Phrase warn status: " & pwWarnEnabled & ". Curren punishment: " & pwWarnAction, Username, vbWhite
Case "papprove"
If Not InArray(flagAcc, f) Then Exit Sub
If ucmd <> 1 Then Exit Sub
If Not dicPendSafeList.Exists(cmd(1)) Then
DsP Origin, "That user is not pending addition to the safelist.", Username, vbWhite
Else
DSP Origin, cmd(1) & " has been approved to the safelist.", Username, vbWhite
dicPendSafeList.Remove(cmd(1))
Command BotVars.Username, "/safeadd " & cmd(1), True
End If
Case "pdisapprove"
If ucmd = 0 Or ucmd > 1 Then Exit Sub
If Not InArray(flagAcc, f) Then Exit Sub
If Not dicPendSafeList.Exists(cmd(1)) Then
DsP Origin, "That user is not pending addition to the safelist.", Username, vbWhite
Else
DSP Origin, "Denied " & cmd(1) & " from being re-added to the safelist.", Username, vbWhite
dicPendSafeList.Remove(cmd(1))
End If
Case "psafelist"
If ucmd = 0 Or ucmd > 1 Then Exit Sub
If Not InArray(flagAcc, f) Then Exit Sub
For each key in dicPendSafeList.Keys
pendString = pendString & key & ", "
Next
DSP Origin, "The following users are waiting approval to the safelist: " & Left(pendString, Len(pendString) - 2), Username, vbWhite
Case "cpw"
If a < 30 Then Exit Sub
If ucmd = 0 Or ucmd > 1 Then Exit Sub
If ucmd = 0 Then
DSP Origin, "You have " & dicWarnedUsers.Item(Username) & " warns.", Username, vbWhite
Exit Sub
End If
If Not dicWarnedUsers.Exists(cmd(1)) And a > 60 Then
DSP Origin, "That user does not exist."
ElseIf a < 60 Then
DSP Origin, "You do not have enough access to check the status of another user.", Username, vbWhite
Else
DSP Origin, cmd(1) & " has " & dicWarnedUsers.Item(cmd(1)) & " warns.", Username, vbWhite
End If
Case "pwlist"
If a < 20 Then Exit Sub
DSP Origin, "The following words/phrases will give you a warning: " & preparePWString, Username, vbWhite
Case "addpwarn"
If a < 70 Then Exit Sub
If ucmd < 1 Then Exit Sub
addPhrase = Split(Message, cmd(0) & " ")(1)
DSP Origin, "Added the phrase """ & addPhrase & """ to the phrase warn list.", Username, vbWhite
dicPhraseWarns.Item(addPhrase) = 1
Case "delpwarn"
If a < 70 Then Exit Sub
If ucmd < 1 Then Exit Sub
getPhrase = Split(Message, cmd(0) & " ")(1)
If Not dicPhraseWarns.Exists(getPhrase) Then
DSP Origin, "That is not a valid word/phrase on the phrase list.", Username, vbWhite
Else
dicPhraseWarns.Remove(getPhrase)
DSP Origin, "Removed the word/phrase " & getPhrase & " from the phrase list.", Username, vbWhite
End If
End Select
countWords = Ubound(Split(Message))
'// Determine length of time before the command can be used again
pwSpamTime = Int(10 + (countWords * 3))
pwCmdLocked = True
TimerInterval "pw", "UnlockCommands", pwSpamTime
TimerEnabled "pw", "UnlockCommands", True
End Sub
Sub pw_UnlockCommands_Timer()
pwCmdLocked = False
TimerEnabled "pw", "UnlockCommands", False
End Sub
Function InArray(Arr, Item)
If Not IsArray(Arr) Then
InArray = False
Else
Found = False
If Len(item) > 1 Then
For i=0 to Len(Item) - 1
getFlag = Mid(Item, i+1, 1)
For ii=0 to Ubound(Arr)
If Lcase(arr(ii)) = Lcase(getFlag) Then
InArray = True
Exit Function
End If
Next
Next
Else
For i = LBound(Arr) To UBOund(Arr)
If LCase(Arr(i)) = LCase(Item) Then
InArray = True
Exit Function
End If
Next
InArray = False
End If
End If
End Function
Sub pw_Event_Close()
SetSetting "pw", "warnLimit", pwWarnLimit, "Number of warns before action is carried out", False
SetSetting "pw", "warnAction", pwWarnAction, "Action to take when user reaches maximum warn level", False
SetSetting "pw", "warnEnabled", pwWarnEnabled, "Determines whether users will be warned or not", False
SetSetting "pw", "whisperMessage", pwWhisperMessage, "Determines whether or not the bot whispers a user when they receive a warn", False
preparePWString = vbNullString
For Each key in dicPhraseWarns.Keys
preparePWString = preparePWString & key & ", "
Next
If Len(preparePWString) <= 2 Then Exit Sub
preparePWString = Left(preparePWString, Len(preparePWStreing) - 2)
SetSetting "pw", "PhraseWarns", preparePWString, "List of phrase warns", False
Set writeWarns = fso.OpenTextFile(warnFile, 2, True)
For Each key in dicWarnedUsers.Keys
writeWarns.WriteLine key & ":" & dicWarnedUsers.Item(key) & ":" & dicReasons.Item(key)
Next
writeWarns.Close
End Sub
.papprove <Username>
~Allows Username to be readded to the safelist
.pdisprove <Username>
~Does not allow Username to be readded to the safelist
.psafelist
~Displays usernames who are pending approval to be added back to the safelist.
If GetSetting("pw", "Dummy") = "" Then
SetSetting "pw", "Dummy", True, "", False
Command BotVars.Username, "/set DummyAcc 999", True
AddChat vbGreen, "[PW] Set up the dummy account for the timeban command."
End If
Case "kick", "ban"
AddQ "/" & pwWarnAction & " " & PsD2 & Username & " Phrase warns activated"
Case "timeban"
Call timeban_Event_UserTalk("DummyAcc", "", BotVars.Trigger & "timeban " & Username & " " & pwNumMinutes, 0)
End Select