Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F665835
calc_plugin.ex
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
940 B
Subscribers
None
calc_plugin.ex
View Options
defmodule
LSG.IRC.CalcPlugin
do
@moduledoc
"""
#
calc
* **!calc `<expression>`**: évalue l'expression mathématique `<expression>`.
"""
def
irc_doc
,
do
:
@moduledoc
def
start_link
()
do
GenServer
.
start_link
(
__MODULE__
,
[],
name
:
__MODULE__
)
end
def
init
(
_
)
do
{
:ok
,
_
}
=
Registry
.
register
(
IRC.PubSub
,
"trigger:calc"
,
[
plugin
:
__MODULE__
])
{
:ok
,
nil
}
end
def
handle_info
({
:irc
,
:trigger
,
"calc"
,
message
=
%
IRC.Message
{
trigger
:
%
IRC.Trigger
{
type
:
:bang
,
args
:
expr_list
}}},
state
)
do
expr
=
Enum
.
join
(
expr_list
,
" "
)
result
=
try
do
case
Abacus
.
eval
(
expr
)
do
{
:ok
,
result
}
->
result
error
->
inspect
(
error
)
end
rescue
error
->
if
(
error
[
:message
],
do
:
"
#{
error
.
message
}
"
,
else
:
"erreur"
)
end
message
.
replyfun
.
(
"
#{
message
.
sender
.
nick
}
:
#{
expr
}
=
#{
result
}
"
)
{
:noreply
,
state
}
end
def
handle_info
(
msg
,
state
)
do
{
:noreply
,
state
}
end
end
File Metadata
Details
Attached
Mime Type
text/x-ruby
Expires
Sat, Feb 28, 9:08 AM (1 d, 12 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
87196
Default Alt Text
calc_plugin.ex (940 B)
Attached To
rNOLA Nola
Event Timeline
Log In to Comment