home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 35 Internet / 35-Internet.zip / dmi125.zip / DMI-Cmd.Cmd < prev    next >
OS/2 REXX Batch file  |  1996-09-26  |  18KB  |  461 lines

  1. /*********************************************************************/
  2. /* DMI IRC REXX Command Script for REXX Clients.  v1.25   26 Sep 96  */
  3. /*********************************************************************/
  4. /* Outbound Functions                                     26 Sep 96  */
  5. /*********************************************************************/
  6.  
  7. Parse Upper Arg Winhandle WinName OurNick Verb Parm1 Parms
  8. Parse Arg xWinHandle xWinName xUs xVerb xParm1 xParms
  9. Parse Upper Arg yWinHandle yWinName yOurNick yVerb yParm1 yParm2 yParm3 yParms
  10. Parse Arg zWinHandle zWinName zOurNick zVerb zParm1 zParm2 zParm3 zParms
  11. Parse Arg AllArgs
  12.  
  13. Pool = 'OS2ENVIRONMENT'
  14. CMD = Value('COMSPEC',, Pool)
  15. DataDir = Value('DataDir',, Pool)
  16. IF ((Right(DataDir, 1) \= '\') & (DataDir \= '')) then
  17.    Value('DataDir', DataDir'\', Pool)
  18. CurrentList = DataDir || 'Current.Lst'
  19. ServerList = DataDir || 'Servers.Lst'
  20. DMIMsg = '*DMI*'
  21. OS2Msg = '*OS2*'
  22. ErrStr = '*[Error]*'
  23. Version = '1.25'
  24. Title = '-=-=-=-=-= DMI v'|| Version ||' =-=-=-=-=-'
  25.  
  26. SIGNAL ON SYNTAX
  27. /* LineOut('C:\IRC-Out.Txt', AllArgs); LineOut('C:\IRC-Out.Txt');*/ /* For debugging */
  28.  
  29. If (Pos('/', Verb) = 0) then 
  30.    Return 'OK'
  31. If (Pos('/', Verb) = 1) then do        /* Check for '/' meaning a command */
  32.    If (Verb = '/DMI') then do          /* DMI Variable Viewing/Setting */
  33.       if (Parm1 <> '') then do
  34.          if (Parms <> '') then do
  35.             Value(Parm1, xParms, Pool)
  36.             IrcRexxDisplay(DMIMsg xParm1 'set to ' || xParms || '.', WinHandle)
  37.          end
  38.          else do
  39.             TempStr = Value(Parm1,,Pool)
  40.             IrcRexxDisplay(DMIMsg xParm1 'is currently set to '||TempStr||'.', WinHandle)
  41.          end
  42.       end
  43.       else IrcRexxDisplay(ErrStr "Usage: /DMI <variable> [new value]", Winhandle)
  44.       Return ''
  45.    end
  46.    If (Verb = '/DW') then do
  47.       if (Parm1 <> '') then do
  48.          IrcRexxCommand("/WHO *" || xParm1 || "*", WinHandle)
  49.       end
  50.       else do
  51.          IrcRexxDisplay(ErrStr 'Usage: /DW <Domain>', WinHandle)
  52.       end
  53.       Return ''
  54.    end
  55.    If (Verb = '/LIST') then do
  56.       If Parm1 = '' then do
  57.          IrcRexxDisplay(ErrStr 'Are you sure you want to list EVERY channel?', WinHandle)
  58.          Return ''
  59.       end
  60.       else Return 'OK'
  61.    end
  62.    If (Verb = '/NAMES') then do
  63.       If Parm1 = '' then do
  64.          IrcRexxDisplay(ErrStr 'Are you sure you want to list everyone on IRC?', WinHandle)
  65.          Return ''
  66.       end
  67.       else Return 'OK'
  68.    end
  69.    If (Verb = '/JOIN') then do                 /* Join handler */
  70.       if Parm1 = '' then do
  71.          IrcRexxDisplay(ErrStr 'Usage: /JOIN <Channel>', WinHandle)
  72.          Return ''
  73.       end
  74.       else Return 'OK'
  75.    end
  76.    If (Verb = '/KICK') then do                 /* Kick handler */
  77.       If Parm1 = '' then do
  78.          IrcRexxDisplay(ErrStr 'Usage: /KICK <User> [Reason]', WinHandle)
  79.       end
  80.       if Parms == '' then
  81.          IrcRexxSend('KICK' xWinName xParm1 ':DMI v' || Version, WinHandle)
  82.       else
  83.          IrcRexxSend('KICK' xWinName xParm1 ':' || xParms, WinHandle)
  84.       Return ''
  85.    end
  86.    If (Verb == '/NOTICE') then do               /* Notice */
  87.       if ((Parm1 == '') | (Parms == '')) then
  88.          IrcRexxDisplay(ErrStr 'Usage: /NOTICE <User> <Text>', WinHandle)
  89.       else do
  90.          IrcRexxSend('NOTICE' xParm1 ':'|| xParms, WinHandle)
  91.          IrcRexxDisplay('-> ='xParm1'=' xParms, WinHandle)
  92.       end
  93.       Return ''
  94.    end
  95.    If (Verb == '/CALC') then do
  96.       if (Parm1 == '') then
  97.          IrcRexxDisplay(ErrStr 'Usage: /CALC <Expression for OS2Bot to calculate>', WinHandle)
  98.       else 
  99.          IrcRexxSend('PRIVMSG OS2bot :CALC' xParm1 xParms, WinHandle)
  100.       Return ''
  101.    end
  102.    If (Verb == '/PHONE') then do
  103.       if (Parm1 == '') then
  104.          IrcRexxDisplay(ErrStr 'Usage: /PHONE <Expression for OS2Bot to calculate>', WinHandle)
  105.       else 
  106.          IrcRexxSend('PRIVMSG OS2bot :PHONE' xParm1 xParms, WinHandle)
  107.       Return ''
  108.    end
  109.    If (Verb == '/WHOIS') then do
  110.       if Parm1 <> '' then do
  111.          Value('GetInfo', 'ON', Pool)
  112.          Value('CmdHandle', WinHandle, Pool)
  113.          IrcRexxSend('WHOIS' xParm1 xParms, WinHandle)
  114.       end
  115.       else IrcRexxDisplay(ErrStr 'Usage: /WHOIS <User to check>', WinHandle)
  116.       Return ''
  117.    end
  118.    If (Verb == '/IDLE') then do
  119.       if Parm1 <> '' then do
  120.          Value('GetIdle', 'ON', Pool)
  121.          Value('IdleNick', xParm1, Pool)
  122.          Value('CmdHandle', WinHandle, Pool)
  123.          IrcRexxSend('WHOIS' xParm1, WinHandle)
  124.       end
  125.       else IrcRexxDisplay(ErrStr 'Usage: /IDLE <User to check>', WinHandle)
  126.       Return ''
  127.    end
  128.    If Verb = '/HOST' then do              /* Host function (doing a HOST command) */
  129.       if (Parm1 <> '') then do
  130.          Address CMD 'HOST' xParm1 '|RXQUEUE'
  131.          do Temp = 1 to Queued()
  132.             Parse pull ThisLine
  133.             If ThisLine = '' then iterate
  134.             IrcRexxDisplay(OS2Msg ThisLine, WinHandle)
  135.          end
  136.       end
  137.       else IrcRexxDisplay(ErrStr "Usage: /HOST <Site to look up>", WinHandle)
  138.       Return ''
  139.    end
  140.    If Verb = '/OSPING' then do              /* Host function (doing a HOST command) */
  141.       if (Parm1 <> '') then do
  142.          Address CMD 'PING' xParm1 '25 5 |RXQUEUE'
  143.          do Temp = 1 to Queued()
  144.             Parse pull ThisLine
  145.             If ThisLine = '' then iterate
  146.             IrcRexxDisplay(OS2Msg ThisLine, WinHandle)
  147.          end
  148.       end
  149.       else IrcRexxDisplay(ErrStr "Usage: /OSPING <Site to check>", WinHandle)
  150.       Return ''
  151.    end
  152.    If (Verb = '/OSSEND') then do            /* OS command send function */
  153.       if (Parm1 <> '') then do
  154.          Address CMD xParm1 xParms '|RXQUEUE'
  155.          do Temp = 1 to Queued()
  156.             Parse pull ThisLine
  157.             If ThisLine = '' then iterate
  158.             IrcRexxSend('PRIVMSG' xWinName ':'ThisLine, WinHandle)
  159.             IrcRexxDisplay('>' ThisLine, WinHandle)
  160.          end
  161.       end
  162.       else IrcRexxDisplay(ErrStr 'Usage: /OSSEND <Command> [Parameters]', WinHandle)
  163.       Return ''
  164.    end
  165.    If (Verb = '/OSMSG') then do            /* OS command send function */
  166.       if ((Parm1 <> '') & (Parms <> '')) then do
  167.          Address CMD xParm1 xParms '|RXQUEUE'
  168.          do Temp = 1 to Queued()
  169.             Parse pull ThisLine
  170.             If ThisLine = '' then
  171.                iterate
  172.             IrcRexxSend('PRIVMSG' xParm1 ':'ThisLine, WinHandle)
  173.             IrcRexxDisplay('-> *'xParm1'*' ThisLine, WinHandle)
  174.          end
  175.       end
  176.       else
  177.          IrcRexxDisplay(ErrStr 'Usage: /OSMSG <Nick> <Command> [Parameters]', WinHandle)
  178.       Return ''
  179.    end
  180.    If (Verb = '/EXEC') then do            /* OS command send function */
  181.       if (Parm1 <> '') then do
  182.          Address CMD xParm1 xParms '|RXQUEUE'
  183.          do Temp = 1 to Queued()
  184.             Parse pull ThisLine
  185.             If ThisLine = '' then iterate
  186.             IrcRexxDisplay(OS2Msg ThisLine, WinHandle)
  187.          end
  188.       end
  189.       else
  190.          IrcRexxDisplay(ErrStr 'Usage: /EXEC <Command> [Parameters]', WinHandle)
  191.       Return ''
  192.    end
  193.    If (Verb = '/CUTLOG') then do            /* OS command send function */
  194.       if ((Pos('#', Parm1) = 1) | (Pos('&', Parm1) = 1)) then
  195.          Address CMD 'SHORTEN' ParseName(xParm1)'.log' xParms '|RXQUEUE'
  196.       else do
  197.          IrcRexxCommand('/LOG OFF', WinHandle)
  198.          Address CMD 'SHORTEN' ParseName(xWinName)'.log' xParms '|RXQUEUE'
  199.          IrcRexxCommand('/LOG ON', WinHandle)
  200.       end
  201.       do Temp = 1 to Queued()
  202.          Parse pull ThisLine
  203.          If ThisLine = '' then iterate
  204.          IrcRexxDisplay(OS2Msg ThisLine, WinHandle)
  205.       end
  206.       Return ''
  207.    end
  208.    If (Verb = '/WALL') then do
  209.       if (Parm1 <> '') then do
  210.          Value('Walling', 'ON', Pool)
  211.          if ((Pos('#', Parm1) >= 1) | (Pos('&', Parm1) >= 1)) then do
  212.             Value('WallMsg', '[Wall/'xParm1'] 'xParms, Pool)
  213.             IrcRexxSend('NAMES' xParm1, WinHandle)
  214.          end
  215.          else do
  216.             Value('WallMsg', '[Wall/'xWinName'] 'xParm1 xParms, Pool)
  217.             IrcRexxSend('NAMES' xWinName, WinHandle)
  218.          end
  219.       end
  220.       else IrcRexxDisplay(ErrMsg 'Usage: /WALL <Channel> <Message>', WinHandle)
  221.       Return ''
  222.    end
  223.    If (Verb = '/WALLOP') then do
  224.       if (Parm1 <> '') then do
  225.          Value('WallOping', 'ON', Pool)
  226.          if ((Pos('#', Parm1) >= 1) | (Pos('&', Parm1) >= 1)) then do
  227.             Value('WallMsg', '[WallOp/'xParm1'] 'xParms, Pool)
  228.             IrcRexxSend('NAMES' xParm1, WinHandle)
  229.          end
  230.          else do
  231.             Value('WallMsg', '[Wall/'xWinName'] 'xParm1 xParms, Pool)
  232.             IrcRexxSend('NAMES' xWinName, WinHandle)
  233.          end
  234.       end
  235.       else IrcRexxDisplay(ErrMsg 'Usage: /WALLOP <Channel> <Message>', WinHandle)
  236.       Return ''
  237.    end
  238.    If (Verb = '/GETSERVERS') then do        /* Split Finder routines*/
  239.       Value('CmdHandle', WinHandle, Pool)
  240.       Value('GetSrvr','ON',Pool)
  241.       Value('srvrs.','',Pool)
  242.       Value('srvrs.0','0',Pool)
  243.       Value('cnt','0',Pool)
  244.       IrcRexxDisplay(DMIMsg 'Getting list of active servers...(This may take a few moments)', WinHandle)
  245.       IrcRexxSend('LINKS', WinHandle)
  246.       Return ''
  247.    end
  248.    If (Verb = '/FINDSPLIT') then do
  249.       Value('CmdHandle', WinHandle, Pool)
  250.       Value('getcurr','ON',Pool)
  251.       Value('currsvrs.','',Pool)
  252.       Value('currsvrs.0','0',Pool)
  253.       Value('currcnt','0',Pool)
  254.       IrcRexxDisplay(DMIMsg 'Getting list of active servers...(This may take a few moments)',WinHandle)
  255.       IrcRexxSend('LINKS', WinHandle)
  256.       Return ''
  257.    end
  258.    If (Verb == '/WRITESVR') then do
  259.       CALL library
  260.       SysFileDelete(ServerList)
  261.       LineOut(ServerList, '#Begin_List#', 1)
  262.       Count = Value('cnt',,Pool)
  263.       do s = 1 to Count
  264.          tempword = Value('srvrs.'s,,Pool)
  265.          LineOut(ServerList, tempword)
  266.       end
  267.       LineOut(ServerList)
  268.       IrcRexxDisplay(DMIMsg Value('Cnt',, Pool) 'servers written to' ServerList, WinHandle)
  269.       Return ''
  270.    end
  271.    If (Verb == '/WRITECURRSVR') then do
  272.       CALL library
  273.       SysFileDelete(CurrentList)
  274.       LineOut(CurrentList, '#Begin_List#', 1)
  275.       cnt = Value('currcnt',,Pool)
  276.       do s = 1 to cnt
  277.          tempword = Value('currsvrs.'s,,Pool)
  278.          LineOut(CurrentList, tempword)
  279.       end
  280.       LineOut(CurrentList)
  281.       IrcRexxDisplay(DMIMsg Value('currcnt',, Pool) 'servers written to' CurrentList, WinHandle)
  282.       IrcRexxCommand('/SPLITTERS', WinHandle)
  283.       Return ''
  284.    end
  285.    If Verb = '/SPLITTERS' then do
  286.       IrcRexxDisplay(DMIMsg 'Looking for split servers...', WinHandle)
  287.       LineIn(ServerList, 1, 0)
  288.       Do While Lines(ServerList)
  289.          tmpline = LineIn(ServerList)
  290.          drop aresult.
  291.          if (SysFileSearch(TmpLine, CurrentList, 'aresult.') == 0) then do
  292.             if (aresult.0 = 0) then do
  293.                IrcRexxDisplay(DMIMsg 'Currently split:' tmpline '', WinHandle)
  294.             end
  295.          end
  296.       end
  297.       LineOut(ServerList)
  298.       IrcRexxCommand('/ADDNEW', WinHandle)
  299.       Return ''
  300.    end
  301.    If (Verb == '/ADDNEW') then do
  302.       IrcRexxDisplay(DMIMsg 'Looking for new servers...', WinHandle)
  303.       Do While Lines(CurrentList)
  304.          tmpline = LineIn(CurrentList)
  305.          drop aresult.
  306.          if (SysFileSearch(tmpline, ServerList, 'aresult.') = 0) then do
  307.             if (aresult.0 = 0) then do
  308.                IrcRexxDisplay(DMIMsg 'New server found & added: 'tmpline'', WinHandle)
  309.                LineOut(ServerList, TmpLine)
  310.             end
  311.          end
  312.       end
  313.       LineOut(ServerList)
  314.       LineOut(CurrentList)
  315.       Return ''
  316.    end
  317.    If (Verb == '/CSTAT') then do
  318.       Value('CmdHandle', WinHandle, Pool)
  319.       Value('CStating','ON', Pool)
  320.       if (Parm1 <> '') then
  321.          Temp = xParm1
  322.       else
  323.          Temp = xWinName
  324.       IrcRexxSend('NAMES' Temp, WinHandle)
  325.       IrcRexxSend('MODE' Temp, WinHandle)
  326.       IrcRexxSend('LIST' Temp, WinHandle)
  327.       Return ''
  328.    end
  329.    If (Verb = '/RESET') then do             /* Reset Message Queue */
  330.       hdrline = '-=-=-=-=-= DMI v'|| Version ||' Message Log =-=-=-=-=-'
  331.       CALL Library
  332.       MessageLog = DataDir || 'Messages.Log'
  333.       SysFileDelete(MessageLog)
  334.       LineOut(MessageLog, hdrline, 1)
  335.       LineOut(MessageLog)
  336.       IrcRexxDisplay(DMIMsg 'Message log file reset', WinHandle)
  337.       Return ''
  338.    end
  339.    If (Verb == '/PLAY') then Return PlayMsg('N')   /* View the Message Queue */
  340.    If (Verb == '/LPLAY') then Return PlayMsg('L')  /* View the Message Queue with user@host info */
  341.    If (Verb == '/CHECK') then do                   /* Check the number of messages in the buffer */
  342.       MessageLog = DataDir || 'Messages.Log'
  343.       MsgLog = Value('MsgLog',,Pool)
  344.       counter = 0
  345.       if (MsgLog \= 'ON') then
  346.          IrcRexxDisplay(DMIMsg 'Message log is disabled.', WinHandle)
  347.       Do While Lines(MessageLog)
  348.          message = LineIn(MessageLog)
  349.          Parse Var message nick id msg
  350.          if nick = '-=-=-=-=-=' then
  351.             NOP
  352.          else
  353.             counter = counter + 1
  354.       end
  355.       if (counter < 1) then IrcRexxDisplay(DMIMsg 'There are no messages saved.', WinHandle)
  356.       if (counter = 1) then IrcRexxDisplay(DMIMsg 'There is 1 message logged', WinHandle)
  357.       if (counter > 1) then IrcRexxDisplay(DMIMsg 'There are' counter 'messages logged', WinHandle)
  358.       LineOut(MessageLog)
  359.       Return ''
  360.    end
  361.    If (Verb == '/GONE') then do              /* Set away, turn on MSG Logger */
  362.      if (Parm1 <> '') then do
  363.          IrcRexxSend('AWAY :('xParm1 xParms') since' Time('C') Date('U')'', WinHandle)
  364.          IrcRexxCommand('/ALLME is gone! ('xParm1 xParms') [Recording]', WinHandle)
  365.          Value('MsgLog', 'ON', Pool)
  366.       end
  367.       else do
  368.          AwayMsg = Value('AwayMsg',,Pool)
  369.          IrcRexxSend('AWAY :('AwayMsg') since' Time('C') Date('U')'')
  370.          IrcRexxCommand('/ME is gone! ('AwayMsg') [Recording]', WinHandle)
  371.          IrcRexxCommand('/DMI MsgLog ON', WinHandle)
  372.       end
  373.       Return ''
  374.    end
  375.    If (Verb == '/BACK') then do              /* Turn of MSG Logger, reset Away, play MSGs */
  376.       IrcRexxCommand('/DMI MsgLog OFF', WinHandle)
  377.       PlayMsg('N')
  378.       IrcRexxCommand('/AWAY', WinHandle)
  379.       IrcRexxCommand('/ALLME is back.', WinHandle)
  380.       Return ''
  381.    end
  382.    If (Verb == '/ALIAS') then Return Alias(AllArgs)
  383.    If (Verb == '/AUTO') then Return AutoMode(AllArgs)
  384.    If (Verb = '/XDCC') then Return XDCC_Out(AllArgs)
  385.    If (Verb = '/HELP' | Verb = '/?') then Return ViewHelp(Parm1)
  386.    AliasList = DataDir || 'Aliases.Lst'
  387.    do while Lines(AliasList)           /* Line isn't a normal command, check for alias */
  388.       Fileline = LineIn(AliasList)
  389.       if Fileline = '' then leave
  390.       Parse Var FileLine Alias CodeLine
  391.       If Verb = Translate(Alias) then do
  392.          Interpret CodeLine
  393.          Return ''
  394.       end
  395.    end
  396.    Return "OK"                         /* If we got here, no command - Pass it to client */
  397. end
  398. Return 'OK'                            /* We should not get here, but just in case... */
  399.  
  400. PlayMsg:
  401.    Parse Upper Arg Option
  402.    MsgLog = Value('MsgLog',,Pool)
  403.    MessageLog = DataDir || 'Messages.Log'
  404.    counter = 0
  405.    hdrline = '-=-=-=-=-= DMI v'|| Version ||' Message Log =-=-=-=-=-'
  406.    if (MsgLog \= 'ON') then IrcRexxDisplay(DMIMsg 'Message log disabled.', WinHandle)
  407.    Do While Lines(MessageLog)
  408.       message = LineIn(MessageLog)
  409.       Parse Var message nick id day mon yr times msg
  410.       if nick = '-=-=-=-=-=' then do
  411.          IrcRexxDisplay(hdrline, WinHandle)
  412.       end
  413.       else do
  414.          counter = counter + 1
  415.          If (Option == 'L') then
  416.             IrcRexxDisplay(counter || ':' '*' || nick || '*' || '' id '' || day mon yr times msg, WinHandle)
  417.          else
  418.             IrcRexxDisplay(counter || ':' '*' || nick || '*' msg, WinHandle)
  419.       end
  420.    end
  421.    LineOut(MessageLog)
  422.    IrcRexxDisplay(hdrline, WinHandle)
  423. Return ''
  424.  
  425. ParseName:                             /* This is a mess, but it works.    */
  426.    Parse arg TextName
  427.    TempName = Strip(Substr(Translate(TextName ,'','/'), 1, 8))
  428.    Parse var TempName Temp1 Temp2 Temp3 Temp4 Temp5 Temp6 Temp7 Temp8
  429.    TempName = Temp1||Temp2||Temp3||Temp4||Temp5||Temp6||Temp7||Temp8
  430. Return TempName
  431.  
  432. ViewHelp:
  433.    Parse Upper Arg TmpFile
  434.    If (TmpFile == '') then
  435.       HelpFile = Stream(DataDir || 'MAIN.HLP', 'C', 'QUERY EXISTS')
  436.    else
  437.       HelpFile = Stream(DataDir || TmpFile || '.HLP', 'C', 'QUERY EXISTS')
  438.    If (HelpFile \= '') then do
  439.       IrcRexxDisplay(Center(Title, 78),WinHandle)
  440.       do while Lines(HelpFile)
  441.          TempLine = LineIn(HelpFile)
  442.          If (Pos('%', TempLine) = 1) then
  443.             IrcRexxDisplay(Center(Substr(TempLine, 4), Substr(TempLine, 2, 2)), WinHandle)
  444.          else
  445.             IrcRexxDisplay(TempLine, WinHandle)
  446.       end
  447.    end
  448.    else
  449.       IrcRexxDisplay(ErrStr 'That is not a valid help menu!', WinHandle)
  450. Return ''
  451.  
  452. Library:
  453.    CALL RxFuncAdd 'SysLoadFuncs', 'RexxUtil', 'SysLoadFuncs'
  454.    CALL SysLoadFuncs
  455. Return
  456.  
  457. SYNTAX:
  458.    IrcRexxDisplay(ErrStr 'REXX Syntax Error' RC '(' || ErrorText(RC) || ') at line' SIGL 'of DMI-Cmd.Cmd.', WinHandle);
  459. Return ''
  460.  
  461.