| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Bot::Cobalt::Plugin::Rehash; |
|
2
|
|
|
|
|
|
|
$Bot::Cobalt::Plugin::Rehash::VERSION = '0.021003'; |
|
3
|
1
|
|
|
1
|
|
1327
|
use strictures 2; |
|
|
1
|
|
|
|
|
5
|
|
|
|
1
|
|
|
|
|
28
|
|
|
4
|
1
|
|
|
1
|
|
128
|
use v5.10; |
|
|
1
|
|
|
|
|
2
|
|
|
5
|
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
3
|
use Bot::Cobalt; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
5
|
|
|
7
|
1
|
|
|
1
|
|
609
|
use Bot::Cobalt::Common; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
5
|
|
|
8
|
1
|
|
|
1
|
|
5
|
use Bot::Cobalt::Conf; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
16
|
|
|
9
|
1
|
|
|
1
|
|
358
|
use Bot::Cobalt::Lang; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
38
|
|
|
10
|
|
|
|
|
|
|
|
|
11
|
1
|
|
|
1
|
|
6
|
use File::Spec; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
20
|
|
|
12
|
|
|
|
|
|
|
|
|
13
|
1
|
|
|
1
|
|
3
|
use strictures 2; |
|
|
1
|
|
|
|
|
7
|
|
|
|
1
|
|
|
|
|
44
|
|
|
14
|
|
|
|
|
|
|
|
|
15
|
1
|
|
|
1
|
0
|
1049
|
sub new { bless [], shift } |
|
16
|
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub Cobalt_register { |
|
18
|
0
|
|
|
0
|
0
|
|
my ($self, $core) = splice @_, 0, 2; |
|
19
|
|
|
|
|
|
|
|
|
20
|
0
|
|
|
|
|
|
register( $self, 'SERVER', |
|
21
|
|
|
|
|
|
|
'rehash', 'public_cmd_rehash' |
|
22
|
|
|
|
|
|
|
); |
|
23
|
|
|
|
|
|
|
|
|
24
|
0
|
|
|
|
|
|
logger->info("Registered, commands: !rehash"); |
|
25
|
|
|
|
|
|
|
|
|
26
|
0
|
|
|
|
|
|
PLUGIN_EAT_NONE |
|
27
|
|
|
|
|
|
|
} |
|
28
|
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub Cobalt_unregister { |
|
30
|
0
|
|
|
0
|
0
|
|
my ($self, $core) = splice @_, 0, 2; |
|
31
|
0
|
|
|
|
|
|
logger->info("Unregistered"); |
|
32
|
0
|
|
|
|
|
|
PLUGIN_EAT_NONE |
|
33
|
|
|
|
|
|
|
} |
|
34
|
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub Bot_rehash { |
|
36
|
0
|
|
|
0
|
0
|
|
my ($self, $core) = splice @_, 0, 2; |
|
37
|
|
|
|
|
|
|
|
|
38
|
0
|
|
|
|
|
|
$self->_rehash_core_cf; |
|
39
|
0
|
|
|
|
|
|
$self->_rehash_channels_cf; |
|
40
|
0
|
|
|
|
|
|
$self->_rehash_plugins_cf; |
|
41
|
|
|
|
|
|
|
|
|
42
|
0
|
|
|
|
|
|
PLUGIN_EAT_NONE |
|
43
|
|
|
|
|
|
|
} |
|
44
|
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub Bot_public_cmd_rehash { |
|
46
|
0
|
|
|
0
|
0
|
|
my ($self, $core) = splice @_, 0, 2; |
|
47
|
0
|
|
|
|
|
|
my $msg = ${$_[0]}; |
|
|
0
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
|
|
49
|
0
|
|
|
|
|
|
my $context = $msg->context; |
|
50
|
0
|
|
|
|
|
|
my $channel = $msg->channel; |
|
51
|
0
|
|
|
|
|
|
my $nick = $msg->src_nick; |
|
52
|
|
|
|
|
|
|
|
|
53
|
0
|
|
|
|
|
|
my $auth_lev = core->auth->level($context, $nick); |
|
54
|
0
|
|
|
|
|
|
my $auth_usr = core->auth->username($context, $nick); |
|
55
|
|
|
|
|
|
|
|
|
56
|
0
|
|
0
|
|
|
|
my $pcfg = plugin_cfg($self) || {}; |
|
57
|
0
|
|
0
|
|
|
|
my $required_lev = $pcfg->{LevelRequired} // 9999; |
|
58
|
|
|
|
|
|
|
|
|
59
|
0
|
0
|
|
|
|
|
unless ($auth_lev >= $required_lev) { |
|
60
|
0
|
|
|
|
|
|
my $resp = core->rpl( q{RPL_NO_ACCESS}, |
|
61
|
|
|
|
|
|
|
nick => $nick |
|
62
|
|
|
|
|
|
|
); |
|
63
|
|
|
|
|
|
|
|
|
64
|
0
|
|
|
|
|
|
broadcast 'message', $context, $channel, $resp; |
|
65
|
|
|
|
|
|
|
|
|
66
|
0
|
|
|
|
|
|
return PLUGIN_EAT_ALL |
|
67
|
|
|
|
|
|
|
} |
|
68
|
|
|
|
|
|
|
|
|
69
|
0
|
|
0
|
|
|
|
my $type = lc($msg->message_array->[0] || 'all'); |
|
70
|
|
|
|
|
|
|
|
|
71
|
0
|
|
|
|
|
|
my $meth = '_cmd_'.$type; |
|
72
|
|
|
|
|
|
|
|
|
73
|
0
|
|
|
|
|
|
logger->debug("dispatching $meth for $nick ($auth_usr)"); |
|
74
|
|
|
|
|
|
|
|
|
75
|
0
|
|
|
|
|
|
my $resp; |
|
76
|
0
|
0
|
|
|
|
|
if ( $self->can($meth) ) { |
|
77
|
|
|
|
|
|
|
## Handlers return a response or die() : |
|
78
|
|
|
|
|
|
|
$resp = try { |
|
79
|
0
|
|
|
0
|
|
|
$self->$meth($msg) |
|
80
|
|
|
|
|
|
|
} catch { |
|
81
|
0
|
|
|
0
|
|
|
my $error = $_; |
|
82
|
0
|
|
|
|
|
|
logger->error("Rehash ($type) failure; $error"); |
|
83
|
0
|
|
|
|
|
|
"Failed rehash: $error" |
|
84
|
0
|
|
|
|
|
|
}; |
|
85
|
|
|
|
|
|
|
} else { |
|
86
|
0
|
|
|
|
|
|
$resp = "Unknown config group, try: core, plugins, langset, channels" |
|
87
|
|
|
|
|
|
|
} |
|
88
|
|
|
|
|
|
|
|
|
89
|
0
|
|
|
|
|
|
broadcast 'message', $context, $channel, $resp; |
|
90
|
|
|
|
|
|
|
|
|
91
|
0
|
|
|
|
|
|
PLUGIN_EAT_ALL |
|
92
|
|
|
|
|
|
|
} |
|
93
|
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
## Command handlers: |
|
95
|
|
|
|
|
|
|
sub _cmd_all { |
|
96
|
0
|
|
|
0
|
|
|
my ($self, $msg) = @_; |
|
97
|
|
|
|
|
|
|
|
|
98
|
0
|
|
|
|
|
|
$self->_rehash_core_cf; |
|
99
|
0
|
|
|
|
|
|
$self->_rehash_channels_cf; |
|
100
|
0
|
|
|
|
|
|
$self->_rehash_plugins_cf; |
|
101
|
|
|
|
|
|
|
|
|
102
|
0
|
|
|
|
|
|
"Rehashed loaded configuration objects." |
|
103
|
|
|
|
|
|
|
} |
|
104
|
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
sub _cmd_channels { |
|
106
|
0
|
|
|
0
|
|
|
my ($self, $msg) = @_; |
|
107
|
|
|
|
|
|
|
|
|
108
|
0
|
|
|
|
|
|
$self->_rehash_channels_cf; |
|
109
|
|
|
|
|
|
|
|
|
110
|
0
|
|
|
|
|
|
"Rehashed current channels configuration." |
|
111
|
|
|
|
|
|
|
} |
|
112
|
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
sub _cmd_core { |
|
114
|
0
|
|
|
0
|
|
|
my ($self, $msg) = @_; |
|
115
|
|
|
|
|
|
|
|
|
116
|
0
|
|
|
|
|
|
$self->_rehash_core_cf; |
|
117
|
|
|
|
|
|
|
|
|
118
|
0
|
|
|
|
|
|
"Rehashed core configuration." |
|
119
|
|
|
|
|
|
|
} |
|
120
|
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
sub _cmd_plugins { |
|
122
|
0
|
|
|
0
|
|
|
my ($self, $msg) = @_; |
|
123
|
|
|
|
|
|
|
|
|
124
|
0
|
|
|
|
|
|
$self->_rehash_plugins_cf; |
|
125
|
|
|
|
|
|
|
|
|
126
|
0
|
|
|
|
|
|
"Rehashed plugins configuration." |
|
127
|
|
|
|
|
|
|
} |
|
128
|
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
sub _cmd_langset { |
|
130
|
0
|
|
|
0
|
|
|
my ($self, $msg) = @_; |
|
131
|
|
|
|
|
|
|
|
|
132
|
0
|
|
|
|
|
|
my $lang = $msg->message_array->[1]; |
|
133
|
|
|
|
|
|
|
|
|
134
|
0
|
|
|
|
|
|
$self->_rehash_langset($lang); |
|
135
|
|
|
|
|
|
|
|
|
136
|
0
|
|
|
|
|
|
"Rehashed loaded language set" |
|
137
|
|
|
|
|
|
|
} |
|
138
|
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
## Actual configuration reloaders: |
|
141
|
|
|
|
|
|
|
sub _rehash_plugins_cf { |
|
142
|
0
|
|
|
0
|
|
|
my ($self) = @_; |
|
143
|
|
|
|
|
|
|
|
|
144
|
0
|
|
|
|
|
|
require Bot::Cobalt::Conf::File::Plugins; |
|
145
|
|
|
|
|
|
|
|
|
146
|
0
|
|
|
|
|
|
my $new_cfg_obj = Bot::Cobalt::Conf::File::Plugins->new( |
|
147
|
|
|
|
|
|
|
etcdir => core()->etc, |
|
148
|
|
|
|
|
|
|
cfg_path => core()->cfg->plugins->cfg_path, |
|
149
|
|
|
|
|
|
|
); |
|
150
|
|
|
|
|
|
|
|
|
151
|
0
|
|
|
|
|
|
core()->cfg->set_plugins( $new_cfg_obj ); |
|
152
|
|
|
|
|
|
|
|
|
153
|
0
|
|
|
|
|
|
logger->info("Reloaded plugins.conf"); |
|
154
|
|
|
|
|
|
|
|
|
155
|
0
|
|
|
|
|
|
broadcast 'rehashed', 'plugins'; |
|
156
|
|
|
|
|
|
|
} |
|
157
|
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
sub _rehash_channels_cf { |
|
159
|
0
|
|
|
0
|
|
|
my ($self) = @_; |
|
160
|
|
|
|
|
|
|
|
|
161
|
0
|
|
|
|
|
|
require Bot::Cobalt::Conf::File::Channels; |
|
162
|
|
|
|
|
|
|
|
|
163
|
0
|
|
|
|
|
|
my $new_cfg_obj = Bot::Cobalt::Conf::File::Channels->new( |
|
164
|
|
|
|
|
|
|
cfg_path => core()->cfg->channels->cfg_path, |
|
165
|
|
|
|
|
|
|
); |
|
166
|
|
|
|
|
|
|
|
|
167
|
0
|
|
|
|
|
|
core()->cfg->set_channels( $new_cfg_obj ); |
|
168
|
|
|
|
|
|
|
|
|
169
|
0
|
|
|
|
|
|
logger->info("Reloaded channels config."); |
|
170
|
|
|
|
|
|
|
|
|
171
|
0
|
|
|
|
|
|
broadcast 'rehashed', 'channels'; |
|
172
|
|
|
|
|
|
|
} |
|
173
|
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
sub _rehash_core_cf { |
|
175
|
0
|
|
|
0
|
|
|
my ($self) = @_; |
|
176
|
|
|
|
|
|
|
|
|
177
|
0
|
|
|
|
|
|
require Bot::Cobalt::Conf::File::Core; |
|
178
|
|
|
|
|
|
|
|
|
179
|
0
|
|
|
|
|
|
my $new_cfg_obj = Bot::Cobalt::Conf::File::Core->new( |
|
180
|
|
|
|
|
|
|
cfg_path => core()->cfg->core->cfg_path, |
|
181
|
|
|
|
|
|
|
); |
|
182
|
|
|
|
|
|
|
|
|
183
|
0
|
|
|
|
|
|
core()->cfg->set_core( $new_cfg_obj ); |
|
184
|
|
|
|
|
|
|
|
|
185
|
0
|
|
|
|
|
|
logger->info("Reloaded core config."); |
|
186
|
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
## Bot_rehash ($type) : |
|
188
|
0
|
|
|
|
|
|
broadcast 'rehashed', 'core'; |
|
189
|
|
|
|
|
|
|
} |
|
190
|
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
sub _rehash_langset { |
|
192
|
0
|
|
|
0
|
|
|
my ($self, $langset) = @_; |
|
193
|
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
## FIXME document that you should rehash core then rehash langset |
|
195
|
|
|
|
|
|
|
## for updated Language: directives |
|
196
|
|
|
|
|
|
|
|
|
197
|
0
|
|
0
|
|
|
|
$langset ||= core()->cfg->core->language; |
|
198
|
|
|
|
|
|
|
|
|
199
|
0
|
|
|
|
|
|
my $lang_dir = File::Spec->catdir( core()->etc, 'langs' ); |
|
200
|
|
|
|
|
|
|
|
|
201
|
0
|
|
|
|
|
|
my $lang_obj = Bot::Cobalt::Lang->new( |
|
202
|
|
|
|
|
|
|
use_core => 1, |
|
203
|
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
lang_dir => $lang_dir, |
|
205
|
|
|
|
|
|
|
lang => $langset, |
|
206
|
|
|
|
|
|
|
); |
|
207
|
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
die "Language set $langset has no RPLs" |
|
209
|
0
|
0
|
|
|
|
|
unless scalar keys %{ $lang_obj->rpls } ; |
|
|
0
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
|
|
211
|
0
|
|
|
|
|
|
core()->set_langset( $lang_obj ); |
|
212
|
0
|
|
|
|
|
|
core()->set_lang( $lang_obj->rpls ); |
|
213
|
|
|
|
|
|
|
|
|
214
|
0
|
|
|
|
|
|
logger->info("Reloaded core langset ($langset)"); |
|
215
|
|
|
|
|
|
|
|
|
216
|
0
|
|
|
|
|
|
broadcast 'rehashed', 'langset'; |
|
217
|
|
|
|
|
|
|
} |
|
218
|
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
1; |
|
221
|
|
|
|
|
|
|
__END__ |