TizzyT

CustomReplies for XwitchBot - TizzyT

Mar 16th, 2014
214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 2.67 KB | None | 0 0
  1. Imports Globals.GlobalResources
  2. Imports System.IO
  3.  
  4. Public Class Class1
  5.     Implements Globals.Plgn
  6.  
  7.     Private commandsDir As String = My.Application.Info.DirectoryPath & "\Plugins\CustomReplies"
  8.     Private di As New IO.DirectoryInfo(commandsDir)
  9.  
  10.     Public Sub Config() Implements Globals.Plgn.Config
  11.         Process.Start(commandsDir)
  12.     End Sub
  13.  
  14.     Public ReadOnly Property Name As String Implements Globals.Plgn.Name
  15.         Get
  16.             Return "CustomReplies - TizzyT"
  17.         End Get
  18.     End Property
  19.  
  20.     Public Function ProcessMessage(InputMessage As Message) As Boolean Implements Globals.Plgn.ProcessMessage
  21.         If InputMessage.Type = MessageType.PRIVMSG And InputMessage.Raw.StartsWith(":") Then
  22.             Dim diar1 As IO.FileInfo() = di.GetFiles("*.txt")
  23.             Dim dra As IO.FileInfo
  24.             For Each dra In diar1
  25.                 Dim Command As String = dra.Name.Substring(0, dra.Name.Length - 6).Trim
  26.                 If InputMessage.Message.StartsWith(Command) Then
  27.                     Dim param As String = InputMessage.Message.Remove(0, Command.Length + 2).Trim
  28.                     Dim line As String
  29.                     Using sr As New StreamReader(dra.FullName)
  30.                         line = sr.ReadToEnd()
  31.                     End Using
  32.                     line = line.Replace("<PARAM>", param)
  33.                     line = line.Replace(vbCrLf, " ")
  34.                     line = line.Replace(vbCr, " ")
  35.                     line = line.Replace(vbLf, " ")
  36.                     If line.Contains("<RND>") Then
  37.                         Dim RND As New Random
  38.                         Dim Parts() As String = line.Split(New String() {"<RND>"}, StringSplitOptions.None)
  39.                         line = ""
  40.                         For i = 0 To Parts.Length - 2
  41.                             Dim range As String = Parts(i + 1).Split(">")(0)
  42.                             Dim low As String = range.Split(",")(0)
  43.                             Dim high As String = range.Split(",")(1)
  44.                             Parts(i) &= RND.Next(CInt(low), CInt(high + 1))
  45.                             Parts(i + 1) = Parts(i + 1).Replace(low & "," & high & ">", "")
  46.                             line &= Parts(i)
  47.                         Next
  48.                         line &= Parts(Parts.Length - 1)
  49.                     End If
  50.                     AddToSend("PRIVMSG " & GetCurrentChan() & " :" & ParseMessage(InputMessage, line))
  51.                 End If
  52.             Next
  53.         End If
  54.     End Function
  55.  
  56.     Public Sub New()
  57.         If Not System.IO.Directory.Exists(commandsDir) Then
  58.             System.IO.Directory.CreateDirectory(commandsDir)
  59.         End If
  60.     End Sub
  61. End Class
Advertisement
Add Comment
Please, Sign In to add comment