Skip to content

Commit

Permalink
notifications support for channels
Browse files Browse the repository at this point in the history
  • Loading branch information
0xAX committed Apr 27, 2013
1 parent 5c48f2f commit e7de105
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 4 deletions.
1 change: 1 addition & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
* Notification support.
* Added channels concept. Write only transports.
* Twitter channel added.
* Notification support for channels.

## Ybot-0.3.3 --> released

Expand Down
4 changes: 2 additions & 2 deletions src/channel/twitter/ybot_twitter_client.erl
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ start_link(Consumer, ConsumerSecret, AccessToken, AccessTokenSecret) ->
-spec send_message(TwitterClient :: pid(), Messsage :: string()) -> ok.
send_message(TwitterClient, Messsage) ->
% send message
gen_server:cast(TwitterClient, {send_message, Messsage}).
gen_server:cast(TwitterClient, {send_message, "", Messsage}).

init([Consumer, ConsumerSecret, AccessToken, AccessTokenSecret]) ->
% init interanal state
Expand All @@ -47,7 +47,7 @@ init([Consumer, ConsumerSecret, AccessToken, AccessTokenSecret]) ->
handle_call(_Request, _From, State) ->
{reply, ignored, State}.

handle_cast({send_message, Messsage}, State) ->
handle_cast({send_message, _From, Messsage}, State) ->
Consumer = {binary_to_list(State#state.consumer, binary_to_list(State#state.consumer_secret), hmac_sha1)},
% update twitter status
oauth:post("https://api.twitter.com/1/statuses/update.json", [{"status", Messsage}], Consumer,
Expand Down
4 changes: 4 additions & 0 deletions src/ybot_manager.erl
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ handle_call({get_plugin, PluginName}, _From, State) ->
handle_call(get_transports, _From, State) ->
{reply, State#state.transports, State};

%% @doc get channels info
handle_call(get_channels, _From, State) ->
{reply, State#state.channels, State};

%% @doc get all runned transports pid
handle_call(get_runnned_transports, _From, State) ->
% Return all runned transports
Expand Down
17 changes: 16 additions & 1 deletion src/ybot_notification_handler.erl
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,21 @@ handle_cast({init_handler, {PluginName, TranportsList, Timeout}, NotificationDir
end
end,
gen_server:call(ybot_manager, get_transports))),

% Get necessary channels
Channels = lists:flatten(lists:map(fun(Channel) ->
% Check is notification for this channel or not
IsChannel = lists:member(element(1, Channel), TranportsList),
case IsChannel of
true ->
element(2, Channel);
false ->
[]
end
end,
gen_server:call(ybot_manager, get_channels))),
% Make transports list
Transports = lists:append(RunnedTransports, Channels),
% Get plugin file with extension
[PluginWithExt | _] = filelib:wildcard(atom_to_list(PluginName) ++ "*", NotificationDir),
% Get lang
Expand All @@ -65,7 +80,7 @@ handle_cast({init_handler, {PluginName, TranportsList, Timeout}, NotificationDir
% start notifications
erlang:send_after(Timeout * 1000, self(), execute),
% return
{noreply, State#state{transports = RunnedTransports, lang = Lang, timeout = Timeout * 1000, plugin_path = PluginPath}};
{noreply, State#state{transports = Transports, lang = Lang, timeout = Timeout * 1000, plugin_path = PluginPath}};

handle_cast(_Msg, State) ->
{noreply, State}.
Expand Down
2 changes: 1 addition & 1 deletion ybot.config
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@
%
{notification,
[ % {plugin name :: atom(), [transport list :: atom()], timeout_in_seconds :: integer()}
{ackbar, [irc], 60}
{ackbar, [irc, twitter], 60}
]
},

Expand Down

0 comments on commit e7de105

Please sign in to comment.