Tony Olagbaiye 3 years ago
parent 8a8ad87012
commit 6d8af6ed0f
No known key found for this signature in database
GPG Key ID: 9E2FF3BDEBDFC910

4
.gitignore vendored

@ -1,6 +1,4 @@
# Prerequisites
debian/weechat-slack/
.debhelper/
*~
compile_commands.json
cscope*
.depend

3
.gitmodules vendored

@ -1,6 +1,3 @@
[submodule "libwebsockets"]
path = libwebsockets
url = https://github.com/warmcat/libwebsockets
[submodule "json-c"]
path = json-c
url = https://github.com/json-c/json-c

@ -4,15 +4,17 @@ ifdef DEBUG
endif
RM=rm -f
FIND=find
CFLAGS+=$(DBGCFLAGS) -fno-omit-frame-pointer -fPIC -std=gnu99 -g -Wall -Wextra -Werror-implicit-function-declaration -Wno-missing-field-initializers -Ilibwebsockets/include -Ijson-c
CFLAGS+=$(DBGCFLAGS) -fno-omit-frame-pointer -fPIC -std=gnu99 -g -Wall -Wextra -Werror-implicit-function-declaration -Wno-missing-field-initializers -Ilibstrophe -Ijson-c
LDFLAGS+=-shared -g $(DBGCFLAGS) $(DBGLDFLAGS)
LDLIBS=-lgnutls
LDLIBS=
PREFIX ?= /usr/local
LIBDIR ?= $(PREFIX)/lib
INSTALL ?= /usr/bin/install
SRCS=slack.c \
SRCS=xmpp.c \
OLDSRCS=slack.c \
slack-api.c \
slack-buffer.c \
slack-channel.c \
@ -41,35 +43,26 @@ SRCS=slack.c \
request/slack-request-conversations-members.c \
request/slack-request-emoji-list.c \
request/slack-request-users-list.c
OBJS=$(subst .c,.o,$(SRCS)) libwebsockets/lib/libwebsockets.a json-c/libjson-c.a
OBJS=$(subst .c,.o,$(SRCS)) libstrophe/.libs/libstrophe.a json-c/libjson-c.a
all: libwebsockets/lib/libwebsockets.a json-c/libjson-c.a weechat-slack
all: libstrophe/.libs/libstrophe.a json-c/libjson-c.a weechat-xmpp
weechat-slack: $(OBJS)
$(CC) $(LDFLAGS) -o slack.so $(OBJS) $(LDLIBS)
weechat-xmpp: $(OBJS)
$(CC) $(LDFLAGS) -o xmpp.so $(OBJS) $(LDLIBS)
ifeq ($(shell which python),)
slack-emoji.inc: slack-emoji.pl
cpan LWP::Simple
cpan JSON
perl slack-emoji.pl > slack-emoji.inc
else
slack-emoji.inc: slack-emoji.py
pip install requests
env python3 slack-emoji.py > slack-emoji.inc
endif
libwebsockets/lib/libwebsockets.a:
cd libwebsockets && env CFLAGS= LDFLAGS= cmake -DLWS_STATIC_PIC=ON -DLWS_WITH_SHARED=OFF -DLWS_WITHOUT_TESTAPPS=ON -DLWS_WITH_LIBEV=OFF -DLWS_WITH_LIBUV=OFF -DLWS_WITH_LIBEVENT=OFF -DCMAKE_BUILD_TYPE=DEBUG .
$(MAKE) -C libwebsockets
libstrophe/.libs/libstrophe.a:
cd libstrophe && ./bootstrap.sh && env CFLAGS= LDFLAGS= ./configure
$(MAKE) -C libstrophe
libstrophe: libstrophe/.libs/libstrophe.a
json-c/libjson-c.a:
cd json-c && env CFLAGS= LDFLAGS= cmake -DCMAKE_C_FLAGS=-fPIC .
$(MAKE) -C json-c json-c-static
json-c: json-c/libjson-c.a
depend: .depend
.depend: libwebsockets/lib/libwebsockets.a json-c/libjson-c.a $(SRCS)
.depend: libstrophe/.libs/libstrophe.a json-c/libjson-c.a $(SRCS)
$(RM) ./.depend
$(CC) $(CFLAGS) -MM $^>>./.depend
@ -78,8 +71,9 @@ tidy:
clean:
$(RM) $(OBJS)
$(MAKE) -C libwebsockets clean
$(MAKE) -C json-c clean
$(MAKE) -C libstrophe clean || true
$(MAKE) -C libwebsockets clean || true
$(MAKE) -C json-c clean || true
git submodule foreach --recursive git clean -xfd || true
git submodule foreach --recursive git reset --hard || true
git submodule update --init --recursive || true
@ -87,18 +81,13 @@ clean:
distclean: clean
$(RM) *~ .depend
install: slack.so
install: xmpp.so
ifeq ($(shell id -u),0)
$(INSTALL) -s -t $(DESTDIR)$(LIBDIR)/weechat/plugins -D -m 0644 slack.so
$(INSTALL) -s -t $(DESTDIR)$(LIBDIR)/weechat/plugins -D -m 0644 xmpp.so
else
$(INSTALL) -s -t ~/.weechat/plugins -D -m 0755 slack.so
$(INSTALL) -s -t ~/.weechat/plugins -D -m 0755 xmpp.so
endif
package-debian:
env ARCH=i386 gbp buildpackage --git-arch=i386 --git-ignore-new --git-pbuilder
env ARCH=amd64 gbp buildpackage --git-arch=amd64 --git-ignore-new --git-pbuilder
# gbp buildpackage -S --git-ignore-new
.PHONY: tags cs
tags:

31
debian/changelog vendored

@ -1,31 +0,0 @@
weechat-slack (0.1.5) sid; urgency=medium
[ Tony Olagbaiye ]
* Initial release.
* Bot messages
* Slackbot responses
* CTags
* Fix channel mentions. Closes #2
* License headers
* Administration
* Add TODO to readme
* Fix makefile to find libwebsockets.h
* Build libwebsockets first
* Revert libwebsockets header change
* Build libjson-c before too
* Typo
* Move sanitizers to debug build
* Fix make install
* Fix install finally
* Just remove `make install` from travis
* Update README.org
* Handle message.me_message (ref #5)
* Monkeypatch message.bot_message for undoc'd slackbot msgs. Fixes #6
* Implement chat.meMessage for /me (closes #5)
* Update README.org
* Update README.org
* Describe debug process
[ Bao ]
-- Bao <bao@mail.fron.io> Thu, 10 May 2018 15:18:26 +0100

1
debian/compat vendored

@ -1 +0,0 @@
11

26
debian/control vendored

@ -1,26 +0,0 @@
Source: weechat-slack
Section: net
Priority: optional
Maintainer: Tony Olagbaiye <frony0@gmail.com>
Build-Depends:
cmake, pkg-config,
debhelper (>= 11),
libssl-dev,
libgnutls28-dev,
perl
Standards-Version: 4.0.0
Homepage: https://weechat.org/
Vcs-Git: https://github.com/bqv/weechat-slack.git
Vcs-Browser: https://github.com/bqv/weechat-slack
Package: weechat-slack
Architecture: any
Depends:
weechat (>= 1.7),
${shlibs:Depends},
${misc:Depends}
Description: Fast, light and extensible chat client - Slack plugin
WeeChat (Wee Enhanced Environment for Chat) is a fast and light chat client
for many operating systems. Everything can be done with a keyboard.
.
This package provides the Slack API plugin.

2865
debian/copyright vendored

File diff suppressed because it is too large Load Diff

17
debian/rules vendored

@ -1,17 +0,0 @@
#!/usr/bin/make -f
DEB_HOST_MULTIARCH ?= $(shell dpkg-architecture -qDEB_HOST_MULTIARCH)
#export DH_VERBOSE = 1
#export DEB_BUILD_MAINT_OPTIONS = hardening=+all
#export DEB_CFLAGS_MAINT_APPEND = -Wall -pedantic
export DEB_LDFLAGS_MAINT_APPEND = -Wl,--as-needed
%:
dh $@ --without autoreconf
override_dh_auto_install:
dh_auto_install -- LIBDIR=/usr/lib/$(DEB_HOST_MULTIARCH)
override_dh_install:
dh_install

@ -1,6 +0,0 @@
# This is an override for the following lintian errors:
# E: weechat-slack source: source-is-missing libwebsockets/plugins/generic-sessions/assets/lwsgs.js
# E: weechat-slack source: source-is-missing libwebsockets/plugins/generic-sessions/assets/md5.min.js
# The source is not missing, all sources are included.
# This is a lintian false-positive.
weechat-slack source: source-is-missing

@ -1 +0,0 @@
Subproject commit f1c56bc233a5f05c01c93a5c250a31b4d309ecac

@ -1,97 +0,0 @@
#!/usr/bin/perl -l
# 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/.
use strict;
use warnings;
use LWP::Simple;
use Data::Dumper;
use JSON qw (decode_json);
use List::Util qw (max);
our ($json, @array);
$json = get('https://raw.githubusercontent.com/iamcal/emoji-data/master/emoji.json');
@array = @{ decode_json($json) };
my $maxtexts = max (map { 1 + @{$_} } (grep defined, map { $_->{'texts'} } @array));
my $maxnames = max (map { 1 + @{$_} } (grep defined, map { $_->{'short_names'} } @array));
print "
// 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/.
#include <stdlib.h>
#define MAX_TEXTS $maxtexts
#define MAX_NAMES $maxnames
struct t_slack_emoji_by_name {
const char *name;
const char *unicode;
const char *text_to;
const char *text_from[MAX_TEXTS];
};
struct t_slack_emoji_by_text {
const char *text;
const char *unicode;
const char *name_to;
const char *name_from[MAX_NAMES];
};
";
print "static struct t_slack_emoji_by_name slack_emoji_by_name[] =";
my $c = '{';
my %byname = map { my $o = $_; map {($_, $o)} @{$o->{'short_names'}} } @array;
my @sortedbyname = sort { $a cmp $b } keys %byname;
foreach my $name (@sortedbyname)
{
my $_0 = "\":$name:\"";
my @_1 = split /-/, $byname{$name}->{'unified'};
my $_1 = "\"";
foreach my $codepoint (@_1) {
if (hex $codepoint < 0xA0) { $_1 .= chr hex $codepoint } else { $_1 .= "\\u$codepoint" }
};
$_1 .= "\"";
$_1 =~ tr/A-Za-z/a-za-z/;
my $_2 = $byname{$name}->{'text'};
if (defined $_2) { $_2 = "\"$_2\"" } else { $_2 = "NULL" };
$_2 =~ s/\\/\\\\/g;
my $_3 = "{";
foreach my $text (@{$byname{$name}->{'texts'}}) { if (defined $text) { $_3 .= "\"$text\", " } };
$_3 .= "NULL}";
$_3 =~ s/\\/\\\\/g;
print "$c { $_0, $_1, $_2, $_3 }";
$c = ',';
}
print "};";
print "";
print "static struct t_slack_emoji_by_text slack_emoji_by_text[] =";
$c = '{';
my %bytext = map { my $o = $_; map {($_, $o)} @{$o->{'texts'}} } @array;
my @sortedbytext = sort { $a cmp $b } keys %bytext;
foreach my $text (@sortedbytext)
{
my $_0 = "\"$text\"";
$_0 =~ s/\\/\\\\/g;
my @_1 = split /-/, $bytext{$text}->{'unified'};
my $_1 = "\"";
foreach my $codepoint (@_1) {
if (hex $codepoint < 0xA0) { $_1 .= chr hex $codepoint } else { $_1 .= "\\u$codepoint" }
};
$_1 .= "\"";
$_1 =~ tr/A-Za-z/a-za-z/;
my $_2 = $bytext{$text}->{'short_name'};
if (defined $_2) { $_2 = "\":$_2:\"" } else { $_2 = "NULL" };
my $_3 = "{";
foreach my $name (@{$bytext{$text}->{'short_names'}}) { if (defined $name) { $_3 .= "\":$name:\", " } };
$_3 .= "NULL}";
print "$c { $_0, $_1, $_2, $_3 }";
$c = ',';
}
print "};";

@ -1,59 +0,0 @@
#!/usr/bin/env python3
# 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/.
import requests
import json
import ast
emoji = requests.get("https://raw.githubusercontent.com/iamcal/emoji-data/master/emoji.json").json()
print("""
// 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/.
#include <stdlib.h>
#define MAX_TEXTS %d
#define MAX_NAMES %d
struct t_slack_emoji_by_name {
const char *name;
const char *unicode;
const char *text_to;
const char *text_from[MAX_TEXTS];
};
struct t_slack_emoji_by_text {
const char *text;
const char *unicode;
const char *name_to;
const char *name_from[MAX_NAMES];
};
"""%(max(len(o['texts'] if o['texts'] else []) for o in emoji) + 1,
max(len(o['short_names'] if o['short_names'] else []) for o in emoji) + 1))
print("static struct t_slack_emoji_by_name slack_emoji_by_name[] =")
print("{"+"\n".join(", {{ {0}, {1}, {2}, {3} }}".format(
json.dumps(":"+name+":"),
json.dumps(ast.parse("\"\\u"+"\\u".join(o['unified'].split('-'))+"\"", mode='eval').body.s),
json.dumps(o['text']),
"{"+json.dumps(o['texts']+[None] if o['texts'] else [None])[1:-1]+"}")
for o,name in sorted(((o,name) for o in emoji for name in o['short_names']),
key=lambda x: x[1])
).replace("null", "NULL")[1:])
print("};")
print("")
print("static struct t_slack_emoji_by_text slack_emoji_by_text[] =")
print("{"+"\n".join(", {{ {0}, {1}, {2}, {3} }}".format(
json.dumps(text),
json.dumps(ast.parse("\"\\u"+"\\u".join(o['unified'].split('-'))+"\"", mode='eval').body.s),
json.dumps(":"+o['short_name']+":"),
"{"+json.dumps(list(map(lambda name: ":"+name+":", o['short_names']))+[None]
if o['short_names'] else [None])[1:-1]+"}")
for o,text in sorted(((o,text) for o in emoji if o['texts'] for text in o['texts']),
key=lambda x:x[1])
).replace("null", "NULL")[1:])
print("};")

106
xmpp.c

@ -0,0 +1,106 @@
// 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/.
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <strophe.h>
#include <json.h>
#include "weechat-plugin.h"
#include "xmpp.h"
//#include "slack-config.h"
//#include "slack-command.h"
//#include "slack-workspace.h"
//#include "slack-api.h"
//#include "slack-buffer.h"
//#include "slack-completion.h"
WEECHAT_PLUGIN_NAME(XMPP_PLUGIN_NAME);
WEECHAT_PLUGIN_DESCRIPTION(N_("XMPP protocol"));
WEECHAT_PLUGIN_AUTHOR("bqv <weechat@fron.io>");
WEECHAT_PLUGIN_VERSION(XMPP_PLUGIN_VERSION);
WEECHAT_PLUGIN_LICENSE("MPL2");
WEECHAT_PLUGIN_PRIORITY(5500);
struct t_weechat_plugin *weechat_xmpp_plugin = NULL;
struct t_hook *xmpp_hook_timer = NULL;
struct t_gui_bar_item *xmpp_typing_bar_item = NULL;
void xmpp_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"), XMPP_PLUGIN_NAME,
buf, line);
}
int weechat_plugin_init(struct t_weechat_plugin *plugin, int argc, char *argv[])
{
(void) argc;
(void) argv;
weechat_plugin = plugin;
//lws_set_log_level(LLL_ERR | LLL_WARN /*| LLL_NOTICE | LLL_INFO | LLL_DEBUG
// | LLL_PARSER | LLL_HEADER | LLL_EXT | LLL_CLIENT
// | LLL_LATENCY | LLL_USER | LLL_COUNT*/,
// xmpp_lwsl_emit_weechat);
//if (!xmpp_config_init())
// return WEECHAT_RC_ERROR;
//xmpp_config_read();
//xmpp_command_init();
//xmpp_api_init();
//xmpp_completion_init();
//xmpp_hook_timer = weechat_hook_timer(0.1 * 1000, 0, 0,
// &xmpp_workspace_timer_cb,
// NULL, NULL);
if (!weechat_bar_search("typing"))
{
weechat_bar_new("typing", "off", "400", "window", "${typing}",
"bottom", "horizontal", "vertical",
"1", "1", "default", "default", "default",
"off", "xmpp_typing");
}
//xmpp_typing_bar_item = weechat_bar_item_new("xmpp_typing",
// &xmpp_buffer_typing_bar_cb,
// NULL, NULL);
return WEECHAT_RC_OK;
}
int weechat_plugin_end(struct t_weechat_plugin *plugin)
{
/* make C compiler happy */
(void) plugin;
if (xmpp_typing_bar_item)
weechat_bar_item_remove(xmpp_typing_bar_item);
if (xmpp_hook_timer)
weechat_unhook(xmpp_hook_timer);
//xmpp_config_write();
//xmpp_workspace_disconnect_all();
//xmpp_workspace_free_all();
return WEECHAT_RC_OK;
}

@ -0,0 +1,14 @@
// 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/.
#ifndef _XMPP_H_
#define _XMPP_H_
#define weechat_plugin weechat_xmpp_plugin
#define XMPP_PLUGIN_NAME "xmpp"
#define XMPP_PLUGIN_VERSION "0.1"
extern struct t_weechat_plugin *weechat_xmpp_plugin;
#endif /*XMPP_H*/
Loading…
Cancel
Save