From 0ff2476e87091fe9aa3155d3ba0b099c9b280852 Mon Sep 17 00:00:00 2001 From: Krytarik Raido Date: Thu, 13 Oct 2022 19:34:04 +0200 Subject: [PATCH] Make 'isvip' output differentiate between types. Also drop capability checks off functions where they are already done at command level. --- README.md | 14 +++++++------- plugin.py | 53 ++++++++++++++++++----------------------------------- 2 files changed, 25 insertions(+), 42 deletions(-) diff --git a/README.md b/README.md index e2241cd..daf2162 100644 --- a/README.md +++ b/README.md @@ -28,11 +28,11 @@ Then `@load ChanTracker`. @b,e,i,q [] [,] [y] [w] [d] [h] [m] [s] [<-1> or empty means forever] ) -- +mode targets for duration is mandatory @ub,ue,ui,uq [] []) -- sets -mode on them, if * found, remove them all @check [] returns list of users who will be affected by such pattern - @edit [,] [y] [w] [d] [h] [m] [s] [<-1>] means forever) -- change expiration of some active modes + @edit [,] [y] [w] [d] [h] [m] [s] [<-1>] means forever) -- change expiration of some active modes @info returns information about a mode change @affect returns affected users by a mode placed - @mark [,] add a comment about a mode change - @editandmark [,] [,] [y] [w] [d] [h] [m] [s] [<-1>] [] edit duration and add comment on a mode change + @mark [,] add a comment about a mode change + @editandmark [,] [y] [w] [d] [h] [m] [s] [<-1>] [] edit duration and add comment on a mode change @pending [] (pending [--mode=] [--oper=] [--never] [] ) -- returns active items for --mode if given, filtered by --oper if given, --never never expire only if given @query [--deep] [--never] [--active] [--channel=] ) -- 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 [] returns list of modes that affects the nick,hostmask given @@ -42,7 +42,7 @@ Then `@load ChanTracker`. @summary [] returns some stats about @addpattern [] (qbeId) [y] [w] [d] [h] [m] [s] ) add a which triggers for if the appears more than (0 for immediate action) during in seconds @addregexpattern [] (qbeId) [y] [w] [d] [h] [m] [s] //) add a which triggers for if the appears more than (0 for immediate action) during in seconds - @rmpattern [] [] remove patterns + @rmpattern [] [,] remove patterns @lspattern [] [] return patterns in filtered by optional or @addtmp [] add temporary pattern which follows repeat punishments @rmtmp [] 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 + @defaultcapability remove 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 User.whoami @admin capability add whoami -If your bot manages different channels or communities, remove all `User.` from `defaultcapabilities`, +If your bot manages different channels or communities, remove all `User.` 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. diff --git a/plugin.py b/plugin.py index 4e0984d..1c92af4 100644 --- a/plugin.py +++ b/plugin.py @@ -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): """[] [y] [w] [d] [h] [m] [s] copy elements in on ; <-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 is vip in ; 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): - """[] [] + """[] [,] remove patterns by """ 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):