urbit/main/bin/chat.hoon

384 lines
11 KiB
Plaintext
Raw Normal View History

2013-10-16 06:24:12 +04:00
!:
2014-05-31 02:41:22 +04:00
:: /=main=/bin/chat/hoon
2013-10-16 06:24:12 +04:00
::
2013-11-26 23:28:15 +04:00
=> %= .
+
=> +
=> ^/===/lib/pony
=> ^/===/lib/chat
=+ ^= flag
$? %all
%monitor
%never
%leet
%nub
%time
[%haus p=@p]
[%r p=room]
==
2014-05-31 02:41:22 +04:00
=+ flags=*(list flag)
2013-11-26 23:28:15 +04:00
=> |%
2014-05-31 02:41:22 +04:00
++ chk-flag |=(f=@tas (lien flags |=(flag =(f +<))))
2013-11-26 23:28:15 +04:00
++ chat
%+ cook |=(a=^chat a)
;~ pose
(cold [%how ~] wut)
(cold [%out ~] zap)
2014-05-31 02:41:22 +04:00
%+ stag %who %+ stag %tcc (teklist ^room tis cen room)
(cold [%who %ttt ~] ;~(plug tis tis tis))
(cold [%who %tis ~] tis)
%+ stag %kil (teklist ,@p hep sig fed:ag)
%+ stag %res (teklist ,@p lus sig fed:ag)
;~(pfix pam (stag %all (stag %$ (stag %& mess))))
;~(pfix bar (stag %all (stag %$ (stag %| mess))))
2013-11-26 23:28:15 +04:00
(stag %say ;~(plug ;~(pfix sig fed:ag) ;~(pfix ace mess)))
(stag %def mess)
==
::
2014-05-31 02:41:22 +04:00
++ teklist
|* [t=_,* pep=_rule pef=_rule sef=_rule]
;~(pfix pep (cook (list t) (plus (ifix [pef (star ace)] sef))))
::
2013-11-26 23:28:15 +04:00
++ expn
%- sear
:_ text
|= a=@t
^- (unit ,[p=@t q=tank])
=+ hun=(rush a wide:vast)
2013-12-26 21:12:07 +04:00
?~ hun ~
2013-11-26 23:28:15 +04:00
?~(a ~ [~ a (sell (slap seed u.hun))])
::
2014-05-31 02:41:22 +04:00
++ room
%+ cook |=(a=(list ,@t) `^room`(crip a))
(plus ;~(pose low nud hep))
::
2013-11-26 23:28:15 +04:00
++ mess
%+ cook |=(a=^mess a)
;~ pose
(stag %do ;~(pfix pat text))
(stag %ex ;~(pfix hax expn))
(stag %do (full (easy '')))
2013-11-26 23:28:15 +04:00
(stag %qu text)
==
++ text (boss 256 (star ;~(pose (shim 32 126) (shim 128 255))))
--
|%
++ rend
2014-05-31 02:41:22 +04:00
|= [sen=@da roo=@tas chr=tape nym=tape dum=^mess] :: roo=^room
2013-11-26 23:28:15 +04:00
^- tank
2014-05-31 02:41:22 +04:00
=+ da=(yell sen)
2013-11-26 23:28:15 +04:00
?- -.dum
%do =+ msg=?:(=(0 p.dum) "remains quietly present" (trip p.dum))
:- %leaf
%+ welp
?. (chk-flag %time) ~
(weld (timestamp sen) " ")
"%{(trip roo)} {chr}{nym} {msg}"
2014-05-31 02:41:22 +04:00
%ex :~ %rose
[" " "" ""]
:- %leaf
%+ welp
?. (chk-flag %time) ~
(weld (timestamp sen) " ")
"%{(trip roo)} {chr}{nym} {(trip p.dum)}"
2014-05-31 02:41:22 +04:00
q.dum
==
%qu
:- %leaf
%+ welp
?. (chk-flag %time) ~
(weld (timestamp sen) " ")
2014-05-31 02:41:22 +04:00
"%{(trip roo)} {chr}{nym}: {(trip p.dum)}"
2013-11-26 23:28:15 +04:00
==
2014-05-31 02:41:22 +04:00
::
++ timestamp
|= t=@da
=+ da=(yell t)
"{?:((gth 10 h.da) "0" "")}{(scow %ud h.da)}:".
"{?:((gth 10 m.da) "0" "")}{(scow %ud m.da)}"
2014-05-31 02:41:22 +04:00
++ read-wlist
|= pax=path
%- (unit (list))
=+ fil=((hard arch) .^(%cy pax))
?~ q.fil ~
`(cue p:((hard ,[%dtzy %uw p=@]) (ream ((hard ,@) .^(%cx pax)))))
2013-11-26 23:28:15 +04:00
--
==
=> %= .
-
:- :* bud=(sein `@p`-<) :: chat server
oot=_@ud :: outstanding, server
2013-11-26 23:28:15 +04:00
tod=*(map ,@p ,@ud) :: outstanding, friend
giz=*(list gift) :: stuff to send
sad=`sand`[%& &] :: default state
wak=_@da :: next wakeup
2013-11-26 23:28:15 +04:00
dun=| :: done
2014-05-31 02:41:22 +04:00
kills=*(list ,@p)
roo=`^room`coci
2013-11-26 23:28:15 +04:00
==
[who=`@p`-< how=`path`->]
==
2013-10-16 06:24:12 +04:00
|= [est=time *]
2014-05-31 02:41:22 +04:00
|= args=(list flag)
=. flags `(list flag)`args
=+ sta=est :: move up to declaration of state
2013-11-26 23:28:15 +04:00
=. wak est
=. bud
?: (lien args |=(a=flag &(?=(^ a) ?=(%haus -.a))))
(roll args |=([p=flag q=@p] ?:(&(?=(^ p) ?=(%haus -.p)) p.p q)))
2014-05-31 02:41:22 +04:00
bud
=. roo
?: (lien args |=(a=flag &(?=(^ a) ?=(%r -.a))))
(roll args |=([p=flag q=^room] ?:(&(?=(^ p) ?=(%r -.p)) p.p q)))
roo
2014-05-31 02:41:22 +04:00
=. kills %- (list ,@p)
%+ fall
(read-wlist /[(scot %p who)]/conf/[(scot %da est)]/chat/killfile/wlist)
~
2013-11-26 23:28:15 +04:00
|- ^- bowl
=< abet:init
|%
++ abet `bowl`[(flop giz) ?:(dun ~ [~ hope vent(giz ~)])]
++ hope :: wait for events
=< apex
|% ++ apex ^- (list slip)
;: weld
buds
pals
regs
==
::
++ buds ^- (list slip)
?: =(0 oot) ~
[[/re [%ow ~]] ~]
::
++ pals ^- (list slip)
=| alx=(list slip)
|- ^+ alx
?~ tod alx
%= $
tod r.tod
alx %= $
tod l.tod
2013-11-26 23:28:15 +04:00
alx :_(alx [[%ra (scot %p p.n.tod) ~] [%ow ~]])
==
==
::
++ regs ^- (list slip)
2014-05-31 02:41:22 +04:00
:~ [/ob [%lq %ob]]
2013-11-26 23:28:15 +04:00
[/wa [%wa wak]]
[/ya [%lq %ya]]
^- slip
:- /up
:+ %up %text
:_ ""
=+ wyt=?:(?=(& -.sad) !=(0 oot) (~(has by tod) p.sad))
%+ weld
2014-05-31 02:41:22 +04:00
?. ?=(& -.sad)
(scow %p p.sad)
:(weld "%" (trip roo) ?:(p.sad " &" " |"))
2013-11-26 23:28:15 +04:00
?:(wyt "... " " ")
==
--
::
++ init (joke:(joke ~ [%who roo ~]) ~ [%ego roo est])
2013-11-26 23:28:15 +04:00
++ joke :: send message
|= [hur=(unit ,@p) msg=*]
^+ +>
?~ hur
2014-05-31 02:41:22 +04:00
+>(oot +(oot), giz :_(giz [%sq bud %bo /re msg]))
2013-11-26 23:28:15 +04:00
%= +>
giz :_(giz [%sq u.hur %ya [%ra (scot %p u.hur) ~] msg])
tod =+ dut=(~(get by tod) u.hur)
(~(put by tod) u.hur ?~(dut 1 +(u.dut)))
==
::
++ nice :: got response
|= [hur=(unit ,@p) kay=cape]
^+ +>
=. +>
?~ hur
+>(oot (dec oot))
=+ dyt=(need (~(get by tod) u.hur))
%_ +>.$
tod
?: =(1 dyt)
(~(del by tod) u.hur)
2013-11-26 23:28:15 +04:00
(~(put by tod) u.hur (dec dyt))
==
?- kay
%good +>
%dead (show %leaf "server {(scow %p ?~(hur bud u.hur))} choked")
==
::
++ priv :: private message
|= [now=@da her=@p mes=^mess]
2013-11-26 23:28:15 +04:00
^+ +>
2014-05-31 02:41:22 +04:00
?: (dead her) +>
=+ ^= nym
=+ yow=(scot %p her)
=+ ^= woy
%- (hard ,@t)
2014-06-01 21:54:39 +04:00
.^(%a (scot %p who) %name (scot %da now) (scot %p her) ~)
?: =(%$ woy) yow
(cat 3 yow (cat 3 ' ' woy))
(show (rend est '(private)' "" (trip nym) mes))
2013-11-26 23:28:15 +04:00
::
++ said :: server message
|= [her=@p duz=(list zong)]
^+ +>
?~ duz +>
%= $
duz t.duz
+>
=. giz
?. ?& ?=(%all -.i.duz)
=+ ^= r
%+ rexp (scow %p who)
(trip =>(t.i.duz ?@(+ p p)))
&(!=(~ r) !=([~ ~] r) !=([~ ~ ~] r))
==
~
[[%xy /d [%blit [%bel ~]~]] giz]
2014-05-31 02:41:22 +04:00
%- shew
^- (list tank)
?- -.i.duz
%all
?: |((dead p.s.i.duz) !=(roo q.i.duz))
2014-05-31 02:41:22 +04:00
~
:_ ~
%- rend
:* p.i.duz
q.i.duz
?:(=(%white r.i.duz) "& " "| ")
(trip q.s.i.duz)
t.i.duz
==
%who
?. =(q.i.duz roo) ~
%+ ~(rep by r.i.duz) *(list tank)
2014-05-31 02:41:22 +04:00
|= [p=[r=^room u=(list user)] q=(list tank)]
:* [%leaf "%{(trip r.p)}:"]
:+ %rose [", " " " ""]
%+ turn
%+ weld
(skim u.p |=(a=user =(p.a who)))
(skip u.p |=(a=user =(p.a who)))
|=(a=user [%leaf (trip q.a)])
q
==
?(%new %out)
?. ?& !(dead p.r.i.duz)
=(q.i.duz roo)
?| (chk-flag %all)
?& (lth sta p.i.duz)
(chk-flag %monitor)
== ==
==
2014-05-31 02:41:22 +04:00
~
:_ ~ :- %leaf
;: weld
?. (chk-flag %time) ~
(timestamp p.i.duz)
?- -.i.duz
%new " +"
%out " -"
==
?: (chk-flag %nub)
(trip q.r.i.duz)
(scow %p p.r.i.duz)
?: (chk-flag %monitor) ~
(weld " %" (trip q.i.duz))
2014-05-31 02:41:22 +04:00
== ==
2013-10-16 06:24:12 +04:00
==
2014-05-31 02:41:22 +04:00
::
++ dead
|= her=@p
(lien kills |=(@p =(her +<)))
::
++ kill
|= her=(list ,@p)
%= +>
2014-05-31 21:58:39 +04:00
kills (weld her (skip kills |=(a=@p (lien her |=(b=@p =(a b))))))
2014-05-31 02:41:22 +04:00
giz
2014-05-31 21:58:39 +04:00
=+ j=(jam (weld her (skip kills |=(a=@p (lien her |=(b=@p =(a b)))))))
2014-05-31 02:41:22 +04:00
=+ encoded=(cat 3 (scot %uw j) `@t`10) :: Base-64 encoding
:_ giz
:- %ok
(foal /[(scot %p who)]/conf/[(scot %da est)]/chat/killfile/wlist encoded)
2014-05-31 02:41:22 +04:00
==
::
++ resurrect
|= her=(list ,@p)
%= +>
2014-05-31 21:58:39 +04:00
kills (skip kills |=(a=@p (lien her |=(b=@p =(a b)))))
2014-05-31 02:41:22 +04:00
giz
2014-05-31 21:58:39 +04:00
=+ j=(jam (skip kills |=(a=@p (lien her |=(b=@p =(a b))))))
2014-05-31 02:41:22 +04:00
=+ encoded=(cat 3 (scot %uw j) `@t`10) :: Base-64 encoding
:_ giz
:- %ok
(foal /[(scot %p who)]/conf/[(scot %da est)]/chat/killfile/wlist encoded)
2013-11-26 23:28:15 +04:00
==
::
++ shew |=(tax=(list tank) +>(giz [[%lo tax] giz])) :: print to screen
++ show |=(tan=tank +>(giz [[%la tan] giz])) :: print to screen
2013-11-26 23:28:15 +04:00
++ take :: alarm event
|- ^+ +
=. wak (add ~m1 (max wak est))
?.(=(0 oot) + (joke ~ `zing`[%ego roo est]))
2013-11-26 23:28:15 +04:00
::
++ toke :: user action
|= txt=@t
^+ +>
2014-05-31 02:41:22 +04:00
?: =(0 txt) +>
2013-11-26 23:28:15 +04:00
=+ rey=(rush txt chat)
?~ rey
2013-11-26 23:28:15 +04:00
(show %leaf "invalid input")
?- -.u.rey
2014-05-31 02:41:22 +04:00
%all ?~ p.u.rey
(joke(sad [%& q.u.rey]) ~ `zing`[%all roo q.u.rey r.u.rey])
2014-05-31 02:41:22 +04:00
(joke(sad [%& q.u.rey]) ~ `zing`u.rey)
%def
2014-05-31 02:41:22 +04:00
%- joke
2013-11-26 23:28:15 +04:00
?: ?=(& -.sad)
[~ `zing`[%all roo p.sad p.u.rey]]
2013-11-26 23:28:15 +04:00
[[~ p.sad] `^mess`p.u.rey]
%how (shew (turn (lore ^:@/===doc%/help/txt) |=(a=@t [%leaf (trip a)])))
2014-05-31 02:41:22 +04:00
%out (show(dun &) %leaf "see you space cowboy...")
2013-11-26 23:28:15 +04:00
%say (joke(sad [%| p.u.rey]) [~ p.u.rey] `^mess`q.u.rey)
2014-05-31 02:41:22 +04:00
%who ?- p.u.rey
%tis %+ joke ~ ^- zing :+ %who roo `~[roo]
%ttt %+ joke ~ ^- zing :+ %who roo ~
%tcc %+ joke ~ ^- zing :+ %who roo `q.u.rey
2014-05-31 02:41:22 +04:00
==
%kil (kill p.u.rey)
%res (resurrect p.u.rey)
2013-11-26 23:28:15 +04:00
==
::
++ vent :: handle event
|= [now=@da pax=path nut=note]
^- bowl
=. est now
=< abet
?+ -.pax +>
%ob
?> ?=(%lq -.nut)
=+ n=((soft (list zong)) r.nut)
?~ n
~& %chat-zong-fail +>+
(said p.nut u.n)
2013-11-26 23:28:15 +04:00
%re ?>(?=(%ow -.nut) (nice ~ p.nut))
%ra ?> &(?=(%ow -.nut) ?=(^ t.pax))
2013-12-26 21:12:07 +04:00
(nice [~ (need (slaw %p i.t.pax))] p.nut)
2013-11-26 23:28:15 +04:00
%up ?>(?=(%up -.nut) (toke p.nut))
%wa ?>(?=(%wa -.nut) take)
%ya
?> ?=(%lq -.nut)
=+ n=((soft ^mess) r.nut)
?~ n
~& %chat-zong-fail +>+
(priv now p.nut u.n)
2013-11-26 23:28:15 +04:00
==
--