Skip to content

Commit

Permalink
Add dummy example module for muc_log hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
badlop committed May 7, 2024
1 parent 5262975 commit 0080c8e
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions src/mod_muc_log_console.erl
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
-module(mod_muc_log_console).

-behaviour(gen_mod).

%% API
-export([start/2, stop/1, get_url/2,
check_access_log/3, add_to_log/5]).

-export([mod_options/1, depends/2, mod_doc/0]).

-include("logger.hrl").
-include_lib("xmpp/include/xmpp.hrl").
-include("mod_muc_room.hrl").
-include("translate.hrl").

%%====================================================================
%% API
%%====================================================================
start(Host, _Opts) ->
ejabberd_hooks:add(muc_log_add, Host, ?MODULE, add_to_log, 70),
ejabberd_hooks:add(muc_log_check_access_log, Host, ?MODULE, check_access_log, 70),
ejabberd_hooks:add(muc_log_get_url, Host, ?MODULE, get_url, 70),
ok.

stop(Host) ->
ejabberd_hooks:delete(muc_log_add, Host, ?MODULE, add_to_log, 70),
ejabberd_hooks:delete(muc_log_check_access_log, Host, ?MODULE, check_access_log, 70),
ejabberd_hooks:delete(muc_log_get_url, Host, ?MODULE, get_url, 70),
gen_mod:stop_child(?MODULE, Host).

add_to_log(_Host, _Type, Data, Room, _Opts) ->
?INFO_MSG("MUC Console Logging: add to log~n Data: ~p~n Room: ~p", [Data, Room]),
ok.

check_access_log(Acc, Host, From) ->
?INFO_MSG("MUC Console Logging: check access log for Host ~s and From ~s", [Host, jid:encode(From)]),
Acc.

get_url(Acc, #state{room = Room, host = Host, server_host = _ServerHost}) ->
?INFO_MSG("MUC Console Logging: get url of room ~s@~s", [Room, Host]),
Acc.

depends(_Host, _Opts) ->
[{mod_muc, hard}].

mod_options(_) ->
[].

mod_doc() ->
#{desc =>
[?T("Example module.")]}.

0 comments on commit 0080c8e

Please sign in to comment.