cinch-bot_template 0.1.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 +7 -0
- data/.gitignore +28 -0
- data/Gemfile +3 -0
- data/LICENSE +21 -0
- data/README.md +38 -0
- data/Rakefile +11 -0
- data/bin/cinch-mktpl +4 -0
- data/cinch-bot_template.gemspec +33 -0
- data/lib/cinch/bot_template.rb +1 -0
- data/lib/cinch/bot_template/cinch-bot_template.rb +60 -0
- data/lib/cinch/bot_template/classes/bot.rb +73 -0
- data/lib/cinch/bot_template/classes/config.rb +86 -0
- data/lib/cinch/bot_template/classes/exceptions.rb +8 -0
- data/lib/cinch/bot_template/classes/gen_init.rb +69 -0
- data/lib/cinch/bot_template/classes/hello.rb +60 -0
- data/lib/cinch/bot_template/classes/plugin.rb +51 -0
- data/lib/cinch/bot_template/desc/bot.rb +22 -0
- data/lib/cinch/bot_template/desc/gen.rb +27 -0
- data/lib/cinch/bot_template/desc/hello.rb +17 -0
- data/lib/cinch/bot_template/desc/plugin.rb +22 -0
- data/lib/cinch/bot_template/main/bot.rb +19 -0
- data/lib/cinch/bot_template/main/cli.rb +51 -0
- data/lib/cinch/bot_template/main/config.rb +20 -0
- data/lib/cinch/bot_template/main/desc.rb +10 -0
- data/lib/cinch/bot_template/main/plugin.rb +15 -0
- data/lib/cinch/bot_template/main/spinner.rb +22 -0
- data/lib/cinch/bot_template/main/thor.rb +102 -0
- data/lib/cinch/bot_template/templates/bot.rb +157 -0
- data/lib/cinch/bot_template/templates/config.rb +58 -0
- data/lib/cinch/bot_template/templates/hello.rb +32 -0
- data/lib/cinch/bot_template/templates/plugin.rb +30 -0
- data/lib/cinch/bot_template/version.rb +5 -0
- metadata +189 -0
@@ -0,0 +1,157 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
module Cinch
|
3
|
+
module BotTemplate
|
4
|
+
module Templates
|
5
|
+
class Bot
|
6
|
+
|
7
|
+
|
8
|
+
def generate(multi:, config_file:)
|
9
|
+
cfg = config_file
|
10
|
+
if multi
|
11
|
+
bot = <<~BOT
|
12
|
+
#! /usr/bin/env ruby
|
13
|
+
require 'cinch'
|
14
|
+
require 'yaml'
|
15
|
+
require 'cinch/plugins/identify'
|
16
|
+
require 'cinch/plugins/basic_ctcp'
|
17
|
+
|
18
|
+
$cfg = YAML.load_file("#{cfg}")
|
19
|
+
$bots = Hash.new
|
20
|
+
$threads = Array.new
|
21
|
+
|
22
|
+
$cfg['bot']['networks'].each do |name, ncfg|
|
23
|
+
bot = Cinch::Bot.new do
|
24
|
+
configure do |c|
|
25
|
+
c.server = ncfg.dig('server')
|
26
|
+
c.port = ncfg.dig('port')
|
27
|
+
c.nick = ncfg.dig('nickname')
|
28
|
+
c.user = ncfg.dig('username')
|
29
|
+
c.realname = ncfg.dig('realname')
|
30
|
+
c.plugins.plugins << Cinch::Plugins::Identify
|
31
|
+
identify_with = ncfg.fetch('identify-with')
|
32
|
+
case identify_with
|
33
|
+
when 'nickserv'
|
34
|
+
begin
|
35
|
+
c.plugins.options[Cinch::Plugins::Identify] = {
|
36
|
+
:username => ncfg.fetch('sasl-username'),
|
37
|
+
:password => ncfg.fetch('sasl-password'),
|
38
|
+
:type => :nickserv,
|
39
|
+
}
|
40
|
+
rescue KeyError
|
41
|
+
end
|
42
|
+
when 'sasl'
|
43
|
+
begin
|
44
|
+
c.sasl.username = ncfg.fetch('sasl-username')
|
45
|
+
c.sasl.password = ncfg.fetch('sasl-password')
|
46
|
+
rescue KeyError
|
47
|
+
end
|
48
|
+
when 'cert'
|
49
|
+
begin
|
50
|
+
c.ssl.client_cert = ncfg.fetch('certfp')
|
51
|
+
rescue KeyError
|
52
|
+
end
|
53
|
+
end
|
54
|
+
c.channels = ncfg.fetch('channels')
|
55
|
+
c.ssl.use = ncfg.fetch('ssl')
|
56
|
+
c.ssl.verify = ncfg.fetch('sslverify')
|
57
|
+
c.messages_per_second = ncfg.fetch('mps')
|
58
|
+
|
59
|
+
c.plugins.plugins << Cinch::Plugins::BasicCTCP
|
60
|
+
c.plugins.options[Cinch::Plugins::BasicCTCP][:replies] = {
|
61
|
+
version: Bot.version
|
62
|
+
}
|
63
|
+
end
|
64
|
+
end
|
65
|
+
bot.loggers.clear
|
66
|
+
|
67
|
+
bot.loggers.level = :debug
|
68
|
+
$bots[name] = bot
|
69
|
+
end
|
70
|
+
$bots.each do |key, bot|
|
71
|
+
puts "Starting IRC connection for \#{key}..."
|
72
|
+
$threads << Thread.new { bot.start }
|
73
|
+
end
|
74
|
+
|
75
|
+
class Bot
|
76
|
+
def Bot.version
|
77
|
+
$cfg['bot']['version']
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
BOT
|
82
|
+
|
83
|
+
bot
|
84
|
+
else
|
85
|
+
bot = <<~BOT
|
86
|
+
#! /usr/bin/env ruby
|
87
|
+
require 'cinch'
|
88
|
+
require 'yaml'
|
89
|
+
require 'cinch/plugins/identify'
|
90
|
+
require 'cinch/plugins/basic_ctcp'
|
91
|
+
|
92
|
+
$cfg = YAML.load_file("#{cfg}")
|
93
|
+
$threads = Array.new
|
94
|
+
|
95
|
+
bot = Cinch::Bot.new do
|
96
|
+
configure do |c|
|
97
|
+
c.server = $cfg.dig('bot', 'server')
|
98
|
+
c.port = $cfg.dig('bot', 'port')
|
99
|
+
c.nick = $cfg.dig('bot', 'nickname')
|
100
|
+
c.user = $cfg.dig('bot', 'username')
|
101
|
+
c.realname = $cfg.dig('bot', 'realname')
|
102
|
+
c.plugins.plugins << Cinch::Plugins::Identify
|
103
|
+
identify_with = $cfg.dig('bot', 'identify-with')
|
104
|
+
case identify_with
|
105
|
+
when 'nickserv'
|
106
|
+
begin
|
107
|
+
c.plugins.options[Cinch::Plugins::Identify] = {
|
108
|
+
:username => $cfg.dig('bot', 'sasl', 'username'),
|
109
|
+
:password => $cfg.fetch('bot','sasl', 'password'),
|
110
|
+
:type => :nickserv,
|
111
|
+
}
|
112
|
+
rescue KeyError
|
113
|
+
end
|
114
|
+
when 'sasl'
|
115
|
+
begin
|
116
|
+
c.sasl.username = $cfg.dig('bot', 'sasl', 'username')
|
117
|
+
c.sasl.password = $cfg.dig('bot', 'sasl', 'password')
|
118
|
+
rescue KeyError
|
119
|
+
end
|
120
|
+
when 'cert'
|
121
|
+
begin
|
122
|
+
c.ssl.client_cert = $cfg.dig('bot', 'cert')
|
123
|
+
rescue KeyError
|
124
|
+
end
|
125
|
+
end
|
126
|
+
c.channels = $cfg.dig('bot', 'channels')
|
127
|
+
c.ssl.use = $cfg.dig('bot', 'use_ssl')
|
128
|
+
c.ssl.verify = $cfg.dig('bot', 'use_ssl_verify')
|
129
|
+
c.messages_per_second = $cfg.dig('bot', 'mps')
|
130
|
+
|
131
|
+
c.plugins.plugins << Cinch::Plugins::BasicCTCP
|
132
|
+
c.plugins.options[Cinch::Plugins::BasicCTCP][:replies] = {
|
133
|
+
version: Bot.version,
|
134
|
+
}
|
135
|
+
|
136
|
+
# Add more plugins here.
|
137
|
+
end
|
138
|
+
bot.loggers.clear
|
139
|
+
|
140
|
+
bot.loggers.level = :debug
|
141
|
+
end
|
142
|
+
$threads << Thread.new { bot.start }
|
143
|
+
|
144
|
+
class Bot
|
145
|
+
def Bot.version
|
146
|
+
$cfg['bot']['version']
|
147
|
+
end
|
148
|
+
end
|
149
|
+
BOT
|
150
|
+
|
151
|
+
bot
|
152
|
+
end
|
153
|
+
end
|
154
|
+
end
|
155
|
+
end
|
156
|
+
end
|
157
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
module Cinch
|
3
|
+
module BotTemplate
|
4
|
+
module Templates
|
5
|
+
class Config
|
6
|
+
def generate(nick:, multi:, networks:)
|
7
|
+
|
8
|
+
if multi
|
9
|
+
head = "bot:\n networks:\n"
|
10
|
+
body = []
|
11
|
+
networks.each do |network, server|
|
12
|
+
body <<
|
13
|
+
<<-BODY
|
14
|
+
#{network}:
|
15
|
+
server: #{server}
|
16
|
+
port: 6697
|
17
|
+
use_ssl: true
|
18
|
+
use_ssl_verify: false
|
19
|
+
mps: 3.0
|
20
|
+
nickname: #{nick}
|
21
|
+
username: #{nick}
|
22
|
+
realname: #{nick}
|
23
|
+
identify-with: sasl
|
24
|
+
#cert: "/path/to/cert"
|
25
|
+
sasl:
|
26
|
+
username: #{nick}
|
27
|
+
password: PASSWORD
|
28
|
+
channels:
|
29
|
+
- "#chat"
|
30
|
+
BODY
|
31
|
+
end
|
32
|
+
head + body.join
|
33
|
+
|
34
|
+
else
|
35
|
+
<<-BOT
|
36
|
+
bot:
|
37
|
+
server: #{networks}
|
38
|
+
port: 6697
|
39
|
+
use_ssl: true
|
40
|
+
use_ssl_verify: false
|
41
|
+
mps: 3.0
|
42
|
+
nickname: #{nick}
|
43
|
+
username: #{nick}
|
44
|
+
realname: #{nick}
|
45
|
+
identify-with: sasl
|
46
|
+
#cert: "/path/to/cert"
|
47
|
+
sasl:
|
48
|
+
username: #{nick}
|
49
|
+
password: PASSWORD
|
50
|
+
channels:
|
51
|
+
- "#chat"
|
52
|
+
BOT
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
module Cinch
|
3
|
+
module BotTemplate
|
4
|
+
module Templates
|
5
|
+
class Hello
|
6
|
+
def generate(nick:)
|
7
|
+
|
8
|
+
|
9
|
+
hello = <<~HELLO
|
10
|
+
require 'cinch'
|
11
|
+
|
12
|
+
bot = Cinch::Bot.new do
|
13
|
+
configure do |c|
|
14
|
+
c.server = "irc.electrocode.net"
|
15
|
+
c.channels = ["#bots"]
|
16
|
+
c.nick = '#{nick}'
|
17
|
+
end
|
18
|
+
|
19
|
+
on :message, "hello" do |m|
|
20
|
+
m.reply "Hello, \#{m.user.nick}"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
bot.start
|
25
|
+
HELLO
|
26
|
+
|
27
|
+
hello
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
require 'active_support/core_ext/string'
|
3
|
+
module Cinch
|
4
|
+
module BotTemplate
|
5
|
+
module Templates
|
6
|
+
class Plugin
|
7
|
+
def Plugin.generate(plugin_names:)
|
8
|
+
plugins = {}
|
9
|
+
plugin_names.each do |plugin|
|
10
|
+
name = "#{plugin.capitalize}Plugin"
|
11
|
+
|
12
|
+
bot = <<~BOT
|
13
|
+
class #{name}
|
14
|
+
include Cinch::Plugin
|
15
|
+
match /^hello$/, method: :hello_world
|
16
|
+
# @param [Cinch::Message] m cinch message object
|
17
|
+
def hello_world(m)
|
18
|
+
m.reply "Hello \#{m.user.nick}"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
BOT
|
22
|
+
plugins[plugin+'.rb'] = bot
|
23
|
+
|
24
|
+
end
|
25
|
+
plugins
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
metadata
ADDED
@@ -0,0 +1,189 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: cinch-bot_template
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ken Spencer
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-04-15 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: cinch
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.3'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: activesupport
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '5.1'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '5.1'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: thor
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0.20'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0.20'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: highline
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.7'
|
62
|
+
- - ">="
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: 1.7.10
|
65
|
+
type: :runtime
|
66
|
+
prerelease: false
|
67
|
+
version_requirements: !ruby/object:Gem::Requirement
|
68
|
+
requirements:
|
69
|
+
- - "~>"
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: '1.7'
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: 1.7.10
|
75
|
+
- !ruby/object:Gem::Dependency
|
76
|
+
name: paint
|
77
|
+
requirement: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - ">="
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: 2.0.1
|
82
|
+
- - "<="
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: '3.0'
|
85
|
+
type: :runtime
|
86
|
+
prerelease: false
|
87
|
+
version_requirements: !ruby/object:Gem::Requirement
|
88
|
+
requirements:
|
89
|
+
- - ">="
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: 2.0.1
|
92
|
+
- - "<="
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: '3.0'
|
95
|
+
- !ruby/object:Gem::Dependency
|
96
|
+
name: require_all
|
97
|
+
requirement: !ruby/object:Gem::Requirement
|
98
|
+
requirements:
|
99
|
+
- - "~>"
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '2.0'
|
102
|
+
type: :runtime
|
103
|
+
prerelease: false
|
104
|
+
version_requirements: !ruby/object:Gem::Requirement
|
105
|
+
requirements:
|
106
|
+
- - "~>"
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
version: '2.0'
|
109
|
+
- !ruby/object:Gem::Dependency
|
110
|
+
name: bundler
|
111
|
+
requirement: !ruby/object:Gem::Requirement
|
112
|
+
requirements:
|
113
|
+
- - "~>"
|
114
|
+
- !ruby/object:Gem::Version
|
115
|
+
version: '1.16'
|
116
|
+
type: :development
|
117
|
+
prerelease: false
|
118
|
+
version_requirements: !ruby/object:Gem::Requirement
|
119
|
+
requirements:
|
120
|
+
- - "~>"
|
121
|
+
- !ruby/object:Gem::Version
|
122
|
+
version: '1.16'
|
123
|
+
description: Generate cinch bot skeletons
|
124
|
+
email:
|
125
|
+
- me@iotaspencer.me
|
126
|
+
executables:
|
127
|
+
- cinch-mktpl
|
128
|
+
extensions: []
|
129
|
+
extra_rdoc_files: []
|
130
|
+
files:
|
131
|
+
- ".gitignore"
|
132
|
+
- Gemfile
|
133
|
+
- LICENSE
|
134
|
+
- README.md
|
135
|
+
- Rakefile
|
136
|
+
- bin/cinch-mktpl
|
137
|
+
- cinch-bot_template.gemspec
|
138
|
+
- lib/cinch/bot_template.rb
|
139
|
+
- lib/cinch/bot_template/cinch-bot_template.rb
|
140
|
+
- lib/cinch/bot_template/classes/bot.rb
|
141
|
+
- lib/cinch/bot_template/classes/config.rb
|
142
|
+
- lib/cinch/bot_template/classes/exceptions.rb
|
143
|
+
- lib/cinch/bot_template/classes/gen_init.rb
|
144
|
+
- lib/cinch/bot_template/classes/hello.rb
|
145
|
+
- lib/cinch/bot_template/classes/plugin.rb
|
146
|
+
- lib/cinch/bot_template/desc/bot.rb
|
147
|
+
- lib/cinch/bot_template/desc/gen.rb
|
148
|
+
- lib/cinch/bot_template/desc/hello.rb
|
149
|
+
- lib/cinch/bot_template/desc/plugin.rb
|
150
|
+
- lib/cinch/bot_template/main/bot.rb
|
151
|
+
- lib/cinch/bot_template/main/cli.rb
|
152
|
+
- lib/cinch/bot_template/main/config.rb
|
153
|
+
- lib/cinch/bot_template/main/desc.rb
|
154
|
+
- lib/cinch/bot_template/main/plugin.rb
|
155
|
+
- lib/cinch/bot_template/main/spinner.rb
|
156
|
+
- lib/cinch/bot_template/main/thor.rb
|
157
|
+
- lib/cinch/bot_template/templates/bot.rb
|
158
|
+
- lib/cinch/bot_template/templates/config.rb
|
159
|
+
- lib/cinch/bot_template/templates/hello.rb
|
160
|
+
- lib/cinch/bot_template/templates/plugin.rb
|
161
|
+
- lib/cinch/bot_template/version.rb
|
162
|
+
homepage: https://github.com/IotaSpencer/cinch-bot_template
|
163
|
+
licenses:
|
164
|
+
- MIT
|
165
|
+
metadata: {}
|
166
|
+
post_install_message:
|
167
|
+
rdoc_options: []
|
168
|
+
require_paths:
|
169
|
+
- lib
|
170
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
171
|
+
requirements:
|
172
|
+
- - ">="
|
173
|
+
- !ruby/object:Gem::Version
|
174
|
+
version: '2.3'
|
175
|
+
- - "<="
|
176
|
+
- !ruby/object:Gem::Version
|
177
|
+
version: '3.0'
|
178
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
179
|
+
requirements:
|
180
|
+
- - ">="
|
181
|
+
- !ruby/object:Gem::Version
|
182
|
+
version: '0'
|
183
|
+
requirements: []
|
184
|
+
rubyforge_project:
|
185
|
+
rubygems_version: 2.7.6
|
186
|
+
signing_key:
|
187
|
+
specification_version: 4
|
188
|
+
summary: Generate cinch bot skeletons
|
189
|
+
test_files: []
|