Heya Mailbank,

M> Hi Mat
M> May I take a look at rebot?

Couple of requests for this, what I'll print here probably doesn't
work because I've cut something vital out. However it'd be much easier
to see what's going on after I cut the reams and reams of game server
functions and other stuff out out. I also learned a great many things
so I'm actually going to ditch this and re-write it in sort of proper
Rebol with half as many temporary variables;

< -- Cut -- >

Rebol []

ircserver: "irc.server.com"
ircport: 6667
channel: "#channel"
nick: "Rebot"
usern: "Rebot"
hostn: "0wnerage.com"
servern: "irc.server.com"
realn: "Rebol Bot Alpha 1"

bold: to-char 2
underline: to-char 31

SendCMD: func [
  irccommand
  ][
  insert irccon irccommand
]

get-status: func [

SendChan: func [
  whattosay
   ][
 sendCMD rejoin ["PRIVMSG " channel " :" whattosay]
]

PrivMSG: func [
  whattosay
  ][  
  SendCMD rejoin ["PRIVMSG " currentnick " :" whattosay]
]
  
Quitchannel: func [
 quitmsg
 ][
 SendCMD rejoin ["PART " channel " :" quitmsg ]
]

HelpSubject: func [
  hsubject
 ][
 switch hsubject [
   "search" [PrivMSG "Usage: Search <playername>"]
   "commands" [PrivMSG rejoin [Nick " commands: commands, search,
   bbcnews, translate, serverstatus, serverannounce"] ]
 ]
]
 

ProcessPublic: func [
  ][
  channelwords: parse channeltext none
  if nick = pick channelwords 1 [
    publiccommand: find/tail channeltext nick
    publickeyword: pick parse publiccommand none 1
    switch publickeyword [
      "quit" [ SendChan "Bah :("
        Quitchannel "Nobody loves me..."
        wait irccon
        close irccon
        halt ]
      comment {loads of switches for public commands goes here}
      ]
  ]
]

ProcessPrivate: func [
  ][
  Print "Processing private msg"
  privatewords: parse msgtext none
  command: pick privatewords 1
  print command
  switch command [
    "search" [ searchOGA ]
    "commands" [ HelpSubject "commands"]
    "cmds" [ HelpSubject "commands"]
    comment {loads of switches for private /msg commands go here}
  ]
]   

ReadIRC: func [
  ][
  ircout: copy irccon

  for i 1 lnircout 1 [  
    ln: pick ircout i
    lnwords: parse ln none
    keyword: pick lnwords 1
    irccommand: pick lnwords 2
    if keyword = "PING" [
      pingstamp: pick lnwords 2
      SendCMD rejoin ["PONG " pingstamp]
    ]
    parse ln [thru ":" copy currentnick to "!"] 
    if irccommand = "PRIVMSG" [
      if channel = pick lnwords 3 [
        channeltext: find/tail ln " :"
        ProcessPublic
      ]
      if nick = pick lnwords 3 [
        msgtext: find/tail ln " :"
        ProcessPrivate
      ]
    ]
  ]
  return ircout
]
  
Comment { THIS IS THE MAIN LOOP }  

ircurl: make url! rejoin ["tcp://" ircserver ":" ircport]

if error? try [irccon: open/lines/no-wait ircurl] [
  print ["Error connecting to server" ircurl]
  halt
]
  
sendCMD rejoin ["NICK " nick]
wait irccon
print readIRC
sendCMD rejoin ["USER " usern " " hostn " " servern " " realn]
sendCMD rejoin ["JOIN " channel]
SendChan "Rebot is my name and 0wnerage is my game! /msg rebot commands"

do forever [
  print readirc
  wait irccon
]





-- 
Mat Bettinson - EuroGamer's Gaming Evangelist with a Goatee
http://www.eurogamer.net | http://www.eurogamer-network.com


-- 
To unsubscribe from this list, please send an email to
[EMAIL PROTECTED] with "unsubscribe" in the 
subject, without the quotes.

Reply via email to