本文整理汇总了Python中supybot.ircdb.makeChannelCapability函数的典型用法代码示例。如果您正苦于以下问题:Python makeChannelCapability函数的具体用法?Python makeChannelCapability怎么用?Python makeChannelCapability使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了makeChannelCapability函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: doMode
def doMode(self, irc, msg):
channel = msg.args[0]
chanOp = ircdb.makeChannelCapability(channel, 'op')
chanVoice = ircdb.makeChannelCapability(channel, 'voice')
chanHalfOp = ircdb.makeChannelCapability(channel, 'halfop')
if not ircdb.checkCapability(msg.prefix, chanOp):
irc.sendMsg(ircmsgs.deop(channel, msg.nick))
for (mode, value) in ircutils.separateModes(msg.args[1:]):
if not value:
continue
if ircutils.strEqual(value, msg.nick):
# We allow someone to mode themselves to oblivion.
continue
if irc.isNick(value):
hostmask = irc.state.nickToHostmask(value)
if mode == '+o':
if not self.isOp(irc, channel, hostmask):
irc.queueMsg(ircmsgs.deop(channel, value))
elif mode == '+h':
if not ircdb.checkCapability(hostmask, chanHalfOp):
irc.queueMsg(ircmsgs.dehalfop(channel, value))
elif mode == '+v':
if not ircdb.checkCapability(hostmask, chanVoice):
irc.queueMsg(ircmsgs.devoice(channel, value))
elif mode == '-o':
if ircdb.checkCapability(hostmask, chanOp):
irc.queueMsg(ircmsgs.op(channel, value))
elif mode == '-h':
if ircdb.checkCapability(hostmask, chanOp):
irc.queueMsg(ircmsgs.halfop(channel, value))
elif mode == '-v':
if ircdb.checkCapability(hostmask, chanOp):
irc.queueMsg(ircmsgs.voice(channel, value))
else:
assert ircutils.isUserHostmask(value)
示例2: do
def do(type):
cap = ircdb.makeChannelCapability(channel, type)
cap_auto = ircdb.makeChannelCapability(channel, "auto" + type)
try:
apply_mode = ircdb.checkCapability(
msg.prefix,
cap,
ignoreOwner=not self.registryValue("owner"),
ignoreChannelOp=True,
ignoreDefaultAllow=True,
)
except KeyError:
apply_mode = False
if self.registryValue("alternativeCapabilities", channel):
try:
override = ircdb.checkCapability(
msg.prefix,
cap_auto,
ignoreOwner=not self.registryValue("owner"),
ignoreChannelOp=True,
ignoreDefaultAllow=True,
)
except KeyError:
override = False
else:
override = False
if apply_mode or override:
if override or self.registryValue(type, channel):
self.log.info("Scheduling auto-%s of %s in %s.", type, msg.prefix, channel)
def dismiss():
"""Determines whether or not a mode has already
been applied."""
l = getattr(irc.state.channels[channel], type + "s")
return msg.nick in l
msgmaker = getattr(ircmsgs, type)
schedule_msg(msgmaker(channel, msg.nick), dismiss)
raise Continue # Even if fallthrough, let's only do one.
elif not fallthrough:
self.log.debug(
"%s has %s, but supybot.plugins.AutoMode.%s"
" is not enabled in %s, refusing to fall "
"through.",
msg.prefix,
cap,
type,
channel,
)
raise Continue
示例3: part
def part(self, irc, msg, args, channel, reason):
"""[<channel>] [<reason>]
Tells the bot to part the list of channels you give it. <channel> is
only necessary if you want the bot to part a channel other than the
current channel. If <reason> is specified, use it as the part
message. Otherwise, the default part message specified in
supybot.plugins.Channel.partMsg will be used. No part message will be
used if no default is configured.
"""
if channel is None:
if irc.isChannel(msg.args[0]):
channel = msg.args[0]
else:
irc.error(Raise=True)
capability = ircdb.makeChannelCapability(channel, 'op')
hostmask = irc.state.nickToHostmask(msg.nick)
if not ircdb.checkCapabilities(hostmask, [capability, 'admin']):
irc.errorNoCapability(capability, Raise=True)
try:
network = conf.supybot.networks.get(irc.network)
network.channels().remove(channel)
except KeyError:
pass
if channel not in irc.state.channels:
irc.error(_('I\'m not in %s.') % channel, Raise=True)
reason = (reason or self.registryValue("partMsg", channel))
reason = ircutils.standardSubstitute(irc, msg, reason)
irc.queueMsg(ircmsgs.part(channel, reason))
if msg.nick in irc.state.channels[channel].users:
irc.noReply()
else:
irc.replySuccess()
示例4: checkChangeAllowed
def checkChangeAllowed(self, irc, msg, channel, user, record):
if user.id == record.by:
return True
cap = ircdb.makeChannelCapability(channel, 'op')
if ircdb.checkCapability(msg.prefix, cap):
return True
irc.errorNoCapability(cap)
示例5: inFilter
def inFilter(self, irc, msg):
self.filtering = True
# We need to check for bad words here rather than in doPrivmsg because
# messages don't get to doPrivmsg if the user is ignored.
if msg.command == 'PRIVMSG':
channel = msg.args[0]
self.updateRegexp(channel)
s = ircutils.stripFormatting(msg.args[1])
if ircutils.isChannel(channel) and self.registryValue('kick', channel):
if self.words and self.regexp.search(s):
c = irc.state.channels[channel]
cap = ircdb.makeChannelCapability(channel, 'op')
if c.isHalfopPlus(irc.nick):
if c.isHalfopPlus(msg.nick) or \
ircdb.checkCapability(msg.prefix, cap):
self.log.debug("Not kicking %s from %s, because "
"they are halfop+ or can't be "
"kicked.", msg.nick, channel)
else:
message = self.registryValue('kick.message', channel)
irc.queueMsg(ircmsgs.kick(channel, msg.nick, message))
else:
self.log.warning('Should kick %s from %s, but not opped.',
msg.nick, channel)
return msg
示例6: checkChannelCapability
def checkChannelCapability(irc, msg, args, state, cap):
if not state.channel:
getChannel(irc, msg, args, state)
cap = ircdb.canonicalCapability(cap)
cap = ircdb.makeChannelCapability(state.channel, cap)
if not ircdb.checkCapability(msg.prefix, cap):
state.errorNoCapability(cap, Raise=True)
示例7: nicks
def nicks(self, irc, msg, args, channel, optlist):
"""[<channel>] [--count]
Returns the nicks in <channel>. <channel> is only necessary if the
message isn't sent in the channel itself. Returns only the number of
nicks if --count option is provided.
"""
# Make sure we don't elicit information about private channels to
# people or channels that shouldn't know
capability = ircdb.makeChannelCapability(channel, 'op')
hostmask = irc.state.nickToHostmask(msg.nick)
if 's' in irc.state.channels[channel].modes and \
msg.args[0] != channel and \
not ircdb.checkCapability(hostmask, capability) and \
(ircutils.isChannel(msg.args[0]) or \
msg.nick not in irc.state.channels[channel].users):
irc.error(_('You don\'t have access to that information.'),
Raise=True)
L = list(irc.state.channels[channel].users)
keys = [option for (option, arg) in optlist]
if 'count' not in keys:
utils.sortBy(str.lower, L)
private = self.registryValue("nicksInPrivate", channel)
irc.reply(utils.str.commaAndify(L), private=private)
else:
irc.reply(str(len(L)))
示例8: doPrivmsg
def doPrivmsg(self, irc, msg):
(recipients, text) = msg.args
for channel in recipients.split(','):
if irc.isChannel(channel):
noLogPrefix = self.registryValue('noLogPrefix', channel)
cap = ircdb.makeChannelCapability(channel, 'logChannelMessages')
try:
logChannelMessages = ircdb.checkCapability(msg.prefix, cap,
ignoreOwner=True)
except KeyError:
logChannelMessages = True
nick = msg.nick or irc.nick
if msg.tagged('LogsToDB__relayed'):
(nick, text) = text.split(' ', 1)
nick = nick[1:-1]
msg.args = (recipients, text)
if (noLogPrefix and text.startswith(noLogPrefix)) or \
not logChannelMessages:
text = '-= THIS MESSAGE NOT LOGGED =-'
if ircmsgs.isAction(msg):
self.doLog(irc, channel,
'* %s %s\n', nick, ircmsgs.unAction(msg))
else:
self.doLog(irc, channel, '<%s> %s\n', nick, text)
message = msg.args[1]
self.logViewerDB.add_message(msg.nick, msg.prefix, message, channel)
self.logViewerFile.write_message(msg.nick, message)
示例9: voice
def voice(self, irc, msg, args, channel, nicks):
"""[<channel>] [<nick> ...]
If you have the #channel,voice capability, this will voice all the
<nick>s you provide. If you don't provide any <nick>s, this will
voice you. <channel> is only necessary if the message isn't sent in the
channel itself.
"""
if nicks:
if len(nicks) == 1 and msg.nick in nicks:
capability = "voice"
else:
capability = "op"
else:
nicks = [msg.nick]
capability = "voice"
capability = ircdb.makeChannelCapability(channel, capability)
if ircdb.checkCapability(msg.prefix, capability):
def f(L):
return ircmsgs.voices(channel, L)
self._sendMsgs(irc, nicks, f)
else:
irc.errorNoCapability(capability)
示例10: checkAndAct
def checkAndAct (self,irc,prefix,chan,kind,items,text,msg):
protected = ircdb.makeChannelCapability(chan.name, 'protected')
if ircdb.checkCapability(prefix, protected):
return
for pattern in list(items.keys()):
item = chan.kinds[kind][pattern]
if item.enable == '1':
for match in re.finditer(item.re, text):
if match:
act = item.action
account = ''
gecos = ''
if prefix.split('!')[0] in chan.nicks:
(prefix,account,gecos) = chan.nicks[prefix.split('!')[0]]
act = act.replace('$nick',prefix.split('!')[0])
act = act.replace('$hostmask',prefix)
act = act.replace('$account',account)
act = act.replace('$username',gecos)
act = act.replace('$id',str(item.uid))
act = act.replace('$channel',chan.name)
act = act.replace('$*',text)
if act.find(' :') != -1:
a = text.split(' :')
if len(a) > 1:
act = act.replace('$text',text.split(' :')[1])
for (i, j) in enumerate(match.groups()):
act = re.sub(r'\$' + str(i+1), match.group(i+1), act)
self.act(irc,msg,chan.name,act,item.owner)
break
示例11: newpoll
def newpoll(self, irc, msg, args, channel, interval, answers, question):
"""<number of minutes for announce interval> <"answer,answer,..."> question
Creates a new poll with the given question and answers. <channel> is
only necessary if the message isn't sent in the channel itself."""
capability = ircdb.makeChannelCapability(channel, 'op')
if not ircdb.checkCapability(msg.prefix, capability):
irc.error('Need ops')
return
db = self.getDb(channel)
cursor = db.cursor()
self._execute_query(cursor, 'INSERT INTO polls VALUES (?,?,?,?,?)', None, datetime.datetime.now(), 1, None, question)
pollid = cursor.lastrowid
# used to add choices into db. each choice represented by character, starting at capital A (code 65)
def genAnswers():
for i, answer in enumerate(answers, start=65):
yield pollid, chr(i), answer
cursor.executemany('INSERT INTO choices VALUES (?,?,?)', genAnswers())
db.commit()
irc.reply('Started new poll #%s' % pollid)
# function called by schedule event. can not have args
def runPoll():
self._runPoll(irc, channel, pollid)
# start schedule. will announce poll/choices to channel at interval
schedule.addPeriodicEvent(runPoll, interval*60, name='%s_poll_%s' % (channel, pollid))
self.poll_schedules.append('%s_poll_%s' % (channel, pollid))
示例12: _checkManageCapabilities
def _checkManageCapabilities(self, irc, msg, channel):
"""Check if the user has any of the required capabilities to manage
the channel topic.
The list of required capabilities is in requireManageCapability
channel config.
Also allow if the user is a chanop. Since they can change the topic
manually anyway.
"""
c = irc.state.channels[channel]
if msg.nick in c.ops or msg.nick in c.halfops or 't' not in c.modes:
return True
capabilities = self.registryValue('requireManageCapability', channel)
if capabilities:
for capability in re.split(r'\s*;\s*', capabilities):
if capability.startswith('channel,'):
capability = ircdb.makeChannelCapability(
channel, capability[8:])
if capability and ircdb.checkCapability(msg.prefix, capability):
return
capabilities = self.registryValue('requireManageCapability',
channel)
irc.errorNoCapability(capabilities, Raise=True)
else:
return
示例13: learn
def learn(self, irc, msg, args, channel, key, factoid):
db = self.getDb(channel)
cursor = db.cursor()
cursor.execute("SELECT id, locked FROM keys WHERE key LIKE %s", key)
if cursor.rowcount == 0:
cursor.execute("""INSERT INTO keys VALUES (NULL, %s, 0)""", key)
db.commit()
cursor.execute("SELECT id, locked FROM keys WHERE key LIKE %s", key)
(id, locked) = map(int, cursor.fetchone())
capability = ircdb.makeChannelCapability(channel, "factoids")
if not locked:
if ircdb.users.hasUser(msg.prefix):
name = ircdb.users.getUser(msg.prefix).name
else:
name = msg.nick
cursor.execute(
"""INSERT INTO factoids VALUES
(NULL, %s, %s, %s, %s)""",
id,
name,
int(time.time()),
factoid,
)
db.commit()
irc.replySuccess()
else:
irc.error("That factoid is locked.")
示例14: setUp
def setUp(self):
ChannelPluginTestCase.setUp(self)
self.prefix = "[email protected]"
self.nick = "foo"
self.irc.feedMsg(ircmsgs.privmsg(self.irc.nick, "register foo bar", prefix=self.prefix))
_ = self.irc.takeMsg()
chanop = ircdb.makeChannelCapability(self.channel, "op")
ircdb.users.getUser(self.nick).addCapability(chanop)
示例15: _kban
def _kban(self, irc, msg, args, bannedNick, reason):
# Check that they're not trying to make us kickban ourself.
channel = msg.args[0]
if not irc.isNick(bannedNick[0]):
self.log.warning('%q tried to kban a non nick: %q',
msg.prefix, bannedNick)
raise callbacks.ArgumentError
elif bannedNick == irc.nick:
self.log.warning('%q tried to make me kban myself.', msg.prefix)
irc.error('I cowardly refuse to kickban myself.')
return
if not reason:
reason = msg.nick
try:
bannedHostmask = irc.state.nickToHostmask(bannedNick)
except KeyError:
irc.error(format('I haven\'t seen %s.', bannedNick), Raise=True)
capability = ircdb.makeChannelCapability(channel, 'op')
banmaskstyle = conf.supybot.protocols.irc.banmask
banmask = banmaskstyle.makeBanmask(bannedHostmask, ["host", "user"])
# Check (again) that they're not trying to make us kickban ourself.
if ircutils.hostmaskPatternEqual(banmask, irc.prefix):
if ircutils.hostmaskPatternEqual(bannedHostmask, irc.prefix):
self.log.warning('%q tried to make me kban myself.',msg.prefix)
irc.error('I cowardly refuse to ban myself.')
return
else:
self.log.warning('Using exact hostmask since banmask would '
'ban myself.')
banmask = bannedHostmask
# Now, let's actually get to it. Check to make sure they have
# #channel,op and the bannee doesn't have #channel,op; or that the
# bannee and the banner are both the same person.
def doBan():
if irc.state.channels[channel].isOp(bannedNick):
irc.queueMsg(ircmsgs.deop(channel, bannedNick))
irc.queueMsg(ircmsgs.ban(channel, banmask))
irc.queueMsg(ircmsgs.kick(channel, bannedNick, reason))
def f():
if channel in irc.state.channels and \
banmask in irc.state.channels[channel].bans:
irc.queueMsg(ircmsgs.unban(channel, banmask))
schedule.addEvent(f, 3600)
if bannedNick == msg.nick:
doBan()
elif ircdb.checkCapability(msg.prefix, capability):
if ircdb.checkCapability(bannedHostmask, capability):
self.log.warning('%s tried to ban %q, but both have %s',
msg.prefix, bannedHostmask, capability)
irc.error(format('%s has %s too, you can\'t ban him/her/it.',
bannedNick, capability))
else:
doBan()
else:
self.log.warning('%q attempted kban without %s',
msg.prefix, capability)
irc.errorNoCapability(capability)
exact,nick,user,host