Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F665836
base.ex
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
4 KB
Subscribers
None
base.ex
View Options
defmodule
Nola.Plugins.Base
do
def
irc_doc
,
do
:
nil
def
start_link
()
do
GenServer
.
start_link
(
__MODULE__
,
[],
name
:
__MODULE__
)
end
def
init
([])
do
regopts
=
[
plugin
:
__MODULE__
]
{
:ok
,
_
}
=
Registry
.
register
(
Nola.PubSub
,
"trigger:version"
,
regopts
)
{
:ok
,
_
}
=
Registry
.
register
(
Nola.PubSub
,
"trigger:help"
,
regopts
)
{
:ok
,
_
}
=
Registry
.
register
(
Nola.PubSub
,
"trigger:liquidrender"
,
regopts
)
{
:ok
,
_
}
=
Registry
.
register
(
Nola.PubSub
,
"trigger:plugin"
,
regopts
)
{
:ok
,
_
}
=
Registry
.
register
(
Nola.PubSub
,
"trigger:plugins"
,
regopts
)
{
:ok
,
nil
}
end
def
handle_info
({
:irc
,
:trigger
,
"plugins"
,
msg
=
%{
trigger
:
%{
type
:
:bang
,
args
:
[]}}},
_
)
do
enabled_string
=
Nola.Plugins
.
enabled
()
|>
Enum
.
map
(
fn
(
mod
)
->
mod
|>
Macro
.
underscore
()
|>
String
.
split
(
"/"
,
parts
:
:infinity
)
|>
List
.
last
()
|>
Enum
.
sort
()
end
)
|>
Enum
.
join
(
", "
)
msg
.
replyfun
.
(
"Enabled plugins:
#{
enabled_string
}
"
)
{
:noreply
,
nil
}
end
def
handle_info
({
:irc
,
:trigger
,
"plugin"
,
%{
trigger
:
%{
type
:
:query
,
args
:
[
plugin
]}}
=
m
},
_
)
do
module
=
Module
.
concat
([
Nola.Plugins
,
Macro
.
camelize
(
plugin
)])
with
true
<-
Code
.
ensure_loaded?
(
module
),
pid
when
is_pid
(
pid
)
<-
GenServer
.
whereis
(
module
)
do
m
.
replyfun
.
(
"loaded, active:
#{
inspect
(
pid
)
}
"
)
else
false
->
m
.
replyfun
.
(
"not loaded"
)
nil
->
msg
=
case
Nola.Plugins
.
get
(
module
)
do
:disabled
->
"disabled"
{
_
,
false
,
_
}
->
"disabled"
_
->
"not active"
end
m
.
replyfun
.
(
msg
)
end
{
:noreply
,
nil
}
end
def
handle_info
({
:irc
,
:trigger
,
"plugin"
,
%{
trigger
:
%{
type
:
:plus
,
args
:
[
plugin
]}}
=
m
},
_
)
do
module
=
Module
.
concat
([
Nola.Plugins
,
Macro
.
camelize
(
plugin
)])
with
true
<-
Code
.
ensure_loaded?
(
module
),
Nola.Plugins
.
switch
(
module
,
true
),
{
:ok
,
pid
}
<-
Nola.Plugins
.
start
(
module
)
do
m
.
replyfun
.
(
"started:
#{
inspect
(
pid
)
}
"
)
else
false
->
m
.
replyfun
.
(
"not loaded"
)
:ignore
->
m
.
replyfun
.
(
"disabled or throttled"
)
{
:error
,
_
}
->
m
.
replyfun
.
(
"start error"
)
end
{
:noreply
,
nil
}
end
def
handle_info
({
:irc
,
:trigger
,
"plugin"
,
%{
trigger
:
%{
type
:
:tilde
,
args
:
[
plugin
]}}
=
m
},
_
)
do
module
=
Module
.
concat
([
Nola.Plugins
,
Macro
.
camelize
(
plugin
)])
with
true
<-
Code
.
ensure_loaded?
(
module
),
pid
when
is_pid
(
pid
)
<-
GenServer
.
whereis
(
module
),
:ok
<-
GenServer
.
stop
(
pid
),
{
:ok
,
pid
}
<-
Nola.Plugins
.
start
(
module
)
do
m
.
replyfun
.
(
"restarted:
#{
inspect
(
pid
)
}
"
)
else
false
->
m
.
replyfun
.
(
"not loaded"
)
nil
->
m
.
replyfun
.
(
"not active"
)
end
{
:noreply
,
nil
}
end
def
handle_info
({
:irc
,
:trigger
,
"plugin"
,
%{
trigger
:
%{
type
:
:minus
,
args
:
[
plugin
]}}
=
m
},
_
)
do
module
=
Module
.
concat
([
Nola.Plugins
,
Macro
.
camelize
(
plugin
)])
with
true
<-
Code
.
ensure_loaded?
(
module
),
pid
when
is_pid
(
pid
)
<-
GenServer
.
whereis
(
module
),
:ok
<-
GenServer
.
stop
(
pid
)
do
Nola.Plugins
.
switch
(
module
,
false
)
m
.
replyfun
.
(
"stopped:
#{
inspect
(
pid
)
}
"
)
else
false
->
m
.
replyfun
.
(
"not loaded"
)
nil
->
m
.
replyfun
.
(
"not active"
)
end
{
:noreply
,
nil
}
end
def
handle_info
({
:irc
,
:trigger
,
"liquidrender"
,
m
=
%{
trigger
:
%{
args
:
args
}}},
_
)
do
template
=
Enum
.
join
(
args
,
" "
)
m
.
replyfun
.
(
Tmpl
.
render
(
template
,
m
))
{
:noreply
,
nil
}
end
def
handle_info
({
:irc
,
:trigger
,
"help"
,
m
=
%{
trigger
:
%{
type
:
:bang
}}},
_
)
do
url
=
NolaWeb.Router.Helpers
.
irc_url
(
NolaWeb.Endpoint
,
:index
,
m
.
network
,
NolaWeb
.
format_chan
(
m
.
channel
))
m
.
replyfun
.
(
"->
#{
url
}
"
)
{
:noreply
,
nil
}
end
def
handle_info
({
:irc
,
:trigger
,
"version"
,
message
=
%{
trigger
:
%{
type
:
:bang
}}},
_
)
do
{
:ok
,
vsn
}
=
:application
.
get_key
(
:nola
,
:vsn
)
ver
=
List
.
to_string
(
vsn
)
url
=
NolaWeb.Router.Helpers
.
irc_url
(
NolaWeb.Endpoint
,
:index
)
elixir_ver
=
Application
.
started_applications
()
|>
List
.
keyfind
(
:elixir
,
0
)
|>
elem
(
2
)
|>
to_string
()
otp_ver
=
:erlang
.
system_info
(
:system_version
)
|>
to_string
()
|>
String
.
trim
()
system
=
:erlang
.
system_info
(
:system_architecture
)
|>
to_string
()
brand
=
Nola
.
brand
(
:name
)
owner
=
"
#{
Nola
.
brand
(
:owner
)
}
<
#{
Nola
.
brand
(
:owner_email
)
}
>"
message
.
replyfun
.
([
<<
"🤖 I am a robot running"
,
2
,
"
#{
brand
}
, version
#{
ver
}
"
,
2
,
" — source:
#{
Nola
.
source_url
()
}
"
>>,
"🦾 Elixir
#{
elixir_ver
}
#{
otp_ver
}
on
#{
system
}
"
,
"👷♀️ Owner: h
#{
owner
}
"
,
"🌍 Web interface:
#{
url
}
"
])
{
:noreply
,
nil
}
end
def
handle_info
(
msg
,
_
)
do
{
:noreply
,
nil
}
end
end
File Metadata
Details
Attached
Mime Type
text/x-ruby
Expires
Sat, Feb 28, 9:09 AM (1 d, 14 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
87439
Default Alt Text
base.ex (4 KB)
Attached To
rNOLA Nola
Event Timeline
Log In to Comment