MyChat Scripts Engine: mGetUsersListInGroupsByNames, get a list of users from several groups
Function to obtain a list of users unique identifiers (UIN) from a set of groups. Group names are separated by commas or the "|" symbol with no spaces between them. The letter case is important.
Syntax
function mGetUsersListInGroupsByNames(sGroupNames: string): string;
Parameters and return values
Parameter |
Type |
Value |
sGroupNames |
string |
group names, separated by commas or the "|" symbol. The letter case is important. |
Function result
A text string with a list of users UINs, which are in groups. The numbers are unique and don't repeat even if a user exists in several groups at the same time. Groups are divided by commas or the "|" symbol.
If a group does not exist or there is no users in it, then the function returns an empty string.
Example
The script linked to the "Every 5 minutes" event. At the activation time (At 10:30 AM, for example), the script looks for the "d:\messages\broadcast\10.30.txt" file and sends a notification to all users of "Co-worker" group with a return receipt that contains a text from this file.
If a file name begins with the letter "w' ("w10.10.txt", for example) then a notification is send only in working days, from Monday to Friday. The notification expiration date is set before the end of the current day.
const
sGroups = 'Co-worker'; // users groups list, separated by commas or the "|" symbol
sPath = 'd:\messages\broadcast\'; // path where you can take files for notifications
var
sFullName, sFileName, sMsg, sUsersList: string;
iDay: integer;
bFlag: boolean;
begin
iDay := DayOfTheWeek(Now);
sFileName := FormatDatetime('hh.nn', Now) + '.txt';
sFullName := sPath + sFileName;
bFlag := false;
if FileExists(sFullName) then bFlag := true
else if iDay < 6 then begin
sFullName := sPath + 'w' + sFileName;
bFlag := FileExists(sFullName);
end;
if bFlag then begin
sMsg := Trim(LoadTextFromFile(sFullName, 0));
if length(sMsg) > 0 then begin
sUsersList := mGetUsersListInGroupsByNames(sGroups);
if length(sUsersList) > 0 then
mSendBroadcast(sMsg, sUsersList, EndOfTheDay(Now), 1);
end;
end;
end.
Script work result
A return receipt notification that is send from MyChat Server built-in bot: