MyChat Scripts: function mAddNewBBSMessage for creating announcements on the common board
Add a new message on the Bulletin board.
Syntax
function mAddNewBBSMessage(const sMsg:string; const dtExpire: double; const bStick: boolean): integer;
Parameters and return values
Parameter |
Type |
Value |
sMsg |
string |
message text; |
dtExpire |
double |
announcement expiration time. Calculated in UTC automatically; |
bStick |
boolean |
if "true", then a message will be placed on top of all messages ignoring date sorting. |
Function result
>0 |
message was posted successfully, the result is equal to the message index in the database; |
-1 |
message can't be empty; |
-2 |
announcement expiration time can't be older than a current date. |
Example
// ---------------------------------------
// Script created by Alexey Pikurov (support@nsoft-s.com)
// 18.01.2021 20:45:13
// ---------------------------------------
var
iUIN: integer;
dtExpired: double;
sUsersList, sUserFullName, sMsg, sGender, sToday: string;
begin
dtExpired := Now; // getting the current date
sToday := FormatDateTime('ddmmyyyy', dtExpired);
// if we worked today, do nothing
// to not send greetings again for the same people
if mDBStorageGetData('birthday-script') = sToday then exit
else mDBStorageSetData('birthday-script', sToday);
sUsersList := mGetBirthdayUsers(dtExpired); // getting the list of UINs who have a birthday today
while length(sUsersList) > 0 do begin
iUIN := StrToInt(Fetch(sUsersList, ','));
sUserFullName := mGetUserFullNameByPreset(iUIN, 0); // 0 — "John J. Doe"
if mGetUserAttribute(iUIN, 'Sex') = '2' then sGender := 'her' // getting a user's gender
else sGender := 'him';
// creating a string for greetings
sMsg := 'Today ' + sUserFullName + ' is celebrating a birthday!' +
CRLF +
'We wish ' + sGender + ' all the best' +
'from the bottom of our hearts!';
// if it is a weekend, add a number of days to Monday
case DayOfTheWeek(dtExpired) of
6: IncDay(dtExpired, 2);
7: IncDay(dtExpired, 1);
end;
// ...and post greetings on the Bulletin board to display for all users
mAddNewBBSMessage(sMsg, dtExpired, false);
end;
end.
Script work result
Today John J. Doe is celebrating a birthday!
We wish him all the best from the bottom of our hearts!