lita-tox 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 91236f6acf23d6db25acc452a0de0e1426abf5c4
4
+ data.tar.gz: 07e2890f818d7865861a1044be77a3fa1fdecca7
5
+ SHA512:
6
+ metadata.gz: 5fef9b677b83c02c1b65d0fa3a8d29c97734c18968c886e0ca9c9bc6f5c043a21863a5547b97d46dbd6857520ab8e19e12e36b1489d92765a9ea33cf8cacba35
7
+ data.tar.gz: a31101312fce11274b71815770028ad35c8d4d1ec0ba632930b5d7837e81e1f09134bb9ac75b613bf126d0350454635a28f8535392d4cc1dfbf9fd09b3f6ac42
data/.gitignore ADDED
@@ -0,0 +1,39 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /test/tmp/
9
+ /test/version_tmp/
10
+ /tmp/
11
+
12
+ Makefile
13
+ *.o
14
+ *.so
15
+
16
+ ## Specific to RubyMotion:
17
+ .dat*
18
+ .repl_history
19
+ build/
20
+
21
+ ## Documentation cache and generated files:
22
+ /.yardoc/
23
+ /_yardoc/
24
+ /doc/
25
+ /rdoc/
26
+
27
+ ## Environment normalisation:
28
+ /.bundle/
29
+ /vendor/bundle
30
+ /lib/bundler/man/
31
+
32
+ # for a library or gem, you might want to ignore these files since the code is
33
+ # intended to run in multiple environments; otherwise, check them in:
34
+ /Gemfile.lock
35
+ /.ruby-version
36
+ /.ruby-gemset
37
+
38
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
39
+ .rvmrc
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,3 @@
1
+ AllCops:
2
+ Exclude:
3
+ - vendor/**/*
data/.simplecov ADDED
@@ -0,0 +1,8 @@
1
+ require 'coveralls'
2
+
3
+ SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
4
+ SimpleCov::Formatter::HTMLFormatter,
5
+ Coveralls::SimpleCov::Formatter,
6
+ ]
7
+
8
+ SimpleCov.start { add_filter '/spec/' }
data/.travis.yml ADDED
@@ -0,0 +1,14 @@
1
+ language: ruby
2
+
3
+ rvm:
4
+ - 2.0
5
+ - 2.1
6
+ - 2.2
7
+
8
+ script: bundle exec rake
9
+
10
+ before_install:
11
+ - gem update --system
12
+
13
+ services:
14
+ - redis-server
data/.yardopts ADDED
@@ -0,0 +1,5 @@
1
+ --protected
2
+ --private
3
+ --markup markdown
4
+ -
5
+ LICENSE
data/CHANGELOG.md ADDED
@@ -0,0 +1,22 @@
1
+ # Change Log
2
+
3
+ ## [v0.1.0](https://github.com/braiden-vasco/lita-tox/tree/v0.1.0) (2015-09-13)
4
+ **Merged pull requests:**
5
+
6
+ - Add instructions [\#13](https://github.com/braiden-vasco/lita-tox/pull/13) ([braiden-vasco](https://github.com/braiden-vasco))
7
+ - Basic implementation [\#12](https://github.com/braiden-vasco/lita-tox/pull/12) ([braiden-vasco](https://github.com/braiden-vasco))
8
+ - Basic "tox" extension implementation [\#11](https://github.com/braiden-vasco/lita-tox/pull/11) ([braiden-vasco](https://github.com/braiden-vasco))
9
+ - Add code documentation [\#10](https://github.com/braiden-vasco/lita-tox/pull/10) ([braiden-vasco](https://github.com/braiden-vasco))
10
+ - Initialize Lita adapter [\#9](https://github.com/braiden-vasco/lita-tox/pull/9) ([braiden-vasco](https://github.com/braiden-vasco))
11
+ - Add changelog generator [\#8](https://github.com/braiden-vasco/lita-tox/pull/8) ([braiden-vasco](https://github.com/braiden-vasco))
12
+ - Use YARD [\#7](https://github.com/braiden-vasco/lita-tox/pull/7) ([braiden-vasco](https://github.com/braiden-vasco))
13
+ - Configure Coveralls [\#6](https://github.com/braiden-vasco/lita-tox/pull/6) ([braiden-vasco](https://github.com/braiden-vasco))
14
+ - Configure Travis CI [\#5](https://github.com/braiden-vasco/lita-tox/pull/5) ([braiden-vasco](https://github.com/braiden-vasco))
15
+ - Add README [\#4](https://github.com/braiden-vasco/lita-tox/pull/4) ([braiden-vasco](https://github.com/braiden-vasco))
16
+ - Configure testing [\#3](https://github.com/braiden-vasco/lita-tox/pull/3) ([braiden-vasco](https://github.com/braiden-vasco))
17
+ - Configure linting [\#2](https://github.com/braiden-vasco/lita-tox/pull/2) ([braiden-vasco](https://github.com/braiden-vasco))
18
+ - Initialize gem [\#1](https://github.com/braiden-vasco/lita-tox/pull/1) ([braiden-vasco](https://github.com/braiden-vasco))
19
+
20
+
21
+
22
+ \* *This Change Log was automatically generated by [github_changelog_generator](https://github.com/skywinder/Github-Changelog-Generator)*
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in lita-tox.gemspec
4
+ gemspec
5
+
6
+ gem 'coveralls', require: false
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Braiden Vasco
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
data/README.md ADDED
@@ -0,0 +1,71 @@
1
+ Lita::Adapters::Tox
2
+ ===================
3
+
4
+ [![Gem Version](https://badge.fury.io/rb/lita-tox.svg)](http://badge.fury.io/rb/lita-tox)
5
+ [![Build Status](https://travis-ci.org/braiden-vasco/lita-tox.svg)](https://travis-ci.org/braiden-vasco/lita-tox)
6
+ [![Coverage Status](https://coveralls.io/repos/braiden-vasco/lita-tox/badge.svg)](https://coveralls.io/r/braiden-vasco/lita-tox)
7
+
8
+ [Tox](https://tox.chat) adapter for the [Lita](http://lita.io) chat bot.
9
+
10
+ **WARNING**
11
+
12
+ Still in development. Read the README carefully.
13
+
14
+
15
+ TODO
16
+ ----
17
+
18
+ Current development version have some limitations
19
+ which should be fixed in first release:
20
+
21
+ * Adapter doesn't save Tox state, so you have to send friendship
22
+ request again after each run. Current Tox ID is shown at start
23
+ as Lita's information message
24
+
25
+ * Only private chats are supported. Adapter will not respond to group invite
26
+
27
+ * **libtoxcore** is not included in the gem. It should be compiled manually
28
+ to build the gem native extension successfully (see the instructions below)
29
+
30
+ * JRuby is not supported. Only C extension for Tox is implemented
31
+
32
+ * Message length is limited to value of `TOX_MAX_MESSAGE_LENGTH`
33
+ (see [source code of **libtoxcore**](https://github.com/irungentoo/toxcore/blob/2ab3b14731061cc04d3ccc50a35093c11d018298/toxcore/tox.h#L252-L255))
34
+
35
+ * Adapter has incomplete API for Lita. Only basic methods are implemented
36
+
37
+
38
+ Usage
39
+ -----
40
+
41
+ At first, see the documentation for Lita: http://docs.lita.io/
42
+
43
+ ### Installation
44
+
45
+ **libtoxcore** should be compiled manually at your computer or server.
46
+ Follow the instructions at
47
+ [that file](https://github.com/irungentoo/toxcore/blob/2ab3b14731061cc04d3ccc50a35093c11d018298/INSTALL.md)
48
+
49
+ When **libtoxcore** is installed, add **lita-tox**
50
+ to your Lita instance's Gemfile:
51
+
52
+ ```ruby
53
+ gem 'lita-tox', '~> 0.1.0'
54
+ ```
55
+
56
+ ### Configuration
57
+
58
+ No configuration is needed. You only have to specify adapter as `:tox`
59
+
60
+ #### Example
61
+
62
+ This is an example `lita_config.rb` file:
63
+
64
+ ```ruby
65
+ Lita.configure do |config|
66
+ config.robot.name = 'Lita'
67
+ config.robot.mention_name = 'lita'
68
+
69
+ config.robot.adapter = :tox
70
+ end
71
+ ```
data/Rakefile ADDED
@@ -0,0 +1,37 @@
1
+ require 'rubygems'
2
+
3
+ gemspec = Gem::Specification.load('lita-tox.gemspec')
4
+
5
+ github_user, github_project =
6
+ gemspec.homepage.scan(%r{^https://github\.com/([^/]+)/([^/]+)/?$})[0]
7
+
8
+ require 'bundler/gem_tasks'
9
+
10
+ task default: [:spec, :lint]
11
+
12
+ require 'rspec/core/rake_task'
13
+ RSpec::Core::RakeTask.new
14
+
15
+ task lint: [:rubocop]
16
+
17
+ require 'rubocop/rake_task'
18
+ RuboCop::RakeTask.new
19
+
20
+ require 'yard'
21
+ YARD::Rake::YardocTask.new
22
+
23
+ desc 'Generate changelog'
24
+ task :changelog, [:token] do |_t, args|
25
+ cmd = 'github_changelog_generator'
26
+ cmd << " -u #{github_user}"
27
+ cmd << " -p #{github_project}"
28
+ cmd << " -t #{args[:token]}" if args[:token]
29
+
30
+ sh cmd
31
+ end
32
+
33
+ require 'rake/extensiontask'
34
+
35
+ Rake::ExtensionTask.new 'tox' do |ext|
36
+ ext.lib_dir = 'lib/tox'
37
+ end
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'lita-tox'
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ require 'pry'
11
+ Pry.start
12
+
13
+ # require 'irb'
14
+ # IRB.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,31 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'mkmf'
4
+
5
+ NAME = 'tox'
6
+
7
+ LIBTOXCORE = 'toxcore'
8
+
9
+ have_header 'time.h' and
10
+ have_header 'tox/tox.h' and
11
+
12
+ have_func 'sprintf' and
13
+ have_func 'sscanf' and
14
+ have_func 'nanosleep' and
15
+
16
+ have_library LIBTOXCORE, 'tox_options_default' and
17
+ have_library LIBTOXCORE, 'tox_new' and
18
+ have_library LIBTOXCORE, 'tox_get_savedata_size' and
19
+ have_library LIBTOXCORE, 'tox_get_savedata' and
20
+ have_library LIBTOXCORE, 'tox_self_get_address' and
21
+ have_library LIBTOXCORE, 'tox_bootstrap' and
22
+ have_library LIBTOXCORE, 'tox_kill' and
23
+ have_library LIBTOXCORE, 'tox_version_is_compatible' and
24
+ have_library LIBTOXCORE, 'tox_iteration_interval' and
25
+ have_library LIBTOXCORE, 'tox_iterate' and
26
+ have_library LIBTOXCORE, 'tox_friend_add_norequest' and
27
+ have_library LIBTOXCORE, 'tox_friend_send_message' and
28
+ have_library LIBTOXCORE, 'tox_callback_friend_request' and
29
+ have_library LIBTOXCORE, 'tox_callback_friend_message' and
30
+
31
+ create_makefile "#{NAME}/#{NAME}" or exit(1)
data/ext/tox/tox.c ADDED
@@ -0,0 +1,372 @@
1
+ #include <ruby.h>
2
+
3
+ #include <time.h>
4
+
5
+ #include <tox/tox.h>
6
+
7
+ #define TOX_IS_COMPATIBLE TOX_VERSION_IS_API_COMPATIBLE
8
+ TOX_VERSION_REQUIRE(0, 0, 0);
9
+
10
+ void Init_tox();
11
+
12
+ #define IP_LENGTH_MAX 15
13
+
14
+ typedef char IP[IP_LENGTH_MAX + 1];
15
+ typedef char Key[(TOX_PUBLIC_KEY_SIZE * 2) + 1];
16
+
17
+ typedef struct Node {
18
+ IP ip;
19
+ int port;
20
+ Key key;
21
+ } Node;
22
+
23
+ typedef uint8_t KeyBin[TOX_PUBLIC_KEY_SIZE];
24
+
25
+ static void Key_to_KeyBin(const char *key, uint8_t *key_bin);
26
+
27
+ typedef struct cTox_ {
28
+ Tox *tox;
29
+ } cTox_;
30
+
31
+ static VALUE cTox;
32
+
33
+ static VALUE cTox_alloc(VALUE klass);
34
+ static void cTox_free(void *ptr);
35
+ static VALUE cTox_initialize_with(VALUE self, VALUE options);
36
+ static VALUE cTox_savedata(VALUE self);
37
+ static VALUE cTox_id(VALUE self);
38
+ static VALUE cTox_bootstrap(VALUE self, VALUE options);
39
+ static VALUE cTox_kill(VALUE self);
40
+ static VALUE cTox_loop(VALUE self);
41
+ static VALUE cTox_friend_add_norequest(VALUE self, VALUE key);
42
+ static VALUE cTox_friend_send_message(VALUE self, VALUE friend_number, VALUE text);
43
+
44
+ static void on_friend_request(
45
+ Tox *tox,
46
+ const uint8_t *key,
47
+ const uint8_t *data,
48
+ size_t length,
49
+ VALUE self);
50
+
51
+ static void on_friend_message(
52
+ Tox *tox,
53
+ uint32_t friend_number,
54
+ TOX_MESSAGE_TYPE type,
55
+ const uint8_t *text,
56
+ size_t length,
57
+ VALUE self);
58
+
59
+ typedef struct Tox_Options cTox_cOptions_;
60
+
61
+ static VALUE cTox_cOptions;
62
+
63
+ static VALUE cTox_cOptions_alloc(VALUE klass);
64
+ static void cTox_cOptions_free(void *ptr);
65
+ static VALUE cTox_cOptions_initialize(VALUE self);
66
+ static VALUE cTox_cOptions_data_EQUALS(VALUE self, VALUE data);
67
+
68
+ void Init_tox()
69
+ {
70
+ if (!TOX_VERSION_IS_ABI_COMPATIBLE())
71
+ rb_raise(rb_eLoadError, "incompatible Tox ABI version");
72
+
73
+ cTox = rb_define_class("Tox", rb_cObject);
74
+ rb_define_alloc_func(cTox, cTox_alloc);
75
+ rb_define_method(cTox, "initialize_with", cTox_initialize_with, 1);
76
+ rb_define_method(cTox, "savedata", cTox_savedata, 0);
77
+ rb_define_method(cTox, "id", cTox_id, 0);
78
+ rb_define_method(cTox, "bootstrap", cTox_bootstrap, 1);
79
+ rb_define_method(cTox, "kill", cTox_kill, 0);
80
+ rb_define_method(cTox, "loop", cTox_loop, 0);
81
+ rb_define_method(cTox, "friend_add_norequest", cTox_friend_add_norequest, 1);
82
+ rb_define_method(cTox, "friend_send_message", cTox_friend_send_message, 2);
83
+
84
+ cTox_cOptions = rb_define_class_under(cTox, "Options", rb_cObject);
85
+ rb_define_alloc_func(cTox_cOptions, cTox_cOptions_alloc);
86
+ rb_define_method(cTox_cOptions, "initialize", cTox_cOptions_initialize, 0);
87
+ rb_define_method(cTox_cOptions, "data=", cTox_cOptions_data_EQUALS, 1);
88
+ }
89
+
90
+ /******************************************************************************
91
+ * KeyBin
92
+ ******************************************************************************/
93
+
94
+ void Key_to_KeyBin(const char *const key, uint8_t *const key_bin)
95
+ {
96
+ long i;
97
+
98
+ for (i = 0; i < TOX_PUBLIC_KEY_SIZE; ++i)
99
+ sscanf(&key[i * 2], "%2hhx", &key_bin[i]);
100
+ }
101
+
102
+ /******************************************************************************
103
+ * Tox
104
+ ******************************************************************************/
105
+
106
+ VALUE cTox_alloc(const VALUE klass)
107
+ {
108
+ cTox_ *tox;
109
+
110
+ tox = ALLOC(cTox_);
111
+
112
+ return Data_Wrap_Struct(klass, NULL, cTox_free, tox);
113
+ }
114
+
115
+ void cTox_free(void *const ptr)
116
+ {
117
+ free(ptr);
118
+ }
119
+
120
+ VALUE cTox_initialize_with(const VALUE self, const VALUE options)
121
+ {
122
+ cTox_ *tox;
123
+ cTox_cOptions_ *tox_options;
124
+
125
+ TOX_ERR_NEW error;
126
+
127
+ // check if `options` is instance of `Tox::Options`
128
+ if (Qfalse == rb_funcall(options, rb_intern("is_a?"), 1, cTox_cOptions))
129
+ rb_raise(rb_eTypeError, "argument 1 should be Tox::Options");
130
+
131
+ Data_Get_Struct(self, cTox_, tox);
132
+ Data_Get_Struct(options, cTox_cOptions_, tox_options);
133
+
134
+ tox->tox = tox_new(tox_options, &error);
135
+
136
+ if (error != TOX_ERR_NEW_OK)
137
+ rb_raise(rb_eRuntimeError, "tox_new() failed");
138
+
139
+ tox_callback_friend_request(tox->tox, (tox_friend_request_cb*)on_friend_request, (void*)self);
140
+ tox_callback_friend_message(tox->tox, (tox_friend_message_cb*)on_friend_message, (void*)self);
141
+
142
+ return self;
143
+ }
144
+
145
+ VALUE cTox_savedata(const VALUE self)
146
+ {
147
+ cTox_ *tox;
148
+
149
+ size_t data_size;
150
+ char *data;
151
+
152
+ Data_Get_Struct(self, cTox_, tox);
153
+
154
+ data_size = tox_get_savedata_size(tox->tox);
155
+ data = ALLOC_N(char, data_size);
156
+
157
+ tox_get_savedata(tox->tox, (uint8_t*)data);
158
+
159
+ return rb_str_new(data, data_size);
160
+ }
161
+
162
+ VALUE cTox_id(const VALUE self)
163
+ {
164
+ cTox_ *tox;
165
+
166
+ char address[TOX_ADDRESS_SIZE];
167
+ char id[2 * TOX_ADDRESS_SIZE];
168
+
169
+ unsigned long i;
170
+
171
+ Data_Get_Struct(self, cTox_, tox);
172
+
173
+ tox_self_get_address(tox->tox, (uint8_t*)address);
174
+
175
+ for (i = 0; i < TOX_ADDRESS_SIZE; ++i)
176
+ sprintf(&id[2 * i], "%02X", address[i] & 0xFF);
177
+
178
+ return rb_str_new(id, 2 * TOX_ADDRESS_SIZE);
179
+ }
180
+
181
+ VALUE cTox_bootstrap(const VALUE self, const VALUE options)
182
+ {
183
+ cTox_ *tox;
184
+
185
+ VALUE ip;
186
+ VALUE port;
187
+ VALUE key;
188
+
189
+ Node node;
190
+ KeyBin key_bin;
191
+
192
+ TOX_ERR_BOOTSTRAP error;
193
+
194
+ Check_Type(options, T_HASH);
195
+
196
+ ip = rb_hash_aref(options, ID2SYM(rb_intern("ip")));
197
+ port = rb_hash_aref(options, ID2SYM(rb_intern("port")));
198
+ key = rb_hash_aref(options, ID2SYM(rb_intern("key")));
199
+
200
+ if (ip == Qnil) rb_raise(rb_eRuntimeError, "option \"ip\" is required");
201
+ if (port == Qnil) rb_raise(rb_eRuntimeError, "option \"port\" is required");
202
+ if (key == Qnil) rb_raise(rb_eRuntimeError, "option \"key\" is required");
203
+
204
+ Data_Get_Struct(self, cTox_, tox);
205
+
206
+ memcpy(node.ip, RSTRING_PTR(ip), RSTRING_LEN(ip) + 1);
207
+ node.port = NUM2INT(port);
208
+ memcpy(node.key, RSTRING_PTR(key), RSTRING_LEN(key) + 1);
209
+
210
+ Key_to_KeyBin(node.key, key_bin);
211
+
212
+ tox_bootstrap(tox->tox, node.ip, node.port, key_bin, &error);
213
+
214
+ if (error == TOX_ERR_BOOTSTRAP_OK)
215
+ return Qtrue;
216
+ else
217
+ return Qfalse;
218
+ }
219
+
220
+ VALUE cTox_kill(const VALUE self)
221
+ {
222
+ cTox_ *tox;
223
+
224
+ Data_Get_Struct(self, cTox_, tox);
225
+
226
+ tox_kill(tox->tox);
227
+
228
+ return self;
229
+ }
230
+
231
+ VALUE cTox_loop(const VALUE self)
232
+ {
233
+ cTox_ *tox;
234
+
235
+ struct timespec delay;
236
+
237
+ Data_Get_Struct(self, cTox_, tox);
238
+
239
+ rb_funcall(self, rb_intern("running="), 1, Qtrue);
240
+
241
+ delay.tv_sec = 0;
242
+
243
+ while (rb_funcall(self, rb_intern("running"), 0)) {
244
+ delay.tv_nsec = tox_iteration_interval(tox->tox) * 1000000;
245
+ nanosleep(&delay, NULL);
246
+
247
+ tox_iterate(tox->tox);
248
+ }
249
+
250
+ return self;
251
+ }
252
+
253
+ VALUE cTox_friend_add_norequest(const VALUE self, const VALUE key)
254
+ {
255
+ cTox_ *tox;
256
+
257
+ Check_Type(key, T_STRING);
258
+
259
+ Data_Get_Struct(self, cTox_, tox);
260
+
261
+ return LONG2FIX(tox_friend_add_norequest(tox->tox, (uint8_t*)RSTRING_PTR(key), NULL));
262
+ }
263
+
264
+ VALUE cTox_friend_send_message(const VALUE self, const VALUE friend_number, const VALUE text)
265
+ {
266
+ cTox_ *tox;
267
+
268
+ // Don't know yet how to check for integers
269
+ // Check_Type(friend_number, T_INTEGER);
270
+ Check_Type(text, T_STRING);
271
+
272
+ Data_Get_Struct(self, cTox_, tox);
273
+
274
+ return LONG2FIX(tox_friend_send_message(
275
+ tox->tox,
276
+ NUM2LONG(friend_number),
277
+ TOX_MESSAGE_TYPE_NORMAL,
278
+ (uint8_t*)RSTRING_PTR(text),
279
+ RSTRING_LEN(text),
280
+ NULL
281
+ ));
282
+ }
283
+
284
+ void on_friend_request(
285
+ Tox *const tox,
286
+ const uint8_t *const key,
287
+ const uint8_t *const data,
288
+ const size_t length,
289
+ const VALUE self)
290
+ {
291
+ VALUE rb_on_friend_request;
292
+
293
+ rb_on_friend_request = rb_iv_get(self, "@on_friend_request");
294
+
295
+ if (Qnil != rb_on_friend_request)
296
+ rb_funcall(
297
+ rb_on_friend_request,
298
+ rb_intern("call"),
299
+ 2,
300
+ rb_str_new((char*)key, TOX_PUBLIC_KEY_SIZE),
301
+ rb_str_new((char*)data, length)
302
+ );
303
+ }
304
+
305
+ void on_friend_message(
306
+ Tox *const tox,
307
+ const uint32_t friend_number,
308
+ const TOX_MESSAGE_TYPE type,
309
+ const uint8_t *const text,
310
+ const size_t length,
311
+ const VALUE self)
312
+ {
313
+ VALUE rb_on_friend_message;
314
+
315
+ if (type != TOX_MESSAGE_TYPE_NORMAL)
316
+ return;
317
+
318
+ rb_on_friend_message = rb_iv_get(self, "@on_friend_message");
319
+
320
+ if (Qnil != rb_on_friend_message)
321
+ rb_funcall(
322
+ rb_on_friend_message,
323
+ rb_intern("call"),
324
+ 2,
325
+ LONG2FIX(friend_number),
326
+ rb_str_new((char*)text, length)
327
+ );
328
+ }
329
+
330
+ /******************************************************************************
331
+ * Tox::Options
332
+ ******************************************************************************/
333
+
334
+ VALUE cTox_cOptions_alloc(const VALUE klass)
335
+ {
336
+ cTox_cOptions_ *tox_options;
337
+
338
+ tox_options = ALLOC(cTox_cOptions_);
339
+
340
+ return Data_Wrap_Struct(klass, NULL, cTox_cOptions_free, tox_options);
341
+ }
342
+
343
+ void cTox_cOptions_free(void *const ptr)
344
+ {
345
+ free(ptr);
346
+ }
347
+
348
+ VALUE cTox_cOptions_initialize(const VALUE self)
349
+ {
350
+ cTox_cOptions_ *tox_options;
351
+
352
+ Data_Get_Struct(self, cTox_cOptions_, tox_options);
353
+
354
+ tox_options_default(tox_options);
355
+
356
+ return self;
357
+ }
358
+
359
+ VALUE cTox_cOptions_data_EQUALS(const VALUE self, const VALUE savedata)
360
+ {
361
+ cTox_cOptions_ *tox_options;
362
+
363
+ Check_Type(savedata, T_STRING);
364
+
365
+ Data_Get_Struct(self, cTox_cOptions_, tox_options);
366
+
367
+ tox_options->savedata_type = TOX_SAVEDATA_TYPE_TOX_SAVE;
368
+ tox_options->savedata_data = (uint8_t*)RSTRING_PTR(savedata);
369
+ tox_options->savedata_length = RSTRING_LEN(savedata);
370
+
371
+ return savedata;
372
+ }
data/lib/lita-tox.rb ADDED
@@ -0,0 +1,9 @@
1
+ # rubocop:disable Style/FileName
2
+
3
+ require 'lita'
4
+
5
+ Lita.load_locales Dir[File.expand_path(
6
+ File.join('..', '..', 'locales', '*.yml'), __FILE__
7
+ )]
8
+
9
+ require 'lita/adapters/tox'
@@ -0,0 +1,47 @@
1
+ require 'tox'
2
+
3
+ ##
4
+ # Lita module.
5
+ #
6
+ module Lita
7
+ ##
8
+ # Lita adapters module.
9
+ #
10
+ module Adapters
11
+ ##
12
+ # Tox adapter for the Lita chat bot.
13
+ #
14
+ class Tox < Adapter
15
+ def initialize(robot)
16
+ @tox = ::Tox.new
17
+
18
+ log.info("ID: #{@tox.id}")
19
+
20
+ @tox.on_friend_request do |key|
21
+ @tox.friend_add_norequest(key)
22
+ end
23
+
24
+ @tox.on_friend_message do |friend_number, text|
25
+ user = User.new(friend_number)
26
+ source = Source.new(user: user)
27
+ message = Message.new(robot, text, source)
28
+
29
+ message.command!
30
+ robot.receive(message)
31
+ end
32
+ end
33
+
34
+ def run
35
+ @tox.loop
36
+ end
37
+
38
+ def send_messages(target, messages)
39
+ messages.reject(&:empty?).each do |message|
40
+ @tox.friend_send_message(target.user.id.to_i, message)
41
+ end
42
+ end
43
+ end
44
+
45
+ Lita.register_adapter(:tox, Tox)
46
+ end
47
+ end
data/lib/tox.rb ADDED
@@ -0,0 +1,53 @@
1
+ require 'tox/tox'
2
+
3
+ class Tox
4
+ NODES = [
5
+ %w(192.254.75.102 33445 951C88B7E75C867418ACDB5D273821372BB5BD652740BCDF623A4FA293E75D2F),
6
+ %w(144.76.60.215 33445 04119E835DF3E78BACF0F84235B300546AF8B936F035185E2A8E9E0A67C8924F),
7
+ %w(23.226.230.47 33445 A09162D68618E742FFBCA1C2C70385E6679604B2D80EA6E84AD0996A1AC8A074),
8
+ %w(178.62.125.224 33445 10B20C49ACBD968D7C80F2E8438F92EA51F189F4E70CFBBB2C2C8C799E97F03E),
9
+ %w(178.21.112.187 33445 4B2C19E924972CB9B57732FB172F8A8604DE13EEDA2A6234E348983344B23057),
10
+ %w(195.154.119.113 33445 E398A69646B8CEACA9F0B84F553726C1C49270558C57DF5F3C368F05A7D71354),
11
+ %w(192.210.149.121 33445 F404ABAA1C99A9D37D61AB54898F56793E1DEF8BD46B1038B9D822E8460FAB67),
12
+ %w(76.191.23.96 33445 93574A3FAB7D612FEA29FD8D67D3DD10DFD07A075A5D62E8AF3DD9F5D0932E11),
13
+ %w(46.38.239.179 33445 F5A1A38EFB6BD3C2C8AF8B10D85F0F89E931704D349F1D0720C3C4059AF2440A),
14
+ %w(178.62.250.138 33445 788236D34978D1D5BD822F0A5BEBD2C53C64CC31CD3149350EE27D4D9A2F9B6B),
15
+ %w(78.225.128.39 33445 7A2306BFBA665E5480AE59B31E116BE9C04DCEFE04D9FE25082316FA34B4DA0C),
16
+ %w(130.133.110.14 33445 461FA3776EF0FA655F1A05477DF1B3B614F7D6B124F7DB1DD4FE3C08B03B640F),
17
+ %w(104.167.101.29 33445 5918AC3C06955962A75AD7DF4F80A5D7C34F7DB9E1498D2E0495DE35B3FE8A57),
18
+ %w(195.154.109.148 33445 391C96CB67AE893D4782B8E4495EB9D89CF1031F48460C06075AA8CE76D50A21),
19
+ %w(192.3.173.88 33445 3E1FFDEB667BFF549F619EC6737834762124F50A89C8D0DBF1DDF64A2DD6CD1B),
20
+ %w(205.185.116.116 33445 A179B09749AC826FF01F37A9613F6B57118AE014D4196A0E1105A98F93A54702),
21
+ %w(198.98.51.198 33445 1D5A5F2F5D6233058BF0259B09622FB40B482E4FA0931EB8FD3AB8E7BF7DAF6F),
22
+ %w(80.232.246.79 33445 A7A060D553B017D9D8F038E265C7AFB6C70BAAC55070197F9C007432D0038E0F),
23
+ %w(108.61.165.198 33445 8E7D0B859922EF569298B4D261A8CCB5FEA14FB91ED412A7603A585A25698832),
24
+ %w(212.71.252.109 33445 C4CEB8C7AC607C6B374E2E782B3C00EA3A63B80D4910B8649CCACDD19F260819),
25
+ %w(194.249.212.109 33445 3CEE1F054081E7A011234883BC4FC39F661A55B73637A5AC293DDF1251D9432B),
26
+ %w(194.249.212.109 443 3CEE1F054081E7A011234883BC4FC39F661A55B73637A5AC293DDF1251D9432B),
27
+ %w(103.38.216.87 33445 601AEE6FC8C17E8CD8F8F1FFC4D4AD84E59A73BE451F037194E7A404E3795320),
28
+ %w(185.25.116.107 33445 DA4E4ED4B697F2E9B000EEFE3A34B554ACD3F45F5C96EAEA2516DD7FF9AF7B43),
29
+ %w(192.99.168.140 33445 6A4D0607A296838434A6A7DDF99F50EF9D60A2C510BBF31FE538A25CB6B4652F),
30
+ ]
31
+
32
+ attr_accessor :running
33
+
34
+ def initialize(options = Tox::Options.new)
35
+ initialize_with(options)
36
+
37
+ NODES.each do |node|
38
+ bootstrap({
39
+ ip: node[0],
40
+ port: node[1].to_i,
41
+ key: node[2],
42
+ })
43
+ end
44
+ end
45
+
46
+ def on_friend_request(&block)
47
+ @on_friend_request = block
48
+ end
49
+
50
+ def on_friend_message(&block)
51
+ @on_friend_message = block
52
+ end
53
+ end
data/lita-tox.gemspec ADDED
@@ -0,0 +1,38 @@
1
+ # coding: utf-8
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = 'lita-tox'
5
+ spec.version = '0.1.0'
6
+ spec.authors = ['Braiden Vasco']
7
+ spec.email = ['braiden-vasco@mailtor.net']
8
+
9
+ spec.summary = 'Tox adapter for the Lita chat bot'
10
+ spec.description = 'Tox adapter for the Lita chat bot.'
11
+ spec.homepage = 'https://github.com/braiden-vasco/lita-tox'
12
+ spec.license = 'MIT'
13
+
14
+ spec.metadata['lita_plugin_type'] = 'adapter'
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
17
+ f.match(%r{^(test|spec|features)/})
18
+ end
19
+
20
+ spec.bindir = 'exe'
21
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
+ spec.require_paths = ['lib']
23
+
24
+ spec.extensions << 'ext/tox/extconf.rb'
25
+
26
+ spec.add_development_dependency 'bundler', '~> 1.7'
27
+ spec.add_development_dependency 'rake', '~> 10.0'
28
+ spec.add_development_dependency 'rubocop', '~> 0.31'
29
+ spec.add_development_dependency 'rspec', '~> 3.3'
30
+ spec.add_development_dependency 'simplecov', '~> 0.10'
31
+ spec.add_development_dependency 'yard', '~> 0.8'
32
+ spec.add_development_dependency 'redcarpet', '~> 3.3'
33
+ spec.add_development_dependency 'github_changelog_generator', '~> 1.6'
34
+ spec.add_development_dependency 'rake-compiler', '~> 0.9'
35
+ spec.add_development_dependency 'pry', '~> 0.10'
36
+
37
+ spec.add_runtime_dependency 'lita', '~> 4.4'
38
+ end
data/locales/en.yml ADDED
@@ -0,0 +1,4 @@
1
+ en:
2
+ lita:
3
+ adapters:
4
+ tox:
metadata ADDED
@@ -0,0 +1,221 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: lita-tox
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Braiden Vasco
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-09-13 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rubocop
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0.31'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '0.31'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.3'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.3'
69
+ - !ruby/object:Gem::Dependency
70
+ name: simplecov
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0.10'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0.10'
83
+ - !ruby/object:Gem::Dependency
84
+ name: yard
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '0.8'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '0.8'
97
+ - !ruby/object:Gem::Dependency
98
+ name: redcarpet
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '3.3'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '3.3'
111
+ - !ruby/object:Gem::Dependency
112
+ name: github_changelog_generator
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '1.6'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '1.6'
125
+ - !ruby/object:Gem::Dependency
126
+ name: rake-compiler
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: '0.9'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: '0.9'
139
+ - !ruby/object:Gem::Dependency
140
+ name: pry
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - "~>"
144
+ - !ruby/object:Gem::Version
145
+ version: '0.10'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - "~>"
151
+ - !ruby/object:Gem::Version
152
+ version: '0.10'
153
+ - !ruby/object:Gem::Dependency
154
+ name: lita
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - "~>"
158
+ - !ruby/object:Gem::Version
159
+ version: '4.4'
160
+ type: :runtime
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - "~>"
165
+ - !ruby/object:Gem::Version
166
+ version: '4.4'
167
+ description: Tox adapter for the Lita chat bot.
168
+ email:
169
+ - braiden-vasco@mailtor.net
170
+ executables: []
171
+ extensions:
172
+ - ext/tox/extconf.rb
173
+ extra_rdoc_files: []
174
+ files:
175
+ - ".gitignore"
176
+ - ".rspec"
177
+ - ".rubocop.yml"
178
+ - ".simplecov"
179
+ - ".travis.yml"
180
+ - ".yardopts"
181
+ - CHANGELOG.md
182
+ - Gemfile
183
+ - LICENSE
184
+ - README.md
185
+ - Rakefile
186
+ - bin/console
187
+ - bin/setup
188
+ - ext/tox/extconf.rb
189
+ - ext/tox/tox.c
190
+ - lib/lita-tox.rb
191
+ - lib/lita/adapters/tox.rb
192
+ - lib/tox.rb
193
+ - lita-tox.gemspec
194
+ - locales/en.yml
195
+ homepage: https://github.com/braiden-vasco/lita-tox
196
+ licenses:
197
+ - MIT
198
+ metadata:
199
+ lita_plugin_type: adapter
200
+ post_install_message:
201
+ rdoc_options: []
202
+ require_paths:
203
+ - lib
204
+ required_ruby_version: !ruby/object:Gem::Requirement
205
+ requirements:
206
+ - - ">="
207
+ - !ruby/object:Gem::Version
208
+ version: '0'
209
+ required_rubygems_version: !ruby/object:Gem::Requirement
210
+ requirements:
211
+ - - ">="
212
+ - !ruby/object:Gem::Version
213
+ version: '0'
214
+ requirements: []
215
+ rubyforge_project:
216
+ rubygems_version: 2.4.8
217
+ signing_key:
218
+ specification_version: 4
219
+ summary: Tox adapter for the Lita chat bot
220
+ test_files: []
221
+ has_rdoc: