-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathklesk.pl
351 lines (271 loc) · 12.5 KB
/
klesk.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
#!/bin/perl
=head1 NAME
ql-klesk-chatbot
=head1 SYNOPSIS
BASEQ3_DIR="C:/Program Files (x86)/Steam/steamapps/common/Quake Live/76561198827372787/baseq3"
PLAYER_NAME="Klesk"
tail -f -n 0 "${BASEQ3_DIR}/qconsole.log" | ./klesk.pl --dir "${BASEQ3_DIR}" --name "${PLAYER_NAME}"
=head1 DESCRIPTION
Parses Quake Live console output to produce .cfg files suitable for imitating the Q3 bot Klesk's bot-chatter.
=head1 AUTHORS
=over 1
=item
Anthony - L<https://github.com/ajxs/>
=item
CaptainTaichou - L<http://http://www.esreality.com/?a=users&user_id=39953/>
=back
=head1 METHODS
=cut
use strict;
use warnings;
use Getopt::Long;
use constant DEBUG => 1;
# Forces no-buffering
$| = 1;
my $baseq3_dir = 0;
my $player_name = 0;
GetOptions ('dir=s' => \$baseq3_dir,
'name=s' => \$player_name);
die("Insufficient arguments! Exiting.") if !$baseq3_dir or !$player_name;
my $cfg_insult = "$baseq3_dir/klesk-insult.cfg";
my $cfg_insult_talker = "$baseq3_dir/klesk-insult-talker.cfg";
my $cfg_praise = "$baseq3_dir/klesk-praise.cfg";
my $cfg_taunt = "$baseq3_dir/klesk-taunt.cfg";
# In case these need to be specially tailored.
my $victim_name_regex_str = "(.*)";
my $enemy_name_regex_str = "(.*)";
# Regex strings used to match console output
my $victim_gt_regex_str = "$victim_name_regex_str was pummeled by $player_name\$";
my $victim_mg_regex_str = "$victim_name_regex_str was machinegunned by $player_name\$";
my $victim_sg_regex_str = "$victim_name_regex_str was gunned down by $player_name\$";
my $victim_gl_direct_regex_str = "$victim_name_regex_str ate $player_name\'s grenade\$";
my $victim_gl_splash_regex_str = "$victim_name_regex_str was shredded by $player_name\'s shrapnel\$";
my $victim_rl_direct_regex_str = "$victim_name_regex_str ate $player_name\'s rocket\$";
my $victim_rl_splash_regex_str = "$victim_name_regex_str almost dodged $player_name\'s rocket\$";
my $victim_lg_regex_str = "$victim_name_regex_str was electrocuted by $player_name\$";
my $victim_rg_regex_str = "$victim_name_regex_str was railed by $player_name\$";
my $victim_pg_regex_str = "$victim_name_regex_str was melted by $player_name\'s plasmagun\$";
my $victim_ng_regex_str = "$victim_name_regex_str was nailed by $player_name\$";
my $victim_cg_regex_str = "$victim_name_regex_str got lead poisoning from $player_name\'s Chaingun\$";
my $victim_bfg_regex_str = "$victim_name_regex_str was blasted by $player_name\'s BFG\$";
my $victim_telefrag_regex_str = "$victim_name_regex_str tried to invade $player_name\'s personal space\$";
my $enemy_gt_regex_str = "$player_name was pummeled by $enemy_name_regex_str\$";
my $enemy_mg_regex_str = "$player_name was machinegunned by $enemy_name_regex_str\$";
my $enemy_sg_regex_str = "$player_name was gunned down by $enemy_name_regex_str\$";
my $enemy_gl_direct_regex_str = "$player_name ate $enemy_name_regex_str\'s grenade\$";
my $enemy_gl_splash_regex_str = "$player_name was shredded by $enemy_name_regex_str\'s shrapnel\$";
my $enemy_rl_direct_regex_str = "$player_name ate $enemy_name_regex_str\'s rocket\$";
my $enemy_rl_splash_regex_str = "$player_name almost dodged $enemy_name_regex_str\'s rocket\$";
my $enemy_lg_regex_str = "$player_name was electrocuted by $enemy_name_regex_str\$";
my $enemy_rg_regex_str = "$player_name was railed by $enemy_name_regex_str\$";
my $enemy_pg_regex_str = "$player_name was melted by $enemy_name_regex_str\'s plasmagun\$";
my $enemy_ng_regex_str = "$player_name was nailed by $enemy_name_regex_str\$";
my $enemy_cg_regex_str = "$player_name got lead poisoning from $enemy_name_regex_str\'s Chaingun\$";
my $enemy_bfg_regex_str = "$player_name was blasted by $enemy_name_regex_str\'s BFG\$";
my $enemy_telefrag_regex_str = "$player_name tried to invade $enemy_name_regex_str\'s personal space\$";
# so we can substitute names in later.
my $target_name_replace_string = "___name___";
# insult arrays
my @insult_array_death_praise = ("Peace now. We thank.",
"You alpha one. $target_name_replace_string make new race.",
"Too easy for $target_name_replace_string...$target_name_replace_string is chosen.",
"We come to your mind now, $target_name_replace_string. We stronger.",
"Now you learn secret. We be you.",
"Is sad.",
"Bigger voice, $target_name_replace_string, than all in me together."
);
my @insult_array_death_rail = ("No sense it. No happy.",
"$target_name_replace_string ruins all world.",
"No thoughts to sense. Just... ssssss... camper ...",
"No good this destiny, $target_name_replace_string. We change. You get eat."
);
my @insult_array_death_bfg = ("Too many poppers!",
"Each voice get boom-boom.",
"Shrieking! Too many noise. Too many hurt!",
"My pieces make altar. You need to pray.",
);
my @insult_array_death_gaunt = ("Touch of single-brainer burns many.",
"Energy scatter. Discord! Die, die, dying."
);
my @insult_array_death = ("Now We know mystery you not know, $target_name_replace_string.",
"Forever all know $target_name_replace_string kill Klesk. All hate $target_name_replace_string.",
"All is chaos! $target_name_replace_string win? No order to universe.",
"Single-brainer $target_name_replace_string too stupid to find joy. No deserve.",
"We devolve to $target_name_replace_string level. We fail.",
"Colossal ridiculity is $target_name_replace_string.",
"We will find you, $target_name_replace_string ... kill body, swallow soul, scatter thoughts. Nothing of $target_name_replace_string remain."
);
my @insult_array_random = ("We hear you, $target_name_replace_string. Your mind cry out inferior.",
"We am many, you only one, $target_name_replace_string.",
"$target_name_replace_string voice run with spilling blood and gut. Is ecstacy.",
"Better $target_name_replace_string serve as nest for egglings.",
"Only great survive. $target_name_replace_string easy die.",
"You think stupid, $target_name_replace_string. You weak! Klesk do favor killing you.",
"There only black empty for $target_name_replace_string. No revelation."
);
my @insult_array_kill_rail = ("We see you always, $target_name_replace_string. Nowhere to hide.",
"Poke little hole in $target_name_replace_string. You spill out. Happy.",
"Poor $target_name_replace_string. So much left, but voice is quiet."
);
my @insult_array_kill_gaunt = ("Close ... close, $target_name_replace_string. We smell you fear of die.",
"We watch light leave eyes of $target_name_replace_string. We like."
);
my @insult_array_kill = ("My egglings in you hatch, $target_name_replace_string.",
"Much happiness me. I wish you back so kill you over again.",
"To followers We feed you.",
"One little voice to silence. Not enough, but happy.",
"$target_name_replace_string mind weak, body weak. It follows. Too easy.",
"Glide on $target_name_replace_string spill guts. Dance of joy.",
"Hollow skull, make $target_name_replace_string candle. Need focus."
);
############################################################
=over 1
=item extract_victim_name()
Extracts the victim name, if applicable, from the line piped from STDIN
Input: $line
Output: ($victim_name, $victim_rail_status, $victim_gaunt_status, $victim_bfg_status);
=back
=cut
############################################################
sub extract_victim_name {
my ( $line ) = @_;
my $victim_name = '';
my $victim_gaunt_status = 0;
my $victim_rail_status = 0;
my $victim_bfg_status = 0;
if($line =~ qr/$victim_gt_regex_str/i) {
$victim_name = $1;
$victim_gaunt_status = 1;
}
if($line =~ qr/$victim_rg_regex_str/i) {
$victim_name = $1;
$victim_rail_status = 1;
}
if($line =~ qr/$victim_bfg_regex_str/i) {
$victim_name = $1;
$victim_bfg_status = 1;
}
$victim_name = $1 if $line =~ qr/$victim_mg_regex_str/i;
$victim_name = $1 if $line =~ qr/$victim_sg_regex_str/i;
$victim_name = $1 if $line =~ qr/$victim_gl_direct_regex_str/i;
$victim_name = $1 if $line =~ qr/$victim_gl_splash_regex_str/i;
$victim_name = $1 if $line =~ qr/$victim_rl_direct_regex_str/i;
$victim_name = $1 if $line =~ qr/$victim_rl_splash_regex_str/i;
$victim_name = $1 if $line =~ qr/$victim_lg_regex_str/i;
$victim_name = $1 if $line =~ qr/$victim_pg_regex_str/i;
$victim_name = $1 if $line =~ qr/$victim_ng_regex_str/i;
$victim_name = $1 if $line =~ qr/$victim_cg_regex_str/i;
$victim_name = $1 if $line =~ qr/$victim_telefrag_regex_str/i;
return ($victim_name, $victim_rail_status, $victim_gaunt_status, $victim_bfg_status);
}
############################################################
=over 1
=item extract_enemy_name()
Extracts the enemy name, if applicable, from the line piped from STDIN
Input: $line
Output: ($enemy_name, $enemy_rail_status, $enemy_gaunt_status, $enemy_bfg_status);
=back
=cut
############################################################
sub extract_enemy_name {
my ( $line ) = @_;
my $enemy_name = '';
my $enemy_gaunt_status = 0;
my $enemy_rail_status = 0;
my $enemy_bfg_status = 0;
if($line =~ qr/$enemy_gt_regex_str/i) {
$enemy_name = $1;
$enemy_gaunt_status = 1;
}
if($line =~ qr/$enemy_rg_regex_str/i) {
$enemy_name = $1;
$enemy_rail_status = 1;
}
if($line =~ qr/$enemy_bfg_regex_str/i) {
$enemy_name = $1;
$enemy_bfg_status = 1;
}
$enemy_name = $1 if $line =~ qr/$enemy_mg_regex_str/i;
$enemy_name = $1 if $line =~ qr/$enemy_sg_regex_str/i;
$enemy_name = $1 if $line =~ qr/$enemy_gl_direct_regex_str/i;
$enemy_name = $1 if $line =~ qr/$enemy_gl_splash_regex_str/i;
$enemy_name = $1 if $line =~ qr/$enemy_rl_direct_regex_str/i;
$enemy_name = $1 if $line =~ qr/$enemy_rl_splash_regex_str/i;
$enemy_name = $1 if $line =~ qr/$enemy_lg_regex_str/i;
$enemy_name = $1 if $line =~ qr/$enemy_pg_regex_str/i;
$enemy_name = $1 if $line =~ qr/$enemy_ng_regex_str/i;
$enemy_name = $1 if $line =~ qr/$enemy_cg_regex_str/i;
$enemy_name = $1 if $line =~ qr/$enemy_telefrag_regex_str/i;
return ($enemy_name, $enemy_rail_status, $enemy_gaunt_status, $enemy_bfg_status);
}
MAINLOOP: while (<STDIN>) {
chomp($_);
my $line = $_;
# Strip colours
$line =~ s/\^[0-9]//g;
my $victim_name = '';
my $victim_gaunt_status = 0;
my $victim_rail_status = 0;
my $victim_bfg_status = 0;
my $enemy_name = '';
my $enemy_gaunt_status = 0;
my $enemy_rail_status = 0;
my $enemy_bfg_status = 0;
my $talker_name = '';
($victim_name, $victim_rail_status, $victim_gaunt_status, $victim_bfg_status) = extract_victim_name($line);
($enemy_name, $enemy_rail_status, $enemy_gaunt_status, $enemy_bfg_status) = extract_enemy_name($line);
my $write_string = '';
my @write_string_list = ();
my $write_string_rand_index = 0;
if($victim_name) {
if ($victim_rail_status) {
@write_string_list = @insult_array_kill_rail;
} elsif ($victim_gaunt_status) {
@write_string_list = @insult_array_kill_gaunt;
} else {
@write_string_list = @insult_array_kill;
}
$write_string_rand_index = rand(scalar @write_string_list);
$write_string = $write_string_list[$write_string_rand_index];
$write_string =~ s/$target_name_replace_string/$victim_name/g;
print "cfg_taunt: \"$write_string\"\n" if DEBUG;
open (FILE, '>', $cfg_taunt) or die "Unable to open cfg for writing! Exiting.";
print FILE "say $write_string";
close(FILE);
} elsif($enemy_name) {
if ($enemy_rail_status) {
@write_string_list = @insult_array_death_rail;
} elsif ($enemy_gaunt_status) {
@write_string_list = @insult_array_death_gaunt;
} elsif ($enemy_bfg_status) {
@write_string_list = @insult_array_death_bfg;
} else {
@write_string_list = @insult_array_death;
}
$write_string_rand_index = rand(scalar @write_string_list);
$write_string = $write_string_list[$write_string_rand_index];
$write_string =~ s/$target_name_replace_string/$enemy_name/g;
print "cfg_insult: \"$write_string\"\n" if DEBUG;
open (FILE, '>', $cfg_insult) or die "Unable to open cfg for writing! Exiting.";
print FILE "say $write_string";
close(FILE);
# Write praise
$write_string_rand_index = rand(scalar @insult_array_death_praise);
$write_string = $insult_array_death_praise[$write_string_rand_index];
$write_string =~ s/$target_name_replace_string/$enemy_name/g;
print "cfg_praise: \"$write_string\"\n" if DEBUG;
open (FILE, '>', $cfg_praise) or die "Unable to open cfg for writing! Exiting.";
print FILE "say $write_string";
close(FILE);
} elsif($line =~ /(.*):/i) {
# regex matches everything up to final colon, should survive weird post-steam names.
$talker_name = $1;
$write_string_rand_index = rand(scalar @insult_array_random);
$write_string = $insult_array_random[$write_string_rand_index];
$write_string =~ s/$target_name_replace_string/$talker_name/g;
print "cfg_insult_talker: \"$write_string\"\n" if DEBUG;
open (FILE, '>', $cfg_insult_talker) or die "Unable to open cfg for writing! Exiting.";
print FILE "say $write_string";
close(FILE);
}
}