lita-tox 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7594dc6e702a18b828fe46e1b8b64d9ad508690b
4
- data.tar.gz: 53a3a8abf586220ae055867fbbb7608fe432072b
3
+ metadata.gz: 25e2ab942844a8990a9784e0d004b330231f9939
4
+ data.tar.gz: 11520285ad007b9c500d73d415db3d474375e481
5
5
  SHA512:
6
- metadata.gz: 89053fb6c2db27721f1e51d8a5cccea01f5cdc2604b89ad499ea00b6b733bd16690aee497f9ab24d98994656baeec7a1ffd2b963cfff5333ebd960c7425c82d9
7
- data.tar.gz: 45f399f7696d54b47c19815da80716cdc9140ce4b4c030f16ff412d821c31fbf1799d979d2267d9626cf45a04208cf0ab13446a55d059768e6f6579ee32d44af
6
+ metadata.gz: b201826ff6de4691bb3c0143a3d118b31b249d4d5a0248bcdf444f62ef4f6a7b786e11f56aa0fdd4e73af4b018c1ba88d89c31a1bb6d5bdd3b7f7e2128296317
7
+ data.tar.gz: 672c193d9290b8c86f174406974d6578aea1ffc93bf1b248e20e8230ceab70816987c019c46d5eca348b2f30729da3ca3018fa7197123657226795bcb9320911
data/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # Change Log
2
2
 
3
+ ## [v0.3.0](https://github.com/braiden-vasco/lita-tox/tree/v0.3.0) (2015-09-15)
4
+ [Full Changelog](https://github.com/braiden-vasco/lita-tox/compare/v0.2.0...v0.3.0)
5
+
6
+ **Closed issues:**
7
+
8
+ - Setup Tox user nickname and status [\#21](https://github.com/braiden-vasco/lita-tox/issues/21)
9
+
3
10
  ## [v0.2.0](https://github.com/braiden-vasco/lita-tox/tree/v0.2.0) (2015-09-14)
4
11
  [Full Changelog](https://github.com/braiden-vasco/lita-tox/compare/v0.1.0...v0.2.0)
5
12
 
data/README.md CHANGED
@@ -48,14 +48,21 @@ When **libtoxcore** is installed, add **lita-tox**
48
48
  to your Lita instance's Gemfile:
49
49
 
50
50
  ```ruby
51
- gem 'lita-tox', '~> 0.2.0'
51
+ gem 'lita-tox', '~> 0.3.0'
52
52
  ```
53
53
 
54
54
  ### Configuration
55
55
 
56
+ `config.robot.name` will be used as Tox user name
57
+
58
+ Mentions in Tox usually use user name, Tox clients usually allow mentioning
59
+ by writing first letters of user name and pressing `<Tab>`, so don't use
60
+ `config.robot.mention_name`
61
+
56
62
  #### Optional attributes
57
63
 
58
64
  - `savedata_filename` (String) - Path to file where Tox state will be stored (if provided)
65
+ - `status` (String) - Tox user status
59
66
 
60
67
  #### Example
61
68
 
@@ -63,11 +70,11 @@ This is an example `lita_config.rb` file:
63
70
 
64
71
  ```ruby
65
72
  Lita.configure do |config|
66
- config.robot.name = 'Lita'
67
- config.robot.mention_name = 'lita'
73
+ config.robot.name = 'Lita chat bot'
68
74
 
69
75
  config.robot.adapter = :tox
70
76
 
71
77
  config.savedata_filename = 'savedata'
78
+ config.status = "Send me \"#{config.robot.name}: help\""
72
79
  end
73
80
  ```
data/ext/tox/extconf.rb CHANGED
@@ -33,5 +33,11 @@ have_library LIBTOXCORE, 'tox_group_message_send' and
33
33
  have_library LIBTOXCORE, 'tox_callback_group_invite' and
34
34
  have_library LIBTOXCORE, 'tox_callback_group_message' and
35
35
  have_library LIBTOXCORE, 'tox_group_peernumber_is_ours' and
36
+ have_library LIBTOXCORE, 'tox_self_get_name_size' and
37
+ have_library LIBTOXCORE, 'tox_self_get_name' and
38
+ have_library LIBTOXCORE, 'tox_self_set_name' and
39
+ have_library LIBTOXCORE, 'tox_self_get_status_message_size' and
40
+ have_library LIBTOXCORE, 'tox_self_get_status_message' and
41
+ have_library LIBTOXCORE, 'tox_self_set_status_message' and
36
42
 
37
43
  create_makefile "#{NAME}/#{NAME}" or exit(1)
data/ext/tox/tox.c CHANGED
@@ -43,6 +43,10 @@ static VALUE cTox_friend_send_message(VALUE self, VALUE friend_number, VALUE tex
43
43
  static VALUE cTox_join_groupchat(VALUE self, VALUE friend_number, VALUE data);
44
44
  static VALUE cTox_group_message_send(VALUE self, VALUE group_number, VALUE text);
45
45
  static VALUE cTox_group_peernumber_is_ours(VALUE self, VALUE group_number, VALUE peer_number);
46
+ static VALUE cTox_name(VALUE self);
47
+ static VALUE cTox_name_ASSIGN(VALUE self, VALUE name);
48
+ static VALUE cTox_status_message(VALUE self);
49
+ static VALUE cTox_status_message_ASSIGN(VALUE self, VALUE text);
46
50
 
47
51
  static void on_friend_request(
48
52
  Tox *tox,
@@ -104,6 +108,10 @@ void Init_tox()
104
108
  rb_define_method(cTox, "join_groupchat", cTox_join_groupchat, 2);
105
109
  rb_define_method(cTox, "group_message_send", cTox_group_message_send, 2);
106
110
  rb_define_method(cTox, "group_peernumber_is_ours", cTox_group_peernumber_is_ours, 2);
111
+ rb_define_method(cTox, "name", cTox_name, 0);
112
+ rb_define_method(cTox, "name=", cTox_name_ASSIGN, 1);
113
+ rb_define_method(cTox, "status_message", cTox_status_message, 0);
114
+ rb_define_method(cTox, "status_message=", cTox_status_message_ASSIGN, 1);
107
115
 
108
116
  cTox_cOptions = rb_define_class_under(cTox, "Options", rb_cObject);
109
117
  rb_define_alloc_func(cTox_cOptions, cTox_cOptions_alloc);
@@ -372,6 +380,78 @@ VALUE cTox_group_peernumber_is_ours(
372
380
  return Qfalse;
373
381
  }
374
382
 
383
+ VALUE cTox_name(const VALUE self)
384
+ {
385
+ cTox_ *tox;
386
+
387
+ char name[TOX_MAX_NAME_LENGTH];
388
+ size_t name_size;
389
+
390
+ Data_Get_Struct(self, cTox_, tox);
391
+
392
+ name_size = tox_self_get_name_size(tox->tox);
393
+
394
+ if (name_size > 0)
395
+ tox_self_get_name(tox->tox, (uint8_t*)name);
396
+
397
+ return rb_str_new(name, name_size);
398
+ }
399
+
400
+ VALUE cTox_name_ASSIGN(const VALUE self, const VALUE name)
401
+ {
402
+ cTox_ *tox;
403
+
404
+ bool result;
405
+ TOX_ERR_SET_INFO error;
406
+
407
+ Check_Type(name, T_STRING);
408
+
409
+ Data_Get_Struct(self, cTox_, tox);
410
+
411
+ result = tox_self_set_name(tox->tox, (uint8_t*)RSTRING_PTR(name), RSTRING_LEN(name), &error);
412
+
413
+ if (error != TOX_ERR_SET_INFO_OK || !result)
414
+ return Qfalse;
415
+ else
416
+ return Qtrue;
417
+ }
418
+
419
+ VALUE cTox_status_message(const VALUE self)
420
+ {
421
+ cTox_ *tox;
422
+
423
+ char text[TOX_MAX_STATUS_MESSAGE_LENGTH];
424
+ size_t text_size;
425
+
426
+ Data_Get_Struct(self, cTox_, tox);
427
+
428
+ text_size = tox_self_get_status_message_size(tox->tox);
429
+
430
+ if (text_size > 0)
431
+ tox_self_get_status_message(tox->tox, (uint8_t*)text);
432
+
433
+ return rb_str_new(text, text_size);
434
+ }
435
+
436
+ VALUE cTox_status_message_ASSIGN(const VALUE self, const VALUE text)
437
+ {
438
+ cTox_ *tox;
439
+
440
+ bool result;
441
+ TOX_ERR_SET_INFO error;
442
+
443
+ Check_Type(text, T_STRING);
444
+
445
+ Data_Get_Struct(self, cTox_, tox);
446
+
447
+ result = tox_self_set_status_message(tox->tox, (uint8_t*)RSTRING_PTR(text), RSTRING_LEN(text), &error);
448
+
449
+ if (error != TOX_ERR_SET_INFO_OK || !result)
450
+ return Qfalse;
451
+ else
452
+ return Qtrue;
453
+ }
454
+
375
455
  void on_friend_request(
376
456
  Tox *const tox,
377
457
  const uint8_t *const key,
@@ -13,6 +13,7 @@ module Lita
13
13
  #
14
14
  class Tox < Adapter
15
15
  config :savedata_filename, type: String
16
+ config :status, type: String
16
17
 
17
18
  def initialize(robot)
18
19
  super
@@ -29,6 +30,9 @@ module Lita
29
30
 
30
31
  log.info("ID: #{@tox.id}")
31
32
 
33
+ @tox.name = robot.name if robot.name
34
+ @tox.status_message = config.status if config.status
35
+
32
36
  @tox.on_friend_request do |key|
33
37
  @tox.friend_add_norequest(key)
34
38
  end
data/lita-tox.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = 'lita-tox'
5
- spec.version = '0.2.0'
5
+ spec.version = '0.3.0'
6
6
  spec.authors = ['Braiden Vasco']
7
7
  spec.email = ['braiden-vasco@mailtor.net']
8
8
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lita-tox
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Braiden Vasco
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-09-14 00:00:00.000000000 Z
11
+ date: 2015-09-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler