Archived
1
0
Fork 0

Merge branch 'development'

This commit is contained in:
Braiden Vasco 2015-09-15 20:16:05 +00:00
commit 5bd19736ee
6 changed files with 108 additions and 4 deletions

View file

@ -1,5 +1,12 @@
# Change Log
## [v0.3.0](https://github.com/braiden-vasco/lita-tox/tree/v0.3.0) (2015-09-15)
[Full Changelog](https://github.com/braiden-vasco/lita-tox/compare/v0.2.0...v0.3.0)
**Closed issues:**
- Setup Tox user nickname and status [\#21](https://github.com/braiden-vasco/lita-tox/issues/21)
## [v0.2.0](https://github.com/braiden-vasco/lita-tox/tree/v0.2.0) (2015-09-14)
[Full Changelog](https://github.com/braiden-vasco/lita-tox/compare/v0.1.0...v0.2.0)

View file

@ -48,14 +48,21 @@ When **libtoxcore** is installed, add **lita-tox**
to your Lita instance's Gemfile:
```ruby
gem 'lita-tox', '~> 0.2.0'
gem 'lita-tox', '~> 0.3.0'
```
### Configuration
`config.robot.name` will be used as Tox user name
Mentions in Tox usually use user name, Tox clients usually allow mentioning
by writing first letters of user name and pressing `<Tab>`, so don't use
`config.robot.mention_name`
#### Optional attributes
- `savedata_filename` (String) - Path to file where Tox state will be stored (if provided)
- `status` (String) - Tox user status
#### Example
@ -63,11 +70,11 @@ This is an example `lita_config.rb` file:
```ruby
Lita.configure do |config|
config.robot.name = 'Lita'
config.robot.mention_name = 'lita'
config.robot.name = 'Lita chat bot'
config.robot.adapter = :tox
config.savedata_filename = 'savedata'
config.status = "Send me \"#{config.robot.name}: help\""
end
```

View file

@ -33,5 +33,11 @@ have_library LIBTOXCORE, 'tox_group_message_send' and
have_library LIBTOXCORE, 'tox_callback_group_invite' and
have_library LIBTOXCORE, 'tox_callback_group_message' and
have_library LIBTOXCORE, 'tox_group_peernumber_is_ours' and
have_library LIBTOXCORE, 'tox_self_get_name_size' and
have_library LIBTOXCORE, 'tox_self_get_name' and
have_library LIBTOXCORE, 'tox_self_set_name' and
have_library LIBTOXCORE, 'tox_self_get_status_message_size' and
have_library LIBTOXCORE, 'tox_self_get_status_message' and
have_library LIBTOXCORE, 'tox_self_set_status_message' and
create_makefile "#{NAME}/#{NAME}" or exit(1)

View file

@ -43,6 +43,10 @@ static VALUE cTox_friend_send_message(VALUE self, VALUE friend_number, VALUE tex
static VALUE cTox_join_groupchat(VALUE self, VALUE friend_number, VALUE data);
static VALUE cTox_group_message_send(VALUE self, VALUE group_number, VALUE text);
static VALUE cTox_group_peernumber_is_ours(VALUE self, VALUE group_number, VALUE peer_number);
static VALUE cTox_name(VALUE self);
static VALUE cTox_name_ASSIGN(VALUE self, VALUE name);
static VALUE cTox_status_message(VALUE self);
static VALUE cTox_status_message_ASSIGN(VALUE self, VALUE text);
static void on_friend_request(
Tox *tox,
@ -104,6 +108,10 @@ void Init_tox()
rb_define_method(cTox, "join_groupchat", cTox_join_groupchat, 2);
rb_define_method(cTox, "group_message_send", cTox_group_message_send, 2);
rb_define_method(cTox, "group_peernumber_is_ours", cTox_group_peernumber_is_ours, 2);
rb_define_method(cTox, "name", cTox_name, 0);
rb_define_method(cTox, "name=", cTox_name_ASSIGN, 1);
rb_define_method(cTox, "status_message", cTox_status_message, 0);
rb_define_method(cTox, "status_message=", cTox_status_message_ASSIGN, 1);
cTox_cOptions = rb_define_class_under(cTox, "Options", rb_cObject);
rb_define_alloc_func(cTox_cOptions, cTox_cOptions_alloc);
@ -372,6 +380,78 @@ VALUE cTox_group_peernumber_is_ours(
return Qfalse;
}
VALUE cTox_name(const VALUE self)
{
cTox_ *tox;
char name[TOX_MAX_NAME_LENGTH];
size_t name_size;
Data_Get_Struct(self, cTox_, tox);
name_size = tox_self_get_name_size(tox->tox);
if (name_size > 0)
tox_self_get_name(tox->tox, (uint8_t*)name);
return rb_str_new(name, name_size);
}
VALUE cTox_name_ASSIGN(const VALUE self, const VALUE name)
{
cTox_ *tox;
bool result;
TOX_ERR_SET_INFO error;
Check_Type(name, T_STRING);
Data_Get_Struct(self, cTox_, tox);
result = tox_self_set_name(tox->tox, (uint8_t*)RSTRING_PTR(name), RSTRING_LEN(name), &error);
if (error != TOX_ERR_SET_INFO_OK || !result)
return Qfalse;
else
return Qtrue;
}
VALUE cTox_status_message(const VALUE self)
{
cTox_ *tox;
char text[TOX_MAX_STATUS_MESSAGE_LENGTH];
size_t text_size;
Data_Get_Struct(self, cTox_, tox);
text_size = tox_self_get_status_message_size(tox->tox);
if (text_size > 0)
tox_self_get_status_message(tox->tox, (uint8_t*)text);
return rb_str_new(text, text_size);
}
VALUE cTox_status_message_ASSIGN(const VALUE self, const VALUE text)
{
cTox_ *tox;
bool result;
TOX_ERR_SET_INFO error;
Check_Type(text, T_STRING);
Data_Get_Struct(self, cTox_, tox);
result = tox_self_set_status_message(tox->tox, (uint8_t*)RSTRING_PTR(text), RSTRING_LEN(text), &error);
if (error != TOX_ERR_SET_INFO_OK || !result)
return Qfalse;
else
return Qtrue;
}
void on_friend_request(
Tox *const tox,
const uint8_t *const key,

View file

@ -13,6 +13,7 @@ module Lita
#
class Tox < Adapter
config :savedata_filename, type: String
config :status, type: String
def initialize(robot)
super
@ -29,6 +30,9 @@ module Lita
log.info("ID: #{@tox.id}")
@tox.name = robot.name if robot.name
@tox.status_message = config.status if config.status
@tox.on_friend_request do |key|
@tox.friend_add_norequest(key)
end

View file

@ -2,7 +2,7 @@
Gem::Specification.new do |spec|
spec.name = 'lita-tox'
spec.version = '0.2.0'
spec.version = '0.3.0'
spec.authors = ['Braiden Vasco']
spec.email = ['braiden-vasco@mailtor.net']