cinch-bot_template 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- 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
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 056c79a1ad9b78b1ed2a88a977f8fdc1d22950b14cacbc344b57a710ac4a2287
|
4
|
+
data.tar.gz: 17450f9825158342a1a6d94b3867fc1654439b271dd0780867d477817302ad7a
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f61ab09e67e842de45b7e8aeaac15982a9e7beb5c45a7a17d25b96a27c3049b7f6c49d392bafd63032d816acc0e6d218813f3ac246665fe4857d3cbcebe3c4aa
|
7
|
+
data.tar.gz: c2fde1de43b123e5eed92aa16d317ecd306db0b09e71eb8b274a91cfea843309426f592517d5bb8e2b51823b7b4ee6efe36f7b7f6ef950202de8a97ea4ab66bb
|
data/.gitignore
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# Because this is a gem, ignore Gemfile.lock:
|
2
|
+
|
3
|
+
Gemfile.lock
|
4
|
+
|
5
|
+
# And because this is Ruby, ignore the following
|
6
|
+
# (source: https://github.com/github/gitignore/blob/master/Ruby.gitignore):
|
7
|
+
|
8
|
+
*.gem
|
9
|
+
*.rbc
|
10
|
+
.bundle
|
11
|
+
.config
|
12
|
+
coverage
|
13
|
+
InstalledFiles
|
14
|
+
lib/bundler/man
|
15
|
+
pkg
|
16
|
+
rdoc
|
17
|
+
spec/reports
|
18
|
+
test/tmp
|
19
|
+
test/version_tmp
|
20
|
+
tmp
|
21
|
+
Gemfile.lock
|
22
|
+
/vendor/bundle
|
23
|
+
|
24
|
+
# YARD artifacts
|
25
|
+
.yardoc
|
26
|
+
_yardoc
|
27
|
+
doc/
|
28
|
+
/.idea/
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT LICENSE
|
2
|
+
|
3
|
+
Copyright (c) Ken Spencer <me@iotaspencer.me>
|
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,38 @@
|
|
1
|
+
# cinch-bot_template
|
2
|
+
|
3
|
+
|
4
|
+
[![Gem](https://img.shields.io/gem/v/cinch-bot_template.svg?style=for-the-badge)](https://rubygems.org/gems/cinch-bot_template)
|
5
|
+
|
6
|
+
[![Gem](https://img.shields.io/gem/dt/cinch-bot_template.svg?style=for-the-badge)](https://rubygems.org/gems/cinch-bot_template)
|
7
|
+
[![Gem](https://img.shields.io/gem/dtv/cinch-bot_template.svg?style=for-the-badge)](https://rubygems.org/gems/cinch-bot_template)
|
8
|
+
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg?style=for-the-badge)](https://opensource.org/licenses/MIT)
|
9
|
+
|
10
|
+
[![forthebadge](https://forthebadge.com/images/badges/uses-badges.svg)](https://forthebadge.com)
|
11
|
+
[![forthebadge](https://forthebadge.com/images/badges/built-with-love.svg)](https://forthebadge.com)
|
12
|
+
[![forthebadge](https://forthebadge.com/images/badges/uses-git.svg)](https://forthebadge.com)
|
13
|
+
|
14
|
+
## Contact
|
15
|
+
|
16
|
+
[![E-mail](https://img.shields.io/badge/Email-Me-green.svg?style=for-the-badge)](mailto:me@iotaspencer.me)
|
17
|
+
[![Twitter Follow](https://img.shields.io/twitter/follow/IotaEcode.svg?label=Follow%20Me%20on%20Twitter&style=for-the-badge)](https://twitter.com/IotaEcode)
|
18
|
+
|
19
|
+
[![Website](https://img.shields.io/website-up-down-green-red/https/iotaspencer.me.svg?label=My%20Site%20-%20IotaSpencer%2Eme&style=for-the-badge)](https://iotaspencer.me)
|
20
|
+
|
21
|
+
[![Website](https://img.shields.io/website/http/shields.io.svg?label=cinch-bot_template%20on%20IotaSpencer.me&style=for-the-badge)](https://iotaspencer.me/projects/cinch-bot_template)
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
### Generate a Hello World Skeleton
|
26
|
+
|
27
|
+
|
28
|
+
```shell
|
29
|
+
$ cinch-mktpl hello
|
30
|
+
```
|
31
|
+
```
|
32
|
+
What's the bot's name
|
33
|
+
> Cinch
|
34
|
+
|
35
|
+
What should the executable file be named.
|
36
|
+
The generator will add .rb automatically.
|
37
|
+
> start
|
38
|
+
```
|
data/Rakefile
ADDED
data/bin/cinch-mktpl
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
$:.unshift File.expand_path('../lib', __FILE__)
|
4
|
+
require 'pathname'
|
5
|
+
require 'cinch/bot_template/version'
|
6
|
+
|
7
|
+
Gem::Specification.new do |s|
|
8
|
+
s.name = "cinch-bot_template"
|
9
|
+
s.version = Cinch::BotTemplate::VERSION
|
10
|
+
s.authors = ["Ken Spencer"]
|
11
|
+
s.email = ["me@iotaspencer.me"]
|
12
|
+
s.homepage = "https://github.com/IotaSpencer/cinch-bot_template"
|
13
|
+
s.summary = "Generate cinch bot skeletons"
|
14
|
+
s.description = s.summary
|
15
|
+
s.license = 'MIT'
|
16
|
+
s.files = `git ls-files -z`.split("\x0").reject do |f|
|
17
|
+
f.match(%r{^(test)/})
|
18
|
+
end
|
19
|
+
s.platform = Gem::Platform::RUBY
|
20
|
+
s.require_paths = ['lib']
|
21
|
+
s.executables = Pathname('./bin').entries.map(&:to_s).delete_if { |x| %w(. ..).include?(x) }
|
22
|
+
|
23
|
+
s.required_ruby_version = ['>= 2.3', '<= 3.0']
|
24
|
+
|
25
|
+
|
26
|
+
s.add_runtime_dependency 'cinch', '~> 2.3'
|
27
|
+
s.add_runtime_dependency 'activesupport', '~> 5.1'
|
28
|
+
s.add_runtime_dependency 'thor', '~> 0.20'
|
29
|
+
s.add_runtime_dependency 'highline', '~> 1.7', '>= 1.7.10'
|
30
|
+
s.add_runtime_dependency 'paint', '>= 2.0.1', '<= 3.0'
|
31
|
+
s.add_runtime_dependency 'require_all', '~> 2.0'
|
32
|
+
s.add_development_dependency 'bundler', '~> 1.16'
|
33
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'cinch/bot_template/cinch-bot_template'
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require 'thor'
|
2
|
+
require 'cinch/bot_template/main/thor'
|
3
|
+
require 'cinch/bot_template/main/desc'
|
4
|
+
require 'cinch/bot_template/main/plugin'
|
5
|
+
require 'cinch/bot_template/main/bot'
|
6
|
+
require 'cinch/bot_template/classes/hello'
|
7
|
+
require 'cinch/bot_template/main/config'
|
8
|
+
require 'cinch/bot_template/classes/exceptions'
|
9
|
+
require 'cinch/bot_template/main/cli'
|
10
|
+
require 'cinch/bot_template/main/spinner'
|
11
|
+
|
12
|
+
module Cinch
|
13
|
+
module BotTemplate
|
14
|
+
module CLI
|
15
|
+
class App < Thor
|
16
|
+
def self.exit_on_failure?
|
17
|
+
true
|
18
|
+
end
|
19
|
+
class_option(:debug, type: :boolean, hide: true)
|
20
|
+
|
21
|
+
map %w[--version -v] => :__print_version
|
22
|
+
desc '--version, -v', 'Print the version'
|
23
|
+
|
24
|
+
# Prints version string
|
25
|
+
# @return [NilClass] nil
|
26
|
+
def __print_version
|
27
|
+
puts Cinch::BotTemplate::VERSION
|
28
|
+
end
|
29
|
+
|
30
|
+
desc 'gen [DIR] [options]', 'Generate a skeleton of a full bot'
|
31
|
+
method_option 'multi-server', type: :boolean, default: false, aliases: %w(-m), required: false, hide: true
|
32
|
+
|
33
|
+
long_desc Cinch::BotTemplate::Descs::Gen.Gen
|
34
|
+
|
35
|
+
def gen
|
36
|
+
generator = Cinch::BotTemplate::CLI::Base.new(shell: self.shell, options: options)
|
37
|
+
generator.generate
|
38
|
+
end
|
39
|
+
|
40
|
+
desc 'hello', 'Creates a simple hello world bot in one file'
|
41
|
+
long_desc Cinch::BotTemplate::Descs::Hello.Gen
|
42
|
+
|
43
|
+
def hello
|
44
|
+
generator = Cinch::BotTemplate::Classes::Hello.new(shell: self.shell)
|
45
|
+
generator.generate
|
46
|
+
end
|
47
|
+
|
48
|
+
desc 'plugin [command] [options]', 'Generate a plugin'
|
49
|
+
subcommand('plugin', Cinch::BotTemplate::Plugin)
|
50
|
+
|
51
|
+
desc 'bot [command] [options]', 'Generate a bot file'
|
52
|
+
subcommand('bot', Cinch::BotTemplate::Bot)
|
53
|
+
|
54
|
+
desc 'config [command] [options]', 'Generate a bot config'
|
55
|
+
subcommand('config', Cinch::BotTemplate::Config)
|
56
|
+
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
require 'thor'
|
2
|
+
require 'highline'
|
3
|
+
|
4
|
+
require 'cinch/bot_template/templates/bot'
|
5
|
+
module Cinch
|
6
|
+
module BotTemplate
|
7
|
+
module Classes
|
8
|
+
class Bot
|
9
|
+
def initialize(options:, shell:, all: false)
|
10
|
+
@hl = HighLine.new($stdin, $stderr, 80)
|
11
|
+
@opts = Hash.new { |hash, key| hash[key] = {} }
|
12
|
+
@options = options
|
13
|
+
@all = all
|
14
|
+
@shell = shell
|
15
|
+
|
16
|
+
end
|
17
|
+
|
18
|
+
# @note What the executable file will be named + .rb
|
19
|
+
def get_001_bot_file
|
20
|
+
@hl.say "What should the executable file be named."
|
21
|
+
unless @all
|
22
|
+
@hl.say "Use a hyphen by itself '-' to output to stdout "
|
23
|
+
@hl.say "instead of a file."
|
24
|
+
end
|
25
|
+
|
26
|
+
@hl.say "The generator will add .rb automatically."
|
27
|
+
filename = @hl.ask " > ", String
|
28
|
+
if filename == '-'
|
29
|
+
@opts['stdout'] = true
|
30
|
+
return
|
31
|
+
end
|
32
|
+
@opts['bot']['file'] = filename.include?('.rb') ? filename : filename + '.rb'
|
33
|
+
end
|
34
|
+
def get_002_config_file
|
35
|
+
@shell.say "Grabbing config path from state..."
|
36
|
+
@opts['config_path'] = Pathname(@directory).join(@config_file)
|
37
|
+
end
|
38
|
+
|
39
|
+
# @param [Pathname] directory Bot directory
|
40
|
+
# @param [Pathname] config_file configuration path
|
41
|
+
def generate(directory:, config_file:)
|
42
|
+
@directory = directory
|
43
|
+
@config_file = config_file
|
44
|
+
if @options.fetch(:debug, nil)
|
45
|
+
at_exit do
|
46
|
+
puts @options
|
47
|
+
puts @opts
|
48
|
+
end
|
49
|
+
end
|
50
|
+
meths = self.methods.select { |x| x =~ /^get_[0-9]+_.*/ }
|
51
|
+
meths.sort! { |m, n| m.to_s.gsub(/^get_([0-9]+)_.*/, '\1').to_i <=> n.to_s.gsub(/^get_([0-9]+)_.*/, '\1').to_i }
|
52
|
+
meths.each do |m|
|
53
|
+
self.send(m)
|
54
|
+
end
|
55
|
+
@hl.say "Generating..."
|
56
|
+
tpl = Cinch::BotTemplate::Templates::Bot.new.generate(
|
57
|
+
multi: @options['multi-server'],
|
58
|
+
config_file: @config_file,
|
59
|
+
)
|
60
|
+
if @opts.fetch('stdout', nil)
|
61
|
+
puts tpl
|
62
|
+
else
|
63
|
+
filename = Pathname(directory).join(@opts.dig('bot', 'file'))
|
64
|
+
open filename, 'a+' do |fd|
|
65
|
+
fd.puts tpl
|
66
|
+
end
|
67
|
+
File.chmod(775, filename)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
@@ -0,0 +1,86 @@
|
|
1
|
+
require 'thor'
|
2
|
+
require 'highline'
|
3
|
+
|
4
|
+
require 'cinch/bot_template/templates/config'
|
5
|
+
module Cinch
|
6
|
+
module BotTemplate
|
7
|
+
module Classes
|
8
|
+
class Config
|
9
|
+
def initialize(options:, shell:, all: false)
|
10
|
+
@hl = HighLine.new($stdin, $stderr, 80)
|
11
|
+
@opts = Hash.new { |hash, key| hash[key] = {} }
|
12
|
+
@options = options
|
13
|
+
@all = all
|
14
|
+
@shell = shell
|
15
|
+
|
16
|
+
end
|
17
|
+
|
18
|
+
# @param [String] file_path File path to config as string to parse
|
19
|
+
def parse_config_path(file_path)
|
20
|
+
begin
|
21
|
+
path = Pathname(file_path)
|
22
|
+
path = File.expand_path(path)
|
23
|
+
path.to_s
|
24
|
+
rescue
|
25
|
+
at_exit do
|
26
|
+
puts "Could not parse config path. Exiting.."
|
27
|
+
end
|
28
|
+
|
29
|
+
exit 1
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
def get_001_bot_networks
|
35
|
+
if @options['multi-server']
|
36
|
+
@hl.say "What networks? "
|
37
|
+
nets = {}
|
38
|
+
networks = @hl.ask "> " do |q|
|
39
|
+
q.gather = /#\$/
|
40
|
+
end
|
41
|
+
networks.each do |network|
|
42
|
+
nets[network] = @hl.ask("Server for #{network}?")
|
43
|
+
end
|
44
|
+
@opts['bot']['networks'] = nets
|
45
|
+
else
|
46
|
+
@hl.say "Server "
|
47
|
+
server = @hl.ask "> "
|
48
|
+
@opts['bot']['server'] = server
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
|
53
|
+
# @note The bot's nickname
|
54
|
+
def get_002_bot_name
|
55
|
+
@hl.say "What's the bot's main nickname"
|
56
|
+
@opts['bot']['nick'] = @hl.ask " > ", String
|
57
|
+
end
|
58
|
+
|
59
|
+
|
60
|
+
def generate(directory = Pathname('.'))
|
61
|
+
meths = self.methods.select { |x| x =~ /^get_[0-9]+_.*/ }
|
62
|
+
meths.sort! { |m, n| m.to_s.gsub(/^get_([0-9]+)_.*/, '\1').to_i <=> n.to_s.gsub(/^get_([0-9]+)_.*/, '\1').to_i }
|
63
|
+
meths.each do |m|
|
64
|
+
self.send(m)
|
65
|
+
end
|
66
|
+
@hl.say "Generating..."
|
67
|
+
tpl = Cinch::BotTemplate::Templates::Config.new.generate(
|
68
|
+
nick: @opts.dig('bot', 'nick'),
|
69
|
+
multi: @options.dig('multi-server'),
|
70
|
+
networks: @options.dig('multi-server') ? @opts.dig('bot', 'networks') : @opts.dig('bot', 'server')
|
71
|
+
|
72
|
+
)
|
73
|
+
if @opts.fetch('stdout', nil)
|
74
|
+
puts tpl
|
75
|
+
else
|
76
|
+
filename = directory.join(@opts.dig('bot', 'nick')+'.yml')
|
77
|
+
open filename, 'a+' do |fd|
|
78
|
+
fd.puts tpl
|
79
|
+
end
|
80
|
+
filename
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
require 'paint'
|
2
|
+
require 'pathname'
|
3
|
+
module Cinch
|
4
|
+
module BotTemplate
|
5
|
+
module Classes
|
6
|
+
class Init
|
7
|
+
attr :directory
|
8
|
+
|
9
|
+
def initialize(options:, shell:, all:)
|
10
|
+
@hl = HighLine.new($stdin, $stderr, 80)
|
11
|
+
@opts = Hash.new { |hash, key| hash[key] = {} }
|
12
|
+
@options = options
|
13
|
+
@all = all
|
14
|
+
@shell = shell
|
15
|
+
end
|
16
|
+
|
17
|
+
# @note There's more a format on return of [parsed,input]
|
18
|
+
# @overload check_path
|
19
|
+
# Success => [parsed,input]
|
20
|
+
# Error => [parsed,input,error]
|
21
|
+
# Error+ => [parsed,input,error,varstring,varstring,varstring]
|
22
|
+
# @param [String] path Check path for existence.
|
23
|
+
# @return [Array<Boolean,String>] if there was an error
|
24
|
+
# @return [Array<String>] path if successful
|
25
|
+
def check_path(path)
|
26
|
+
current_dir = Pathname('.').expand_path.realdirpath
|
27
|
+
home_dir = Pathname('~').expand_path.realdirpath
|
28
|
+
path_string = path
|
29
|
+
path_instance = Pathname(path)
|
30
|
+
path_full = Pathname(path).expand_path.realdirpath
|
31
|
+
|
32
|
+
if current_dir == home_dir and path_full == home_dir or path_string == '~'
|
33
|
+
abort Paint['Error', 'red', :bold] + ': Will not create files in user home, use a subdirectory'
|
34
|
+
else
|
35
|
+
[path_full, path]
|
36
|
+
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
|
41
|
+
def generate
|
42
|
+
@shell.say "What path should be used to house the bot?"
|
43
|
+
@shell.say "If directories don't exist, they will be created."
|
44
|
+
@shell.say "'~' and '.' are available for compactness"
|
45
|
+
@shell.say "However '~' is disallowed when using it by itself"
|
46
|
+
@shell.say "This is so you don't put a bot directly in your home directory."
|
47
|
+
@shell.say "ex: '~/bots/cinchfolder', '.' or './cinchfolder'"
|
48
|
+
path = @shell.ask("What directory?")
|
49
|
+
|
50
|
+
path_response = self.check_path(path)
|
51
|
+
if path_response.length == 2 # Success
|
52
|
+
parsed = path_response.first
|
53
|
+
if parsed.exist?
|
54
|
+
@directory = parsed
|
55
|
+
else
|
56
|
+
@directory = parsed
|
57
|
+
FileUtils.mkpath(@directory.to_s)
|
58
|
+
|
59
|
+
end
|
60
|
+
|
61
|
+
elsif path_response.length == 3 # Error
|
62
|
+
|
63
|
+
elsif path_response.length > 3 # Error+
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|