Skip to content

Commit df45a61

Browse files
committed
Channel: Make 'invite' command's required capability configurable
It still requires 'op' by default, but can now be changed with a config value. This can be useful on servers that do not have a 'free invite' channel mode (like Charybdis/Solanum's +g)
1 parent c81ff28 commit df45a61

File tree

3 files changed

+50
-4
lines changed

3 files changed

+50
-4
lines changed

plugins/Channel/config.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
###
22
# Copyright (c) 2004-2005, Jeremiah Fincher
33
# Copyright (c) 2009, James McCoy
4-
# Copyright (c) 2010-2021, Valentin Lorentz
4+
# Copyright (c) 2010-2025, Valentin Lorentz
55
# All rights reserved.
66
#
77
# Redistribution and use in source and binary forms, with or without
@@ -63,4 +63,9 @@ def configure(advanced):
6363
be used (they are optional in the IRC protocol). The standard
6464
substitutions ($version, $nick, etc.) are all handled appropriately.""")))
6565

66+
conf.registerGroup(Channel, 'invite')
67+
conf.registerChannelValue(Channel.invite, 'requireCapability',
68+
registry.String('op', _("""Determines what capability (if any) the bot should
69+
require people trying to use the 'invite' command to have.""")))
70+
6671
# vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79:

plugins/Channel/plugin.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
###
22
# Copyright (c) 2002-2005, Jeremiah Fincher
33
# Copyright (c) 2009-2012, James McCoy
4-
# Copyright (c) 2010-2021, Valentin Lorentz
4+
# Copyright (c) 2010-2025, Valentin Lorentz
55
# All rights reserved.
66
#
77
# Redistribution and use in source and binary forms, with or without
@@ -508,10 +508,17 @@ def invite(self, irc, msg, args, channel, nick):
508508
to join <channel>. <channel> is only necessary if the message isn't
509509
sent in the channel itself.
510510
"""
511+
capability = self.registryValue('invite.requireCapability',
512+
channel, irc.network)
513+
if capability:
514+
capability = ircdb.makeChannelCapability(channel, capability)
515+
if not ircdb.checkCapability(msg.prefix, capability):
516+
irc.errorNoCapability(capability, Raise=True)
517+
511518
nick = nick or msg.nick
512519
self._sendMsg(irc, ircmsgs.invite(nick, channel))
513520
self.invites[(irc.getRealIrc(), ircutils.toLower(nick))] = irc
514-
invite = wrap(invite, ['op', ('haveHalfop+', _('invite someone')),
521+
invite = wrap(invite, [('haveHalfop+', _('invite someone')),
515522
additional('nick')])
516523

517524
def do341(self, irc, msg):

plugins/Channel/test.py

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
###
22
# Copyright (c) 2002-2005, Jeremiah Fincher
33
# Copyright (c) 2009, James McCoy
4-
# Copyright (c) 2010-2021, Valentin Lorentz
4+
# Copyright (c) 2010-2025, Valentin Lorentz
55
# All rights reserved.
66
#
77
# Redistribution and use in source and binary forms, with or without
@@ -414,5 +414,39 @@ def getAfterJoinMessages():
414414
self.assertEqual(m.args[0], '#foo')
415415
self.assertEqual(m.args[1], 'reason')
416416

417+
def testInvite(self):
418+
self.irc.feedMsg(ircmsgs.op(self.channel, self.nick))
419+
m = self.getMsg('invite foo')
420+
self.assertEqual(m.command, 'INVITE')
421+
self.assertEqual(m.args, ('foo', self.channel))
422+
423+
def testInviteNoCapability(self):
424+
self.irc.feedMsg(ircmsgs.op(self.channel, self.nick))
425+
m = self.assertError('invite foo',
426+
frm='test!user@with__no_testcap__')
427+
428+
def testInviteCustomCapability(self):
429+
self.irc.feedMsg(ircmsgs.op(self.channel, self.nick))
430+
431+
self.assertError('invite foo',
432+
frm='test!user@with__no_testcap__')
433+
434+
with conf.supybot.plugins.Channel.invite.requireCapability.context('freeinvite'):
435+
m = self.getMsg('invite foo',
436+
frm='test!user@with__no_testcap__')
437+
self.assertEqual(m.command, 'INVITE')
438+
self.assertEqual(m.args, ('foo', self.channel))
439+
440+
self.assertNotError('channel capability set -freeinvite')
441+
442+
self.assertError('invite foo',
443+
frm='test!user@with__no_testcap__')
444+
445+
with conf.supybot.plugins.Channel.invite.requireCapability.context(''):
446+
m = self.getMsg('invite foo',
447+
frm='test!user@with__no_testcap__')
448+
self.assertEqual(m.command, 'INVITE')
449+
self.assertEqual(m.args, ('foo', self.channel))
450+
417451
# vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79:
418452

0 commit comments

Comments
 (0)