ssc.nob 0.1.0-java

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.
@@ -0,0 +1,162 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: UTF-8
3
+ # frozen_string_literal: true
4
+
5
+ #--
6
+ # This file is part of SSC.Nob.
7
+ # Copyright (c) 2020 Jonathan Bradley Whited (@esotericpig)
8
+ #
9
+ # SSC.Nob is free software: you can redistribute it and/or modify
10
+ # it under the terms of the GNU General Public License as published by
11
+ # the Free Software Foundation, either version 3 of the License, or
12
+ # (at your option) any later version.
13
+ #
14
+ # SSC.Nob is distributed in the hope that it will be useful,
15
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
16
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
+ # GNU General Public License for more details.
18
+ #
19
+ # You should have received a copy of the GNU General Public License
20
+ # along with SSC.Nob. If not, see <https://www.gnu.org/licenses/>.
21
+ #++
22
+
23
+
24
+ require 'ssc.nob/util'
25
+
26
+ require 'ssc.nob/ssc_chat_log/message'
27
+
28
+
29
+ module SSCNob
30
+ class SSCChatLog
31
+ ###
32
+ # @author Jonathan Bradley Whited (@esotericpig)
33
+ # @since 0.1.0
34
+ ###
35
+ class MessageParser
36
+ attr_reader :config
37
+ attr_reader :fin
38
+ attr_accessor :namelen
39
+
40
+ def initialize(config: nil,fin: nil,namelen: nil)
41
+ @config = config
42
+ @fin = fin
43
+ @namelen = namelen
44
+ end
45
+
46
+ def parse(line)
47
+ line = Util.rstrip(line)
48
+
49
+ msg = nil
50
+
51
+ case line[0]
52
+ when 'C'
53
+ msg = parse_chat(line)
54
+ when 'E'
55
+ msg = parse_freq(line)
56
+ when 'P'
57
+ msg = parse_private(line)
58
+ when 'T'
59
+ msg = parse_team(line)
60
+ else
61
+ case line
62
+ when /\A .+\> .*\z/ # ' Name> Msg'
63
+ msg = parse_pub(line)
64
+ when /\(\d+\) killed by: / # ' Name(100) killed by: Name'
65
+ msg = parse_kill(line)
66
+ when /\A Message Name Length\: \d+\z/ # ' Message Name Length: 24'
67
+ msg = parse_q_namelen(line)
68
+ end
69
+ end
70
+
71
+ msg = Message.new(line) if msg.nil?()
72
+
73
+ return msg
74
+ end
75
+
76
+ # 'T Name> Msg'
77
+ def parse_basic(line,type:)
78
+ i = @namelen.nil?() ? line.index('> ',2) : (@namelen + 2)
79
+
80
+ username = line[2...i]
81
+ username = Util.strip(username.to_s())
82
+ message = line[i + 1..-1]
83
+ message = Util.strip(message.to_s())
84
+
85
+ return Message.new(line,type: type,meta: {
86
+ username: username,
87
+ message: message,
88
+ })
89
+ end
90
+
91
+ # 'C 1:Name> Msg'
92
+ # - Not affected by namelen, always full name.
93
+ def parse_chat(line)
94
+ i = line.index(':',2)
95
+ j = line.index('> ',i)
96
+
97
+ channel = line[2...i]
98
+ channel = Util.strip(channel.to_s()).to_i()
99
+ username = line[i + 1...j]
100
+ username = Util.strip(username.to_s())
101
+ message = line[j + 1..-1]
102
+ message = Util.strip(message.to_s())
103
+
104
+ return Message.new(line,type: :chat,meta: {
105
+ channel: channel,
106
+ username: username,
107
+ message: message,
108
+ })
109
+ end
110
+
111
+ def parse_freq(line)
112
+ return parse_basic(line,type: :freq)
113
+ end
114
+
115
+ # ' Name(100) killed by: Name'
116
+ def parse_kill(line)
117
+ i = line.index(/\(\d+\)/,2)
118
+ j = line.index(')',i)
119
+ k = line.index(':',j)
120
+
121
+ killed = line[2...i]
122
+ killed = Util.strip(killed.to_s())
123
+ bounty = line[i + 1...j]
124
+ bounty = Util.strip(bounty.to_s()).to_i()
125
+ killer = line[k + 1..-1]
126
+ killer = Util.strip(killer.to_s())
127
+
128
+ return Message.new(line,type: :kill,meta: {
129
+ killed: killed,
130
+ bounty: bounty,
131
+ killer: killer,
132
+ })
133
+ end
134
+
135
+ def parse_private(line)
136
+ return parse_basic(line,type: :private)
137
+ end
138
+
139
+ def parse_pub(line)
140
+ return parse_basic(line,type: :pub)
141
+ end
142
+
143
+ # ' Message Name Length: 24'
144
+ def parse_q_namelen(line)
145
+ i = line.index(':')
146
+
147
+ namelen = line[i + 1..-1]
148
+ namelen = Util.strip(namelen.to_s()).to_i()
149
+
150
+ @namelen = namelen
151
+
152
+ return Message.new(line,type: :q_namelen,meta: {
153
+ namelen: namelen,
154
+ })
155
+ end
156
+
157
+ def parse_team(line)
158
+ return parse_basic(line,type: :team)
159
+ end
160
+ end
161
+ end
162
+ end
@@ -0,0 +1,124 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: UTF-8
3
+ # frozen_string_literal: true
4
+
5
+ #--
6
+ # This file is part of SSC.Nob.
7
+ # Copyright (c) 2020 Jonathan Bradley Whited (@esotericpig)
8
+ #
9
+ # SSC.Nob is free software: you can redistribute it and/or modify
10
+ # it under the terms of the GNU General Public License as published by
11
+ # the Free Software Foundation, either version 3 of the License, or
12
+ # (at your option) any later version.
13
+ #
14
+ # SSC.Nob is distributed in the hope that it will be useful,
15
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
16
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
+ # GNU General Public License for more details.
18
+ #
19
+ # You should have received a copy of the GNU General Public License
20
+ # along with SSC.Nob. If not, see <https://www.gnu.org/licenses/>.
21
+ #++
22
+
23
+
24
+ require 'forwardable'
25
+ require 'highline'
26
+ require 'rainbow'
27
+ require 'singleton'
28
+ require 'tty-spinner'
29
+
30
+
31
+ module SSCNob
32
+ ###
33
+ # @author Jonathan Bradley Whited (@esotericpig)
34
+ # @since 0.1.0
35
+ ###
36
+ class Userface
37
+ extend Forwardable
38
+ include Singleton
39
+
40
+ attr_reader :line
41
+ attr_reader :rain
42
+
43
+ def_delegators :@line,:agree,:ask,:choose,:indent,:say
44
+ def_delegator :@rain,:wrap,:color
45
+
46
+ def initialize()
47
+ super()
48
+
49
+ @line = HighLine.new()
50
+ @rain = Rainbow.new()
51
+
52
+ @line.use_color = true
53
+ @rain.enabled = true
54
+ end
55
+
56
+ def cmd(cmd)
57
+ return color(cmd).yellow.bold
58
+ end
59
+
60
+ def coffee()
61
+ return color('C\_/').saddlebrown.bold
62
+ end
63
+
64
+ def error(msg)
65
+ return "#{color('Error:').red.bold} #{msg}"
66
+ end
67
+
68
+ def gt(msg=nil)
69
+ return "#{color('>').yellow.bold} #{msg}"
70
+ end
71
+
72
+ def love(msg)
73
+ return color(msg).red.bold
74
+ end
75
+
76
+ def spin(msg,&block)
77
+ spinner = TTY::Spinner.new("[:spinner] #{msg}...",
78
+ interval: 4,frames: ['o_O','O_o']
79
+ )
80
+
81
+ if block_given?()
82
+ spinner.run(&block)
83
+ else
84
+ spinner.auto_spin()
85
+ end
86
+
87
+ return spinner
88
+ end
89
+
90
+ def ssc()
91
+ return color('Subspace Continuum').purple.bold
92
+ end
93
+
94
+ def title(title)
95
+ return color(title).blue.bold
96
+ end
97
+
98
+ def type(msg)
99
+ msg.each_char() do |c|
100
+ print c
101
+ sleep(0.05)
102
+ end
103
+ end
104
+
105
+ def types(msg)
106
+ type(msg)
107
+ puts
108
+ end
109
+
110
+ def user(user)
111
+ return color(user).limegreen.bold
112
+ end
113
+ end
114
+
115
+ ###
116
+ # @author Jonathan Bradley Whited (@esotericpig)
117
+ # @since 0.1.0
118
+ ###
119
+ module Uface
120
+ def uface()
121
+ return Userface.instance
122
+ end
123
+ end
124
+ end
@@ -0,0 +1,52 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: UTF-8
3
+ # frozen_string_literal: true
4
+
5
+ #--
6
+ # This file is part of SSC.Nob.
7
+ # Copyright (c) 2020 Jonathan Bradley Whited (@esotericpig)
8
+ #
9
+ # SSC.Nob is free software: you can redistribute it and/or modify
10
+ # it under the terms of the GNU General Public License as published by
11
+ # the Free Software Foundation, either version 3 of the License, or
12
+ # (at your option) any later version.
13
+ #
14
+ # SSC.Nob is distributed in the hope that it will be useful,
15
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
16
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
+ # GNU General Public License for more details.
18
+ #
19
+ # You should have received a copy of the GNU General Public License
20
+ # along with SSC.Nob. If not, see <https://www.gnu.org/licenses/>.
21
+ #++
22
+
23
+
24
+ module SSCNob
25
+ ###
26
+ # @author Jonathan Bradley Whited (@esotericpig)
27
+ # @since 0.1.0
28
+ ###
29
+ module Util
30
+ def self.blank?(str)
31
+ return str.nil?() || strip(str).empty?()
32
+ end
33
+
34
+ def self.lstrip(str)
35
+ return nil if str.nil?()
36
+
37
+ return str.gsub(/\A[[:space:]]+/,'')
38
+ end
39
+
40
+ def self.rstrip(str)
41
+ return nil if str.nil?()
42
+
43
+ return str.gsub(/[[:space:]]+\z/,'')
44
+ end
45
+
46
+ def self.strip(str)
47
+ return nil if str.nil?()
48
+
49
+ return str.gsub(/(\A[[:space:]]+)|([[:space:]]+\z)/,'')
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,26 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: UTF-8
3
+ # frozen_string_literal: true
4
+
5
+ #--
6
+ # This file is part of SSC.Nob.
7
+ # Copyright (c) 2020 Jonathan Bradley Whited (@esotericpig)
8
+ #
9
+ # SSC.Nob is free software: you can redistribute it and/or modify
10
+ # it under the terms of the GNU General Public License as published by
11
+ # the Free Software Foundation, either version 3 of the License, or
12
+ # (at your option) any later version.
13
+ #
14
+ # SSC.Nob is distributed in the hope that it will be useful,
15
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
16
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
+ # GNU General Public License for more details.
18
+ #
19
+ # You should have received a copy of the GNU General Public License
20
+ # along with SSC.Nob. If not, see <https://www.gnu.org/licenses/>.
21
+ #++
22
+
23
+
24
+ module SSCNob
25
+ VERSION = '0.1.0'
26
+ end
data/ssc.nob.gemspec ADDED
@@ -0,0 +1,72 @@
1
+ # encoding: UTF-8
2
+ # frozen_string_literal: true
3
+
4
+ #--
5
+ # This file is part of SSC.Nob.
6
+ # Copyright (c) 2020 Jonathan Bradley Whited (@esotericpig)
7
+ #
8
+ # SSC.Nob is free software: you can redistribute it and/or modify
9
+ # it under the terms of the GNU General Public License as published by
10
+ # the Free Software Foundation, either version 3 of the License, or
11
+ # (at your option) any later version.
12
+ #
13
+ # SSC.Nob is distributed in the hope that it will be useful,
14
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
+ # GNU General Public License for more details.
17
+ #
18
+ # You should have received a copy of the GNU General Public License
19
+ # along with SSC.Nob. If not, see <https://www.gnu.org/licenses/>.
20
+ #++
21
+
22
+
23
+ lib = File.expand_path(File.join('..','lib'),__FILE__)
24
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
25
+
26
+ require 'ssc.nob/version'
27
+
28
+
29
+ Gem::Specification.new() do |spec|
30
+ spec.name = 'ssc.nob'
31
+ spec.version = SSCNob::VERSION
32
+ spec.authors = ['Jonathan Bradley Whited (@esotericpig)']
33
+ spec.email = ['bradley@esotericpig.com']
34
+ spec.licenses = ['GPL-3.0-or-later']
35
+ spec.homepage = 'https://github.com/esotericpig/ssc.nob'
36
+ spec.summary = 'Subspace Continuum Nob (Noble One Bot).'
37
+ spec.description = spec.summary
38
+
39
+ spec.metadata = {
40
+ 'bug_tracker_uri' => 'https://github.com/esotericpig/ssc.nob/issues',
41
+ 'changelog_uri' => 'https://github.com/esotericpig/ssc.nob/blob/master/CHANGELOG.md',
42
+ 'homepage_uri' => 'https://github.com/esotericpig/ssc.nob',
43
+ 'source_code_uri' => 'https://github.com/esotericpig/ssc.nob',
44
+ }
45
+
46
+ spec.require_paths = ['lib']
47
+ spec.bindir = 'bin'
48
+ spec.executables = [spec.name]
49
+
50
+ spec.files = [
51
+ Dir.glob(File.join("{#{spec.require_paths.join(',')}}",'**','*.{erb,rb}')),
52
+ Dir.glob(File.join(spec.bindir,'*')),
53
+ Dir.glob(File.join('{test,yard}','**','*.{erb,rb}')),
54
+ %W( Gemfile #{spec.name}.gemspec Rakefile ),
55
+ %w( CHANGELOG.md LICENSE.txt README.md ),
56
+ ].flatten()
57
+
58
+ spec.platform = 'java'
59
+ spec.required_ruby_version = '>= 2.4'
60
+ #spec.requirements = []
61
+
62
+ spec.add_runtime_dependency 'attr_bool' ,'~> 0.1'
63
+ spec.add_runtime_dependency 'highline' ,'~> 2.0'
64
+ spec.add_runtime_dependency 'rainbow' ,'~> 3.0'
65
+ spec.add_runtime_dependency 'tty-spinner','~> 0.9'
66
+
67
+ spec.add_development_dependency 'bundler' ,'~> 2.1'
68
+ spec.add_development_dependency 'minitest','~> 5.14'
69
+ spec.add_development_dependency 'rake' ,'~> 13.0'
70
+
71
+ #spec.post_install_message = ''
72
+ end
metadata ADDED
@@ -0,0 +1,164 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ssc.nob
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: java
6
+ authors:
7
+ - Jonathan Bradley Whited (@esotericpig)
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-04-30 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - "~>"
17
+ - !ruby/object:Gem::Version
18
+ version: '0.1'
19
+ name: attr_bool
20
+ prerelease: false
21
+ type: :runtime
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.1'
27
+ - !ruby/object:Gem::Dependency
28
+ requirement: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - "~>"
31
+ - !ruby/object:Gem::Version
32
+ version: '2.0'
33
+ name: highline
34
+ prerelease: false
35
+ type: :runtime
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '2.0'
41
+ - !ruby/object:Gem::Dependency
42
+ requirement: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '3.0'
47
+ name: rainbow
48
+ prerelease: false
49
+ type: :runtime
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ requirement: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: '0.9'
61
+ name: tty-spinner
62
+ prerelease: false
63
+ type: :runtime
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0.9'
69
+ - !ruby/object:Gem::Dependency
70
+ requirement: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: '2.1'
75
+ name: bundler
76
+ prerelease: false
77
+ type: :development
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '2.1'
83
+ - !ruby/object:Gem::Dependency
84
+ requirement: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - "~>"
87
+ - !ruby/object:Gem::Version
88
+ version: '5.14'
89
+ name: minitest
90
+ prerelease: false
91
+ type: :development
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '5.14'
97
+ - !ruby/object:Gem::Dependency
98
+ requirement: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - "~>"
101
+ - !ruby/object:Gem::Version
102
+ version: '13.0'
103
+ name: rake
104
+ prerelease: false
105
+ type: :development
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '13.0'
111
+ description: Subspace Continuum Nob (Noble One Bot).
112
+ email:
113
+ - bradley@esotericpig.com
114
+ executables:
115
+ - ssc.nob
116
+ extensions: []
117
+ extra_rdoc_files: []
118
+ files:
119
+ - CHANGELOG.md
120
+ - Gemfile
121
+ - LICENSE.txt
122
+ - README.md
123
+ - Rakefile
124
+ - bin/ssc.nob
125
+ - lib/ssc.nob.rb
126
+ - lib/ssc.nob/config.rb
127
+ - lib/ssc.nob/error.rb
128
+ - lib/ssc.nob/ssc_bot.rb
129
+ - lib/ssc.nob/ssc_chat_log.rb
130
+ - lib/ssc.nob/ssc_chat_log/message.rb
131
+ - lib/ssc.nob/ssc_chat_log/message_parser.rb
132
+ - lib/ssc.nob/userface.rb
133
+ - lib/ssc.nob/util.rb
134
+ - lib/ssc.nob/version.rb
135
+ - ssc.nob.gemspec
136
+ homepage: https://github.com/esotericpig/ssc.nob
137
+ licenses:
138
+ - GPL-3.0-or-later
139
+ metadata:
140
+ bug_tracker_uri: https://github.com/esotericpig/ssc.nob/issues
141
+ changelog_uri: https://github.com/esotericpig/ssc.nob/blob/master/CHANGELOG.md
142
+ homepage_uri: https://github.com/esotericpig/ssc.nob
143
+ source_code_uri: https://github.com/esotericpig/ssc.nob
144
+ post_install_message:
145
+ rdoc_options: []
146
+ require_paths:
147
+ - lib
148
+ required_ruby_version: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '2.4'
153
+ required_rubygems_version: !ruby/object:Gem::Requirement
154
+ requirements:
155
+ - - ">="
156
+ - !ruby/object:Gem::Version
157
+ version: '0'
158
+ requirements: []
159
+ rubyforge_project:
160
+ rubygems_version: 2.7.10
161
+ signing_key:
162
+ specification_version: 4
163
+ summary: Subspace Continuum Nob (Noble One Bot).
164
+ test_files: []