urbit/main/bin/chat.hoon

316 lines
10 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
=> %= .
+
=> +
2014-07-30 05:09:11 +04:00
=* sed .
2013-11-26 23:28:15 +04:00
=> ^/===/lib/pony
=+ ^= flag
$? %leet
%monitor
%noob
%quiet
%time
[%tower p=@p]
2014-07-03 02:08:02 +04:00
[%s p=path]
==
2014-08-29 01:30:02 +04:00
=+ [flags=*(list flag) lat=&3:%]
2013-11-26 23:28:15 +04:00
=> |%
2014-07-03 02:08:02 +04:00
++ chat :: user action
$% [%all p=mess] :: say
2014-07-03 22:14:22 +04:00
[%back p=?(%da %dr %ud) q=@] :: backlog
[%def p=mess] :: use current prompt
2014-07-03 02:08:02 +04:00
[%how ~] :: help
[%priv p=@p q=mess] :: private
2014-07-03 02:08:02 +04:00
[%who ~] :: who
== ::
++ idad ,[p=@p q=@t] :: identity
2014-07-03 02:08:02 +04:00
++ mess :: message
$% [%do p=@t] :: act
[%exp p=@t q=tank] :: code
[%say p=@t] :: say
== ::
++ prom :: prompt type
$% [%pub ~] :: public message
[%pri p=ship] :: private message
== ::
++ user :: amigos
$% [%in p=idad] :: coming on the air
[%out p=idad] :: signing off
== ::
2014-07-03 02:08:02 +04:00
++ station path ::
2014-08-01 06:44:49 +04:00
++ zung :: client to server
2014-07-03 22:14:22 +04:00
$% [%backlog p=path q=?(%da %dr %ud) r=@] ::
2014-07-03 02:08:02 +04:00
[%hola p=station] ::
[%mess p=station q=mess] ::
2014-08-01 06:44:49 +04:00
[%tint p=ship] ::
2014-07-03 02:08:02 +04:00
== ::
++ zong :: server to client
$% [%mess p=@da q=ship r=mess] ::
== ::
--
=> |%
2013-11-26 23:28:15 +04:00
++ chat
%+ cook |=(a=^chat a)
;~ pose
(cold [%how ~] wut)
2014-07-03 02:08:02 +04:00
(cold [%who ~] tis)
(stag %back dat)
(stag %priv ;~(plug ;~(pfix sig fed:ag) ;~(pfix ace mess)))
(stag %all ;~(pfix pam mess))
(stag %def mess)
2013-11-26 23:28:15 +04:00
==
::
2014-07-03 02:08:02 +04:00
++ dat
2014-08-28 23:02:56 +04:00
%+ sear
2014-07-03 22:14:22 +04:00
|= p=coin
2014-08-28 23:02:56 +04:00
?. ?=([%$ ?(%da %dr %ud) @] p) ~
(some +.p)
;~(pfix bas bas (star ace) nuck:so)
2014-05-31 02:41:22 +04:00
::
2013-11-26 23:28:15 +04:00
++ expn
%- sear
:_ text
|= a=@t
^- (unit ,[p=@t q=tank])
2014-08-29 01:30:02 +04:00
~! %
=+ hun=(rush a wide:(vang | &1:% &2:% lat |3:%))
2013-12-26 21:12:07 +04:00
?~ hun ~
2014-07-30 05:05:05 +04:00
?~(a ~ [~ a (sell (slap !>(sed) u.hun))])
2013-11-26 23:28:15 +04:00
::
++ mess
%+ cook |=(a=^mess a)
;~ pose
(stag %do ;~(pfix pat text))
2014-07-03 02:08:02 +04:00
(stag %exp ;~(pfix hax expn))
(stag %do (full (easy '')))
2014-07-03 02:08:02 +04:00
(stag %say text)
2013-11-26 23:28:15 +04:00
==
2014-07-03 02:08:02 +04:00
::
++ text (boss 256 (star prn))
2013-11-26 23:28:15 +04:00
--
|%
++ idt
|= from=idad
?: |(!(lien flags |=(a=flag ?=(%noob a))) =("" q.from))
(scow %p p.from)
%- trip
%^ cat 3 %^ cat 3 (scot %p p.from) ' ' q.from
2013-11-26 23:28:15 +04:00
++ rend
|= [from=idad msg=^mess pre=tape tim=@da] :: roo=^room
=+ tst=(lien flags |=(a=flag ?=(%time a)))
2013-11-26 23:28:15 +04:00
^- tank
2014-07-03 02:08:02 +04:00
?- -.msg
%do
=+ mes=?:(=(0 p.msg) "remains quietly present" (trip p.msg))
:- %leaf
%+ weld
?. tst "" (timestamp tim)
"{pre}{(idt from)} {mes}"
%exp
:~ %rose
[" " "" ""]
:- %leaf
%+ weld
?. tst "" (timestamp tim)
"{pre}{(idt from)} {(trip p.msg)}"
q.msg
==
%say
:- %leaf
%+ weld
?. tst "" (timestamp tim)
"{pre}{(idt from)}: {(trip p.msg)}"
2013-11-26 23:28:15 +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)} "
2013-11-26 23:28:15 +04:00
--
2014-07-03 02:08:02 +04:00
::
2013-11-26 23:28:15 +04:00
==
=> %= .
-
:- :* ami=*(map ,@p ,@t) ::
2014-07-03 02:08:02 +04:00
bud=(sein `@p`-<) :: chat server
2013-11-26 23:28:15 +04:00
dun=| :: done
giz=*(list gift) :: stuff to send
mon=*? :: leet mode
nub=*? :: monitor mode
pro=`prom`[%pub ~] :: prompt state
2014-07-03 02:08:02 +04:00
sta=*station :: station
sub=*(list path) :: subscriptions
tod=*(map ,@p ,@ud) :: outstanding, friend
tst=| :: timestamp mode
wak=_@da :: next heartbeat
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)
2014-07-03 02:08:02 +04:00
=. flags args
=. wak est
=. bud
?: (lien args |=(a=flag &(?=(^ a) ?=(%tower -.a))))
(roll args |=([p=flag q=@p] ?:(&(?=(^ p) ?=(%tower -.p)) p.p q)))
2014-05-31 02:41:22 +04:00
bud
=. nub (lien args |=(a=flag ?=(%noob a)))
=. mon (lien args |=(a=flag ?=(%monitor a)))
2014-07-03 02:08:02 +04:00
=. sta
?: (lien args |=(a=flag &(?=(^ a) ?=(%s -.a))))
(roll args |=([p=flag q=station] ?:(&(?=(^ p) ?=(%s -.p)) p.p q)))
2014-07-03 02:08:02 +04:00
sta
=. tst (lien args |=(a=flag ?=(%time a)))
2013-11-26 23:28:15 +04:00
|- ^- bowl
=< abet:init
|%
++ abet `bowl`[(flop giz) ?:(dun ~ [~ hope vent(giz ~)])]
2014-07-03 02:08:02 +04:00
++ hope
:^ [/wa %wa wak]
[/ya %lq %ya]
:^ /up %up %text
:_ ""
?- -.pro
%pub "& "
%pri (weld (scow %p p.pro) " ")
==
%+ welp
(turn sub |=(pax=path [[%gr pax] [%gr ~]]))
%+ turn (~(tap by tod))
|= [p=@p q=@ud]
[[%ra (scot %p p) ~] [%ow ~]]
::
++ iden
|= her=@p
(fall (~(get by ami) her) *@t)
::
2014-08-01 06:44:49 +04:00
++ init
2014-08-02 03:17:24 +04:00
(joke:(subs:(subs:tint (welp sta /amigos)) (welp sta /mensajes)) %hola sta)
::
++ jake
|= [her=@p msg=^mess]
^+ +>
%= +>.$
giz :_(giz [%sq her %ya [%ra (scot %p her) ~] msg])
pro [%pri her]
tod (~(put by tod) her +((fall (~(get by tod) her) 0)))
==
2013-11-26 23:28:15 +04:00
::
++ joke :: send message
2014-08-01 06:44:49 +04:00
|= msg=zung
2013-11-26 23:28:15 +04:00
^+ +>
2014-09-11 03:35:03 +04:00
+>(giz :_(giz [%xz [who %chat ~] who %zung msg]))
2013-11-26 23:28:15 +04:00
::
2014-07-03 02:08:02 +04:00
++ join
|= you=user
2013-11-26 23:28:15 +04:00
^+ +>
?- -.you
%in
=. ami (~(put by ami) p.you)
?. mon +>.$
(show %leaf "{(idt p.you)} comes on the air")
%out
=. ami (~(del by ami) p.p.you)
?. mon +>.$
(show %leaf "{(idt p.you)} signs off")
==
2014-07-03 02:08:02 +04:00
++ joyn
|= yall=(list idad)
^+ +>
=. ami (~(gas by ami) yall)
?. mon +>.$
(shew (turn yall |=(you=idad [%leaf "{(idt you)} is on the air"])))
::
++ nice :: got response
|= [her=@p kay=cape]
^+ +>
=. +>
=+ dyt=(need (~(get by tod) her))
%_ +>.$
tod
?: =(1 dyt)
(~(del by tod) her)
(~(put by tod) her (dec dyt))
==
?- kay
%good +>
%dead (show %leaf "server {(scow %p her)} choked")
==
::
++ priv
|= [now=@da her=@p mes=^mess]
2013-11-26 23:28:15 +04:00
^+ +>
(show (rend [her (iden her)] mes "(private) " now))
2013-11-26 23:28:15 +04:00
::
++ said :: server message
2014-07-03 02:08:02 +04:00
|= duz=(list zong)
2013-11-26 23:28:15 +04:00
^+ +>
?~ duz +>
%= $
duz t.duz
+>
?- -.i.duz
2014-07-08 05:15:53 +04:00
%mess
(show (rend [q.i.duz (iden q.i.duz)] r.i.duz "" p.i.duz))
2014-07-03 02:08:02 +04:00
== ==
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
2014-07-03 02:08:02 +04:00
::
++ subs
|= pax=path
^+ +>
2014-09-11 03:35:03 +04:00
+>(sub [pax sub], giz :_(giz [%zz /g [%gr pax] %show [who %chat ~] who pax]))
2013-11-26 23:28:15 +04:00
::
++ take (joke(wak (add ~m1 (max wak est))) %hola sta) :: beat heart
2014-08-01 06:44:49 +04:00
++ tint (joke %tint bud) :: init local chat
2013-11-26 23:28:15 +04:00
++ toke :: user action
2014-07-03 02:08:02 +04:00
|= [now=@da txt=@t]
2013-11-26 23:28:15 +04:00
^+ +>
2014-05-31 02:41:22 +04:00
?: =(0 txt) +>
2014-08-29 01:30:02 +04:00
=+ rey=(rush txt chat(lat (scot da/est)))
?~ rey
2013-11-26 23:28:15 +04:00
(show %leaf "invalid input")
|-
?- -.u.rey
%all (joke(pro [%pub ~]) %mess sta p.u.rey)
2014-07-03 22:14:22 +04:00
%back (joke %backlog sta p.u.rey q.u.rey)
%def $(u.rey ?-(-.pro %pub [%all p.u.rey], %pri [%priv p.pro p.u.rey]))
2014-08-05 22:35:16 +04:00
%how (shew (turn (lore ^:@/===pub/src/doc/chat/help/txt) |=(a=@t [%leaf (trip a)])))
%priv (jake p.u.rey q.u.rey)
%who
%^ show %rose [", " "" ""]
%+ turn (~(tap by ami))
|= p=idad
:- %leaf
%- trip
%^ cat 3 %^ cat 3 (scot %p p.p) ' ' q.p
2013-11-26 23:28:15 +04:00
==
::
++ vent :: handle event
|= [now=@da pax=path nut=note]
^- bowl
=. est now
=< abet
2014-07-03 02:08:02 +04:00
?+ -.pax ~& [%chat-vent-unknown -.nut] +>.$
%gr ?> ?=(%gr -.nut)
?+ p.nut ~& %chat-vent-logo-fail +>.$
%user (join ((hard user) q.nut))
%users (joyn ((hard (list idad)) q.nut))
2014-08-01 06:44:49 +04:00
%zong =+(zog=((hard zong) q.nut) (said ?:(=(who q.zog) ~ [zog ~])))
2014-08-02 03:17:24 +04:00
%zongs (said (flop ((hard (list zong)) q.nut)))
2014-07-03 02:08:02 +04:00
==
%up ?>(?=(%up -.nut) (toke now p.nut))
%ra ?> &(?=(%ow -.nut) ?=(^ t.pax))
(nice (need (slaw %p i.t.pax)) p.nut)
%wa ?>(?=(%wa -.nut) take)
%ya ?> ?=(%lq -.nut)
=+ n=((soft ^mess) r.nut)
?~ n
~& %chat-mess-fail +>+
(priv now p.nut u.n)
2013-11-26 23:28:15 +04:00
==
--