AntiCAPS script for MyChat Server public channels | All articles |
Often in the chat, especially for servers, which is explicitly shared, there are people who write all their communications WTO SUCH CAPITAL LETTERS. These people are unfamiliar netiquette, and they do not know that the text in upper case means that a VERY loud voice says or yells.
This prevents other people and for such actions is usually punished by moderators. However, moderators are not robots, and for all not to follow. It would be nice to shift control over such "ranters" on the server so that it is controlled in automatic mode yourself.
Open the script editor.

Find events OnChannelMessage in the tree.
And write a script:
function AntiCAPSFilter(input_st:string;max_percent:byte):string; var i, n, nonspace_count:integer; begin nonspace_count:=0; n:=0; for i:=1 to length(input_st) do begin if input_st[i]<>' ' then inc(nonspace_count); if ((input_st[i]>='A') and (input_st[i]<='Z')) or ((input_st[i]>='А') and (input_st[i]<='Я')) or (input_st[i]='І') or (input_st[i]='Ї') or (input_st[i]='Є') then inc(n); end; if round(n*100/nonspace_count)>=max_percent then result:=LowerCase(input_st) else result:=input_st; end; var s, chname:string; uin, uid:integer; begin s:=mGetLastChannelMessage(uin, uid, chname); // AntiCAPS filter s:=AntiCAPSFilter(s,70); mModifyLastChannelMessage(uin, uid, s); end.
Разберём его подробно.
Головная часть скрипта – это самая нижняя часть кода
var s, chname:string; uin, uid:integer; begin s:=mGetLastChannelMessage(uin, uid, chname); // AntiCAPS filter s:=AntiCAPSFilter(s,70); mModifyLastChannelMessage(uin, uid, s); end.
First, when the event is triggered OnChannelMessage, we load a text variable message that was sent to the channel:
s:=mGetLastChannelMessage(uin, uid, chname);
mGetLastChannelMessage – is a function of the MSL language for receiving text messages in the channel. uin - a unique identifier of the user who sent the message, uid - ID of the text channel, chname - textual name of the channel.
After receiving the text messages we call the AntiCAPSFilter:
s:=AntiCAPSFilter(s,70);
This function, if necessary, will modify our message. Number 70 - a threshold filter in percentage. If the original message of letters, written in upper case will be more than 70 percent, then the message will be given to lowercase. If not - then left as is.
Then we call the procedure mModifyLastChannelMessage, which modifies the original message.
Once the script worked, the server will send users to a channel already changed the message.
Now pay attention to the function AntiCAPSFilter and comment on the source code:
function AntiCAPSFilter(input_st:string;max_percent:byte):string; var i, n, nonspace_count:integer; begin nonspace_count:=0; // counter for non-whitespace n:=0; //number of letters in uppercase for i:=1 to length(input_st) do begin // cycle to traverse the line if input_st[i]<>' ' then inc(nonspace_count); // increment counter letters if ((input_st[i]>='A') and (input_st[i]<='Z')) //if the character is an uppercase letter and is or ((input_st[i]>='А') and (input_st[i]<='Я')) // English, Russian or Ukrainian alphabet or (input_st[i]='І') or (input_st[i]='Ї') or (input_st[i]='Є') then inc(n); // then increase the counter end; // usual proportion to calculate the percentage of all uppercase letters // on all posts // if the limit is reached - then transform the entire message in upper case // with LowerCase if round(n*100/nonspace_count)>=max_percent then result:=LowerCase(input_st) else result:=input_st; // otherwise return the original message without modifications end;
And do not forget to check "enable script" on the toolbar, otherwise it simply will not start.
To check the syntactic correctness of the script - press Ctrl + F9.
Download the source code of the script can here
| < <<<===== | =====>>> > |
|---|


