|
|
@ -2,32 +2,33 @@
|
|
|
|
// License, version 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
// 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/.
|
|
|
|
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
|
|
|
|
|
|
|
|
#include <libwebsockets.h>
|
|
|
|
#include <strophe.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include <weechat/weechat-plugin.h>
|
|
|
|
#include "weechat-plugin.h"
|
|
|
|
|
|
|
|
#include "slack.h"
|
|
|
|
#include "xmpp.h"
|
|
|
|
#include "slack-oauth.h"
|
|
|
|
//#include "xmpp-oauth.h"
|
|
|
|
#include "slack-teaminfo.h"
|
|
|
|
//#include "xmpp-teaminfo.h"
|
|
|
|
#include "slack-workspace.h"
|
|
|
|
//#include "xmpp-workspace.h"
|
|
|
|
#include "slack-channel.h"
|
|
|
|
//#include "xmpp-channel.h"
|
|
|
|
#include "slack-buffer.h"
|
|
|
|
//#include "xmpp-buffer.h"
|
|
|
|
#include "slack-message.h"
|
|
|
|
//#include "xmpp-message.h"
|
|
|
|
#include "slack-command.h"
|
|
|
|
#include "xmpp-command.h"
|
|
|
|
#include "request/slack-request-chat-memessage.h"
|
|
|
|
//#include "request/xmpp-request-chat-memessage.h"
|
|
|
|
|
|
|
|
|
|
|
|
void slack_command_display_workspace(struct t_slack_workspace *workspace)
|
|
|
|
/*
|
|
|
|
|
|
|
|
void xmpp_command_display_workspace(xmpp_conn_t *workspace)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
int num_channels, num_pv;
|
|
|
|
int num_channels, num_pv;
|
|
|
|
|
|
|
|
|
|
|
|
if (workspace->is_connected)
|
|
|
|
if (workspace->is_connected)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
num_channels = 0;//slack_workspace_get_channel_count(workspace);
|
|
|
|
num_channels = 0;//xmpp_workspace_get_channel_count(workspace);
|
|
|
|
num_pv = 0;//slack_workspace_get_pv_count(workspace);
|
|
|
|
num_pv = 0;//xmpp_workspace_get_pv_count(workspace);
|
|
|
|
weechat_printf(
|
|
|
|
weechat_printf(
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
" %s %s%s%s.slack.com %s(%s%s%s) [%s%s%s]%s, %d %s, %d pv",
|
|
|
|
" %s %s%s%s.xmpp.com %s(%s%s%s) [%s%s%s]%s, %d %s, %d pv",
|
|
|
|
(workspace->is_connected) ? "*" : " ",
|
|
|
|
(workspace->is_connected) ? "*" : " ",
|
|
|
|
weechat_color("chat_server"),
|
|
|
|
weechat_color("chat_server"),
|
|
|
|
workspace->domain,
|
|
|
|
workspace->domain,
|
|
|
@ -50,7 +51,7 @@ void slack_command_display_workspace(struct t_slack_workspace *workspace)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
weechat_printf(
|
|
|
|
weechat_printf(
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
" %s%s%s.slack.com %s(%s%s%s)%s",
|
|
|
|
" %s%s%s.xmpp.com %s(%s%s%s)%s",
|
|
|
|
weechat_color("chat_server"),
|
|
|
|
weechat_color("chat_server"),
|
|
|
|
workspace->domain,
|
|
|
|
workspace->domain,
|
|
|
|
weechat_color("reset"),
|
|
|
|
weechat_color("reset"),
|
|
|
@ -63,10 +64,10 @@ void slack_command_display_workspace(struct t_slack_workspace *workspace)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void slack_command_workspace_list(int argc, char **argv)
|
|
|
|
void xmpp_command_workspace_list(int argc, char **argv)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
int i, one_workspace_found;
|
|
|
|
int i, one_workspace_found;
|
|
|
|
struct t_slack_workspace *ptr_workspace2;
|
|
|
|
xmpp_conn_t *ptr_workspace2;
|
|
|
|
char *workspace_name = NULL;
|
|
|
|
char *workspace_name = NULL;
|
|
|
|
|
|
|
|
|
|
|
|
for (i = 2; i < argc; i++)
|
|
|
|
for (i = 2; i < argc; i++)
|
|
|
@ -76,14 +77,14 @@ void slack_command_workspace_list(int argc, char **argv)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!workspace_name)
|
|
|
|
if (!workspace_name)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (slack_workspaces)
|
|
|
|
if (xmpp_workspaces)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
weechat_printf(NULL, "");
|
|
|
|
weechat_printf(NULL, "");
|
|
|
|
weechat_printf(NULL, _("All workspaces:"));
|
|
|
|
weechat_printf(NULL, _("All workspaces:"));
|
|
|
|
for (ptr_workspace2 = slack_workspaces; ptr_workspace2;
|
|
|
|
for (ptr_workspace2 = xmpp_workspaces; ptr_workspace2;
|
|
|
|
ptr_workspace2 = ptr_workspace2->next_workspace)
|
|
|
|
ptr_workspace2 = ptr_workspace2->next_workspace)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
slack_command_display_workspace(ptr_workspace2);
|
|
|
|
xmpp_command_display_workspace(ptr_workspace2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
else
|
|
|
@ -92,7 +93,7 @@ void slack_command_workspace_list(int argc, char **argv)
|
|
|
|
else
|
|
|
|
else
|
|
|
|
{
|
|
|
|
{
|
|
|
|
one_workspace_found = 0;
|
|
|
|
one_workspace_found = 0;
|
|
|
|
for (ptr_workspace2 = slack_workspaces; ptr_workspace2;
|
|
|
|
for (ptr_workspace2 = xmpp_workspaces; ptr_workspace2;
|
|
|
|
ptr_workspace2 = ptr_workspace2->next_workspace)
|
|
|
|
ptr_workspace2 = ptr_workspace2->next_workspace)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (weechat_strcasestr(ptr_workspace2->name, workspace_name))
|
|
|
|
if (weechat_strcasestr(ptr_workspace2->name, workspace_name))
|
|
|
@ -105,7 +106,7 @@ void slack_command_workspace_list(int argc, char **argv)
|
|
|
|
workspace_name);
|
|
|
|
workspace_name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
one_workspace_found = 1;
|
|
|
|
one_workspace_found = 1;
|
|
|
|
slack_command_display_workspace(ptr_workspace2);
|
|
|
|
xmpp_command_display_workspace(ptr_workspace2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!one_workspace_found)
|
|
|
|
if (!one_workspace_found)
|
|
|
@ -115,40 +116,40 @@ void slack_command_workspace_list(int argc, char **argv)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void slack_command_add_workspace(struct t_slack_teaminfo *slack_teaminfo)
|
|
|
|
void xmpp_command_add_workspace(struct t_xmpp_teaminfo *xmpp_teaminfo)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
struct t_slack_workspace *workspace;
|
|
|
|
xmpp_conn_t *workspace;
|
|
|
|
|
|
|
|
|
|
|
|
workspace = slack_workspace_casesearch(slack_teaminfo->domain);
|
|
|
|
workspace = xmpp_workspace_casesearch(xmpp_teaminfo->domain);
|
|
|
|
if (workspace)
|
|
|
|
if (workspace)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
weechat_printf(
|
|
|
|
weechat_printf(
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
_("%s%s: workspace \"%s\" already exists, can't add it!"),
|
|
|
|
_("%s%s: workspace \"%s\" already exists, can't add it!"),
|
|
|
|
weechat_prefix("error"), SLACK_PLUGIN_NAME,
|
|
|
|
weechat_prefix("error"), XMPP_PLUGIN_NAME,
|
|
|
|
slack_teaminfo->domain);
|
|
|
|
xmpp_teaminfo->domain);
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
workspace = slack_workspace_alloc(slack_teaminfo->domain);
|
|
|
|
workspace = xmpp_workspace_alloc(xmpp_teaminfo->domain);
|
|
|
|
if (!workspace)
|
|
|
|
if (!workspace)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
weechat_printf(
|
|
|
|
weechat_printf(
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
_("%s%s: unable to add workspace"),
|
|
|
|
_("%s%s: unable to add workspace"),
|
|
|
|
weechat_prefix("error"), SLACK_PLUGIN_NAME);
|
|
|
|
weechat_prefix("error"), XMPP_PLUGIN_NAME);
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
workspace->id = strdup(slack_teaminfo->id);
|
|
|
|
workspace->id = strdup(xmpp_teaminfo->id);
|
|
|
|
workspace->name = strdup(slack_teaminfo->name);
|
|
|
|
workspace->name = strdup(xmpp_teaminfo->name);
|
|
|
|
weechat_config_option_set(workspace->options[SLACK_WORKSPACE_OPTION_TOKEN],
|
|
|
|
weechat_config_option_set(workspace->options[XMPP_WORKSPACE_OPTION_TOKEN],
|
|
|
|
slack_teaminfo->token, 1);
|
|
|
|
xmpp_teaminfo->token, 1);
|
|
|
|
|
|
|
|
|
|
|
|
weechat_printf (
|
|
|
|
weechat_printf (
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
_("%s: workspace %s%s%s.slack.com %s(%s%s%s)%s added"),
|
|
|
|
_("%s: workspace %s%s%s.xmpp.com %s(%s%s%s)%s added"),
|
|
|
|
SLACK_PLUGIN_NAME,
|
|
|
|
XMPP_PLUGIN_NAME,
|
|
|
|
weechat_color("chat_server"),
|
|
|
|
weechat_color("chat_server"),
|
|
|
|
workspace->domain,
|
|
|
|
workspace->domain,
|
|
|
|
weechat_color("reset"),
|
|
|
|
weechat_color("reset"),
|
|
|
@ -158,17 +159,17 @@ void slack_command_add_workspace(struct t_slack_teaminfo *slack_teaminfo)
|
|
|
|
weechat_color("chat_delimiters"),
|
|
|
|
weechat_color("chat_delimiters"),
|
|
|
|
weechat_color("reset"));
|
|
|
|
weechat_color("reset"));
|
|
|
|
|
|
|
|
|
|
|
|
free_teaminfo(slack_teaminfo);
|
|
|
|
free_teaminfo(xmpp_teaminfo);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void slack_command_fetch_workspace(char *token)
|
|
|
|
void xmpp_command_fetch_workspace(char *token)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
slack_teaminfo_fetch(token, &slack_command_add_workspace);
|
|
|
|
xmpp_teaminfo_fetch(token, &xmpp_command_add_workspace);
|
|
|
|
|
|
|
|
|
|
|
|
free(token);
|
|
|
|
free(token);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void slack_command_workspace_register(int argc, char **argv)
|
|
|
|
void xmpp_command_workspace_register(int argc, char **argv)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
char *code;
|
|
|
|
char *code;
|
|
|
|
|
|
|
|
|
|
|
@ -178,27 +179,27 @@ void slack_command_workspace_register(int argc, char **argv)
|
|
|
|
|
|
|
|
|
|
|
|
if (strncmp("xoxp", code, 4) == 0)
|
|
|
|
if (strncmp("xoxp", code, 4) == 0)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
slack_command_fetch_workspace(strdup(code));
|
|
|
|
xmpp_command_fetch_workspace(strdup(code));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
else
|
|
|
|
{
|
|
|
|
{
|
|
|
|
slack_oauth_request_token(code, &slack_command_fetch_workspace);
|
|
|
|
xmpp_oauth_request_token(code, &xmpp_command_fetch_workspace);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
else
|
|
|
|
{
|
|
|
|
{
|
|
|
|
weechat_printf(NULL,
|
|
|
|
weechat_printf(NULL,
|
|
|
|
_("\n#### Retrieving a Slack token via OAUTH ####\n"
|
|
|
|
_("\n#### Retrieving a Xmpp token via OAUTH ####\n"
|
|
|
|
"1) Paste this into a browser: https://slack.com/oauth/authorize?client_id=%s&scope=client\n"
|
|
|
|
"1) Paste this into a browser: https://xmpp.com/oauth/authorize?client_id=%s&scope=client\n"
|
|
|
|
"2) Select the team you wish to access from weechat in your browser.\n"
|
|
|
|
"2) Select the team you wish to access from weechat in your browser.\n"
|
|
|
|
"3) Click \"Authorize\" in the browser **IMPORTANT: the redirect will fail, this is expected**\n"
|
|
|
|
"3) Click \"Authorize\" in the browser **IMPORTANT: the redirect will fail, this is expected**\n"
|
|
|
|
"4) Copy the \"code\" portion of the URL to your clipboard\n"
|
|
|
|
"4) Copy the \"code\" portion of the URL to your clipboard\n"
|
|
|
|
"5) Return to weechat and run `/slack register [code]`\n"),
|
|
|
|
"5) Return to weechat and run `/xmpp register [code]`\n"),
|
|
|
|
SLACK_CLIENT_ID);
|
|
|
|
XMPP_CLIENT_ID);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int slack_command_connect_workspace(struct t_slack_workspace *workspace)
|
|
|
|
int xmpp_command_connect_workspace(xmpp_conn_t *workspace)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (!workspace)
|
|
|
|
if (!workspace)
|
|
|
|
return 0;
|
|
|
|
return 0;
|
|
|
@ -208,19 +209,19 @@ int slack_command_connect_workspace(struct t_slack_workspace *workspace)
|
|
|
|
weechat_printf(
|
|
|
|
weechat_printf(
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
_("%s%s: already connected to workspace \"%s\"!"),
|
|
|
|
_("%s%s: already connected to workspace \"%s\"!"),
|
|
|
|
weechat_prefix("error"), SLACK_PLUGIN_NAME,
|
|
|
|
weechat_prefix("error"), XMPP_PLUGIN_NAME,
|
|
|
|
workspace->domain);
|
|
|
|
workspace->domain);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
slack_workspace_connect(workspace);
|
|
|
|
xmpp_workspace_connect(workspace);
|
|
|
|
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int slack_command_workspace_connect(int argc, char **argv)
|
|
|
|
int xmpp_command_workspace_connect(int argc, char **argv)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
int i, nb_connect, connect_ok;
|
|
|
|
int i, nb_connect, connect_ok;
|
|
|
|
struct t_slack_workspace *ptr_workspace;
|
|
|
|
xmpp_conn_t *ptr_workspace;
|
|
|
|
|
|
|
|
|
|
|
|
(void) argc;
|
|
|
|
(void) argc;
|
|
|
|
(void) argv;
|
|
|
|
(void) argv;
|
|
|
@ -231,10 +232,10 @@ int slack_command_workspace_connect(int argc, char **argv)
|
|
|
|
for (i = 2; i < argc; i++)
|
|
|
|
for (i = 2; i < argc; i++)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
nb_connect++;
|
|
|
|
nb_connect++;
|
|
|
|
ptr_workspace = slack_workspace_search(argv[i]);
|
|
|
|
ptr_workspace = xmpp_workspace_search(argv[i]);
|
|
|
|
if (ptr_workspace)
|
|
|
|
if (ptr_workspace)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (!slack_command_connect_workspace(ptr_workspace))
|
|
|
|
if (!xmpp_command_connect_workspace(ptr_workspace))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
connect_ok = 0;
|
|
|
|
connect_ok = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -244,8 +245,8 @@ int slack_command_workspace_connect(int argc, char **argv)
|
|
|
|
weechat_printf(
|
|
|
|
weechat_printf(
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
_("%s%s: workspace not found \"%s\" "
|
|
|
|
_("%s%s: workspace not found \"%s\" "
|
|
|
|
"(register first with: /slack register)"),
|
|
|
|
"(register first with: /xmpp register)"),
|
|
|
|
weechat_prefix("error"), SLACK_PLUGIN_NAME,
|
|
|
|
weechat_prefix("error"), XMPP_PLUGIN_NAME,
|
|
|
|
argv[i]);
|
|
|
|
argv[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -253,9 +254,9 @@ int slack_command_workspace_connect(int argc, char **argv)
|
|
|
|
return (connect_ok) ? WEECHAT_RC_OK : WEECHAT_RC_ERROR;
|
|
|
|
return (connect_ok) ? WEECHAT_RC_OK : WEECHAT_RC_ERROR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void slack_command_workspace_delete(int argc, char **argv)
|
|
|
|
void xmpp_command_workspace_delete(int argc, char **argv)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
struct t_slack_workspace *workspace;
|
|
|
|
xmpp_conn_t *workspace;
|
|
|
|
char *workspace_domain;
|
|
|
|
char *workspace_domain;
|
|
|
|
|
|
|
|
|
|
|
|
if (argc < 3)
|
|
|
|
if (argc < 3)
|
|
|
@ -269,14 +270,14 @@ void slack_command_workspace_delete(int argc, char **argv)
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
workspace = slack_workspace_search(argv[2]);
|
|
|
|
workspace = xmpp_workspace_search(argv[2]);
|
|
|
|
if (!workspace)
|
|
|
|
if (!workspace)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
weechat_printf(
|
|
|
|
weechat_printf(
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
_("%s%s: workspace \"%s\" not found for \"%s\" command"),
|
|
|
|
_("%s%s: workspace \"%s\" not found for \"%s\" command"),
|
|
|
|
weechat_prefix("error"), SLACK_PLUGIN_NAME,
|
|
|
|
weechat_prefix("error"), XMPP_PLUGIN_NAME,
|
|
|
|
argv[2], "slack delete");
|
|
|
|
argv[2], "xmpp delete");
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (workspace->is_connected)
|
|
|
|
if (workspace->is_connected)
|
|
|
@ -284,26 +285,27 @@ void slack_command_workspace_delete(int argc, char **argv)
|
|
|
|
weechat_printf(
|
|
|
|
weechat_printf(
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
_("%s%s: you cannot delete workspace \"%s\" because you"
|
|
|
|
_("%s%s: you cannot delete workspace \"%s\" because you"
|
|
|
|
"are connected. Try \"/slack disconnect %s\" first."),
|
|
|
|
"are connected. Try \"/xmpp disconnect %s\" first."),
|
|
|
|
weechat_prefix("error"), SLACK_PLUGIN_NAME,
|
|
|
|
weechat_prefix("error"), XMPP_PLUGIN_NAME,
|
|
|
|
argv[2], argv[2]);
|
|
|
|
argv[2], argv[2]);
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
workspace_domain = strdup(workspace->domain);
|
|
|
|
workspace_domain = strdup(workspace->domain);
|
|
|
|
slack_workspace_free(workspace);
|
|
|
|
xmpp_workspace_free(workspace);
|
|
|
|
weechat_printf (
|
|
|
|
weechat_printf (
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
_("%s: workspace %s%s%s has been deleted"),
|
|
|
|
_("%s: workspace %s%s%s has been deleted"),
|
|
|
|
SLACK_PLUGIN_NAME,
|
|
|
|
XMPP_PLUGIN_NAME,
|
|
|
|
weechat_color("chat_server"),
|
|
|
|
weechat_color("chat_server"),
|
|
|
|
(workspace_domain) ? workspace_domain : "???",
|
|
|
|
(workspace_domain) ? workspace_domain : "???",
|
|
|
|
weechat_color("reset"));
|
|
|
|
weechat_color("reset"));
|
|
|
|
if (workspace_domain)
|
|
|
|
if (workspace_domain)
|
|
|
|
free(workspace_domain);
|
|
|
|
free(workspace_domain);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
int slack_command_slack(const void *pointer, void *data,
|
|
|
|
int xmpp_command_xmpp(const void *pointer, void *data,
|
|
|
|
struct t_gui_buffer *buffer, int argc,
|
|
|
|
struct t_gui_buffer *buffer, int argc,
|
|
|
|
char **argv, char **argv_eol)
|
|
|
|
char **argv, char **argv_eol)
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -312,123 +314,122 @@ int slack_command_slack(const void *pointer, void *data,
|
|
|
|
(void) data;
|
|
|
|
(void) data;
|
|
|
|
(void) buffer;
|
|
|
|
(void) buffer;
|
|
|
|
|
|
|
|
|
|
|
|
if (argc <= 1 || weechat_strcasecmp(argv[1], "list") == 0)
|
|
|
|
//if (argc <= 1 || weechat_strcasecmp(argv[1], "list") == 0)
|
|
|
|
{
|
|
|
|
//{
|
|
|
|
slack_command_workspace_list(argc, argv);
|
|
|
|
// xmpp_command_workspace_list(argc, argv);
|
|
|
|
return WEECHAT_RC_OK;
|
|
|
|
// return WEECHAT_RC_OK;
|
|
|
|
}
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
|
|
if (argc > 1)
|
|
|
|
//if (argc > 1)
|
|
|
|
{
|
|
|
|
//{
|
|
|
|
if (weechat_strcasecmp(argv[1], "register") == 0)
|
|
|
|
// if (weechat_strcasecmp(argv[1], "register") == 0)
|
|
|
|
{
|
|
|
|
// {
|
|
|
|
slack_command_workspace_register(argc, argv);
|
|
|
|
// xmpp_command_workspace_register(argc, argv);
|
|
|
|
return WEECHAT_RC_OK;
|
|
|
|
// return WEECHAT_RC_OK;
|
|
|
|
}
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
if (weechat_strcasecmp(argv[1], "connect") == 0)
|
|
|
|
// if (weechat_strcasecmp(argv[1], "connect") == 0)
|
|
|
|
{
|
|
|
|
// {
|
|
|
|
slack_command_workspace_connect(argc, argv);
|
|
|
|
// xmpp_command_workspace_connect(argc, argv);
|
|
|
|
return WEECHAT_RC_OK;
|
|
|
|
// return WEECHAT_RC_OK;
|
|
|
|
}
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
if (weechat_strcasecmp(argv[1], "delete") == 0)
|
|
|
|
// if (weechat_strcasecmp(argv[1], "delete") == 0)
|
|
|
|
{
|
|
|
|
// {
|
|
|
|
slack_command_workspace_delete(argc, argv);
|
|
|
|
// xmpp_command_workspace_delete(argc, argv);
|
|
|
|
return WEECHAT_RC_OK;
|
|
|
|
// return WEECHAT_RC_OK;
|
|
|
|
}
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
WEECHAT_COMMAND_ERROR;
|
|
|
|
// WEECHAT_COMMAND_ERROR;
|
|
|
|
}
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
|
|
return WEECHAT_RC_OK;
|
|
|
|
return WEECHAT_RC_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int slack_command_me(const void *pointer, void *data,
|
|
|
|
int xmpp_command_me(const void *pointer, void *data,
|
|
|
|
struct t_gui_buffer *buffer, int argc,
|
|
|
|
struct t_gui_buffer *buffer, int argc,
|
|
|
|
char **argv, char **argv_eol)
|
|
|
|
char **argv, char **argv_eol)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
struct t_slack_workspace *ptr_workspace = NULL;
|
|
|
|
xmpp_conn_t *ptr_workspace = NULL;
|
|
|
|
struct t_slack_channel *ptr_channel = NULL;
|
|
|
|
//struct t_xmpp_channel *ptr_channel = NULL;
|
|
|
|
struct t_slack_request *request;
|
|
|
|
//struct t_xmpp_request *request;
|
|
|
|
char *text;
|
|
|
|
char *text;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(void) pointer;
|
|
|
|
(void) pointer;
|
|
|
|
(void) data;
|
|
|
|
(void) data;
|
|
|
|
(void) buffer;
|
|
|
|
(void) buffer;
|
|
|
|
(void) argv;
|
|
|
|
(void) argv;
|
|
|
|
|
|
|
|
|
|
|
|
slack_buffer_get_workspace_and_channel(buffer, &ptr_workspace, &ptr_channel);
|
|
|
|
//xmpp_buffer_get_workspace_and_channel(buffer, &ptr_workspace, &ptr_channel);
|
|
|
|
|
|
|
|
|
|
|
|
if (!ptr_workspace)
|
|
|
|
//if (!ptr_workspace)
|
|
|
|
return WEECHAT_RC_ERROR;
|
|
|
|
// return WEECHAT_RC_ERROR;
|
|
|
|
|
|
|
|
|
|
|
|
if (!ptr_channel)
|
|
|
|
//if (!ptr_channel)
|
|
|
|
{
|
|
|
|
//{
|
|
|
|
weechat_printf (
|
|
|
|
// weechat_printf (
|
|
|
|
ptr_workspace->buffer,
|
|
|
|
// ptr_workspace->buffer,
|
|
|
|
_("%s%s: \"%s\" command can not be executed on a workspace buffer"),
|
|
|
|
// _("%s%s: \"%s\" command can not be executed on a workspace buffer"),
|
|
|
|
weechat_prefix("error"), SLACK_PLUGIN_NAME, "me");
|
|
|
|
// weechat_prefix("error"), XMPP_PLUGIN_NAME, "me");
|
|
|
|
return WEECHAT_RC_OK;
|
|
|
|
// return WEECHAT_RC_OK;
|
|
|
|
}
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
|
|
if (!ptr_workspace->is_connected)
|
|
|
|
//if (!ptr_workspace->is_connected)
|
|
|
|
{
|
|
|
|
//{
|
|
|
|
weechat_printf(buffer,
|
|
|
|
// weechat_printf(buffer,
|
|
|
|
_("%s%s: you are not connected to server"),
|
|
|
|
// _("%s%s: you are not connected to server"),
|
|
|
|
weechat_prefix("error"), SLACK_PLUGIN_NAME);
|
|
|
|
// weechat_prefix("error"), XMPP_PLUGIN_NAME);
|
|
|
|
return WEECHAT_RC_OK;
|
|
|
|
// return WEECHAT_RC_OK;
|
|
|
|
}
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
|
|
if (argc > 1)
|
|
|
|
//if (argc > 1)
|
|
|
|
{
|
|
|
|
//{
|
|
|
|
text = malloc(SLACK_MESSAGE_MAX_LENGTH);
|
|
|
|
// text = malloc(XMPP_MESSAGE_MAX_LENGTH);
|
|
|
|
if (!text)
|
|
|
|
// if (!text)
|
|
|
|
{
|
|
|
|
// {
|
|
|
|
weechat_printf(buffer,
|
|
|
|
// weechat_printf(buffer,
|
|
|
|
_("%s%s: error allocating string"),
|
|
|
|
// _("%s%s: error allocating string"),
|
|
|
|
weechat_prefix("error"), SLACK_PLUGIN_NAME);
|
|
|
|
// weechat_prefix("error"), XMPP_PLUGIN_NAME);
|
|
|
|
return WEECHAT_RC_ERROR;
|
|
|
|
// return WEECHAT_RC_ERROR;
|
|
|
|
}
|
|
|
|
// }
|
|
|
|
lws_urlencode(text, argv_eol[1], SLACK_MESSAGE_MAX_LENGTH);
|
|
|
|
// lws_urlencode(text, argv_eol[1], XMPP_MESSAGE_MAX_LENGTH);
|
|
|
|
|
|
|
|
|
|
|
|
request = slack_request_chat_memessage(ptr_workspace,
|
|
|
|
// request = xmpp_request_chat_memessage(ptr_workspace,
|
|
|
|
weechat_config_string(
|
|
|
|
// weechat_config_string(
|
|
|
|
ptr_workspace->options[SLACK_WORKSPACE_OPTION_TOKEN]),
|
|
|
|
// ptr_workspace->options[XMPP_WORKSPACE_OPTION_TOKEN]),
|
|
|
|
ptr_channel->id, text);
|
|
|
|
// ptr_channel->id, text);
|
|
|
|
if (request)
|
|
|
|
// if (request)
|
|
|
|
slack_workspace_register_request(ptr_workspace, request);
|
|
|
|
// xmpp_workspace_register_request(ptr_workspace, request);
|
|
|
|
|
|
|
|
|
|
|
|
free(text);
|
|
|
|
// free(text);
|
|
|
|
}
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
|
|
return WEECHAT_RC_OK;
|
|
|
|
return WEECHAT_RC_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void slack_command_init()
|
|
|
|
void xmpp_command_init()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
weechat_hook_command(
|
|
|
|
weechat_hook_command(
|
|
|
|
"slack",
|
|
|
|
"xmpp",
|
|
|
|
N_("slack control"),
|
|
|
|
N_("xmpp control"),
|
|
|
|
N_("list"
|
|
|
|
N_("list"
|
|
|
|
" || register [token]"
|
|
|
|
" || register [token]"
|
|
|
|
" || connect <workspace>"
|
|
|
|
" || connect <workspace>"
|
|
|
|
" || delete <workspace>"),
|
|
|
|
" || delete <workspace>"),
|
|
|
|
N_(" list: list workspaces\n"
|
|
|
|
N_(" list: list workspaces\n"
|
|
|
|
"register: add a slack workspace\n"
|
|
|
|
"register: add a xmpp workspace\n"
|
|
|
|
" connect: connect to a slack workspace\n"
|
|
|
|
" connect: connect to a xmpp workspace\n"
|
|
|
|
" delete: delete a slack workspace\n"),
|
|
|
|
" delete: delete a xmpp workspace\n"),
|
|
|
|
"list"
|
|
|
|
"list"
|
|
|
|
" || register %(slack_token)"
|
|
|
|
" || register %(xmpp_token)"
|
|
|
|
" || connect %(slack_workspace)"
|
|
|
|
" || connect %(xmpp_workspace)"
|
|
|
|
" || delete %(slack_workspace)",
|
|
|
|
" || delete %(xmpp_workspace)",
|
|
|
|
&slack_command_slack, NULL, NULL);
|
|
|
|
&xmpp_command_xmpp, NULL, NULL);
|
|
|
|
|
|
|
|
|
|
|
|
weechat_hook_command(
|
|
|
|
weechat_hook_command(
|
|
|
|
"me",
|
|
|
|
"me",
|
|
|
|
N_("send a slack action to the current channel"),
|
|
|
|
N_("send a xmpp action to the current channel"),
|
|
|
|
N_("<message>"),
|
|
|
|
N_("<message>"),
|
|
|
|
N_("message: message to send"),
|
|
|
|
N_("message: message to send"),
|
|
|
|
NULL, &slack_command_me, NULL, NULL);
|
|
|
|
NULL, &xmpp_command_me, NULL, NULL);
|
|
|
|
}
|
|
|
|
}
|