Make 'isvip' output differentiate between types.

Also drop capability checks off functions where
they are already done at command level.
This commit is contained in:
Krytarik Raido 2022-10-13 19:34:04 +02:00
parent 7fe15a15d8
commit 0ff2476e87
2 changed files with 25 additions and 42 deletions

View File

@ -28,11 +28,11 @@ Then `@load ChanTracker`.
@b,e,i,q [<channel>] <nick|hostmask>[,<nick|hostmask>] [<years>y] [<weeks>w] [<days>d] [<hours>h] [<minutes>m] [<seconds>s] [<-1> or empty means forever] <reason>) -- +mode targets for duration <reason> is mandatory
@ub,ue,ui,uq [<channel>] <nick|hostmask|*> [<nick|hostmask>]) -- sets -mode on them, if * found, remove them all
@check [<channel>] <pattern> returns list of users who will be affected by such pattern
@edit <id> [,<id>] [<years>y] [<weeks>w] [<days>d] [<hours>h] [<minutes>m] [<seconds>s] [<-1>] means forever) -- change expiration of some active modes
@edit <id>[,<id>] [<years>y] [<weeks>w] [<days>d] [<hours>h] [<minutes>m] [<seconds>s] [<-1>] means forever) -- change expiration of some active modes
@info <id> returns information about a mode change
@affect <id> returns affected users by a mode placed
@mark <id> [,<id>] <message> add a comment about a mode change
@editandmark <id> [,<id>] [,<id>] [<years>y] [<weeks>w] [<days>d] [<hours>h] [<minutes>m] [<seconds>s] [<-1>] [<comment>] edit duration and add comment on a mode change
@mark <id>[,<id>] <message> add a comment about a mode change
@editandmark <id>[,<id>] [<years>y] [<weeks>w] [<days>d] [<hours>h] [<minutes>m] [<seconds>s] [<-1>] [<comment>] edit duration and add comment on a mode change
@pending [<channel>] (pending [--mode=<e|b|q|l>] [--oper=<nick|hostmask>] [--never] [<channel>] ) -- returns active items for --mode if given, filtered by --oper if given, --never never expire only if given
@query [--deep] [--never] [--active] [--channel=<channel>] <pattern|hostmask|comment>) -- search inside ban database, --deep to search on log, --never returns items set forever and active, --active returns only active modes, --channel reduces results to a specific channel
@match [<channel>] <nick|hostmask> returns list of modes that affects the nick,hostmask given
@ -42,7 +42,7 @@ Then `@load ChanTracker`.
@summary [<channel>] returns some stats about <channel>
@addpattern [<channel>] <limit> <life> <mode>(qbeId) [<years>y] [<weeks>w] [<days>d] [<hours>h] [<minutes>m] [<seconds>s] <pattern>) add a <pattern> which triggers <mode> for <duration> if the <pattern> appears more than <limit> (0 for immediate action) during <life> in seconds
@addregexpattern [<channel>] <limit> <life> <mode>(qbeId) [<years>y] [<weeks>w] [<days>d] [<hours>h] [<minutes>m] [<seconds>s] /<pattern>/) add a <pattern> which triggers <mode> for <duration> if the <pattern> appears more than <limit> (0 for immediate action) during <life> in seconds
@rmpattern [<channel>] <id> [<id>] remove patterns
@rmpattern [<channel>] <id>[,<id>] remove patterns
@lspattern [<channel>] [<id|pattern>] return patterns in <channel> filtered by optional <pattern> or <id>
@addtmp [<channel>] <pattern> add temporary pattern which follows repeat punishments
@rmtmp [<channel>] remove temporary patterns if any
@ -307,10 +307,10 @@ Maintaining separate bots for the banning/bantracking functions and other factoi
or amusement functions is good practice.
If the main purpose of your bot is to manage bans etc and never interact with users, you should remove all plugins
from `defaultcapabilities`, which will prevent the bot from responding to various commands and being used as a
from the default capabilities, which will prevent the bot from responding to various commands and being used as a
flood tool by others (like with `@echo SPAM`):
@defaultcapabilities remove <pluginname>
@defaultcapability remove <pluginname>
You could otherwise change the value of `supybot.capabilities.default`, but be prepared to waste a lot of time
each time you add a new user account on your bot. If the setting is changed to `False`, then when you want to grant
@ -320,7 +320,7 @@ access to a command for someone, you must do it this way:
@admin capability add <accountname> User.whoami
@admin capability add <accountname> whoami
If your bot manages different channels or communities, remove all `User.<action>` from `defaultcapabilities`,
If your bot manages different channels or communities, remove all `User.<action>` from the default capabilities,
create one user per channel/community, and add ops' hostmasks to it -- it's easier to manage this way.
Until you have someone with rights in multiple channels/communities, who will need a separate account.

View File

@ -455,8 +455,6 @@ class Ircd(object):
# returns active items for a channel mode
if not (channel and mode and prefix):
return []
if not ircdb.checkCapability(prefix, '%s,op' % channel):
return []
chan = self.getChan(irc, channel)
results = []
r = []
@ -509,8 +507,6 @@ class Ircd(object):
# returns active items that match n
if not (channel and n and db):
return []
if not ircdb.checkCapability(prefix, '%s,op' % channel):
return []
chan = self.getChan(irc, channel)
results = []
r = []
@ -1185,9 +1181,6 @@ class Chan(object):
return i
def addpattern(self, prefix, limit, life, mode, duration, pattern, regexp, db):
if not (ircdb.checkCapability(prefix, '%s,op' % self.name)
or prefix == irc.prefix):
return False
c = db.cursor()
c.execute("""INSERT INTO patterns VALUES (NULL, ?, ?, ?, ?, ?, ?, ?, ?, ?, 0)""",
(self.name, prefix, time.time(), pattern, regexp, limit, life, mode, duration))
@ -1201,9 +1194,6 @@ class Chan(object):
return '[#%s "%s"%s]' % (uid, pattern, r)
def rmpattern(self, prefix, uid, db):
if not (ircdb.checkCapability(prefix, '%s,op' % self.name)
or prefix == irc.prefix):
return False
c = db.cursor()
c.execute("""SELECT id,channel,pattern,regexp FROM patterns
WHERE id=? and channel=? LIMIT 1""", (uid, self.name))
@ -1235,9 +1225,6 @@ class Chan(object):
c.close()
def lspattern(self, prefix, pattern, db):
if not (ircdb.checkCapability(prefix, '%s,op' % self.name)
or prefix != irc.prefix):
return []
c = db.cursor()
results = []
items = []
@ -1842,7 +1829,7 @@ class ChanTracker(callbacks.Plugin, plugins.ChannelDBHandler):
for result in results:
irc.queueMsg(ircmsgs.privmsg(msg.nick, result))
else:
irc.reply('no result')
irc.reply('nothing found')
self.forceTickle = True
self._tickle(irc)
pending = wrap(pending, ['op', getopts({'flood': '', 'mode': 'letter', 'never': '',
@ -2097,7 +2084,7 @@ class ChanTracker(callbacks.Plugin, plugins.ChannelDBHandler):
if len(results):
irc.reply(' '.join(results), private=True)
else:
irc.reply('no results or unknown mode')
irc.reply('nothing found or unknown mode')
self.forceTickle = True
self._tickle(irc)
overlap = wrap(overlap, ['op', 'text'])
@ -2151,7 +2138,7 @@ class ChanTracker(callbacks.Plugin, plugins.ChannelDBHandler):
if len(results):
irc.reply(' '.join(results), private=True)
else:
irc.reply('no results')
irc.reply('nothing found')
self._tickle(irc)
match = wrap(match, ['op', 'text'])
@ -2185,9 +2172,9 @@ class ChanTracker(callbacks.Plugin, plugins.ChannelDBHandler):
"""[<channelSource>] <channelMode> <channelTarget> <targetMode> [<years>y] [<weeks>w] [<days>d] [<hours>h] [<minutes>m] [<seconds>s] <reason>
copy <channelSource> <channelMode> elements in <channelTarget> on <targetMode>; <-1> or empty means forever"""
op = ircdb.makeChannelCapability(target, 'protected')
op = ircdb.makeChannelCapability(target, 'op')
if not ircdb.checkCapability(msg.prefix, op):
irc.errorNoCapability('%s,op' % target)
irc.errorNoCapability(op)
return
chan = self.getChan(irc, channel)
targets = set([])
@ -2232,8 +2219,10 @@ class ChanTracker(callbacks.Plugin, plugins.ChannelDBHandler):
tell if <nick> is vip in <channel>; mostly used for debugging"""
i = self.getIrc(irc)
if nick in i.nicks:
isVip = self._isVip(irc, channel, self.getNick(irc, nick))
irc.reply(str(isVip))
vip = self._isVip(irc, channel, self.getNick(irc, nick))
if not vip:
vip = 'no vip'
irc.reply('%s is %s' % (nick, vip))
else:
irc.reply('nick not found')
self._tickle(irc)
@ -2323,10 +2312,7 @@ class ChanTracker(callbacks.Plugin, plugins.ChannelDBHandler):
chan = self.getChan(irc, channel)
result = chan.addpattern(msg.prefix, limit, life, mode, getDuration(duration),
pattern, 0, self.getDb(irc.network))
if result:
irc.reply(result)
else:
irc.reply('not enough rights to add a pattern on %s' % channel)
irc.reply(result)
addpattern = wrap(addpattern, ['op', 'nonNegativeInt', 'positiveInt', 'letter',
any('getTs', True), rest('text')])
@ -2338,17 +2324,14 @@ class ChanTracker(callbacks.Plugin, plugins.ChannelDBHandler):
chan = self.getChan(irc, channel)
result = chan.addpattern(msg.prefix, limit, life, mode, getDuration(duration),
pattern[0], 1, self.getDb(irc.network))
if result:
irc.reply(result)
else:
irc.reply('not enough rights to add a pattern on %s' % channel)
irc.reply(result)
self.forceTickle = True
self._tickle(irc)
addregexpattern = wrap(addregexpattern, ['op', 'nonNegativeInt', 'positiveInt', 'letter',
any('getTs', True), rest('getPatternAndMatcher')])
def rmpattern(self, irc, msg, args, channel, ids):
"""[<channel>] <id> [<id>]
"""[<channel>] <id>[,<id>]
remove patterns by <id>"""
results = []
@ -2360,7 +2343,7 @@ class ChanTracker(callbacks.Plugin, plugins.ChannelDBHandler):
if len(results):
irc.reply('%s removed: %s' % (len(results), ','.join(results)))
else:
irc.reply('not found or not enough rights')
irc.reply('nothing found')
self.forceTickle = True
self._tickle(irc)
rmpattern = wrap(rmpattern, ['op', many('positiveInt')])
@ -3916,17 +3899,17 @@ class ChanTracker(callbacks.Plugin, plugins.ChannelDBHandler):
def _isVip(self, irc, channel, n):
if n.prefix == irc.prefix:
return True
return 'me!'
if ircdb.checkCapability(n.prefix, 'trusted'):
return True
return 'trusted'
if ircdb.checkCapability(n.prefix, 'protected'):
return True
return 'protected'
protected = ircdb.makeChannelCapability(channel, 'protected')
if ircdb.checkCapability(n.prefix, protected):
return True
return 'protected'
if self.registryValue('ignoreVoicedUser', channel=channel, network=irc.network) \
and irc.state.channels[channel].isVoicePlus(n.prefix.split('!')[0]):
return True
return 'voiced'
return False
def doPrivmsg(self, irc, msg):