summaryrefslogtreecommitdiffstats
path: root/scripts/thankop.pl
blob: 023b04191ebe1977bd512190b844539bc3670e69 (plain)
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
use Irssi 0.8.10 ();
use strict;

use vars qw($VERSION %IRSSI);

$VERSION="0.1.7";
%IRSSI = (
	authors=> 'BC-bd',
	contact=> 'bd@bc-bd.org',
	name=> 'thankop',
	description=> 'Remembers the last person oping you on a channel',
	license=> 'GPL v2',
	url=> 'https://bc-bd.org/svn/repos/irssi/trunk/',
);

# $Id #
# 
#########
# USAGE
###
#
# Type '/thankop' in a channel window to thank the person opping you
#
##########
# OPTIONS
####
#
# /set thankop_command [command]
#		* command  : to be executed. The following $'s are expanded
#		    $N : Nick (some dude)
#		    
#		eg:
#		
#		  /set thankop_command say $N: w00t!
#
#		Would say
#
#		  <nick>: w00t!
#
#		To the channel you got op in, with <nick> beeing the nick who
#		opped you
#
################
###
# Changelog
#
# Version 0.1.7
#  - fix crash if used in a window != CHANNEL
#  - do not thank someone who has already left
#
# Version 0.1.6
#  - added support for multiple networks, thanks to senneth
#  - adapted to signal changes in 0.8.10
#
# Version 0.1.5
#  - change back to setting instead of theme item
#
# Version 0.1.4
#  - added theme item to customize the message (idea from mordeth)
#
# Version 0.1.3
#  - removed '/' from the ->command (thx to mordeth)
#  - removed debug messages (where commented out)
#  
# Version 0.1.2
#  - added version dependency, since some 0.8.4 users complained about a not
#      working script
#  
# Version 0.1.1
#  - unsetting of hash values is done with delete not unset.
#
# Version 0.1.0
#  - initial release
#  
###
################

my %op;

sub cmd_thankop {
	my ($data, $server, $witem) = @_;

	if (!$witem || ($witem->{type} =! "CHANNEL")) {
		Irssi::print("thankop: Window not of type CHANNEL");
		return;
	}

	my $tag = $witem->{server}->{tag}.'/'.$witem->{name};

	# did we record who opped us here
	if (!exists($op{$tag})) {
		$witem->print("thankop: I don't know who op'ed you in here");
		return;
	}

	my $by = $op{$tag};

	# still here?
	if (!$witem->nick_find($by)) {
		$witem->print("thankop: $by already left");
		return;
	}

	my $cmd = Irssi::settings_get_str('thankop_command');
				
	$cmd =~ s/\$N/$by/;
	$witem->command($cmd);
}

sub mode_changed {
	my ($channel, $nick, $by, undef, undef) = @_;

	return if ($channel->{server}->{nick} ne $nick->{nick});

	# since 0.8.10 this is set after signals have been processed
	return if ($channel->{chanop});

	my $tag = $channel->{server}->{tag}.'/'.$channel->{name};

	$op{$tag} = $by;
}

sub channel_destroyed {
	my ($channel) = @_;

	my $tag = $channel->{server}->{tag}.'/'.$channel->{name};

	delete($op{$tag});
}

Irssi::command_bind('thankop','cmd_thankop');
Irssi::signal_add_last('nick mode changed', 'mode_changed');

Irssi::settings_add_str('thankop', 'thankop_command', 'say $N: opthx');