protonbot 0.3.2 → 0.3.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 61920b192eecbc9b7b39d4bf03bba247b78bcdbd
4
- data.tar.gz: 958c3b77f8f26d0645dae278922f1da6fdefeb70
3
+ metadata.gz: e32dd98edcadebac541ea89e89c7d9945ea50929
4
+ data.tar.gz: d5a72e64cdea4d2aeb3d29739299b1c7d55d3357
5
5
  SHA512:
6
- metadata.gz: 0d9310723a7ad08d58fe08cc6d62a636c13f7f38f851e7e7f5823c2efa8543666427ade1470e09c8f58d0d073fbc4e0d2333e93fbea5bb9ed3bdb5d7f3973de3
7
- data.tar.gz: b5def97b97faa11db2d4f485c79b9c760d5698f0a0913d6b555d68640832f555edb8fa6e4b2f81d81091b2562ed760f3ca518a6459b6c984120f43e23f4473a4
6
+ metadata.gz: c32605501bc4afbe317b9fed90af8b6af7a33416ca88c97fef20b41ef160068b5a6130c06271eb90c06c07a5377abf3f29724e3d05ff0e9d672cf93f48107d3e
7
+ data.tar.gz: 873895ef9bee5c6d63a419747249043d861e2196fba9b47c789a1a005a2fe1b9ad31b7b9bd59c50cbda8ae67f6ba1586962476058467bc2b5a9e300d54e9f93c
data/lib/protonbot/bot.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  # Main bot class. Use it to create the bot
2
2
  class ProtonBot::Bot
3
- attr_reader :log, :_log, :dbs, :plugins, :conf, :plugs, :plugthrs
3
+ attr_reader :log, :_log, :dbs, :plugins, :conf, :plugs, :plugthrs, :core
4
4
 
5
5
  # @yield Main bot's block. You'll use it for configuring bot.
6
6
  def initialize(&block)
@@ -15,6 +15,7 @@ class ProtonBot::Bot
15
15
  configure
16
16
  @log.info('Processed config block')
17
17
 
18
+ @parr = []
18
19
  @plugins = {}
19
20
  plugins_load
20
21
  @log.info('Processed plugins block')
@@ -39,14 +39,22 @@ class ProtonBot::Bot
39
39
  # each plugin
40
40
  # @return [Bot] self
41
41
  def plugins_load
42
- @plugins['core'] =
43
- pluginr "#{Gem.loaded_specs['protonbot'].lib_dirs_glob.split(':')[0]}/protonbot/core_plugin/plugin.rb"
42
+ core = pluginr "#{Gem.loaded_specs['protonbot'].lib_dirs_glob.split(':')[0]}/protonbot/core_plugin/plugin.rb"
43
+ core.bot = self
44
+ core.core = core
45
+ core.launch
46
+ @core = core
47
+ @plugins[core.name] = core
48
+ core.log = @_log.wrap("?#{core.name}")
49
+ core.log.info("Started plugin `#{core.name} v#{core.version}` successfully!")
44
50
  @plugin_loader.call if @plugin_loader
45
- @plugins.each do |k, v|
46
- v.bot = self
47
- v.launch
48
- v.log = @_log.wrap("?#{v.name}")
49
- v.log.info("Started plugin `#{v.name} v#{v.version}` successfully!")
51
+ @parr.each do |pl|
52
+ pl.bot = self
53
+ pl.core = @plugins[core.name]
54
+ pl.launch
55
+ @plugins[pl.name] = pl
56
+ pl.log = @_log.wrap("?#{pl.name}")
57
+ pl.log.info("Started plugin `#{pl.name} v#{pl.version}` successfully!")
50
58
  end
51
59
  self
52
60
  end
@@ -69,7 +77,7 @@ class ProtonBot::Bot
69
77
  else
70
78
  raise ArgumentError, 'Unknown type of `dat` plugin! Use Array or String!'
71
79
  end
72
- @plugins[pl.name] = pl
80
+ @parr << pl
73
81
  self
74
82
  end
75
83
 
@@ -85,7 +93,7 @@ class ProtonBot::Bot
85
93
  pl = pluginr(path)
86
94
  raise ProtonBot::PluginError, "`#{path}` did not return plugin!" unless
87
95
  pl.instance_of? ProtonBot::Plugin
88
- @plugins[gemname] = pl
96
+ @parr << pl
89
97
  else
90
98
  raise IOError, "No such file or directory: #{path}"
91
99
  end
@@ -25,7 +25,7 @@ class ProtonBot::Hook
25
25
  when :user_and_target
26
26
  :"last_used_#{dat[:plug].name}_#{dat[:target]}_#{dat[:host]}"
27
27
  end
28
- if dat[:bot].plugins['core'].getpermsr(dat[:plug], dat[:host]).include? 'nocooldown'
28
+ if dat[:bot].core.getpermsr(dat[:plug], dat[:host]).include? 'nocooldown'
29
29
  true
30
30
  elsif hook.extra[lu_sign]
31
31
  curtime = Time.now.to_i
@@ -7,3 +7,8 @@ core.help_add('basic', 'echo', 'echo', 'Sends given message back')
7
7
  cmd(cmd: 'echo') do |dat|
8
8
  dat.reply("#{dat[:split].join(' ')}")
9
9
  end.cooldown!(5)
10
+
11
+ core.help_add('basic', 'plugins', 'plugins', 'List of plugins')
12
+ cmd(cmd: 'plugins') do |dat|
13
+ dat.nreply("%BAvailable plugins:%N #{bot.plugins.map{|_,p|p.name + ' v' + p.version}.join(', ')}")
14
+ end.cooldown!(10)
@@ -1,5 +1,3 @@
1
- require 'yaml'
2
-
3
1
  ProtonBot::Plugin.new do
4
2
  @name = 'Core'
5
3
  @version = ProtonBot::VERSION
@@ -16,11 +16,11 @@
16
16
  # @return [LogWrapper] Log
17
17
  # @!attribute [rw] path
18
18
  # @return [String] Path
19
- # @!attribute [r] core
19
+ # @!attribute [rw] core
20
20
  # @return [Plugin] Core plugin
21
21
  class ProtonBot::Plugin
22
- attr_reader :name, :version, :description, :plugins, :hooks, :core
23
- attr_accessor :bot, :log, :path
22
+ attr_reader :name, :version, :description, :plugins, :hooks
23
+ attr_accessor :bot, :log, :path, :core
24
24
 
25
25
  # @param block [Proc]
26
26
  def initialize(&block)
@@ -33,7 +33,6 @@ class ProtonBot::Plugin
33
33
  # @return [Plugin] self
34
34
  def launch
35
35
  @plugins = @bot.plugins
36
- @core = @bot.plugins['core']
37
36
  instance_exec(&@block)
38
37
  raise ProtonBot::PluginError, 'Plugin-name is not set!' unless
39
38
  @name
@@ -1,4 +1,4 @@
1
1
  module ProtonBot
2
2
  # ProtonBot's version
3
- VERSION = '0.3.2'.freeze
3
+ VERSION = '0.3.3'.freeze
4
4
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: protonbot
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 0.3.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nickolay Ilyushin