-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbot.pl
executable file
·61 lines (49 loc) · 1.88 KB
/
bot.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
#!/usr/bin/perl
use strict;
use warnings;
require dAmnPearl;
# Because I'm lazy as shit.
sub trim { my $str = $_[0]; $str =~ s/^\s+|\s+$//g; return $str; }
# Check for the config file
if (-f './config.txt') {
my ($username, $password, $trigger, $owner, $chanlist, @channels);
use feature 'switch';
open(my $FH, '<', './config.txt');
my $buffer = '';
while (<$FH>) { $buffer .= $_; }
close $FH;
my @lines = split /\r\n/, $buffer;
my $line_number = 0;
foreach my $line (@lines) {
if (length $line > 0 and (my $pos = index($line, '=')) != -1) {
my $key = trim(substr $line, 0, $pos);
given ($key) {
when ('username') { $username = trim(substr $line, ++$pos); }
when ('password') { $password = trim(substr $line, ++$pos); }
when ('trigger') { $trigger = trim(substr $line, ++$pos); }
when ('owner') { $owner = trim(substr $line, ++$pos); }
when ('channels') { $chanlist = trim(substr $line, ++$pos); }
default { }
}
} else {
die "Line $line_number of config.txt is invalid.\n";
}
$line_number++;
}
foreach my $chan (split / /, $chanlist) {
push(@channels, $chan);
}
# Fire up the core.
dAmnPearl::init($username, $password, $trigger, $owner, @channels);
} else {
print "No config file was found. Creating a default config...\n";
open(my $FH, '>', './config.txt');
print $FH "username = dAmnPearl\r\n".
"password = SuperSecretPassword\r\n".
"owner = fella\r\n".
"trigger = !\r\n".
"channels = #Botdom #SomeWhereElse\r\n";
close $FH;
print "Done! Please modify the config.txt file with your bots' details.\n";
exit;
}