Code:
Public Class LimUniqueResponder
Private responses As List(Of String)
Private urg As UniqueRandomGenerator = New UniqueRandomGenerator(0)
Private ReadOnly lim As Integer
' Constructor
Public Sub New(lim As Integer)
responses = New List(Of String)()
Me.lim = lim
End Sub
' Method to get a response
Public Function GetAResponse() As String
If responses.Count = 0 Then
Return ""
End If
Return responses(urg.GetUniqueRandom())
End Function
' Method to check if responses contain a string
Public Function ResponsesContainsStr(item As String) As Boolean
Return responses.Contains(item)
End Function
' Method to check if a string contains any response
Public Function StrContainsResponse(item As String) As Boolean
For Each response As String In responses
If String.IsNullOrEmpty(response) Then
Continue For
End If
If item.Contains(response) Then
Return True
End If
Next
Return False
End Function
' Method to add a response
Public Sub AddResponse(s1 As String)
If Me.responses.Count > lim - 1 Then
responses.RemoveAt(0)
End If
If Not responses.Contains(s1) Then
responses.Add(s1)
urg = New UniqueRandomGenerator(responses.Count)
End If
End Sub
' Method to add multiple responses
Public Sub AddResponses(ParamArray replies As String())
For Each value As String In replies
AddResponse(value)
Next
End Sub
' Method to get a savable string
Public Function GetSavableStr() As String
Return String.Join("_", responses)
End Function
' Method to get the last item
Public Function GetLastItem() As String
If responses.Count = 0 Then
Return ""
End If
Return responses(responses.Count - 1)
End Function
End Class