25
1
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:
Badlop 2024-11-25 13:07:42 +01:00
parent f9cecca362
commit 6790ab01e8
3 changed files with 28 additions and 29 deletions

View File

@ -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

View File

@ -1,22 +1,27 @@
defmodule ModAuthExample do
defmodule Ejabberd.Auth.Example do
@moduledoc """
Example ejabberd auth method written in Elixir.
This is a dummy auth module to demonstrate the usage of Elixir to
create Ejabberd Auth modules.
This is an example to demonstrate the usage of Elixir to
create ejabberd auth methods.
Example configuration:
auth_method: 'Ejabberd.Auth.Example'
"""
import Ejabberd.Logger
@behaviour :ejabberd_auth
import Ejabberd.Logger
@impl true
def start(host) do
info("Using mod_auth_example to authenticate #{host} users")
info("Starting Ejabberd.Auth.Example to authenticate '#{host}' users")
nil
end
@impl true
def stop(host) do
info("Stop using mod_auth_example to authenticate #{host} users")
info("Stopping Ejabberd.Auth.Example to authenticate '#{host}' users")
nil
end

View File

@ -1,14 +1,27 @@
defmodule ModPresenceDemo do
use Ejabberd.Module
defmodule Ejabberd.Module.Example do
@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
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)
:ok
end
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)
:ok
end