IRC Nachrichten "auslesen"

  • Guten Morgen,

    ich versuche gerade mit Autoit und IRC rum zu spielen...

    Mit hilfe von BugFix's IRC Client konnte ich in einen Channel joinen...
    Jetzt versuche ich eine Aktion zu starten, wenn eine spezielle Nachricht geschrieben wird...

    Also ich joine z.B in den Channel #B4sti und warte bis jemand @Uhrzeit schreibt... Dann soll der Script automatisch etwas schreiben...

    Ich dachte dies kann man mit

    [autoit]

    Tcprecv()

    [/autoit]

    machen.. klappt leider nicht...


    [autoit][/autoit][autoit][/autoit][autoit]

    If $recv = "PRIVMSG #TestingChannel :hi" Then
    Msgbox(64,"1","1")
    EndIf

    [/autoit][autoit][/autoit][autoit][/autoit][autoit][/autoit]


    Wie kann ich das lösen?


    Danke!

  • Ich habe gerqde erst einen selber gemacht :D du brauchst dafür

    [autoit]

    stringregexp

    [/autoit]


    PS: Wenn ich wieder am PC bin, kommt noch genaueres

  • Okay, das wäre nett.

    Ich hab mir den Script nochmal angeschaut...
    Ich dachte es würde mit Case

    [autoit]

    'PRIVMSG #TestingChannel :hallo.'

    [/autoit]

    gehen...

    Leider nicht...

    • Offizieller Beitrag

    Ich zeig dir mal meine (etwas bereinigte) Auswerteschleife.
    Ist eigentlich selbsterklärend, ich übergebe z.B. Nick und Message an Auswertefunktionen.

    Spoiler anzeigen
    [autoit]

    While 1
    $recv = TCPRecv($sock, 8192)
    If @error Then
    If Not $Quit_Done Then _FileWriteLog($errLog, "Server has errored or disconnected")
    Exit
    EndIf
    Local $sData = StringSplit($recv, @CRLF)
    For $i = 1 To $sData[0] Step 1
    Local $sTemp = StringSplit($sData[$i], " ")
    If $sTemp[1] = "" Then ContinueLoop
    If $sTemp[1] = "PING" Then _IRCPing($sock, $sTemp[2])
    If $sTemp[0] <= 2 Then ContinueLoop
    Switch $sTemp[2]
    Case "266"
    _IRCJoinChannel ($sock, $channel)
    If IniRead($INI, 'bot', 'auto_identify', 0) = 1 Then _
    _IRCSendMessage($sock, 'IDENTIFY ' & IniRead($INI, 'bot', 'pass', ''), 'NickServ')
    _IRCSendMessage($sock, "Hallo, ich bin der liebe " & $nick & "!", $channel)
    _IRCChangeMode ($sock, IniRead($INI, 'bot', 'mode', '+i'), $channel, $nick)
    Case "332" ; Raumthema
    $thema = ''
    For $k = 5 To $sTemp[0]
    If $k = 5 Then $sTemp[$k] = StringTrimLeft($sTemp[$k], 1)
    $thema &= $sTemp[$k] & ' '
    Next
    If StringStripWS($thema, 3) <> '' Then _IRCSendMessage($sock, "Unser Thema heute: " & $thema, $channel)
    Case 'PRIVMSG'
    $USER = StringTrimLeft(StringLeft($sTemp[1], StringInStr($sTemp[1], '!')-1), 1)
    $text = ''
    $txtUSER = ''
    For $k = 4 To $sTemp[0]
    $text &= $sTemp[$k] & ' '
    Next
    $text = StringTrimLeft($text, 1)
    $text = StringStripWS($text, 2)
    If StringInStr($text, 'ACTION', 1) Then
    $text = StringTrimLeft($text, 8)
    $text = StringLeft($text, StringLen($text)-2)
    _AuswertungAction($USER)
    $startIdle = TimerInit()
    ElseIf StringInStr($text, 'DCC CHAT', 1) Then
    ;~ ConsoleWrite('DCC: ' & $text & @CRLF)
    $text = 'DCC-Chatanfrage von ' & $USER
    Else
    ;~ ConsoleWrite('Else PrivMsg: ' & $text & @CRLF)
    _AuswertungText($USER)
    $startIdle = TimerInit()
    EndIf
    Case 'NOTICE'
    $USER = StringTrimLeft(StringLeft($sTemp[1], StringInStr($sTemp[1], '!')-1), 1)
    $text = ''
    If $sTemp[0] > 3 Then
    For $k = 4 To $sTemp[0]
    If $k = 4 Then
    $text &= StringTrimLeft($sTemp[$k], 1) & ' '
    Else
    $text &= $sTemp[$k] & ' '
    EndIf
    Next
    $text = StringTrimRight($text, 1)
    EndIf
    _AuswertungNotiz($USER, $text)
    $startIdle = TimerInit()
    Case 'JOIN'
    $USER = StringTrimLeft(StringLeft($sTemp[1], StringInStr($sTemp[1], '!')-1), 1)
    _AuswertungJoin($USER)
    $startIdle = TimerInit()
    Case 'NICK'
    $USER_alt = StringTrimLeft(StringLeft($sTemp[1], StringInStr($sTemp[1], '!')-1), 1)
    $USER = StringTrimLeft($sTemp[3], 1)
    _AuswertungNick($USER_alt, $USER)
    $startIdle = TimerInit()
    Case 'PART'
    $USER = StringTrimLeft(StringLeft($sTemp[1], StringInStr($sTemp[1], '!')-1), 1)
    $txt = $USER & ' verläßt den Chatraum '
    $text = ''
    If $sTemp[0] > 3 Then
    For $k = 4 To $sTemp[0]
    If $k = 4 Then
    $text &= StringTrimLeft($sTemp[$k], 1) & ' '
    Else
    $text &= $sTemp[$k] & ' '
    EndIf
    Next
    $text = StringTrimRight($text, 1)
    EndIf
    _AuswertungPartQuit($USER)
    $startIdle = TimerInit()
    Case 'QUIT'
    $USER = StringTrimLeft(StringLeft($sTemp[1], StringInStr($sTemp[1], '!')-1), 1)
    $txt = $USER & ' verläßt den Chatraum '
    If $sTemp[0] > 3 Then
    For $k = 4 To $sTemp[0]
    $text &= $sTemp[$k] & ' '
    Next
    $text = StringTrimRight($text, 1)
    $text = $txt & $text
    EndIf
    _AuswertungPartQuit($USER)
    $startIdle = TimerInit()
    EndSwitch
    Next
    WEnd

    [/autoit]
  • Ah Okay..

    Ich hab mal versucht das bei mir einzubauen.

    Nur jetzt, wenn ich in dem Channel irgendetwas schreibe, wird die Aktion (in meinem Fall die MsgBox) ausgeführt...

    Was mach ich falsch :(


    Hier mal der Script...

    Spoiler anzeigen
    [autoit][/autoit] [autoit][/autoit] [autoit]

    #include 'IRC.au3'

    [/autoit] [autoit][/autoit] [autoit]

    Global $server = 'chat.freenode.net'
    Global $channel = '#TestingChannel'
    Global $nick = 'TestNick1'
    Global $port = 6667

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

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

    [/autoit] [autoit][/autoit] [autoit]

    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

    [/autoit] [autoit][/autoit] [autoit]

    If $sTemp[1] = "" Then ContinueLoop; If its empty, Continue!
    If $sTemp[1] = "PING" Then _IRCPing($sock, $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!", $channel)
    ConsoleWrite("Success")

    [/autoit] [autoit][/autoit] [autoit]

    _IRCChangeMode ($sock, "+i", $nick)

    [/autoit] [autoit][/autoit] [autoit]

    Case 'PRIVMSG'
    $USER = StringTrimLeft(StringLeft($sTemp[1], StringInStr($sTemp[1], '!')-1), 1)
    $text = 'Hallo'
    $txtUSER = ''
    For $k = 4 To $sTemp[0]
    $text &= $sTemp[$k] & ' '
    Next
    $text = StringTrimLeft($text, 1)
    $text = StringStripWS($text, 2)
    If StringInStr($text, 'ACTION', 1) Then
    $text = StringTrimLeft($text, 8)
    $text = StringLeft($text, StringLen($text)-2)
    Msgbox(0,"1","1")
    ; _AuswertungAction($USER)
    $startIdle = TimerInit()
    ElseIf StringInStr($text, 'DCC CHAT', 1) Then
    ;~ ConsoleWrite('DCC: ' & $text & @CRLF)
    $text = 'DCC-Chatanfrage von ' & $USER
    Else
    ;~ ConsoleWrite('Else PrivMsg: ' & $text & @CRLF)
    Msgbox(0,"1","1")
    $startIdle = TimerInit()
    EndIf

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    EndSwitch
    Next

    [/autoit] [autoit][/autoit] [autoit]

    WEnd

    [/autoit] [autoit][/autoit] [autoit]

    #cs
    Common recieves:
    Nick = User who the message is from
    Name = Settable by user, set in the USER command
    host = ISP host

    [/autoit] [autoit][/autoit] [autoit]

    ~~~~PRIVMSG~~~~
    You recieve this when someone has sent a message in a channel,
    gives you there Nick, host, the channel it was said in and the message.

    [/autoit] [autoit][/autoit] [autoit]

    SYNTAX:
    :Nick!Name@host PRIVMSG #Channel :Message

    [/autoit] [autoit][/autoit] [autoit]

    EXAMPLE:
    :Chip![email='Chip@OMN-8243F63D.dsl.bell.ca'][/email] PRIVMSG #Chip :Hey guy's
    Would be a message from Chip to say 'Hey guy's' in the channel #Chip

    [/autoit] [autoit][/autoit] [autoit]

    :Chip![email='Chip@OMN-8243F63D.dsl.bell.ca'][/email] PRIVMSG Bob :Hey Bob!
    Would be a Personal Message from Chip to Bob saying 'Hey Bob!'
    ~~~~~~~~~

    [/autoit] [autoit][/autoit] [autoit]

    ~~~~MODE~~~~
    You recieve this when a mode is changed, a mode can give/take access change certain
    things like who can join a channel etc..

    [/autoit] [autoit][/autoit] [autoit]

    SYNTAX:
    :Nick!Name@host MODE #Channel +/- MODE (USER)

    [/autoit] [autoit][/autoit] [autoit]

    EXAMPLES:
    :ChanServ!services@host MODE #Chip +o Chip
    This says ChanServ (usually a service bot) has given Chip Operator access in the channel #Chip

    [/autoit] [autoit][/autoit] [autoit]

    :ChanServ!services@host MODE #Chip +i
    This makes #Chip invite only, so only OPs can invite users in the channel.

    [/autoit] [autoit][/autoit] [autoit]

    :Chip![email='Chip@OMN-8243F63D.dsl.bell.ca'][/email] MODE Chip +i
    This will make Chip invisible to WHOIS. These are usermodes.
    ~~~~~~~~~

    [/autoit] [autoit][/autoit] [autoit]

    ~~~~PING~~~~
    You recieves these at random to make sure your still online and
    not disconnected.

    [/autoit] [autoit][/autoit] [autoit]

    SYNTAX:
    PING :Randomletters

    [/autoit] [autoit][/autoit] [autoit]

    Usually a PING has random letters that you have to respond with.

    [/autoit] [autoit][/autoit] [autoit]

    EXAMPLE:
    PING :29809dj0d

    [/autoit] [autoit][/autoit] [autoit]

    You would respond with
    PONG 29809dj0d
    ~~~~~~~~~~~

    [/autoit] [autoit][/autoit] [autoit]

    ~~~~JOIN~~~~
    You recieve this when someone joins a channel.

    [/autoit] [autoit][/autoit] [autoit]

    SYNTAX:
    :Nick!Name@Host JOIN :#Channel

    [/autoit] [autoit][/autoit] [autoit]

    EXAMPLE:
    :Chip![email='Chip@OMN-8243F63D.dsl.bell.ca'][/email] JOIN :#Chip
    This would be sent to everybody in #Chip to show that Chip has joined the channel #Chip
    ~~~~~~~~~~~~~

    [/autoit] [autoit][/autoit] [autoit]

    ~~~~KICK~~~~
    You recieve this when someone gets kicked (Including yourself!)

    [/autoit] [autoit][/autoit] [autoit]

    SYNTAX:
    :Nick!Name@Host KICK #Channel User :Reason

    [/autoit] [autoit][/autoit] [autoit]

    EXAMPLE:
    :Chip!Name@Host KICK #Chip Bob :Talk in private
    Would kick Bob from #Chip and say 'Talk in private' in the reason
    ~~~~~~~~~~~~~~

    [/autoit] [autoit][/autoit] [autoit]

    ~~~~QUIT~~~~
    You recieve this when someone disconnects from IRC.

    [/autoit] [autoit][/autoit] [autoit]

    SYNTAX:
    :Nick!Name@Host QUIT :Reason

    [/autoit] [autoit][/autoit] [autoit]

    EXAMPLE:
    :Chip![email='Chip@OMN-8243F63D.dsl.bell.ca'][/email] QUIT :I'm bored
    Would be sent to everyone in the channels Chip was in to say that he left IRC because He was bored.
    ~~~~~~~~~~~~~~

    [/autoit] [autoit][/autoit] [autoit]

    #ce

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit]
  • Ich hab folgendes vor:

    Auf meinem eigenen IRC Server/Channel möchte ich den Script Starten.

    Dann kann ich von überall her den Channel Joinen und dem "bot" z.B schreiben. @bot save: heute um 13 Uhr Essen mit Anna.

    Dann schreibt der bot z.B in eine Datei
    24.12.1991 12:33 Essen mit Anna

    So in der art...