Example of a simple MSL script

Example of a simple MSL script

All articles

Goal: to circulate the list of user information of an arbitrary character.

For example, a provider of Internet services. In this organization connected to a certain number of users, and to communicate on the internal network provider is used MyChat. Often, some subscribers did not pay on time service provider, or simply forget about it. ISP may notify its subscribers about the need to make a subscription fee with MSLMyChat Script Language. This built-in script machine in MyChat Server. Features of this system is very broad.

First you must create a plain text file, which will be listed UIN-s debtors and periods, as well as a file with text messages to them.

For example, a file with the UIN-s «С:\UIN.txt» (format “user|date”), on a computer with MyChat Server contains the text:

  1. 5|01.07.2009-31.07.2009
  2. 678|01.07.2009-31.07.2009
  3. 4|01.07.2009-31.07.2009
  4. 567|01.07.2009-31.07.2009
  5. 56|01.07.2009-31.07.2009
  6. 456|01.06.2009-31.07.2009
  7. 67|01.07.2009-31.07.2009
  8. 34|01.07.2009-31.07.2009
  9. 5|01.07.2009-31.07.2009
  10. 7|01.07.2009-31.07.2009
  11. 97|01.06.2009-31.07.2009
  12. 44|01.07.2009-31.07.2009
  13. 676|01.07.2009-31.07.2009

A file with text messages «C:\MSG.txt» looks like this:
  1. %user please pay for the service access to the Internet, for the period %date. 
  2. Failure to pay within 2 business days - you will be disconnected

Now consider the process of creating a script that will send this message debtors every 4 hours.

For that, go to the script editor on the server:

And choose from the list of events - the script every 4-th hour:

We add our script:

  1. Program UsersAlerts;
  2. Var
  3. UsersCount, I, Uin: integer;
  4. Str, Msg, ms, Date, User: string;
  5.  
  6. Begin
  7. Msg:='';
  8.  // obtain the number of lines in a file with the debtors
  9. UsersCount:= GetTextFileLinesCount('c:\uin.txt');
  10.  
  11. For i:=1 to GetTextFileLinesCount('c:\msg.txt') do
  12. Begin
  13.   // in this cycle load file and merge it into one line
  14. LoadLineFromFile('c:\MSG.txt',i,str);
  15. Msg:=Msg+str+#13#10;
  16. End;
  17.  
  18. For i:=1 to UsersCount do
  19. Begin
  20.   ms:=msg; //save Msg to ms
  21.   LoadLineFromFile('c:\UIN.txt',i,str);//load line from file
  22.   UIN:=strtoint(copy(str,1,pos('|',str)-1));//get Uin Users
  23.   Date:=copy(str,pos('|',str)+1,length(str)-pos('|',str));//get date
  24.   User:=mGetNickFromUIN(UIN);//ask nick his UIN
  25.  
  26.   //replace in the message %user to nick
  27. Insert(User,Ms,pos('%user',ms));
  28. Delete(Ms,pos('%user',ms),5);
  29.  
  30.   //replace in the message %date to date
  31. Insert(Date,Ms,pos('%date',ms));
  32. Delete(Ms,pos('%date',ms),5);
  33.  
  34.   //and send the generated message to the user
  35. mSendPrivateMessage(uin, Ms);
  36. End;
  37. End.

Will it look like this:

Click on the icon with a floppy disk, save the script and check «Enable script».

Done, the server will perform the tasks every 4 hours and notify the debtors.