protonbot-relay 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: '09c15f2e5dce3cd89e1160266b2ab5f5f8a4a1e8'
4
+ data.tar.gz: 1612435c812775edb7a4c75a5adccf228ccb4221
5
+ SHA512:
6
+ metadata.gz: 38caa7830aee4763527bc9f4a51852776d6f02c78161388924da7aa05c4f80999b3fcb1c5810b2e06f1c59b2225dbee56ecf0a8368d51d3323c9871b7c5a3b6d
7
+ data.tar.gz: a577a689b0260b525d5f0bb4da6e76e9b25eb68b62fa8971edb91966392162ba143215df595fd368975f7c2a3002d295bed88467d6770674b681729b396d3b7b
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at nickolay02@inbox.ru. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in protonbot-memos.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Nickolay Ilyushin
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
13
+ all 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
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,35 @@
1
+ # Protonbot::Memos
2
+
3
+ Relays for ProtonBot
4
+
5
+ ## Installation
6
+
7
+ Add this line to your bot's Gemfile and plugin loader:
8
+
9
+ ```ruby
10
+ gem 'protonbot-relay'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ ## Usage
18
+
19
+ Execute `list relays` to get more info.
20
+
21
+ ## Development
22
+
23
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
24
+
25
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
26
+
27
+ ## Contributing
28
+
29
+ Bug reports and pull requests are welcome on GitHub at https://github.com/handicraftsman/protonbot-memos. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
30
+
31
+
32
+ ## License
33
+
34
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
35
+
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "protonbot/relay"
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,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,185 @@
1
+ ProtonBot::Plugin.new do
2
+ @name = 'Relays'
3
+ @version = ProtonBot::Memos::VERSION
4
+ @description = 'Relays for ProtonBot'
5
+
6
+ core.permhash['admin'] << 'manage-relays'
7
+
8
+ @relays = bot.db_cross.query('relays').ensure.write.finish
9
+
10
+ core.help_add('relays', 'addrelay', 'addrelay <serv!chan> <serv!chan>', 'Adds relay')
11
+ cmd(cmd: 'addrelay') do |dat|
12
+ unless @relays
13
+ @relays = bot.db_cross.query('relays').ensure.write.finish
14
+ end
15
+ p1 = dat[:split][0].split('!')
16
+ p2 = dat[:split][1].split('!')
17
+ if p1.length != 2
18
+ dat.nreply 'Invalid p1!'
19
+ elsif p2.length != 2
20
+ dat.nreply 'Invalid p2!'
21
+ else
22
+ obj = {
23
+ 'id' => dat[:split][0] + "@" + dat[:split][1],
24
+ 'p1' => {
25
+ 'server' => p1[0],
26
+ 'channel' => p1[1]
27
+ },
28
+ 'p2' => {
29
+ 'server' => p2[0],
30
+ 'channel' => p2[1]
31
+ }
32
+ }
33
+ if bot.db_cross.query('relays').ensure.select('id' => (dat[:split][0] + "@" + dat[:split][1])).finish.empty? &&
34
+ bot.db_cross.query('relays').ensure.select('id' => (dat[:split][1] + "@" + dat[:split][0])).finish.empty?
35
+ bot.db_cross.query('relays').ensure.insert(obj).write.finish
36
+ @relays << obj
37
+ end
38
+ dat.nreply 'Done!'
39
+ end
40
+ end.perm!('manage-relays')
41
+
42
+ core.help_add('relays', 'delrelay', 'delrelay <serv!chan> <serv!chan>', 'Deletes relay')
43
+ cmd(cmd: 'delrelay') do |dat|
44
+ to_del = nil
45
+ @relays.each do |r|
46
+ if r['id'] == dat[:split][0] + "@" + dat[:split][1]
47
+ to_del = r
48
+ break
49
+ end
50
+ if r['id'] == dat[:split][1] + "@" + dat[:split][0]
51
+ to_del = r
52
+ break
53
+ end
54
+ end
55
+ bot.db_cross.query('relays').ensure.delete(to_del).write.finish
56
+ @relays.delete(to_del)
57
+ dat.nreply 'Done!'
58
+ end.perm!('manage-relays')
59
+
60
+ core.help_add('relays', 'relayinfo', 'relayinfo (id)', 'Shows info about relay')
61
+ cmd(cmd: 'relayinfo') do |dat|
62
+ if dat[:split].empty?
63
+ dat.nreply ProtonBot::Bot::Messages::NOT_ENOUGH_PARAMETERS
64
+ else
65
+ dat[:split].each do |id|
66
+ if @relays[id.to_i]
67
+ r = @relays[id.to_i]
68
+ s = "%C%BLUE#{r['p1']['server']}!#{r['p1']['channel']}%N <-> %C%PURPLE#{r['p2']['server']}!#{r['p2']['channel']}%N"
69
+ dat.nreply("%Br#{id}:%N #{s}")
70
+ else
71
+ dat.nreply("No such relay: #{id}")
72
+ end
73
+ end
74
+ end
75
+ end
76
+
77
+ fun :getchan do |dat, relay, cid=:reply_to|
78
+ this = {'server' => dat[:plug].name, 'channel' => dat[cid]}
79
+ other = nil
80
+ if relay['p1'] == this
81
+ other = relay['p2']
82
+ elsif relay['p2'] == this
83
+ other = relay['p1']
84
+ end
85
+ [this, other]
86
+ end
87
+
88
+ fun :getop do |this, other|
89
+ if other
90
+ bot.plugs[other['server']]
91
+ else
92
+ nil
93
+ end
94
+ end
95
+
96
+ hook(type: :privmsg) do |dat|
97
+ unless @relays
98
+ @relays = bot.db_cross.query('relays').ensure.write.finish
99
+ end
100
+ @relays.each_with_index do |v, k|
101
+ this, other = *getchan(dat, v)
102
+ if op = getop(this, other) and op.chans[other['channel']] and dat[:message][0] != "\x01"
103
+ op.privmsg(other['channel'], "%N[%Br#{k}%B]%N %B<%N#{dat[:nick]}%B>%N #{dat[:message]}")
104
+ end
105
+ end
106
+ end
107
+
108
+ hook(type: :ctcp) do |dat|
109
+ unless @relays
110
+ @relays = bot.db_cross.query('relays').ensure.write.finish
111
+ end
112
+ @relays.each_with_index do |v, k|
113
+ this, other = *getchan(dat, v)
114
+ if op = getop(this, other) and op.chans[other['channel']]
115
+ if dat[:cmd] == 'ACTION'
116
+ op.privmsg(other['channel'], "%N[%Br#{k}%B]%N %B<%N#{dat[:nick]}%B>%N %C%BLUE* #{dat[:split].join(' ')}")
117
+ else
118
+ op.privmsg(other['channel'], "%N[%Br#{k}%B]%N %B<%N#{dat[:nick]}%B>%N %C%BLUE[CTCP] #{dat[:message]}")
119
+ end
120
+ end
121
+ end
122
+ end
123
+
124
+ hook(type: :ujoin) do |dat|
125
+ unless @relays
126
+ @relays = bot.db_cross.query('relays').ensure.write.finish
127
+ end
128
+ @relays.each_with_index do |v, k|
129
+ this, other = *getchan(dat, v, :channel)
130
+ if op = getop(this, other) and op.chans[other['channel']]
131
+ op.privmsg(other['channel'], "%N[%Br#{k}%B]%N %B%C%PURPLE#{dat[:nick]}%N has joined %B%C%GREEN#{dat[:channel]}%N")
132
+ end
133
+ end
134
+ end
135
+
136
+ hook(type: :upart) do |dat|
137
+ unless @relays
138
+ @relays = bot.db_cross.query('relays').ensure.write.finish
139
+ end
140
+ @relays.each_with_index do |v, k|
141
+ this, other = *getchan(dat, v, :channel)
142
+ if op = getop(this, other) and op.chans[other['channel']]
143
+ op.privmsg(other['channel'], "%N[%Br#{k}%B]%N %B%C%PURPLE#{dat[:nick]}%N has left %B%C%GREEN#{dat[:channel]}%N")
144
+ end
145
+ end
146
+ end
147
+
148
+ hook(type: :uquitc) do |dat|
149
+ unless @relays
150
+ @relays = bot.db_cross.query('relays').ensure.write.finish
151
+ end
152
+ @relays.each_with_index do |v, k|
153
+ this, other = *getchan(dat, v, :channel)
154
+ if op = getop(this, other) and op.chans[other['channel']]
155
+ op.privmsg(other['channel'], "%N[%Br#{k}%B]%N %B%C%PURPLE#{dat[:nick]}%N has quit %B%C%BLUE(#{dat[:reason]})%N")
156
+ end
157
+ end
158
+ end
159
+
160
+ hook(type: :ukick) do |dat|
161
+ unless @relays
162
+ @relays = bot.db_cross.query('relays').ensure.write.finish
163
+ end
164
+ @relays.each_with_index do |v, k|
165
+ this, other = *getchan(dat, v, :channel)
166
+ if op = getop(this, other) and op.chans[other['channel']]
167
+ op.privmsg(other['channel'], "%N[%Br#{k}%B]%N %B%C%PURPLE#{dat[:nick]}%N has " +
168
+ "kicked %B%C%PURPLE#{dat[:target]}%N from %B%C%GREEN#{dat[:channel]}%N " +
169
+ "%B%C%BLUE(#{dat[:reason]})%N")
170
+ end
171
+ end
172
+ end
173
+
174
+ hook(type: :unickc) do |dat|
175
+ unless @relays
176
+ @relays = bot.db_cross.query('relays').ensure.write.finish
177
+ end
178
+ @relays.each_with_index do |v, k|
179
+ this, other = *getchan(dat, v, :channel)
180
+ if op = getop(this, other) and op.chans[other['channel']]
181
+ op.privmsg(other['channel'], "%N[%Br#{k}%B]%N %B%C%PURPLE#{dat[:nick]}%N is now known as %B%C%PURPLE#{dat[:to]}%N")
182
+ end
183
+ end
184
+ end
185
+ end
@@ -0,0 +1,5 @@
1
+ module ProtonBot
2
+ module Relay
3
+ VERSION = '0.1.0'.freeze
4
+ end
5
+ end
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'protonbot/relay'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "protonbot-relay"
8
+ spec.version = ProtonBot::Relay::VERSION
9
+ spec.authors = ["Nickolay Ilyushin"]
10
+ spec.email = ["nickolay02@inbox.ru"]
11
+
12
+ spec.summary = 'Relays for ProtonBot'
13
+ spec.description = 'Relays for ProtonBot'
14
+ spec.homepage = 'https://github.com/handicraftsman/ProtonBot-Relay'
15
+ spec.license = 'MIT'
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
+ f.match(%r{^(test|spec|features)/})
19
+ end
20
+ spec.bindir = 'exe'
21
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
+ spec.require_paths = ['lib']
23
+
24
+ spec.add_development_dependency 'bundler', '~> 1.13'
25
+ spec.add_development_dependency 'rake', '~> 10.0'
26
+ spec.add_runtime_dependency 'protonbot', '>= 0.3.7'
27
+ end
metadata ADDED
@@ -0,0 +1,97 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: protonbot-relay
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Nickolay Ilyushin
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-04-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.13'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.13'
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: protonbot
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: 0.3.7
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: 0.3.7
55
+ description: Relays for ProtonBot
56
+ email:
57
+ - nickolay02@inbox.ru
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - CODE_OF_CONDUCT.md
64
+ - Gemfile
65
+ - LICENSE.txt
66
+ - README.md
67
+ - Rakefile
68
+ - bin/console
69
+ - bin/setup
70
+ - lib/protonbot/relay.rb
71
+ - lib/protonbot/relay/plugin.rb
72
+ - protonbot-relay.gemspec
73
+ homepage: https://github.com/handicraftsman/ProtonBot-Relay
74
+ licenses:
75
+ - MIT
76
+ metadata: {}
77
+ post_install_message:
78
+ rdoc_options: []
79
+ require_paths:
80
+ - lib
81
+ required_ruby_version: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ required_rubygems_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ requirements: []
92
+ rubyforge_project:
93
+ rubygems_version: 2.6.8
94
+ signing_key:
95
+ specification_version: 4
96
+ summary: Relays for ProtonBot
97
+ test_files: []