Cinch-Automode 0.0.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 831e6ea6d01c75667b4ac3838c4b0d2b98314c7a
4
+ data.tar.gz: a9ca84fa21ce3a18358d0db99194f521d43bf610
5
+ SHA512:
6
+ metadata.gz: 6706cfa4655d43d45cc3212bd154b9d91f5a8be6744e2ccdc32e6efb3ff99927cbcfc5130f2d24e3b8efd047cb8955462f0d797217594a0e9d507a64fa145c48
7
+ data.tar.gz: 1f9aeb68c3e70283c4671fafa28a51c991dd4ec431dc30d1ed74d7351bdbb5b87e18dff70fb3161dd8075cd0fde6b9c683b01859accf0624871396817a270ba5
@@ -0,0 +1,43 @@
1
+
2
+ # -*- encoding: utf-8 -*-
3
+ $LOAD_PATH.push('lib')
4
+ require 'cinch/plugins/automode/version'
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = 'Cinch-Automode'
8
+ s.version = Cinch::Automode::VERSION.dup
9
+ s.date = '2016-02-28'
10
+ s.summary = 'Cinch plugin to automatically apply modes to people on join'
11
+ s.email = 'lilian.jonsdottir@gmail.com'
12
+ s.homepage = 'https://github.com/lilyseki/Cinch-Automode'
13
+ s.authors = ['Lily Jónsdóttir']
14
+ s.license = 'MIT'
15
+
16
+ s.description = <<-EOF
17
+ Automatically apply a mode to a user based on nick!user@host when they join a
18
+ channel. Also has commands to add and delete users, and apply mode to anyone
19
+ that joins a channel.
20
+ EOF
21
+
22
+ dependencies = [
23
+ [:runtime, 'sequel', '~> 4.31'],
24
+ ]
25
+
26
+ s.files = Dir['**/*']
27
+ s.test_files = Dir['test/**/*'] + Dir['spec/**/*']
28
+ s.executables = Dir['bin/*'].map { |f| File.basename(f) }
29
+ s.require_paths = ['lib']
30
+
31
+ ## Make sure you can build the gem on older versions of RubyGems too:
32
+ s.rubygems_version = '2.5.1'
33
+ s.required_rubygems_version = Gem::Requirement.new('>= 0') if s.respond_to? :required_rubygems_version=
34
+ s.specification_version = 3 if s.respond_to? :specification_version
35
+
36
+ dependencies.each do |type, name, version|
37
+ if s.respond_to?("add_#{type}_dependency")
38
+ s.send("add_#{type}_dependency", name, version)
39
+ else
40
+ s.add_dependency(name, version)
41
+ end
42
+ end
43
+ end
data/LICENSE.md ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+ =====================
3
+
4
+ Copyright (c) 2016 Lily Jónsdottír
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
7
+ this software and associated documentation files (the "Software"), to deal in
8
+ the Software without restriction, including without limitation the rights to
9
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
10
+ the Software, and to permit persons to whom the Software is furnished to do so,
11
+ subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in all
14
+ copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
18
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
19
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
20
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,59 @@
1
+ Automode Plugin for Cinch
2
+ ========================
3
+ Auto op/halfop/voice users based on nick!user@host or apply the mode to an
4
+ entire channel
5
+
6
+ Usage
7
+ -----
8
+
9
+ Until I figure out how to make it into a gem, download the .rb file, and place
10
+ it in a subdirectory of your bot entitled
11
+ `plugins` then require it via `require_relative`.
12
+ Add it to your bot like so:
13
+
14
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ruby
15
+ require 'cinch'
16
+ require_relative 'plugins/automode.rb'
17
+
18
+ bot = Cinch::Bot.new do
19
+ configure do |c|
20
+ c.server = 'your server'
21
+ c.nick = 'your nick'
22
+ c.realname = 'your realname'
23
+ c.user = 'your user'
24
+ c.channels = ['#yourchannel']
25
+ c.plugins.plugins = [Cinch::Plugins::Automode]
26
+ end
27
+
28
+ bot.start
29
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
30
+
31
+ Contained Commands
32
+ ------------------
33
+
34
+ **[automode (on|off)]**
35
+
36
+ Enable/disable the plugin in the current channel. Default is off.
37
+
38
+ **[add (op|halfop|voice) nick user@host]**
39
+
40
+ Add nick with user@host to the auto-(op|halfop|voice) list
41
+
42
+ **[del (op|halfop|voice) nick user@host]**
43
+
44
+ Delete nick with user@host from the auto-(op|halfop|voice) list
45
+
46
+ **[add channel (op|halfop|voice)]**
47
+
48
+ Add the entire channel to the list, so anyone who joins gets the mode.
49
+
50
+ **[del channel (op|halfop|voice)]**
51
+
52
+ Delete the channel from the mode list.
53
+
54
+ License
55
+ -------
56
+
57
+ Licensed under The MIT License (MIT)
58
+
59
+ Please see LICENSE
@@ -0,0 +1,5 @@
1
+ module Cinch
2
+ module Automode
3
+ VERSION = '0.0.1'.freeze
4
+ end
5
+ end
@@ -0,0 +1,259 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding=utf-8
3
+
4
+ require 'sequel'
5
+
6
+ # These are all very annoying.
7
+ # rubocop:disable Metrics/LineLength, Metrics/ClassLength, Metrics/CyclomaticComplexity
8
+ # rubocop:disable Metrics/MethodLength, Metrics/PerceivedComplexity, Metrics/AbcSize
9
+
10
+ module Cinch
11
+ module Plugins
12
+ # Automode plugin using Sequel + SQLite database
13
+ class Automode
14
+ include Cinch::Plugin
15
+ listen_to :join
16
+
17
+ private
18
+
19
+ def initialize(*args)
20
+ super
21
+ @automode = {}
22
+ # Initialize the db
23
+ @db = Sequel.sqlite('riria.db')
24
+ # Create the tables if they don't exist
25
+ @db.create_table? :users do
26
+ primary_key :id
27
+ String :name
28
+ String :mode
29
+ end
30
+ @db.create_table? :hostmasks do
31
+ primary_key :id
32
+ Int :user_id
33
+ String :mask
34
+ end
35
+ @db.create_table? :userchans do
36
+ primary_key :id
37
+ Int :user_id
38
+ String :chan
39
+ end
40
+ @db.create_table? :channels do
41
+ primary_key :id
42
+ String :chan
43
+ String :mode
44
+ end
45
+ end
46
+
47
+ # making shit stand out in the console for debug
48
+ def header(title)
49
+ puts '=' * 5 + " #{title} " + '=' * 5
50
+ end
51
+
52
+ # reading and writing database methods
53
+ def read_db(nick, hostmask, channel)
54
+ # header 'reading?'
55
+ # puts "db class: #{@db.class}"
56
+ # puts "db tables: #{@db.tables}"
57
+ return 'no' unless @db.table_exists?(:users)
58
+
59
+ users = @db[:users] # Users table
60
+ hosts = @db[:hostmasks] # Hostmasks table
61
+ userchans = @db[:userchans] # User channels table
62
+ chans = @db[:channels] # Automode all channels table
63
+
64
+ unless chans.where(chan: channel).all.empty?
65
+ return chans.where(chan: channel).first[:mode]
66
+ end
67
+
68
+ # header 'database'
69
+ # puts users.all
70
+ # puts hosts.all
71
+ # puts userchans.all
72
+ # header 'end database'
73
+
74
+ return 'no' if users.where(nick: nick).first.nil?
75
+ return 'admin' if users.where(nick: nick).first[:mode] == 'admin'
76
+
77
+ user_id = users.where(nick: nick).first[:id]
78
+ has_hostmasks = hosts.where(user_id: user_id).map(:mask)
79
+ has_channels = userchans.where(user_id: user_id).map(:chan)
80
+
81
+ # puts "hostmask: #{hostmask}"
82
+ # puts "hostmasks: #{has_hostmasks}"
83
+ # puts "channels: #{has_channels}"
84
+ # puts "has? #{has_hostmasks.include?(hostmask)}"
85
+ # puts "mode: #{users.where(nick: nick).first[:mode]}"
86
+
87
+ return 'no' unless has_hostmasks.include?(hostmask)
88
+ return 'no' unless has_channels.include?(channel)
89
+ users.where(nick: nick).first[:mode]
90
+ end
91
+
92
+ def write_db(nick, hostmask, mode, in_chan)
93
+ # header 'writing?'
94
+ # puts "db class: #{@db.class}"
95
+ # puts "db tables: #{@db.tables}"
96
+
97
+ users = @db[:users]
98
+ hosts = @db[:hostmasks]
99
+ chans = @db[:userchans]
100
+
101
+ # header 'database'
102
+ # puts users.all
103
+ # puts hosts.all
104
+ # puts chans.all
105
+ # header 'end database'
106
+
107
+ # If user isn't in db, add user to db
108
+ if users.where(nick: nick).first.nil?
109
+ users.insert(nick: nick, mode: mode)
110
+ else
111
+ # If user is in db, update mode with provided
112
+ users.where(nick: nick).update(mode: mode)
113
+ end
114
+
115
+ user_id = users.where(nick: nick).first[:id]
116
+ if hosts.where(user_id: user_id, mask: hostmask).first.nil?
117
+ hosts.insert(user_id: user_id, mask: hostmask)
118
+ end
119
+
120
+ if chans.where(user_id: user_id, chan: in_chan).first.nil?
121
+ chans.insert(user_id: user_id, chan: in_chan)
122
+ end
123
+
124
+ # Words to say
125
+ output = "User #{users.where(nick: nick).first[:nick]} added "
126
+ output << "hostmask #{hosts.where(user_id: user_id).all[-1][:mask]} "
127
+ output << "with mode #{users.where(nick: nick).first[:mode]}"
128
+ # header 'stuff'
129
+ # puts "output: #{output}"
130
+ # puts "user_id: #{user_id}"
131
+
132
+ # header 'database'
133
+ # puts users.all
134
+ # puts hosts.all
135
+ # puts chans.all
136
+ # header 'end database'
137
+
138
+ output
139
+ end
140
+
141
+ def add_channel(chan, mode)
142
+ chans = @db[:channels]
143
+ if chans.where(chan: chan).first.nil?
144
+ chans.insert(chan: chan, mode: mode)
145
+ else
146
+ chans.where(chan: chan).update(mode: mode)
147
+ end
148
+ output = "#{chans.where(chan: chan).first[:chan]} "
149
+ output << "added with mode #{chans.where(chan: chan).first[:mode]}"
150
+ # puts output
151
+ output
152
+ end
153
+
154
+ public
155
+
156
+ match(/automode (on|off)$/, method: :endisable)
157
+ def endisable(m, option)
158
+ hostmask = m.raw.split(' ')[0].delete(':').split('!')[1]
159
+ return unless read_db(m.user.nick, hostmask, nil) == 'admin'
160
+ @automode[m.channel] = option == 'on'
161
+
162
+ m.reply "Automode is now #{@automode[m.channel] ? 'enabled' : 'disabled'}"
163
+ end
164
+
165
+ def listen(m)
166
+ @automode[m.channel] ||= true
167
+ return unless @automode[m.channel]
168
+ return if m.user.nick == bot.nick
169
+ # header 'listen?'
170
+ hostmask = m.raw.split(' ')[0].delete(':').split('!')[1]
171
+ mode = read_db(m.user.nick, hostmask, m.channel.to_s)
172
+ case mode
173
+ when 'admin'
174
+ m.channel.op(m.user)
175
+ when 'op'
176
+ m.channel.op(m.user)
177
+ when 'halfop'
178
+ m.channel.mode("+h #{m.user}")
179
+ when 'voice'
180
+ m.channel.voice(m.user)
181
+ when 'no'
182
+ return
183
+ else
184
+ return
185
+ end
186
+ end
187
+
188
+ match(/add(?: (.+))?/, method: :add_user)
189
+ def add_user(m, query)
190
+ hostmask = m.raw.split(' ')[0].delete(':').split('!')[1]
191
+ return unless read_db(m.user.nick, hostmask, nil) == 'admin'
192
+ # .add mode nick user@host
193
+ query = query.split(' ')
194
+ mode = query[0]
195
+ nick = query[1]
196
+ hostmask = query[2]
197
+ goodtypes = %w(op halfop voice admin)
198
+ goodmask = /(.*)@(.*)/ =~ hostmask
199
+
200
+ if mode == 'channel'
201
+ m.reply add_channel(m.channel.to_s, query[1])
202
+ return
203
+ end
204
+
205
+ m.reply('Bad mode type!') && return unless goodtypes.include?(mode)
206
+ m.reply('Bad hostmask!') && return unless goodmask
207
+ m.reply write_db(nick, hostmask, mode, m.channel.to_s)
208
+ end
209
+
210
+ match(/del(?: (.+))?/, method: :del_user)
211
+ def del_user(m, query)
212
+ hostmask = m.raw.split(' ')[0].delete(':').split('!')[1]
213
+ return unless read_db(m.user.nick, hostmask, nil) == 'admin'
214
+ # .del nick user@host >>> remove host from nick
215
+ # .del nick >>> remove nick from db
216
+ nick = query.split[0]
217
+ host = query.split[1]
218
+ users = @db[:users]
219
+ hosts = @db[:hostmasks]
220
+
221
+ if nick == 'channel'
222
+ chan_todel = m.channel.to_s
223
+ chans = @db[:channels]
224
+ m.reply 'Channel not in db' && return if chans.where(chan: chan_todel).first.nil?
225
+ them = chans.where(chan: chan_todel).first[:mode]
226
+ chans.where(chan: chan_todel).delete
227
+ m.reply "#{chan_todel} with mode #{them} removed"
228
+ return
229
+ end
230
+
231
+ m.reply('User not in db!') && return if users.where(nick: nick).all.empty?
232
+
233
+ user_id = users.where(nick: nick).first[:id]
234
+ if host.nil?
235
+ u_num = users.where(nick: nick).delete
236
+ h_num = hosts.where(user_id: user_id).delete
237
+ if u_num.zero? && h_num.zero?
238
+ m.reply('Not baleeted!')
239
+ else
240
+ m.reply('Baleeted!')
241
+ end
242
+ else
243
+ h_num = hosts.where(user_id: user_id, mask: host).delete
244
+ if h_num.zero?
245
+ m.reply('Not baleeted!')
246
+ else
247
+ m.reply('Baleeted!')
248
+ end
249
+ end
250
+ # header 'database'
251
+ # puts users.all
252
+ # puts hosts.all
253
+ # header 'end database'
254
+ end
255
+ end
256
+ end
257
+ end
258
+
259
+ # vim:tabstop=2 softtabstop=2 expandtab shiftwidth=2 smarttab foldmethod=syntax:
metadata ADDED
@@ -0,0 +1,65 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: Cinch-Automode
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Lily Jónsdóttir
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-02-28 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: sequel
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '4.31'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '4.31'
27
+ description: |
28
+ Automatically apply a mode to a user based on nick!user@host when they join a
29
+ channel. Also has commands to add and delete users, and apply mode to anyone
30
+ that joins a channel.
31
+ email: lilian.jonsdottir@gmail.com
32
+ executables: []
33
+ extensions: []
34
+ extra_rdoc_files: []
35
+ files:
36
+ - Cinch-Automode.gemspec
37
+ - LICENSE.md
38
+ - README.md
39
+ - lib/cinch/plugins/automode.rb
40
+ - lib/cinch/plugins/automode/version.rb
41
+ homepage: https://github.com/lilyseki/Cinch-Automode
42
+ licenses:
43
+ - MIT
44
+ metadata: {}
45
+ post_install_message:
46
+ rdoc_options: []
47
+ require_paths:
48
+ - lib
49
+ required_ruby_version: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ required_rubygems_version: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ version: '0'
59
+ requirements: []
60
+ rubyforge_project:
61
+ rubygems_version: 2.5.1
62
+ signing_key:
63
+ specification_version: 3
64
+ summary: Cinch plugin to automatically apply modes to people on join
65
+ test_files: []