FAQcode

Heya. This is code that any large casts can use to create FAQ pages, help pages, whatever you want to call it. It is designed for PennMUSH using the @config settings that MCM's currently using - you're on your own for porting it.

Edit it, optimize it, whatever you want to do.

Note that topic names should not exceed 19 characters or it will break the code as it is.

@create FAQ Object
@set FAQ Object=!NO_COMMAND
&CMD`FAQ FAQ Object=$^(?s)\+faq(?\:/(\S+))?(?\: +(.+?))?(?\:=(.*))?$:@assert or(not(strlen(%1)),match(setr(choices,setunion(v(VAR`PLAYFLAGS),if(setr(admin,or(controls(%#,me),match(v(OWNERS),%#))),v(VAR`ADMINFLAGS)),|,|)),%1,|))=@pemit %#=ERROR: Invalid switch for +faq! Your choices are: [itemize(%q<choices>,|,and,\,)];@include me/INC`[strfirstof(%1,MAIN)]=%2,%3
@set FAQ Object/CMD`faq=regexp

&VAR`PLAYFLAGS FAQ Object=HELP
&VAR`ADMINFLAGS FAQ Object=SET|GET|DEL|REN|ADDWRI|DELWRI

&FUN`HEADER FAQ Object=if(strlen(%0),center(ansi(b,<)[ansi(hb,*%B)][if(%1,%0,ansi(hw,%0))][ansi(hb,%B*)][ansi(b,>)],78,ansi(b,-=-)),ansi(b,repeat(-=-,26)))
&FUN`SUBHEADER FAQ Object=if(strlen(%0),center(%b[if(%1,%0,ansi(hw,%0))]%b,78,ansi(b,-=-)),ansi(b,repeat(-=-,26)))

&INC`MAIN FAQ Object=@switch/inline gt(strlen(%0),0)=1,{@switch/inline gt(match(%0,iter(setr(attrs,lattr(me/FAQ`*)),get(me/%i0`NAME)|),|),0)=0,{@pemit %#=ERROR: Article by that name does not exist.},1,{th setq(attr,filterbool(#lambda/strmatch(get(me/\%0`NAME),%0),%q<attrs>));th [pemit(%#,u(me/FUN`HEADER,v(%q<attr>`NAME)))][pemit(%#,get(me/%q<attr>`DETAILS))][pemit(%#,u(FUN`SUBHEADER,Set by: [name(v(%q<attr>`BY))] on [convsecs(v(%q<attr>`ON))]))]}},0,{[pemit(%#,u(FUN`HEADER,FAQ Index))][pemit(%#,table(sort(iter(lattr(me/FAQ`*),get(me/%i0`NAME)|),a,|,|),19,78,|))][pemit(%#,u(FUN`SUBHEADER)%R[ansi(hw,WHO MAY WRITE:)] [itemize(iter(sort(setunion(v(OWNERS),owner(me)),name),name(%i0),,|),|,and,\,)])][pemit(%#,u(FUN`SUBHEADER,if(%q<admin>,+faq/help for instructions,+faq <topic> to read)))]}

&INC‘SET FAQ Object=@assert strlen(%0)=@pemit %#=ERROR: Must include a topic name.;@assert strlen(%1)=@pemit %#=ERROR: Must include topic details.;@switch/inline gt(match(%0,iter(setr(attrs,lattr(me/FAQ`*)),get(me/%i0`NAME),,|),|),0)=1,{th setq(attr,filterbool(#lambda/strmatch(get(me/\%0`NAME),%0),%q<attrs>))},0,{th setq(attr,FAQ`[add(lmath(max,iter(lattr(me/FAQ`*),last(%i0,`))),1)])};th attrib_set(me/%q<attr>`NAME,%0);th attrib_set(me/%q<attr>`DETAILS,%1);th attrib_set(me/%q<attr>`BY,%#);th attrib_set(me/%q<attr>`ON,secs());@pemit %#=SUCCESS: Article ’[ansi(hw,%0)]' Set.

&INC`GET Faq Object=@assert strlen(%0)=@pemit %#=ERROR: Must include a topic name.;@switch/inline gt(match(%0,iter(setr(attrs,lattr(me/FAQ`*)),get(me/%i0`NAME),,|),|),0)=0,{@pemit %#=ERROR: Article by that name does not exist.},1,{th setq(attr,filterbool(#lambda/strmatch(get(me/\%0`NAME),%0),%q<attrs>));th [pemit(%#,decompose(get(me/%q<attr>`DETAILS)))]}

&INC`DEL FAQ OBJECT=@assert strlen(%0)=@pemit %#=ERROR: Must include a topic name.;@switch/inline gt(match(%0,iter(setr(attrs,lattr(me/FAQ`*)),get(me/%i0`NAME),,|),|),0)=0,{@pemit %#=ERROR: Article by that name does not exist.},1,{th setq(attr,filterbool(#lambda/strmatch(get(me/\%0`NAME),%0),%q<attrs>));th wipe(me/%q<attr>);@pemit %#=SUCCESS: Article deleted.}

&INC‘REN Faq Object=@assert strlen(%0)=@pemit %#=ERROR: Must include a topic name.;@switch/inline gt(match(%0,iter(setr(attrs,lattr(me/FAQ`*)),get(me/%i0`NAME)|),|),0)=0,{@pemit %#=ERROR: Article by that name does not exist.},1,{th setq(attr,filterbool(#lambda/strmatch(get(me/\%0`NAME),%0),%q<attrs>));@break gt(match(%1,iter(setr(attrs,lattr(me/FAQ`*)),get(me/%i0`NAME)|),|),0)=@pemit %#=ERROR: An article named ’%1' already exists. Cannot rename.;th attrib_set(me/%q<attr>‘NAME,%1);@pemit %#=SUCCESS: Article Renamed to ’[ansi(hw,%1)]'.}

&INC‘ADDWRI Faq Object=@assert controls(%#,me)=@pemit %#=ERROR: Only the FAQ’s owner or admin may add additional FAQ writers.;@assert strlen(%0)=@pemit %#=ERROR: Must include a name!;@assert isdbref(setr(p,pmatch(%0)))=@pemit %#=ERROR: '%0' not found.;@break controls(%#,%qp)=@pemit %#=ERROR: Object owners and admin do not need to be listed.;@break match(%qp,v(OWNERS))=@pemit %#=ERROR: That player is already on the writer list.;th attrib_set(me/OWNERS,setunion(v(owners),%qp));@pemit %#=SUCCESS: [name(%qp)] added to Writers.

&INC‘DELWRI Faq Object=@assert controls(%#,me)=@pemit %#=ERROR: Only the FAQ’s owner or admin may remove FAQ writers.;@assert strlen(%0)=@pemit %#=ERROR: Must include a name!;@assert isdbref(setr(p,pmatch(%0)))=@pemit %#=ERROR: '%0' not found.;@assert match(%qp,v(OWNERS))=@pemit %#=ERROR: That player is not on the writer list.;th attrib_set(me/OWNERS,setdiff(v(owners),%qp));@pemit %#=SUCCESS: [name(%qp)] removed from Writers.

&INC‘HELP Faq object=[pemit(%#,u(FUN`HEADER,FAQ Help))][pemit(%#,This FAQ Object allows an object owner and their selected collaboratives to write FAQ articles, help articles, and basically anything that you’d want to organize by TITLE->TONS OF TEXT with. It is used as follows:%R%R[ansi(hw,+faq)]%RWithout Arguments, displays table of contents and FAQ configuration.%R%R[ansi(hw,+faq <topic>)]%RDisplays a topic's contents.%R%R[ansi(hw,+faq/set <topic>=<contents>)]%RSets or overwrites a topic's details. Topic is created if it does not exist.%R%R[ansi(hw,+faq/del <topic>)]%RDeletes a topic. Warning: cannot be undone.%R%R[ansi(hw,+faq/get <topic>)]%RRetrieves a decompose()'d version of Topic's text for hopefully easy editing.%R%R[ansi(hw,+faq/ren <topic>=<newname>)]%RRenames a topic. Won't work if <newname> already exists on another topic.%R%R[ansi(hw,+faq/addwri <name>)]%RAdds player to the writers list. Can only be used by admin and FAQ object owner.%R%R[ansi(hw,+faq/delwri <name>)]%RRemoves a player from the writers list. Can only be used by admin and FAQ object owner.%R%RFormatting such as ansi and linebreaks are all supported.)][pemit(%#,u(FUN`SUBHEADER))]

By posting to this Wiki you give Multiverse Crisis MUSH an unlimited world-wide right to use all custom text/images however they see fit, and gurrantee all text/images taken from other sources are protected under copyright fair use and are thus legal to post on this Wiki. More info on MCM MUSH.