2018-05-09 04:39:16 +00:00
|
|
|
// This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
// License, version 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
|
2018-04-29 21:26:14 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <time.h>
|
2018-05-01 10:23:37 +00:00
|
|
|
#include <libwebsockets.h>
|
2018-05-02 07:11:57 +00:00
|
|
|
#include <json.h>
|
2018-04-29 21:26:14 +00:00
|
|
|
|
|
|
|
#include "weechat-plugin.h"
|
|
|
|
#include "slack.h"
|
|
|
|
#include "slack-config.h"
|
|
|
|
#include "slack-command.h"
|
2018-05-01 10:23:37 +00:00
|
|
|
#include "slack-workspace.h"
|
2018-05-02 07:11:57 +00:00
|
|
|
#include "slack-api.h"
|
2018-05-06 00:09:58 +00:00
|
|
|
#include "slack-buffer.h"
|
2018-04-29 21:26:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
WEECHAT_PLUGIN_NAME(SLACK_PLUGIN_NAME);
|
|
|
|
WEECHAT_PLUGIN_DESCRIPTION(N_("Slack (slack.com) protocol"));
|
|
|
|
WEECHAT_PLUGIN_AUTHOR("Tony Olagbaiye <frony0@gmail.com>");
|
|
|
|
WEECHAT_PLUGIN_VERSION(SLACK_PLUGIN_VERSION);
|
|
|
|
WEECHAT_PLUGIN_LICENSE("MPL2");
|
2018-05-02 07:11:57 +00:00
|
|
|
WEECHAT_PLUGIN_PRIORITY(5500);
|
2018-04-29 21:26:14 +00:00
|
|
|
|
|
|
|
struct t_weechat_plugin *weechat_slack_plugin = NULL;
|
|
|
|
|
2018-05-01 10:23:37 +00:00
|
|
|
struct t_hook *slack_hook_timer = NULL;
|
|
|
|
|
2018-05-06 00:09:58 +00:00
|
|
|
struct t_gui_bar_item *slack_typing_bar_item = NULL;
|
|
|
|
|
2018-05-01 10:23:37 +00:00
|
|
|
void slack_lwsl_emit_weechat(int level, const char *line)
|
|
|
|
{
|
|
|
|
char buf[50];
|
|
|
|
lwsl_timestamp(level, buf, sizeof(buf));
|
|
|
|
|
|
|
|
weechat_printf(
|
|
|
|
NULL,
|
|
|
|
_("%s%s: %s%s"),
|
|
|
|
weechat_prefix("error"), SLACK_PLUGIN_NAME,
|
|
|
|
buf, line);
|
|
|
|
}
|
|
|
|
|
2018-04-29 21:26:14 +00:00
|
|
|
int weechat_plugin_init(struct t_weechat_plugin *plugin, int argc, char *argv[])
|
|
|
|
{
|
|
|
|
(void) argc;
|
|
|
|
(void) argv;
|
|
|
|
|
|
|
|
weechat_plugin = plugin;
|
|
|
|
|
2018-05-07 17:08:34 +00:00
|
|
|
lws_set_log_level(LLL_ERR | LLL_WARN | LLL_NOTICE /*| LLL_INFO | LLL_DEBUG
|
2018-05-01 10:23:37 +00:00
|
|
|
| LLL_PARSER | LLL_HEADER | LLL_EXT | LLL_CLIENT
|
2018-05-07 17:08:34 +00:00
|
|
|
| LLL_LATENCY | LLL_USER | LLL_COUNT*/,
|
2018-05-01 10:23:37 +00:00
|
|
|
slack_lwsl_emit_weechat);
|
|
|
|
|
2018-04-29 21:26:14 +00:00
|
|
|
if (!slack_config_init())
|
|
|
|
return WEECHAT_RC_ERROR;
|
|
|
|
|
|
|
|
slack_config_read();
|
|
|
|
|
|
|
|
slack_command_init();
|
|
|
|
|
2018-05-02 07:11:57 +00:00
|
|
|
slack_api_init();
|
|
|
|
|
2018-05-04 00:31:06 +00:00
|
|
|
slack_hook_timer = weechat_hook_timer(0.1 * 1000, 0, 0,
|
2018-05-01 10:23:37 +00:00
|
|
|
&slack_workspace_timer_cb,
|
|
|
|
NULL, NULL);
|
|
|
|
|
2018-05-06 00:09:58 +00:00
|
|
|
if (!weechat_bar_search("typing"))
|
|
|
|
{
|
|
|
|
weechat_bar_new("typing", "off", "400", "window", "${typing}",
|
|
|
|
"bottom", "horizontal", "vertical",
|
|
|
|
"1", "1", "default", "default", "default",
|
|
|
|
"off", "slack_typing");
|
|
|
|
}
|
|
|
|
|
|
|
|
slack_typing_bar_item = weechat_bar_item_new("slack_typing",
|
|
|
|
&slack_buffer_typing_bar_cb,
|
|
|
|
NULL, NULL);
|
|
|
|
|
2018-04-29 21:26:14 +00:00
|
|
|
return WEECHAT_RC_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
int weechat_plugin_end(struct t_weechat_plugin *plugin)
|
|
|
|
{
|
|
|
|
/* make C compiler happy */
|
|
|
|
(void) plugin;
|
|
|
|
|
2018-05-06 00:09:58 +00:00
|
|
|
if (slack_typing_bar_item)
|
|
|
|
weechat_bar_item_remove(slack_typing_bar_item);
|
|
|
|
|
2018-05-01 10:23:37 +00:00
|
|
|
if (slack_hook_timer)
|
|
|
|
weechat_unhook(slack_hook_timer);
|
|
|
|
|
|
|
|
slack_config_write();
|
|
|
|
|
|
|
|
slack_workspace_disconnect_all();
|
|
|
|
|
|
|
|
slack_workspace_free_all();
|
|
|
|
|
2018-04-29 21:26:14 +00:00
|
|
|
return WEECHAT_RC_OK;
|
|
|
|
}
|