Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Helpmebot v3 :o Dragged out of the archives
Module Module1
#Region "constants and variables"
'get the connection stuff
Const server As String = "kubrick.freenode.net"
Dim client As New System.Net.Sockets.TcpClient(server, 8001)
Dim streamreader As New System.IO.StreamReader(client.GetStream)
Dim streamwriter As New System.IO.StreamWriter(client.GetStream)
'details reqd. for connection etc.
Dim chan As String
Dim nick As String
Dim pass As String
Const ver As String = "3.3.1.4"
#End Region
Sub connect()
Try
client.Connect(server, 8001)
Catch : End Try
streamwriter.WriteLine("USER " & nick & " * * :" & nick)
streamwriter.Flush()
streamwriter.WriteLine("NICK " & nick)
streamwriter.Flush()
writeline("IDENTIFY " & pass, "NickServ")
'System.Threading.Thread.Sleep(3000)
End Sub
Sub Main()
Console.Title = My.Application.Info.AssemblyName
'Console.WriteLine("Channel?")
chan = "##stwalkerster" 'Console.ReadLine()
'Console.WriteLine("Botnick?")
nick = "stwalkerbot" 'Console.ReadLine()
'Console.WriteLine("Botpass?")
pass = "xxxxxxxxxxxx" 'Console.ReadLine()
streamwriter.AutoFlush = True
Call connect()
streamwriter.WriteLine("JOIN " & chan)
streamwriter.Flush()
Dim line As String = Nothing
Do
'Try
readline: line = streamreader.ReadLine
If (Not line.Contains("@")) Or line.Contains(":" & server) Then GoTo readline
If line.Contains("JOIN") Or line.Contains("PART") Or line.Contains("MODE") Then GoTo readline
Dim nick, username, host, msgtype, channel, command, param1, param2, param3 As String
Call parseline(line, nick, username, host, msgtype, channel, command, param1, param2, param3)
If command.Length >= 5 Then
If command.ToLower.Substring(0, 5) = ("!link") Then
Try
Dim wikilink As String = command.Substring(command.IndexOf("[["))
Dim linktext As String = wikilink.Substring(2, wikilink.IndexOf("]]") - 2)
writeline(nick & ": http://en.wikipedia.org/wiki/" & linktext, channel)
Catch ex As Exception
writeline(nick & ": http://en.wikipedia.org/", channel)
End Try
End If
End If
'Catch ex As Exception
' Try : writeline(ex.InnerException.ToString & ": " & ex.Message, chan) : Catch : End Try
'End Try
System.Threading.Thread.Sleep(500) 'flood protection
Loop
End Sub
Public Sub writeline_raw(ByVal msg As String)
Dim write As String = msg
streamwriter.WriteLine(write)
streamwriter.Flush()
End Sub
Public Sub writeline(ByVal message As String, ByVal channel As String, Optional ByVal type As String = "PRIVMSG", Optional ByVal voice As Boolean = False)
Dim write As String = type & " " & channel & " :" & message
streamwriter.WriteLine(write)
streamwriter.Flush()
Console.WriteLine(write)
End Sub
Sub parseline(ByVal line As String, ByRef nick As String, ByRef username As String, ByRef host As String, _
ByRef msgtype As String, ByRef channel As String, ByRef command As String, _
ByRef param1 As String, ByRef param2 As String, ByRef param3 As String)
':Stwalkerster!i=HydraIRC@wikipedia/Stwalkerster PRIVMSG #Stwalkerbot :message
':nick!username@host msgtype channel :!command param1 param2 param3
If line.Contains("MODE") Then Exit Sub
Dim nick_sep As Integer = line.IndexOf(":")
Dim username_sep As Integer = line.IndexOf("!", 0 + 1)
Dim host_sep As Integer = line.IndexOf("@", username_sep + 1)
Dim msgtype_sep As Integer = line.IndexOf(" ", host_sep + 1)
Dim channel_sep As Integer = line.IndexOf(" ", msgtype_sep + 1)
Dim command_sep As Integer = line.IndexOf(":", channel_sep + 1)
'Dim param1_sep As Integer = line.IndexOf(" ", command_sep + 1)
'Dim param2_sep As Integer = line.IndexOf(" ", param1_sep + 1)
'Dim param3_sep As Integer = line.IndexOf(" ", param2_sep + 1)
nick = line.Substring(nick_sep + 1, username_sep - nick_sep - 1)
username = line.Substring(username_sep + 1, host_sep - username_sep - 1)
host = line.Substring(host_sep + 1, msgtype_sep - host_sep - 1)
msgtype = line.Substring(msgtype_sep + 1, channel_sep - msgtype_sep - 1)
channel = line.Substring(channel_sep + 1, command_sep - channel_sep - 1)
channel = channel.Trim()
' Try
command = line.Substring(command_sep + 1) ', param1_sep - command_sep - 1)
'Catch ex As ArgumentOutOfRangeException
' command = Nothing
'End Try
'Try
' param1 = line.Substring(param1_sep + 1, param2_sep - param1_sep - 1)
'Catch ex As ArgumentOutOfRangeException
' param1 = Nothing
'End Try
'Try
' param2 = line.Substring(param2_sep + 1, param3_sep - param2_sep - 1)
'Catch ex As ArgumentOutOfRangeException
' param2 = Nothing
'End Try
'Try
' param3 = line.Substring(param3_sep + 1)
'Catch ex As ArgumentOutOfRangeException
' param3 = Nothing
'End Try
Console.WriteLine(nick & " " & username & " " & host & " " & msgtype & " " & channel & " " & command) '& " " & param1 & " " & param2 & " " & param3)
End Sub
End Module
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.