mirror of
https://github.com/Mikaela/Limnoria.git
synced 2025-02-08 18:44:06 +01:00
Factoids: Add supybot.plugins.Factoids.requireVoice. Closes GH-378.
This commit is contained in:
parent
ed62c9efb1
commit
1090c4623f
@ -54,6 +54,10 @@ conf.registerGlobalValue(Factoids.web, 'enable',
|
|||||||
conf.registerChannelValue(Factoids.web, 'channel',
|
conf.registerChannelValue(Factoids.web, 'channel',
|
||||||
registry.Boolean(False, _("""Determines whether factoids can be displayed
|
registry.Boolean(False, _("""Determines whether factoids can be displayed
|
||||||
via the web server.""")))
|
via the web server.""")))
|
||||||
|
|
||||||
|
conf.registerChannelValue(Factoids, 'requireVoice',
|
||||||
|
registry.Boolean(False, _("""Only allows a user with voice or above on a
|
||||||
|
channel to use the command.""")))
|
||||||
conf.registerChannelValue(Factoids, 'learnSeparator',
|
conf.registerChannelValue(Factoids, 'learnSeparator',
|
||||||
registry.String('as', _("""Determines what separator must be used in the
|
registry.String('as', _("""Determines what separator must be used in the
|
||||||
learn command. Defaults to 'as' -- learn <key> as <value>. Users might
|
learn command. Defaults to 'as' -- learn <key> as <value>. Users might
|
||||||
|
@ -270,6 +270,9 @@ class Factoids(callbacks.Plugin, plugins.ChannelDBHandler):
|
|||||||
return (keyresults, factresults,)
|
return (keyresults, factresults,)
|
||||||
|
|
||||||
def learn(self, irc, msg, args, channel, key, factoid):
|
def learn(self, irc, msg, args, channel, key, factoid):
|
||||||
|
if self.registryValue('requireVoice', channel) and \
|
||||||
|
not irc.state.channels[channel].isVoicePlus(msg.nick):
|
||||||
|
irc.error(_('You have to be at least voiced to teach factoids.'))
|
||||||
|
|
||||||
# if neither key nor factoid exist, add them.
|
# if neither key nor factoid exist, add them.
|
||||||
# if key exists but factoid doesn't, add factoid, link it to existing key
|
# if key exists but factoid doesn't, add factoid, link it to existing key
|
||||||
|
@ -29,6 +29,7 @@
|
|||||||
###
|
###
|
||||||
|
|
||||||
from supybot.test import *
|
from supybot.test import *
|
||||||
|
import supybot.conf as conf
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import sqlite3
|
import sqlite3
|
||||||
@ -76,6 +77,12 @@ class FactoidsTestCase(ChannelPluginTestCase):
|
|||||||
self.assertError('learn foo bar baz') # No 'as'
|
self.assertError('learn foo bar baz') # No 'as'
|
||||||
self.assertError('learn foo bar') # No 'as'
|
self.assertError('learn foo bar') # No 'as'
|
||||||
|
|
||||||
|
with conf.supybot.plugins.Factoids.requireVoice.context(True):
|
||||||
|
self.assertError('learn jemfinch as my primary author')
|
||||||
|
self.irc.feedMsg(ircmsgs.mode(self.channel,
|
||||||
|
args=('+h', self.nick)))
|
||||||
|
self.assertNotError('learn jemfinch as my primary author')
|
||||||
|
|
||||||
def testChangeFactoid(self):
|
def testChangeFactoid(self):
|
||||||
self.assertNotError('learn foo as bar')
|
self.assertNotError('learn foo as bar')
|
||||||
self.assertNotError('change foo 1 s/bar/baz/')
|
self.assertNotError('change foo 1 s/bar/baz/')
|
||||||
|
@ -330,9 +330,7 @@ def getHaveVoicePlus(irc, msg, args, state, action=_('do that')):
|
|||||||
getChannel(irc, msg, args, state)
|
getChannel(irc, msg, args, state)
|
||||||
if state.channel not in irc.state.channels:
|
if state.channel not in irc.state.channels:
|
||||||
state.error(_('I\'m not even in %s.') % state.channel, Raise=True)
|
state.error(_('I\'m not even in %s.') % state.channel, Raise=True)
|
||||||
if not irc.state.channels[state.channel].isOp(irc.nick) and \
|
if not irc.state.channels[state.channel].isVoicePlus(irc.nick):
|
||||||
not irc.state.channels[state.channel].isHalfop(irc.nick) and \
|
|
||||||
not irc.state.channels[state.channel].isVoice(irc.nick):
|
|
||||||
# isOp includes owners and protected users
|
# isOp includes owners and protected users
|
||||||
state.error(_('I need to be at least voiced to %s.') % action,
|
state.error(_('I need to be at least voiced to %s.') % action,
|
||||||
Raise=True)
|
Raise=True)
|
||||||
@ -350,8 +348,7 @@ def getHaveHalfopPlus(irc, msg, args, state, action=_('do that')):
|
|||||||
getChannel(irc, msg, args, state)
|
getChannel(irc, msg, args, state)
|
||||||
if state.channel not in irc.state.channels:
|
if state.channel not in irc.state.channels:
|
||||||
state.error(_('I\'m not even in %s.') % state.channel, Raise=True)
|
state.error(_('I\'m not even in %s.') % state.channel, Raise=True)
|
||||||
if not irc.state.channels[state.channel].isOp(irc.nick) and \
|
if not irc.state.channels[state.channel].isHalfopPlus(irc.nick):
|
||||||
not irc.state.channels[state.channel].isHalfop(irc.nick):
|
|
||||||
# isOp includes owners and protected users
|
# isOp includes owners and protected users
|
||||||
state.error(_('I need to be at least halfopped to %s.') % action,
|
state.error(_('I need to be at least halfopped to %s.') % action,
|
||||||
Raise=True)
|
Raise=True)
|
||||||
|
@ -245,10 +245,16 @@ class ChannelState(utils.python.Object):
|
|||||||
|
|
||||||
def isOp(self, nick):
|
def isOp(self, nick):
|
||||||
return nick in self.ops
|
return nick in self.ops
|
||||||
|
def isOpPlus(self, nick):
|
||||||
|
return nick in self.ops
|
||||||
def isVoice(self, nick):
|
def isVoice(self, nick):
|
||||||
return nick in self.voices
|
return nick in self.voices
|
||||||
|
def isVoicePlus(self, nick):
|
||||||
|
return nick in self.voices or nick in self.halfops or nick in self.ops
|
||||||
def isHalfop(self, nick):
|
def isHalfop(self, nick):
|
||||||
return nick in self.halfops
|
return nick in self.halfops
|
||||||
|
def isHalfopPlus(self, nick):
|
||||||
|
return nick in self.halfops or nick in self.ops
|
||||||
|
|
||||||
def addUser(self, user):
|
def addUser(self, user):
|
||||||
"Adds a given user to the ChannelState. Power prefixes are handled."
|
"Adds a given user to the ChannelState. Power prefixes are handled."
|
||||||
|
Loading…
Reference in New Issue
Block a user