Sign in to follow this  
Followers 0
zackrspv

[solved] IRC UDF 'Send Reply'

3 posts in this topic

#1 ·  Posted (edited)

Alright, so, i'm using the IRC UDF which is working great!

Now, the below code is just an example; and by far not completed; but as we can see, in my $whoSent variable i have who sent the !KB command to the channel. This will allow me to tailor responses back to those who need it, etc; however, If i just run the script as is with the _IRCSendMessage() function, it goes to the channel; and if i do the _IRCSendAction() command it does an action; i havn't been able to figure out how to do the _IRCSendReply() function.

Can anyone provide any help with this?

IRC Client

$fQuery = ""

TCPStartup()
Global $sock = _IRCConnect($server, $port, $nick); Connects to IRC and Identifies its Nickname

While 1
    $recv = TCPRecv($sock, 8192); Recieve things from server
    If @error Then Exit MsgBox(1, "IRC Example", "Server has errored or disconnected"); If you can't recieve then the server must have died.
    Local $sData = StringSplit($recv, @CRLF); Splits the messages, sometimes the server groups them
    For $i = 1 To $sData[0] Step 1; Does each message seperately
        Local $sTemp = StringSplit($sData[$i], " "); Splits the message by spaces
        If Not $sData[$i] = "" Then TrayTip("IRC Information", $sData[$i], 5)
        $noffset = 1
        If StringInStr($sData[$i], "!KB ", 0) Then
            $fKBFindArray = StringRegExp($sData[$i], "(?i)(?s)(?:^.*):(.*?)(?:!kb)(.*?)(?:\z)", 1, $noffset)
            if $fKBFindArray[0] = "" then
                    $fQuery = $fKBFindArray[1]
                    $queryUser = StringTrimLeft($sData[$i], 1)
                    $fqueryUser = StringRegExp($queryUser, "(?i)(?s)(.*?)!", 1, $noffset)
                    $whoSent = $fqueryUser[0]

;- ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
;- // My IRC Reply would go here.  Something like _IRCSendReply($sock, $whoSent, $reply, [$channel]) if necessary. //       
;- ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
                Else
            EndIf
        EndIf
        If $sTemp[1] = "" Then ContinueLoop; If its empty, Continue!
        If StringInStr($sTemp[1], "PING", 0) Then _IRCPing($sTemp[2]); Checks for PING replys (There smaller then usual messages so its special!
        If $sTemp[0] <= 2 Then ContinueLoop; Useless messages for the most part
        Switch $sTemp[2]; Splits the command msg
            Case "266"; It's what I use as an indictator to show when its done sending you info.
                _IRCJoinChannel($sock, $channel)
                _IRCSendMessage($sock, "Hello!  BTC_KB Bot Ready! Type !KB followed by what you want to search for!", $channel)
                _IRCChangeMode($sock, "+i", $nick)
        EndSwitch
    Next
WEnd

;- ////////////// Function: _ArrayFindAll ///////////////////
;- /////// Purpose: Find all search terms in array //////////
;- //////////////////////////////////////////////////////////
Func _ArrayFindAll($iArray, $iQuery, $iStart = 0, $iEnd = 0, $iCaseSense = 0, $fPartialSearch = True)
    Local $Rtn = ''
    While 1
        $aSrch = _ArraySearch($iArray, $iQuery, $iStart, $iEnd, $iCaseSense, $fPartialSearch)
        If $aSrch <> -1 Then
            $Rtn &= $aSrch & '|'
            $iStart = $aSrch + 1
        Else
            ExitLoop
        EndIf
    WEnd
    If $Rtn <> '' Then
        $Rtn = StringSplit(StringTrimRight($Rtn, 1), '|')
        Return $Rtn
    Else
        Return SetError(1, 1, 'No matches to your query were found')
    EndIf
EndFunc   ;==>_ArrayFindAlloÝ÷ Øw«{l¶¢Énuæó·»Ûjëh×6global $irc
;===============================================================================
;
; Description:      Connects you to a IRC Server, and gives your chosen Nick
; Parameter(s):     $server - IRC Server you wish to connect to
;                   $port - Port to connect to (Usually 6667)
;                   $nick - Nick you choose to use (You can change later)
; Requirement(s):   TCPStartup () to be run
; Return Value(s):  On Success - Socket identifer
;                   On Failure - It will exit on error
; Author(s):        Chip
; Note(s):          English only
;
;===============================================================================
Func _IRCConnect ($server, $port, $nick)
    $irc = TCPConnect(TCPNameToIP($server), $port)
    If $irc = -1 Then Exit MsgBox(1, "IRC.au3 Error", "Server " & $server & " is not responding.")
    TCPSend($irc, "NICK " & $nick & @CRLF)
    $ping = tcprecv($irc,2048)
    if stringleft($ping,4) = "PING" Then
        $pong = stringreplace($ping,"PING :","")
        tcpsend($irc,"PONG " & $pong & @LF)
    EndIf
    TCPSend($irc, "USER " & $nick & " 0 0 " & $nick &@CRLF)
    Return $irc
EndFunc
;===============================================================================
;
; Description:      Joins an IRC Channel
; Parameter(s):     $irc - Socket Identifer from _IRCConnect ()
;                   $chan - Channel you wish to join
; Requirement(s):   _IRCConnect () to be run
; Return Value(s):  On Success - 1
;                   On Failure - -1 = Server disconnected.
; Author(s):        Chip
; Note(s):          English only
;
;===============================================================================
Func _IRCJoinChannel ($irc, $chan)
    If $irc = -1 Then Return 0
    TCPSend($irc, "JOIN " & $chan & @CRLF)
    If @error Then 
        MsgBox(1, "IRC.au3", "Server has disconnected.")
        Return -1
    EndIf
    Return 1
EndFunc

;===============================================================================
;
; Description:      Sends a message using IRC
; Parameter(s):     $irc - Socket Identifer from _IRCConnect ()
;                   $msg - Message you want to send
;                   $chan - Channel/Nick you wish to send to
; Requirement(s):   _IRCConnect () to be run
; Return Value(s):  On Success - 1
;                   On Failure - -1 = Server disconnected.
; Author(s):        Chip
; Note(s):          English only
;
;===============================================================================
Func _IRCSendMessage ($irc, $msg, $chan="")
    If $irc = -1 Then Return 0
    If $chan = "" Then
        TCPSend($irc, $msg & @CRLF)
        If @error Then 
            MsgBox(1, "IRC.au3", "Server has disconnected.")
            Return -1
        EndIf
        Return 1
    EndIf
    TCPSend($irc, "PRIVMSG " & $chan & " :" & $msg & @CRLF)
        If @error Then 
        MsgBox(1, "IRC.au3", "Server has disconnected.")
        Return -1
    EndIf
    Return 1
EndFunc

;===============================================================================
;
; Description:      Changes a MODE on IRC
; Parameter(s):     $irc - Socket Identifer from _IRCConnect ()
;                   $mode - Mode you wish to change
;                   $chan - Channel/Nick you wish to send to
; Requirement(s):   _IRCConnect () to be run
; Return Value(s):  On Success - 1
;                   On Failure - -1 = Server disconnected.
; Author(s):        Chip
; Note(s):          English only
;
;===============================================================================
Func _IRCChangeMode ($irc, $mode, $chan="")
    If $irc = -1 Then Return 0
    If $chan = "" Then
        TCPSend($irc, "MODE " & $mode & @CRLF)
        If @error Then 
        MsgBox(1, "IRC.au3", "Server has disconnected.")
        Return -1
    EndIf
    Return 1
    EndIf
    TCPSend($irc, "MODE " & $chan & " " & $mode & @CRLF)
        If @error Then 
        MsgBox(1, "IRC.au3", "Server has disconnected.")
        Return -1
    EndIf
    Return 1
EndFunc

;===============================================================================
;
; Description:      Returns a PING to Server
; Parameter(s):     $irc - Socket Identifer from _IRCConnect ()
;                   $ret - The end of the PING to return
; Requirement(s):   _IRCConnect () to be run
; Return Value(s):  On Success - 1
;                   On Failure - -1 = Server disconnected.
; Author(s):        Chip
; Note(s):          English only
;
;===============================================================================
Func _IRCPing($ret)
    If $ret = "" Then Return -1
    TCPSend($irc, "PONG " & $ret & @CRLF)
        If @error Then 
        MsgBox(1, "IRC.au3", "Server has disconnected.")
        Return -1
    EndIf
    Return 1
EndFunc

;===============================================================================
;
; Description:      Sends an action
; Note(s):          English only
;
;===============================================================================
Func _IRCSendAction ($irc, $msg, $chan="")
    If $irc = -1 Then Return 0
    If $chan = "" Then
        TCPSend($irc, $msg & @CRLF)
        If @error Then
        
            Return -1
        EndIf
        Return 1
    EndIf
    TCPSend($irc, "PRIVMSG " & $chan & " :" & Chr(1) & "ACTION " & $msg & Chr(1) & @CRLF)
        If @error Then
        
        Return -1
    EndIf
    Return 1
EndFunc


;===============================================================================
;
; Description:      Leave the IRC Channel
; Parameter(s):     $irc - Socket Identifer from _IRCConnect ()
;               $msg - Message to send with PART, optional
; Requirement(s):   _IRCConnect () to be run
; Return Value(s):  On Success - 1
;                   On Failure - -1 = Server disconnected.
;
;===============================================================================
Func _IRCLeaveChannel ($irc, $msg="", $chan="")
    If $irc = -1 Then Return 0
    TCPSend($irc, "PART " & $chan & " :" & $msg & @CRLF)
        If @error Then
        MsgBox(1, "IRC.au3", "Server has disconnected.")
        Return -1
    EndIf
    Return 1
EndFunc

;===============================================================================
;
; Description:      Close the IRC Connection
; Parameter(s):     $irc - Socket Identifer from _IRCConnect ()
;               $msg - Message to send with quit, optional (not able to see with all clients)
; Requirement(s):   _IRCConnect () to be run
; Return Value(s):  On Success - 1
;                   On Failure - -1 = Server disconnected.
;
;===============================================================================
Func _IRCQuit($irc, $msg="")
    If $irc = -1 Then Return 0
    TCPSend($irc, "QUIT :" & $msg & @CRLF)
    Return 1
EndFunc
Edited by zackrspv

-_-------__--_-_-____---_-_--_-__-__-_ ^^€ñ†®øÞÿ ë×阮§ wï†høµ† ƒë@®, wï†høµ† †ïmë, @ñd wï†høµ† @ †ïmïdï†ÿ ƒø® !ïƒë. €×阮 ñø†, bµ† ïñ§†ë@d wï†hïñ, ñ@ÿ, †h®øµghøµ† †hë 맧ëñ§ë øƒ !ïƒë.

Share this post


Link to post
Share on other sites



Alright, so, i'm using the IRC UDF which is working great!

Now, the below code is just an example; and by far not completed; but as we can see, in my $whoSent variable i have who sent the !KB command to the channel. This will allow me to tailor responses back to those who need it, etc; however, If i just run the script as is with the _IRCSendMessage() function, it goes to the channel; and if i do the _IRCSendAction() command it does an action; i havn't been able to figure out how to do the _IRCSendReply() function.

So, i figured maybe something like this:

Func _IRCSendReply ($irc, $whoSent, $reply)
    If $irc = -1 Then Return 0
    TCPSend($irc, "MSG " & $whoSent & " "&$reply & @CRLF)
    If @error Then
        MsgBox(1, "IRC.au3", "Server has disconnected.")
        Return -1
    EndIf
    Return 1
EndFunc

But that doesn't work haha


-_-------__--_-_-____---_-_--_-__-__-_ ^^€ñ†®øÞÿ ë×阮§ wï†høµ† ƒë@®, wï†høµ† †ïmë, @ñd wï†høµ† @ †ïmïdï†ÿ ƒø® !ïƒë. €×阮 ñø†, bµ† ïñ§†ë@d wï†hïñ, ñ@ÿ, †h®øµghøµ† †hë 맧ëñ§ë øƒ !ïƒë.

Share this post


Link to post
Share on other sites

So, i figured maybe something like this:

Func _IRCSendReply ($irc, $whoSent, $reply)
    If $irc = -1 Then Return 0
    TCPSend($irc, "MSG " & $whoSent & " "&$reply & @CRLF)
    If @error Then
        MsgBox(1, "IRC.au3", "Server has disconnected.")
        Return -1
    EndIf
    Return 1
EndFuncoÝ÷ Ø­¶­v¬mÂä¨Zþ«¨µà!k}Ƣحjëh×6Func _IRCSendReply ($irc, $whoSent, $reply)
    If $irc = -1 Then Return 0
    TCPSend($irc, "PRIVMSG " & $whoSent & " "&$reply & @CRLF)
    If @error Then
        MsgBox(1, "IRC.au3", "Server has disconnected.")
        Return -1
    EndIf
    Return 1
EndFunc

-_-------__--_-_-____---_-_--_-__-__-_ ^^€ñ†®øÞÿ ë×阮§ wï†høµ† ƒë@®, wï†høµ† †ïmë, @ñd wï†høµ† @ †ïmïdï†ÿ ƒø® !ïƒë. €×阮 ñø†, bµ† ïñ§†ë@d wï†hïñ, ñ@ÿ, †h®øµghøµ† †hë 맧ëñ§ë øƒ !ïƒë.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0