synacrb 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/synacrb/common.rb +29 -29
- data/lib/synacrb/state.rb +27 -0
- data/lib/synacrb/version.rb +1 -1
- data/lib/synacrb.rb +4 -4
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fb153533096ac14331d01c6e84d065b07cdd6c4e
|
4
|
+
data.tar.gz: a4cf5df045fd3430208a0b8c7bf1087ca365ab52
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 256dec217b8b609d41141a3226ba9c9bc43ef60c8c440b8a494903737c1967e03322a6d99a2dd470f1c44e3bab4eb13ec79364e589873c637beb7d3326456d53
|
7
|
+
data.tar.gz: 7f03ec68e9186ab0ff41966768f63be1768ee64c3caf0151e426c0a7ad0dd7a1486ec0de0ab90d0c22ae2b3db051638d9b12645fb6ea4981e62a920ef65d3383
|
data/lib/synacrb/common.rb
CHANGED
@@ -10,18 +10,19 @@ module Synacrb
|
|
10
10
|
|
11
11
|
LIMIT_BULK = 64
|
12
12
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
13
|
+
ERR_ALREADY_EXISTS = 1
|
14
|
+
ERR_LIMIT_REACHED = 2
|
15
|
+
ERR_LOGIN_BANNED = 3
|
16
|
+
ERR_LOGIN_BOT = 4
|
17
|
+
ERR_LOGIN_INVALID = 5
|
18
|
+
ERR_MAX_CONN_PER_IP = 6
|
19
|
+
ERR_MISSING_FIELD = 7
|
20
|
+
ERR_MISSING_PERMISSION = 8
|
21
|
+
ERR_SELF_PM = 9
|
22
|
+
ERR_UNKNOWN_BOT = 10
|
23
|
+
ERR_UNKNOWN_CHANNEL = 11
|
24
|
+
ERR_UNKNOWN_MESSAGE = 12
|
25
|
+
ERR_UNKNOWN_USER = 13
|
25
26
|
|
26
27
|
PERM_READ = 1
|
27
28
|
PERM_WRITE = 1 << 1
|
@@ -32,7 +33,7 @@ module Synacrb
|
|
32
33
|
|
33
34
|
PERM_ALL = PERM_READ | PERM_WRITE | PERM_MANAGE_CHANNELS | PERM_MANAGE_MESSAGES | PERM_MANAGE_MODES;
|
34
35
|
|
35
|
-
Channel = Struct.new(:default_mode_bot, :default_mode_user, :id, :name)
|
36
|
+
Channel = Struct.new(:default_mode_bot, :default_mode_user, :id, :name, :private)
|
36
37
|
Message = Struct.new(:author, :channel, :id, :text, :timestamp, :timestamp_edit)
|
37
38
|
User = Struct.new(:admin, :ban, :bot, :id, :modes, :name)
|
38
39
|
|
@@ -40,7 +41,7 @@ module Synacrb
|
|
40
41
|
PACKET_CLOSE_ID = 0; Close = Class.new
|
41
42
|
PACKET_ERR_ID = 1;
|
42
43
|
PACKET_RATELIMIT_ID = 2;
|
43
|
-
PACKET_CHANNELCREATE_ID = 3; ChannelCreate = Struct.new(:default_mode_bot, :default_mode_user, :name)
|
44
|
+
PACKET_CHANNELCREATE_ID = 3; ChannelCreate = Struct.new(:default_mode_bot, :default_mode_user, :name, :recipient)
|
44
45
|
PACKET_CHANNELDELETE_ID = 4; ChannelDelete = Struct.new(:id)
|
45
46
|
PACKET_CHANNELUPDATE_ID = 5; ChannelUpdate = Struct.new(:inner)
|
46
47
|
PACKET_COMMAND_ID = 6; Command = Struct.new(:args, :recipient)
|
@@ -51,20 +52,19 @@ module Synacrb
|
|
51
52
|
PACKET_MESSAGEDELETEBULK_ID = 11; MessageDeleteBulk = Struct.new(:channel, :ids)
|
52
53
|
PACKET_MESSAGELIST_ID = 12; MessageList = Struct.new(:after, :before, :channel, :limit)
|
53
54
|
PACKET_MESSAGEUPDATE_ID = 13; MessageUpdate = Struct.new(:id, :text)
|
54
|
-
|
55
|
-
|
56
|
-
PACKET_USERUPDATE_ID = 16; UserUpdate = Struct.new(:admin, :ban, :channel_mode, :id)
|
55
|
+
PACKET_TYPING_ID = 14; Typing = Struct.new(:channel)
|
56
|
+
PACKET_USERUPDATE_ID = 15; UserUpdate = Struct.new(:admin, :ban, :channel_mode, :id)
|
57
57
|
|
58
58
|
# SERVER PACKETS
|
59
|
-
PACKET_CHANNELDELETERECEIVE_ID =
|
60
|
-
PACKET_CHANNELRECEIVE_ID =
|
61
|
-
PACKET_COMMANDRECEIVE_ID =
|
62
|
-
PACKET_LOGINSUCCESS_ID =
|
63
|
-
PACKET_MESSAGEDELETERECEIVE_ID =
|
59
|
+
PACKET_CHANNELDELETERECEIVE_ID = 16; ChannelDeleteReceive = Struct.new(:inner)
|
60
|
+
PACKET_CHANNELRECEIVE_ID = 17; ChannelReceive = Struct.new(:inner)
|
61
|
+
PACKET_COMMANDRECEIVE_ID = 18; CommandReceive = Struct.new(:args, :author)
|
62
|
+
PACKET_LOGINSUCCESS_ID = 19; LoginSuccess = Struct.new(:created, :id, :token)
|
63
|
+
PACKET_MESSAGEDELETERECEIVE_ID = 20; MessageDeleteReceive = Struct.new(:id)
|
64
|
+
PACKET_MESSAGELISTRECEIVED_ID = 21; MessageListReceived = Struct.new(:id)
|
64
65
|
PACKET_MESSAGERECEIVE_ID = 22; MessageReceive = Struct.new(:inner, :new)
|
65
|
-
|
66
|
-
|
67
|
-
PACKET_USERRECEIVE_ID = 25; UserReceive = Struct.new(:inner)
|
66
|
+
PACKET_TYPINGRECEIVE_ID = 23; TypingReceive = Struct.new(:author, :channel)
|
67
|
+
PACKET_USERRECEIVE_ID = 24; UserReceive = Struct.new(:inner)
|
68
68
|
|
69
69
|
def self.encode_u16(input)
|
70
70
|
(input >> 8).chr + (input % 256).chr
|
@@ -99,8 +99,6 @@ module Synacrb
|
|
99
99
|
MessageList
|
100
100
|
when PACKET_MESSAGEUPDATE_ID
|
101
101
|
MessageUpdate
|
102
|
-
when PACKET_PRIVATEMESSAGE_ID
|
103
|
-
PrivateMessage
|
104
102
|
when PACKET_TYPING_ID
|
105
103
|
Typing
|
106
104
|
when PACKET_USERUPDATE_ID
|
@@ -115,10 +113,10 @@ module Synacrb
|
|
115
113
|
LoginSuccess
|
116
114
|
when PACKET_MESSAGEDELETERECEIVE_ID
|
117
115
|
MessageDeleteReceive
|
116
|
+
when PACKET_MESSAGELISTRECEIVED_ID
|
117
|
+
MessageListReceived
|
118
118
|
when PACKET_MESSAGERECEIVE_ID
|
119
119
|
MessageReceive
|
120
|
-
when PACKET_PMRECEIVE_ID
|
121
|
-
PMReceive
|
122
120
|
when PACKET_TYPINGRECEIVE_ID
|
123
121
|
TypingReceive
|
124
122
|
when PACKET_USERRECEIVE_ID
|
@@ -166,6 +164,8 @@ module Synacrb
|
|
166
164
|
PACKET_LOGINSUCCESS_ID
|
167
165
|
elsif packet.instance_of? MessageDeleteReceive
|
168
166
|
PACKET_MESSAGEDELETERECEIVE_ID
|
167
|
+
elsif packet.instance_of? MessageListReceived
|
168
|
+
PACKET_MESSAGELISTRECEIVED_ID
|
169
169
|
elsif packet.instance_of? MessageReceive
|
170
170
|
PACKET_MESSAGERECEIVE_ID
|
171
171
|
elsif packet.instance_of? PMReceive
|
data/lib/synacrb/state.rb
CHANGED
@@ -28,5 +28,32 @@ module Synacrb
|
|
28
28
|
@users[packet.inner.id] = packet.inner
|
29
29
|
end
|
30
30
|
end
|
31
|
+
|
32
|
+
# Search for a private channel with user
|
33
|
+
def get_private_channel(user)
|
34
|
+
@users.keys
|
35
|
+
.map { |channel| @channels[channel] }
|
36
|
+
.compact
|
37
|
+
.find { |channel| channel.private }
|
38
|
+
# the server doesn't send PMs you don't have access to
|
39
|
+
end
|
40
|
+
|
41
|
+
# Search for the recipient in a private channel
|
42
|
+
def get_recipient(channel)
|
43
|
+
if channel.private
|
44
|
+
return nil
|
45
|
+
end
|
46
|
+
get_recipient_unchecked channel.id
|
47
|
+
end
|
48
|
+
|
49
|
+
# Search for the recipient in a private channel.
|
50
|
+
# If the channel isn't private, it returns the first user it can find
|
51
|
+
# that has a special mode in that channel.
|
52
|
+
# So you should probably make sure it's private first.
|
53
|
+
def get_recipient_unchecked(channel_id)
|
54
|
+
@users.values
|
55
|
+
.find { |user| user.modes.keys
|
56
|
+
.any { |channel| channel == channel_id }}
|
57
|
+
end
|
31
58
|
end
|
32
59
|
end
|
data/lib/synacrb/version.rb
CHANGED
data/lib/synacrb.rb
CHANGED
@@ -1,10 +1,10 @@
|
|
1
|
-
require "common.rb"
|
2
|
-
require "encrypter.rb"
|
3
|
-
require "state.rb"
|
4
|
-
|
5
1
|
require "msgpack"
|
6
2
|
require "openssl"
|
7
3
|
require "socket"
|
4
|
+
|
5
|
+
require "synacrb/common"
|
6
|
+
require "synacrb/encrypter"
|
7
|
+
require "synacrb/state"
|
8
8
|
require "synacrb/version"
|
9
9
|
|
10
10
|
module Synacrb
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: synacrb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- jD91mZM2
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-01-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: msgpack
|