IRC Chat Bot Demo
#1
An oldie salvaged from the ashes of the old forums!



Code: (Select All)
TITLE "Steve QB64-IRC Bot"

DIM SHARED Client AS LONG, Server AS STRING, Channel AS STRING
crlf$ = CHR$(13) + CHR$(10)
nick$ = "SqbBot"
pass$ = ""
Server = "irc.freenode.net"
Channel = "#qb64"

PRINT "Connecting to " + Server + "..."
Client = _OPENCLIENT("TCP/IP:6667:" + Server)
IF Client& = 0 THEN PRINT "Error: could not connect...": SLEEP: SYSTEM
IF pass$ > "" THEN SendInfo "PASS" + pass$
SendInfo "NICK " + nick$
SendInfo "USER " + nick$ + " 0 * :" + nick$
PRINT "Connected!"

SendInfo "JOIN " + Channel
SendInfo "TOPIC " + Channel
PRINT "Joined "; Channel

respond = 0
DO
    _LIMIT 1000
    GET #Client&, , In$
    IF LEFT$(In$, 4) = "PING" THEN
        'Respond with PONG
        res$ = "PONG" + MID$(In$, 5) + CHR$(13) + CHR$(10)
        PUT #Client, , res$
    END IF

    'IF In$ <> "" THEN PRINT LEFT$(In$, LEN(In$) - 2) 'Unremark this is we want to see what's being typed by everyone.
    IF In$ <> "" AND respond THEN ProcessInput In$
    IF INSTR(In$, "End of /NAMES list.") THEN respond = -1 'Don't start responding to the automatic server messages, like an idiot bot!
LOOP UNTIL INKEY$ = CHR$(32) 'Spacebar to quit


SUB SendInfo (text$)
text$ = text$ + CHR$(13) + CHR$(10)
PUT #Client&, , text$
END SUB

SUB SendReply (text$)
text$ = "PRIVMSG " + Channel$ + " :" + text$ + CHR$(13) + CHR$(10)
PUT #Client&, , text$
COLOR 14: PRINT text$
END SUB

SUB ProcessInput (text$)

Speaker$ = MID$(text$, 2, INSTR(text$, "!") - 2)
c$ = UCASE$(Channel) + " :"
In$ = UCASE$(LEFT$(text$, LEN(text$) - 2)) + " " ' Strip off the CRLF
eval$ = " " + MID$(In$, INSTR(In$, c$) + LEN(c$)) + " "

IF INSTR(eval$, " SQBBOT ") THEN
    'someone is talking directly to the bot or giving it a command
    IF INSTR(eval$, " QUIT ") THEN SYSTEM 'A means to automatically shut down the bot
    IF INSTR(eval$, " FINISH ") THEN SYSTEM 'A means to automatically shut down the bot
    IF INSTR(eval$, " DIE ") THEN SYSTEM 'A means to automatically shut down the bot
    IF INSTR(eval$, " SHUT DOWN ") THEN SYSTEM 'A means to automatically shut down the bot
    IF INSTR(eval$, " EXIT ") THEN SYSTEM 'A means to automatically shut down the bot
    IF INSTR(eval$, " END ") THEN SYSTEM 'A means to automatically shut down the bot
    IF INSTR(eval$, " TELL") THEN
        IF INSTR(eval$, "TIME") THEN Out$ = Out$ + "The TIME is " + TIME$ + ".  "
        IF INSTR(eval$, "DATE") THEN Out$ = Out$ + "The DATE is " + DATE$ + ".  "
    END IF

    IF INSTR(eval$, " HI ") THEN Out$ = "Hiyas, " + Speaker$ + ".  "
    IF INSTR(eval$, " HELLO ") THEN Out$ = "Hello to you too, " + Speaker$ + ".  "
    IF INSTR(eval$, " YO ") THEN Out$ = "Hola!  " + Speaker$ + "  How's it hanging?  "
    IF INSTR(eval$, " HOLA ") THEN Out$ = "What's happening, " + Speaker$ + "?  "
END IF

IF INSTR(In$, " JOIN ") AND (INSTR(eval$, "JOIN") = 0) THEN Out$ = "Welcome to QB64 Chat, " + Speaker$ + ".  "

IF Out$ <> "" THEN
    COLOR 15
    l = INSTR(In$, "PRIVMSG")
    PRINT Speaker$; " on "; MID$(In$, l + 8) 'I put a print here, so we can see what our bot is responding to, no matter what.
    SendReply Out$
END IF
END SUB


Another program from the depths of my hard drive — the start of an IRC chat bot.  I’m certain many of the old regulars will remember this guy popping up over and over in the IRC channel as folks tested it and then used it as a base to build their own custom bot, but we have a lot of new members around now, and I thought they too deserved the chance to drive us old QB64 chat channel lurkers crazy...

(If anyone still uses IRC chat at all anymore.  Guess it's just another relic left over moldering from the past.  Sad )
Reply


Messages In This Thread
IRC Chat Bot Demo - by SMcNeill - 05-01-2022, 10:27 PM



Users browsing this thread: 1 Guest(s)