Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F77393
buffer.ex
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
1 KB
Subscribers
None
buffer.ex
View Options
defmodule
Nola.Plugins.Buffer
do
@table
__MODULE__
.
ETS
def
irc_doc
,
do
:
nil
def
table
(),
do
:
@table
def
select_buffer
(
network
,
channel
,
limit
\\
50
)
do
import
Ex2ms
spec
=
fun
do
{{
n
,
c
,
_
},
m
}
when
n
==
^
network
and
(
c
==
^
channel
or
is_nil
(
c
))
->
m
end
:ets
.
select
(
@table
,
spec
,
limit
)
end
def
start_link
()
do
GenServer
.
start_link
(
__MODULE__
,
[],
name
:
__MODULE__
)
end
def
init
(
_
)
do
for
e
<-
~w(messages triggers events outputs)
do
{
:ok
,
_
}
=
Registry
.
register
(
Nola.PubSub
,
e
,
plugin
:
__MODULE__
)
end
{
:ok
,
:ets
.
new
(
@table
,
[
:named_table
,
:ordered_set
,
:protected
])}
end
def
handle_info
({
:irc
,
:trigger
,
_
,
message
},
ets
),
do
:
handle_message
(
message
,
ets
)
def
handle_info
({
:irc
,
:text
,
message
},
ets
),
do
:
handle_message
(
message
,
ets
)
def
handle_info
({
:irc
,
:event
,
event
},
ets
),
do
:
handle_message
(
event
,
ets
)
defp
handle_message
(
message
=
%{
network
:
network
},
ets
)
do
key
=
{
network
,
Map
.
get
(
message
,
:channel
),
ts
(
message
.
at
)}
:ets
.
insert
(
ets
,
{
key
,
message
})
{
:noreply
,
ets
}
end
defp
ts
(
nil
),
do
:
ts
(
NaiveDateTime
.
utc_now
())
defp
ts
(
naive
=
%
NaiveDateTime
{})
do
ts
=
naive
|>
DateTime
.
from_naive!
(
"Etc/UTC"
)
|>
DateTime
.
to_unix
()
-
ts
end
end
File Metadata
Details
Attached
Mime Type
text/x-ruby
Expires
Mon, Jul 7, 9:35 AM (1 d, 17 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
49884
Default Alt Text
buffer.ex (1 KB)
Attached To
rNOLA Nola
Event Timeline
Log In to Comment