-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvaihdatopic.pl
102 lines (89 loc) · 3.04 KB
/
vaihdatopic.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
use Irssi;
use Irssi::Irc;
use DBI;
use DBI qw(:sql_types);
use warnings;
use strict;
use utf8;
#use KaaosRadioClass; # LAama1 30.12.2016
use Data::Dumper;
use vars qw($VERSION %IRSSI);
$VERSION = '20190321';
%IRSSI = (
authors => 'LAama1',
contact => 'LAama1@ircnet',
name => 'vaihdatopic',
description => 'Vaihda topic kanavalla.',
license => 'Public Domain',
url => '#salamolo',
changed => $VERSION
);
my $channels = '#salamolo2';
my $myname = 'vaihdatopic.pl';
my $DEBUG = 1;
my $oldTopic = '';
my $helptext_long = 'Vaihda kanavan topic kirjoittamalla !topic <topic> kanavalla tai privassa !topic <#kanava> <topic>.';
my $helptext_short = 'Topic-skriptin help: !help topic';
sub msgit {
my ($server, $nick, $text, @rest) = @_;
$server->command("MSG $nick $text");
}
# Say it public to a channel. Params: $server, $target, $saywhat
sub sayit {
my ($server, $target, $saywhat) = @_;
$server->command("MSG $target $saywhat");
}
sub changeTopic {
my ($server, $target, $topic, @rest) = @_;
my $channelObj = $server->channel_find($target);
$oldTopic = $channelObj->{topic};
dp(__LINE__.": changeTopic target: $target, new topic: $topic, current topic: $oldTopic");
return if $topic eq $oldTopic;
$server->send_raw("topic $target :$topic");
}
sub event_privmsg {
my ($server, $data, $nick, $address) = @_;
if($data =~ /^!topic\s(.{1,470})/gi) {
my $newtopic = $1; # command the user has entered
$server->command("MSG $channels New topic: $newtopic");
changeTopic($server, $channels, $newtopic);
}
}
sub event_pubmsg {
my ($server, $msg, $nick, $address, $target) = @_;
my $enabled_raw = Irssi::settings_get_str('vaihdatopic_enabled_channels');
my @enabled = split(/ /, $enabled_raw);
return unless grep(/$target/i, @enabled);
if ($msg =~ /^\!help vaihda/i) {
sayit($server, $target, $helptext_short);
Irssi::print("$myname: !help request from $nick on $target.");
return;
} elsif ($msg =~ /^!help topic$/i) {
Irssi::print("$myname: !help topic request from $nick on $target.");
sayit($server, $target, $helptext_long);
return;
}
if($data =~ /^!topic$/gi) { # if !topic
#return if KaaosRadioClass::floodCheck() == 1;
sayit($server, $target, "Kanavan nykyinen oletus-topic on: $oldTopic");
Irssi::print("$myname: !topic request from $nick on $target.");
} elsif($msg =~ /^!topic\s(.{1,470})/gi) {
my $newtopic = $1;
changeTopic($server, $target, $newtopic);
Irssi::print("$myname: !topic request from $nick on $target.");
}
}
sub da {
return unless $DEBUG == 1;
Irssi::print("$myname-debug array:");
Irssi::print Dumper (@_);
}
sub dp {
return unless $DEBUG == 1;
Irssi::print("$myname-debug: @_");
}
Irssi::settings_add_str('vaihdatopic', 'vaihdatopic_enabled_channels', '');
Irssi::signal_add_last('message public', 'event_pubmsg');
Irssi::signal_add_last('message private', 'event_privmsg');
Irssi::print("vaihdatopic.pl v. $VERSION -- New commands: /set vaihdatopic_enabled_channels #1 #2");
Irssi::print('vaihdatopic.pl channels: '. Irssi::settings_get_str('vaihdatopic_enabled_channels'));