Skip to content

Instantly share code, notes, and snippets.

@ADHdev
Last active January 18, 2019 05:07
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ADHdev/00a8e7a9cea5f46780768307a77fb4d2 to your computer and use it in GitHub Desktop.
Save ADHdev/00a8e7a9cea5f46780768307a77fb4d2 to your computer and use it in GitHub Desktop.
Global message system
/*******************************************************************************
Key features:
- remembers who you last messaged so you don't have to type it again
- remembers the last type of message you sent
- queues messages for delivery while you're offline or messages are turned off
- lets you colorize, highlight, etc, a standardized prefix
- lets you block people IC (with a personalized IC message if you like)
- lets you hide/gag people's messages IC - warning, they get eaten
- shows you your message status on login
*******************************************************************************/
// Requires: alert(), interval()
// Here's interval() if you don't already have one you can substitute:
/*******************************************************************************
&f.globalp.interval Global Functions Object=if(t(setr(0, extract(squish(trim(strcat(
setq(I, sub(secs(), if(isnum(%0), %0, sub(secs(), idle(%0))))),
setq(W, div(%qI, 604800)),
if(gt(%qW, 0), setq(I, sub(%qI, mul(%qW, 604800)))),
setq(D, div(%qI, 86400)),
if(gt(%qD, 0), setq(I, sub(%qI, mul(%qD, 86400)))),
setq(H, div(%qI, 3600)),
if(gt(%qH, 0), setq(I, sub(%qI, mul(%qH, 3600)))),
setq(M, div(%qI, 60)),
if(gt(%qM, 0), setq(I, sub(%qI, mul(%qM, 60)))),
setq(S, %qI),
if(t(%qW), %qWw)|,
if(t(%qD), %qDd)|,
if(t(%qH), %qHh)|,
if(t(%qM), %qMm)|,
if(t(%qS), %qSs)
), b, |), |), 1, 2, |, %b))), %q0, 0s)
*******************************************************************************/
@create Message Commands <MSG>=10
@set MSG=inherit
@aconnect MSG=@trigger me/switch.msg.summary=%#;
&cmd-msg MSG=$msg*:@switch/first 1=and(strmatch(%0, /*), t(setr(S, first(lattr(me/switch.msg.[first(rest(%0, /), if(strmatch(first(%0), /*/*), /))]*))))), { @trigger me/%qS=first(%0), rest(%0), %#; }, {@trigger me/switch.msg=%0, %#;}
@set MSG/cmd-msg=no_parse
&switch.msg.summary MSG=@pemit setr(P, if(isdbref(%0), %0, %2))=strcat(alert(MSG) Message delivery, %b, if(t(xget(%qP, msg-receive-off)), disabled, enabled), ., %b, You have, %b, setr(0, words(lattr(%qP/_msg-*))), %b, unseen messages., if(gt(%q0, 0), %bType 'msg/view' to view them.));
&switch.msg.off MSG=&msg-receive-off %2=1; @pemit %2=alert(MSG) Message delivery disabled. First 50 messages will be queued for display when you turn messages back on.
&switch.msg.on MSG=@wipe %2/msg-receive-off; @pemit %2=alert(MSG) Message delivery enabled.; @trigger me/switch.msg.view=%0, %1, %2;
&switch.msg.view MSG=@switch/first t(setr(L, lattr(%2/_msg-*)))=1, {@pemit %2=alert(MSG) Here are the messages you missed.; @dolist/notify %qL={@pemit %2=strcat(interval(rest(##, -)) ago:, %b, xget(%2, ##)); @wipe %2/##;}; @wait me=@pemit %2=alert(MSG) All caught up.;}, {@pemit %2=alert(MSG) You have no unseen messages.;};
&switch.msg.block MSG=@eval setq(P, pmatch(first(%1, =))); @assert t(%qP)={@pemit %2=alert(MSG) Could not find player '[first(%1, =)]' (%qP).;}; @eval strcat(setq(R, rest(%1, =)), if(not(t(%qR)), setq(R, 1))); &msg-block-%qP %2=%qR; @pemit %2=alert(MSG) You have blocked [name(%qP)] from sending you messages. When [subj(%qP)] [case(subj(%qP), they, try, tries)] to message you, [subj(%qP)] will receive a message that says:%R[alert(MSG NOT SENT)] [name(%2)] has blocked you[if(match(%qR, 1), ., %bbecause: [s(%qR)])]
&switch.msg.unblock MSG=@eval setq(P, pmatch(first(%1, =))); @assert t(%qP)={@pemit %2=alert(MSG) Could not find player '[first(%1, =)]' (%qP).;}; @assert hasattr(%2, msg-block-%qP)={@pemit %2=alert(MSG) You are not currently blocking [name(%qP)].}; @wipe %2/msg-block-%qP; @pemit %2=alert(MSG) You are no longer blocking [name(%qP)] from sending you messages.
&switch.msg.hide MSG=@eval setq(P, pmatch(first(%1, =))); @assert t(%qP)={@pemit %2=alert(MSG) Could not find player '[first(%1, =)]' (%qP).;}; &msg-hide-%qP %2=1; @pemit %2=alert(MSG) You have hidden all messages from [name(%qP)]. Those messages will be lost forever, and [subj(%qP)] will not be notified that the message was not received.
&switch.msg.unhide MSG=@eval setq(P, pmatch(first(%1, =))); @assert t(%qP)={@pemit %2=alert(MSG) Could not find player '[first(%1, =)]' (%qP).;}; @assert hasattr(%2, msg-hide-%qP)={@pemit %2=alert(MSG) You are not currently blocking [name(%qP)].}; @wipe %2/msg-hide-%qP; @pemit %2=alert(MSG) You are no longer hiding messages from [name(%qP)].
&switch.msg MSG=
@break t(xget(%1, msg-receive-off))={@pemit %1=alert(MSG) You cannot send messages while your ability to receive messages is turned off. Type msg/on to enable the message system.;};
@eval setq(T, if(not(strmatch(%0, %b*)), ucstr(strip(first(%0), /)), xget(%1, last-msg-type)));
@eval setq(L, switch(trim(%0), /* *=*, first(rest(%0), =), *=*, first(%0, =), edit(xget(%1, last-msg-target), |, %b)));
@eval setq(V, trim(switch(%0, *=*, rest(%0, =), %0)));
@eval setq(P, iter(%qL, case(itext(0), me, %1, pmatch(itext(0))),, |));
@eval iter(%qP, if(not(t(itext(0))), setq(E, %qE Could not find player '[if(t(%qL), extract(%qL, inum(0), 1), itext(0))]' ([itext(0)]).)), |);
@break t(squish(trim(%qE)))={@pemit %1=alert(MSG) %qE;};
@set %1=last-msg-target:%qP;
@if t(%qT)={@set %1=last-msg-type:%qT;};
@pemit %1=strcat(alert(To [itemize(iter(%qP, name(itext(0)), |, |), |)]), %b, if(and(t(%qT), hasattr(%1, msg-send-%qT)), s(xget(%1, msg-send-%qT))%b, if(t(%qT), %[%qT%]%b)), switch(%qV, :*, name(%1) [rest(%qV, :)], ;*, name(%1)[rest(%qV, ;)], |*, rest(%qV, |), name(%1) sends%, "%qV"));
@dolist/delimit | [setdiff(setunion(%qP, %qP, |), %1, |)]={
@switch/first 1=
hasattr(##, msg-hide-%1), {},
hasattr(##, msg-block-%1), {
@pemit %1=alert(MSG NOT SENT) [name(##)] has blocked you[if(match(setr(B, u(##/msg-block-%1)), 1), ., %bbecause: %qB)];
},
and(or(t(xget(##, msg-receive-off)), not(hasflag(##, connect))), gte(words(lattr(##/_msg-*)), 50)), {
@pemit %1=alert(MSG NOT SENT) [name(##)] is currently inaccessible to the message system. Your message could not be stored because the message system can only hold the last 50 messages and [poss(##)] message queue is full. You will need to re-send your message later.;
},
or(t(xget(##, msg-receive-off)), not(hasflag(##, connect))), {
&_msg-[secs()] ##=strcat(alert(if(match(%1, ##), To [itemize(iter(%qP, name(itext(0)), |, |), |)], From [name(%1)])), %b, if(and(t(%qT), hasattr(%1, msg-send-%qT)), s(xget(%1, msg-send-%qT))%b, if(t(%qT), %[%qT%]%b)), switch(%qV, :*, name(%1) [rest(%qV, :)], ;*, name(%1)[rest(%qV, ;)], |*, rest(%qV, |), name(%1) sends%, "%qV"));
@pemit %1=alert(MSG NOT RECEIVED) [name(##)] is currently inaccessible to the message system. Queuing message for delivery once [setr(S, subj(##))] [case(%qS, they, return, returns)].;
},
{
@pemit ##=strcat(alert(From [name(%1)][if(gt(words(%qP, |), 1), %bto [itemize(iter(%qP, name(itext(0)), |, |), |)])]), %b, if(and(t(%qT), hasattr(%1, msg-send-%qT)), s(xget(%1, msg-send-%qT))%b, if(t(%qT), %[%qT%]%b)), switch(%qV, :*, name(%1) [rest(%qV, :)], ;*, name(%1)[rest(%qV, ;)], |*, rest(%qV, |), name(%1) sends%, "%qV"));
}
}
/*******************************************************************************
+help/set Messaging=Messaging is vital to roleplay, whether through text, phone, comm, or telepathy. We've done our best to keep it as simple, yet flexible, as possible.%R%R%Tmsg <player>=<text> - send a message%R%Tmsg/<type> <player>=<text> - send a <type> kind of message (examples: text, HUD, comm, telepathic, etc)%R%Tmsg <text> - send message with the same settings as the last one%R%RAfter the first msg is sent, it remembers the last person (or group of people!) you messaged, and the last type of message you sent.%R%RThe message itself can be anything, but displays special behaviors when it starts with :, ;, or |. For examples of these, see below:%R%R%T:tests%T%T%T<-- Gallifrey tests%R%T;'s test%T%T<-- Gallifrey's test%R%T|A test happens.%T<-- A test happens.%R%TTesting!%T%T<-- Gallifrey says, "Testing!"
+help/set Messaging/Color and Shortcuts=Some people like to customize messages to stand out better. To customize your sent messages:%R%R%T&msg-send-ra me=%%cw%%cR%%%[RED ALERT%%%]%R%R%TNow whenever you type msg/ra name=message, they'll see a bright red RED ALERT message. The letters "ra" effectively become a shortcut for "red alert", and your friends see the message as urgent as you meant to show it.
+help/set Messaging/Stopping Spam=Because messages can be spammy, we've implemented several different ways to stop them in-character.%R%R%Tmsg/off - turn off messages for a while. The first 50 you receive will be stored and replayed when you return.%R%R%Tmsg/on - re-enables messaging%R%R%Tmsg/block <name> - block them and tell them they're blocked - they'll get a "you are blocked" style message. You can also use msg/block <name>=<reason> to set the block message to whatever you want.%R%R%Tmsg/unblock <name> - let them message you again%R%R%Tmsg/hide <name> - hide all messages from a person without telling them the messages aren't going through. Warning: those messages get lost forever and you'll have no way of seeing them.%R%R%Tmsg/unhide <name> - unhide messages from the person
+help/set Messaging/Managing Messages=msg/off - turn messages off for a while. People who try to message you will be notified that you're unreachable, and their messages will be queued for when you return, up to 50 max.%R%Rmsg/on - return, and view your messages.%R%Rmsg/view - view any queued messages. Queued messages are deleted after they're viewed.%R%Rmsg/summary - view a summary of your message status.
*******************************************************************************/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment