summaryrefslogtreecommitdiff
path: root/lib/IRC/Client/Plugin/NickServ.pm6
blob: 70f387583a99319eb8a096f0a9cf0441643bcc99 (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
#! /usr/bin/env false

use v6.c;

use Config;
use IRC::Client;

#| The IRC::Client::Plugin to deal with NickServ interaction.
class IRC::Client::Plugin::NickServ does IRC::Client::Plugin
{
	has Config $.config;

	#| Identify with NickServ. This is done on IRC code 376 (end of MOTD),
	#| since this is what most servers accept as the earliest time to start
	#| interacting with the server.
	method irc-n376($e)
	{
		# Extract the config parameters
		my Str $user = $!config<nickserv><nickname> // $!config<bot><nickname>;
		my Str $pass = $!config<nickserv><password>;

		# Nothing to do if we don't have a username and a password
		return unless $user && $pass;

		# Send the identify command
		$e.irc.send-cmd: "NS identify $user $pass";

		# If we're using our preferred nick, we're done
		return unless $e.irc.current-nick eq $e.irc.nick.first;

		# Ghost our nick
		$e.irc.send-cmd: "NS GHOST {$e.irc.nick.first}";

		# Use our nick
		$e.irc.send-cmd: "NICK {$e.irc.nick.first}";
	}
}

# vim: ft=perl6 noet