Code offering: +autojobs
-
Automatically create a job in X days/weeks/months or every X days/weeks/months. Because that could get horribly annoying, only staff can do it. It is managed by @forcing the player to +request something, however, so it does let players at least look at their autojobs (after all, they'll see them when they're +requested). This is based off my earlier Generic Reminders Code. I'll try to keep it up to date as I encounter bugs.
The desc/help:
+autojob <name>=<job title>[ <in|every> [<X>] <days|weeks|months>] (Staff) Examples: +autojob Jamie=Call Mom - will open a new job every day +autojob Jake=Howl at the moooon! every month +autojob John=Feeding Frenzy in 3 days +autojobs - Show all the autojobs you have set. +autojob/view 1 - view autojob #1 on yourself. Staff only: +autojob/view <name>/1 - view autojob #1 on <name>. +autojob/cancel <name>/1 - get rid of autojob #1 on <name>. +autojob/note <name>/1=<stuff> - any notes you want to include in the job Notes: All autojobs are created at 2 AM. This code considers "a month" to be 28 days. Units of time that are not recognized will default to "days". Do not use this code for precision. Most third-party apps work better. Code notes: Required functions: header, footer, isstaff, alert Required objects: Cron object of some kind, Anomaly Jobs Required permissions: WIZARD due to attr reading/setting & @forcing Limitations: Players can run out of space on themselves by setting a million autojobs. Regrets: Did not code the display number to NOT be the ID. Credits: Melpomene@NOLA (melpomine@gmail.com|nola.mechanipus.com 2967)
The code:
@create AutoJob Handler <AJH>=10 @set AJH=SAFE INHERIT @desc AJH=%R[space(3)]+autojob <name>=<job title>[ <in|every> [<X>] <days|weeks|months>] (Staff)%R%R[space(3)]Examples:%R[space(5)]+autojob Jamie=Call Mom - will open a new job every day%R[space(5)]+autojob Jake=Howl at the moooon! every month%R[space(5)]+autojob John=Feeding Frenzy in 3 days%R%R[space(3)]+autojobs - Show all the autojobs you have set.%R[space(3)]+autojob/view 1 - view autojob #1 on yourself.%R%R[space(3)]Staff only:%R%R[space(3)]+autojob/view <name>/1 - view autojob #1 on <name>.%R[space(3)]+autojob/cancel <name>/1 - get rid of autojob #1 on <name>.%R[space(3)]+autojob/note <name>/1=<stuff> - any notes you want to include in the job%R%R[space(3)]Notes:%R[space(5)]All autojobs are created at 2 AM.%R[space(5)]This code considers "a month" to be 28 days.%R[space(5)]Units of time that are not recognized will default to "days".%R[space(5)]Do not use this code for precision. Most third-party apps work better.%R%R[space(3)]Code notes:%R[space(5)]Required functions: header, footer, isstaff, alert%R[space(5)]Required objects: Cron object of some kind, Anomaly Jobs%R[space(5)]Required permissions: WIZARD due to attr reading/setting & @forcing%R[space(5)]Limitations:%R[space(7)]Players can run out of space on themselves by setting a million%R[space(7)]autojobs.%R[space(5)]Regrets: Did not code the display number to NOT be the ID.%R%R[space(3)]Credits: Melpomene@NOLA (melpomine@gmail.com|nola.mechanipus.com 2967)%R &cmd-+autojob AJH=$+autojob *=*:@switch setr(E, if(not(isstaff(%#)), Only staffers may set autojobs., if(not(t(setr(P, pmatch(case(%0, me, %N, %0))), %#)), Could not find player %0., setq(3, extract(%1, sub(words(%1), 2), 3))[null(iter(%q3, if(isnum(%i0), setq(4, 1)))[if(not(t(%q4)), setq(4, switch(%q3, * month, M, * months, M, * day, D, * days, D, * weeks, W, * week, W, 0)))])][if(not(t(%q4)), setq(3, ))][setq(C, switch(%q3, * month, M, * months, M, * day, D, * days, D, * weeks, W, * week, W, 0))][setq(R, switch(%q3, * in *, I, in *, I, * every *, E, every *, E, 0))][setq(N, trim(squish(iter(%q3, if(isnum(%i0), %i0)))))][if(or(not(t(%qN)), not(isnum(%qN))), setq(N, 1))][setq(S, if(or(strmatch(%q3, * in *), strmatch(%q3, in *)), extract(%1, 1, sub(words(%1), match(revwords(%1), in))), if(or(strmatch(%q3, * every *), strmatch(%q3, every *)), extract(%1, 1, sub(words(%1), match(revwords(%1), every))), %1)))][if(not(t(%qS)), Could not figure out what you wanted me to autojob you of!, setq(T, convtime(timefmt($a $b $d 02:00:00 $Y, add(secs(), mul(%qN, case(%qC, W, 604800, M, 2419200, 86400)))))))])))=, {&_autojobCount %qP=setr(I, add(default(%qP/_autojobCount, 0), 1)); &_autojob-%qI-text %qP=%qS; &_autojob-%qI-cycle %qP=[if(t(%qC), %qC, D)]; &_autojob-%qI-next %qP=%qT; &_autojob-%qI-interval %qP=%qN; &_autojob-%qI-setter %qP=%#; &_autojob-%qI-repeat %qP=[case(%qR, I, 0, 1)]; @switch [gt(strlen(get(me/people-[setr(A, v(peopleCount))])), 7500)]=1, {&peopleCount me=setr(A, add(%qA, 1));}; &people-%qA me=[setunion(v(people-%qA), %qP)]; @set me/people-%qA=NO_COMMAND; @pemit %#=alert(autojobs) [name(%qP)] will open a job titled "%qS" [case(%qR, I, in, every)] [if(gt(%qN, 1), %qN%b)][case(%qC, W, week, M, month, day)][if(gt(%qN, 1), s)][case(%qR, I,, . The next autojob is)] on [timefmt($m/$d/$y at 2 AM, %qT)].[case(%qC, M, %bPlease note that a month is considered to be 28 days long.)];}, {@pemit %#=alert(autojobs) %qE;} @set AJH/cmd-+autojob=no_parse &peopleCount AJH=1 @set AJH/peopleCount=NO_COMMAND &trigger_autojobs AJH=@dolist lattr(me/people-*)={@trigger me/trigger_parse-people=##;}; @set AJH/trigger_autojobs=NO_COMMAND &trigger_parse-people AJH=@dolist v(%0)={@trigger/notify me/trigger_autojob-person=##; @wait me={@trigger me/trigger_clean-person=##;};} @set AJH/trigger_parse-people=NO_COMMAND &trigger_clean-person AJH=@switch words(lattr(%0/_autojob-*-text))=0, {@dolist lattr(me/people-*)={&## me=[setdiff(v(##), %0)];};} @set AJH/trigger_clean-person=NO_COMMAND &trigger_autojob-person AJH=@switch t(setr(P, pmatch(%0)))=1, {@dolist lattr(%qP/_autojob-*-text)={@switch setq(0, first(rest(##, -), -))[setq(C, get(%qP/_autojob-%q0-cycle))][setq(I, get(%qP/_autojob-%q0-interval))][setq(R, get(%qP/_autojob-%q0-repeat))][setq(T, get(%qP/_autojob-%q0-next))][setq(S, get(%qP/_autojob-%q0-setter))][lt(%qT, add(secs(), 3600))]=1, {@force %qP=+request [titlestr(setr(V, get(%qP/##)))]=%%R%%RAutojob: %qV[if(hasattr(%qP, _autojob-%q0-note), %%R%%R%%TNote: [get(%qP/_autojob-%q0-note)])]%R%R This is a [case(%qR, 1, repeating, one-time)] +autojob [name(%qS)] set for [name(%qP)]. [case(%qR, 1, The next +autojob will be on [timefmt($m/$d/$y at 2 AM, convtime(timefmt($a $b $d 02:00:00 $Y, add(secs(), mul(%qI, case(%qC, W, 604800, M, 2419200, 86400))))))]. This +autojob will recur every %qI [case(%qC, W, week, M, month, day)][if(gt(%qI, 1), s)].)] To learn more about +autojobs, type +help autojobs.; @switch %qR=1, {&_autojob-%q0-next %qP=[convtime(timefmt($a $b $d 02:00:00 $Y, add(secs(), mul(%qI, case(%qC, W, 604800, M, 2419200, 86400)))))];}, {@wipe %qP/_autojob-%q0-*;}}}} @set AJH/trigger_autojob-person=NO_COMMAND &cmd-+autojobs AJH=$+autojobs:@pemit %#=if(t(setr(R, lattr(%#/_autojob-*-text))), header(Your active autojobs)[space(3)]%cu[ljust(ID, 5)] [ljust(+autojob text, 57)] [ljust(Next, 8)]%cn%R[iter(%qR, space(3)[ljust(setr(0, first(rest(%i0, -), -))., 5)] [ljust(mid(get(%#/%i0), 0, 57), 57)] [ljust(timefmt($m/$d/$y, get(%#/_autojob-%q0-next)), 8)],, %R)][footer(+autojob/view # for more.)], alert(autojobs) You have no active autojobs.); &cmd-+autojobs_person AJH=$+autojobs *:@switch setr(E, if(not(isstaff(%#)), Only staffers may view another player's autojobs., if(not(t(setr(P, pmatch(case(%0, me, %N, %0))), %#)), Could not find player %0.)))=, {@pemit %#=if(t(setr(R, lattr(%qP/_autojob-*-text))), header([name(%qP)]'s active autojobs)[space(3)]%cu[ljust(ID, 5)] [ljust(+autojob text, 57)] [ljust(Next, 8)]%cn%R[iter(%qR, space(3)[ljust(setr(0, first(rest(%i0, -), -))., 5)] [ljust(mid(get(%qP/%i0), 0, 57), 57)] [ljust(timefmt($m/$d/$y, get(%qP/_autojob-%q0-next)), 8)],, %R)][footer(+autojob/view [name(%qP)]/# for more.)], alert(autojobs) [name(%qP)] has no active autojobs.);}, {@pemit %#=alert(autojobs) %qE;}} @set AJH/cmd-+autojobs_person=no_parse &cmd-+autojob_view AJH=$+autojob/view *:@switch strmatch(%0, */*)=1,{},{@switch setr(E, if(not(hasattr(%#, _autojob-%0-text)), You don't have a autojob #%0.))=, {@pemit %#=header(+autojob #%0)%r[wrap(Text: [get(%#/_autojob-%0-text)], 78, Left, space(3))]%R[if(hasattr(%#, _autojob-%0-note), wrap(Note: [get(%#/_autojob-%0-note)], 78, Left, space(3))%R)][columns(Set by: [name(get(%#/_autojob-%0-setter))]|Repeating: [case(setr(R, get(%#/_autojob-%0-repeat)), 1, on, off)]|Next autojob: [timefmt($m/$d/$y at 2 AM, get(%#/_autojob-%0-next))]|Occurs [case(%qR, 1, every, in)]: [setr(I, get(%#/_autojob-%0-interval))] [case(get(%#/_autojob-%0-cycle), W, week, M, month, day)][if(gt(%qI, 1), s)], 36, |, 3)]%R[footer(if(isstaff(%#), +autojob/note %N/%0=<note> to set a note.))];}, {@pemit %#=alert(autojobs) %qE;}} @set AJH/cmd-+autojob_view=no_parse &cmd-+autojob_view_person AJH=$+autojob/view */*:@switch setr(E, if(not(isstaff(%#)), Only staffers may view another player's autojobs., if(not(t(setr(P, pmatch(case(%0, me, %N, %0))), %#)), Could not find player %0., if(not(hasattr(%qP, _autojob-%1-text)), [name(%qP)] doesn't have a +autojob #%1.))))=, {@pemit %#=header([name(%qP)]'s +autojob #%1)%r[wrap(Text: [get(%qP/_autojob-%1-text)], 78, Left, space(3))]%R[if(hasattr(%qP, _autojob-%1-note), wrap(Note: [get(%qP/_autojob-%1-note)], 78, Left, space(3))%R)][columns(Set by: [name(get(%qP/_autojob-%1-setter))]|Repeating: [case(setr(R, get(%qP/_autojob-%1-repeat)), 1, on, off)]|Next +autojob: [timefmt($m/$d/$y at 2 AM, get(%qP/_autojob-%1-next))]|Occurs [case(%qR, 1, every, in)]: [setr(I, get(%qP/_autojob-%1-interval))] [case(get(%qP/_autojob-%1-cycle), W, week, M, month, day)][if(gt(%qI, 1), s)], 36, |, 3)]%R[footer(if(isstaff(%#), +autojob/note [name(%qP)]/%1=<note> to set a note.))];}, {@pemit %#=alert(autojobs) %qE;} @set AJH/cmd-+autojob_view_person=no_parse &cmd-+autojob_note AJH=$+autojob/note */*=*:@switch setr(E, if(not(isstaff(%#)), Only staffers may set autojob notes., if(not(t(setr(P, pmatch(case(%0, me, %N, %0))), %#)), Could not find player %0., if(not(hasattr(%qP, _autojob-%1-text)), [name(%qP)] doesn't have a +autojob #%1.))))=, {&_autojob-%1-note %qP=%2; @pemit %#=alert(autojobs) You set a note for #%1: %2;}, {@pemit %#=alert(autojobs) %qE;} @set AJH/cmd-+autojob_note=no_parse &cmd-+autojob_cancel AJH=$+autojob/cancel */*:@switch setr(E, if(not(isstaff(%#)), Only staffers may set autojobs., if(not(t(setr(P, pmatch(case(%0, me, %N, %0))), %#)), Could not find player %0., if(not(hasattr(%qP, _autojob-%1-text)), [name(%qP)] doesn't have a autojob #%1.))))=, {@pemit %#=alert(autojobs) You have canceled [name(%qP)]'s autojob #%1. If you wish to recreate it, run these commands:%R%R+autojob [name(%qP)]=[get(%qP/_autojob-%1-text)] [case(get(%qP/_autojob-%1-repeat), 1, every, in)] [setr(I, get(%qP/_autojob-%1-interval))] [case(get(%qP/_autojob-%1-cycle), W, week, M, month, day)][if(gt(%qI, 1), s)][if(hasattr(%qP, _autojob-%1-note), %R+autojob/note [add(get(%qP/_autojobCount), 1)]=[get(%qP/_autojob-%1-note)])]; @wipe %qP/_autojob-%1-*;}, {@pemit %#=alert(autojobs) %qE;} @set AJH/cmd-+autojob_note=no_parse @pemit %#=SET A CRON JOB UP. Sample below. For the below code to work, you need to be either holding the cron or in its location. Otherwise, replace the word CRON with your cron's DBref. @force me=&cron_job_AutoJobs CRON=@trigger [num(AJH)]/trigger_autojobs &cron_time_AutoJobs CRON=|||02|00|