From 6790ab01e8c8885820b04350485f6344c4a635f8 Mon Sep 17 00:00:00 2001 From: Badlop Date: Mon, 25 Nov 2024 13:07:42 +0100 Subject: [PATCH] Improve example Elixir modules --- lib/ejabberd/module.ex | 19 ------------------- lib/ejabberd_auth_example.ex | 17 +++++++++++------ lib/mod_example.ex | 21 +++++++++++++++++---- 3 files changed, 28 insertions(+), 29 deletions(-) delete mode 100644 lib/ejabberd/module.ex diff --git a/lib/ejabberd/module.ex b/lib/ejabberd/module.ex deleted file mode 100644 index 9fb3f040c..000000000 --- a/lib/ejabberd/module.ex +++ /dev/null @@ -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 diff --git a/lib/ejabberd_auth_example.ex b/lib/ejabberd_auth_example.ex index 2198b0e4d..5bc37e093 100644 --- a/lib/ejabberd_auth_example.ex +++ b/lib/ejabberd_auth_example.ex @@ -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 diff --git a/lib/mod_example.ex b/lib/mod_example.ex index c5be5bba5..12166810a 100644 --- a/lib/mod_example.ex +++ b/lib/mod_example.ex @@ -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