mirror of
https://github.com/processone/ejabberd.git
synced 2024-12-02 16:37:52 +01:00
Improve example Elixir modules
This commit is contained in:
parent
f9cecca362
commit
6790ab01e8
@ -1,19 +0,0 @@
|
|||||||
defmodule Ejabberd.Module do
|
|
||||||
|
|
||||||
defmacro __using__(opts) do
|
|
||||||
logger_enabled = Keyword.get(opts, :logger, true)
|
|
||||||
|
|
||||||
quote do
|
|
||||||
@behaviour :gen_mod
|
|
||||||
import Ejabberd.Module
|
|
||||||
|
|
||||||
unquote(if logger_enabled do
|
|
||||||
quote do: import Ejabberd.Logger
|
|
||||||
end)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
# gen_mod callbacks
|
|
||||||
def depends(_host, _opts), do: []
|
|
||||||
def mod_opt_type(_), do: []
|
|
||||||
end
|
|
@ -1,22 +1,27 @@
|
|||||||
defmodule ModAuthExample do
|
defmodule Ejabberd.Auth.Example do
|
||||||
|
|
||||||
@moduledoc """
|
@moduledoc """
|
||||||
|
Example ejabberd auth method written in Elixir.
|
||||||
|
|
||||||
This is a dummy auth module to demonstrate the usage of Elixir to
|
This is an example to demonstrate the usage of Elixir to
|
||||||
create Ejabberd Auth modules.
|
create ejabberd auth methods.
|
||||||
|
|
||||||
|
Example configuration:
|
||||||
|
auth_method: 'Ejabberd.Auth.Example'
|
||||||
"""
|
"""
|
||||||
import Ejabberd.Logger
|
|
||||||
@behaviour :ejabberd_auth
|
@behaviour :ejabberd_auth
|
||||||
|
import Ejabberd.Logger
|
||||||
|
|
||||||
@impl true
|
@impl true
|
||||||
def start(host) do
|
def start(host) do
|
||||||
info("Using mod_auth_example to authenticate #{host} users")
|
info("Starting Ejabberd.Auth.Example to authenticate '#{host}' users")
|
||||||
nil
|
nil
|
||||||
end
|
end
|
||||||
|
|
||||||
@impl true
|
@impl true
|
||||||
def stop(host) do
|
def stop(host) do
|
||||||
info("Stop using mod_auth_example to authenticate #{host} users")
|
info("Stopping Ejabberd.Auth.Example to authenticate '#{host}' users")
|
||||||
nil
|
nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -1,14 +1,27 @@
|
|||||||
defmodule ModPresenceDemo do
|
defmodule Ejabberd.Module.Example do
|
||||||
use Ejabberd.Module
|
|
||||||
|
@moduledoc """
|
||||||
|
Example ejabberd module written in Elixir.
|
||||||
|
|
||||||
|
This is an example to demonstrate the usage of Elixir to
|
||||||
|
create ejabberd modules.
|
||||||
|
|
||||||
|
Example configuration:
|
||||||
|
modules:
|
||||||
|
'Ejabberd.Module.Example': {}
|
||||||
|
"""
|
||||||
|
|
||||||
|
@behaviour :gen_mod
|
||||||
|
import Ejabberd.Logger
|
||||||
|
|
||||||
def start(host, _opts) do
|
def start(host, _opts) do
|
||||||
info("Starting ejabberd module Presence Demo")
|
info("Starting Ejabberd.Module.Example for host '#{host}'")
|
||||||
Ejabberd.Hooks.add(:set_presence_hook, host, __MODULE__, :on_presence, 50)
|
Ejabberd.Hooks.add(:set_presence_hook, host, __MODULE__, :on_presence, 50)
|
||||||
:ok
|
:ok
|
||||||
end
|
end
|
||||||
|
|
||||||
def stop(host) do
|
def stop(host) do
|
||||||
info("Stopping ejabberd module Presence Demo")
|
info("Stopping Ejabberd.Module.Example for host '#{host}'")
|
||||||
Ejabberd.Hooks.delete(:set_presence_hook, host, __MODULE__, :on_presence, 50)
|
Ejabberd.Hooks.delete(:set_presence_hook, host, __MODULE__, :on_presence, 50)
|
||||||
:ok
|
:ok
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user