From 4b829341315d7abb312dd1970e81943b53e599fe Mon Sep 17 00:00:00 2001 From: Valentin Lorentz Date: Mon, 14 Jun 2021 21:47:36 +0200 Subject: [PATCH] Services: Add @nickserv and @chanserv command, to message services directly This is because the recommended method ('owner ircquote nickserv register mypassword bot@example.com') does not work on charybdis, as Limnoria inserts a colon before the trailing argument and Charybdis' m_alias module does not parse commands using the IRC syntax, so it considers the leading colon to be part of the email address. The alternative would be to change the recommended command to: 'owner ircquote PRIVMSG nickserv :register mypassword bot@example.com' but it is prone to typos, so I think we should avoid it. --- plugins/Services/plugin.py | 29 +++++++++++++++++++++++++++++ plugins/Services/test.py | 12 ++++++++++++ 2 files changed, 41 insertions(+) diff --git a/plugins/Services/plugin.py b/plugins/Services/plugin.py index 4d901a1ba..cdc5e976f 100644 --- a/plugins/Services/plugin.py +++ b/plugins/Services/plugin.py @@ -558,6 +558,35 @@ class Services(callbacks.Plugin): 'I\'m able to ghost a nick.')) ghost = wrap(ghost, [('checkCapability', 'admin'), additional('nick')]) + def nickserv(self, irc, msg, args, text): + """ + + Sends the to NickServ. For example, to register to NickServ + on Atheme, use: @nickserv REGISTER .""" + nickserv = self.registryValue('NickServ', network=irc.network) + if nickserv: + irc.replySuccess() + irc.queueMsg(ircmsgs.privmsg(nickserv, text)) + else: + irc.error(_('You must set supybot.plugins.Services.NickServ before ' + 'I\'m able to message NickServ')) + nickserv = wrap(nickserv, ['owner', 'text']) + + def chanserv(self, irc, msg, args, text): + """ + + Sends the to ChanServ. For example, to register a channel + on Atheme, use: @chanserv REGISTER <#channel>.""" + chanserv = self.registryValue('ChanServ', network=irc.network) + if chanserv: + irc.replySuccess() + irc.queueMsg(ircmsgs.privmsg(chanserv, text)) + else: + irc.error(_('You must set supybot.plugins.Services.ChanServ before ' + 'I\'m able to message ChanServ')) + chanserv = wrap(chanserv, ['owner', 'text']) + + @internationalizeDocstring def password(self, irc, msg, args, nick, password): """ [] diff --git a/plugins/Services/test.py b/plugins/Services/test.py index 66250f554..a2e783d87 100644 --- a/plugins/Services/test.py +++ b/plugins/Services/test.py @@ -88,6 +88,18 @@ class ServicesTestCase(PluginTestCase): finally: self.assertNotError('services password %s ""' % self.nick) + def testNickserv(self): + self.assertNotError('nickserv foo bar') + m = self.irc.takeMsg() + self.assertEqual(m.command, 'PRIVMSG', m) + self.assertEqual(m.args, ('NickServ', 'foo bar'), m) + + def testChanserv(self): + self.assertNotError('chanserv foo bar') + m = self.irc.takeMsg() + self.assertEqual(m.command, 'PRIVMSG', m) + self.assertEqual(m.args, ('ChanServ', 'foo bar'), m) + def testRegisterNoExperimentalExtensions(self): self.assertRegexp( "register p4ssw0rd", "error: Experimental IRC extensions")