本文整理汇总了Python中sopel.tools.Identifier.is_nick方法的典型用法代码示例。如果您正苦于以下问题:Python Identifier.is_nick方法的具体用法?Python Identifier.is_nick怎么用?Python Identifier.is_nick使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sopel.tools.Identifier
的用法示例。
在下文中一共展示了Identifier.is_nick方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_nick_or_channel_value
# 需要导入模块: from sopel.tools import Identifier [as 别名]
# 或者: from sopel.tools.Identifier import is_nick [as 别名]
def get_nick_or_channel_value(self, name, key):
"""Gets the value `key` associated to the nick or channel `name`."""
name = Identifier(name)
if name.is_nick():
return self.get_nick_value(name, key)
else:
return self.get_channel_value(name, key)
示例2: kickban
# 需要导入模块: from sopel.tools import Identifier [as 别名]
# 或者: from sopel.tools.Identifier import is_nick [as 别名]
def kickban(bot, trigger):
"""
This gives admins the ability to kickban a user.
The bot must be a Channel Operator for this command to work.
.kickban [#chan] user1 user!*@* get out of here
"""
if bot.privileges[trigger.sender][bot.nick] < HALFOP:
return bot.reply("I'm not a channel operator!")
text = trigger.group().split()
argc = len(text)
if argc < 4:
return
opt = Identifier(text[1])
nick = opt
mask = text[2]
channel = trigger.sender
reasonidx = 3
if not opt.is_nick():
if argc < 5:
return
channel = opt
nick = text[2]
mask = text[3]
reasonidx = 4
reason = ' '.join(text[reasonidx:])
mask = configureHostMask(mask)
if mask == '':
return
bot.write(['MODE', channel, '+b', mask])
bot.write(['KICK', channel, nick], reason)
示例3: track_modes
# 需要导入模块: from sopel.tools import Identifier [as 别名]
# 或者: from sopel.tools.Identifier import is_nick [as 别名]
def track_modes(bot, trigger):
"""Track usermode changes and keep our lists of ops up to date."""
# Mode message format: <channel> *( ( "-" / "+" ) *<modes> *<modeparams> )
channel = Identifier(trigger.args[0])
line = trigger.args[1:]
# If the first character of where the mode is being set isn't a #
# then it's a user mode, not a channel mode, so we'll ignore it.
if channel.is_nick():
return
mapping = {'v': sopel.module.VOICE,
'h': sopel.module.HALFOP,
'o': sopel.module.OP,
'a': sopel.module.ADMIN,
'q': sopel.module.OWNER}
modes = []
for arg in line:
if len(arg) == 0:
continue
if arg[0] in '+-':
# There was a comment claiming IRC allows e.g. MODE +aB-c foo, but
# I don't see it in any RFCs. Leaving in the extra parsing for now.
sign = ''
modes = []
for char in arg:
if char == '+' or char == '-':
sign = char
else:
modes.append(sign + char)
else:
arg = Identifier(arg)
for mode in modes:
priv = bot.channels[channel].privileges.get(arg, 0)
# Log a warning if the two privilege-tracking data structures
# get out of sync. That should never happen.
# This is a good place to verify that bot.channels is doing
# what it's supposed to do before ultimately removing the old,
# deprecated bot.privileges structure completely.
ppriv = bot.privileges[channel].get(arg, 0)
if priv != ppriv:
LOGGER.warning("Privilege data error! Please share Sopel's"
"raw log with the developers, if enabled. "
"(Expected {} == {} for {} in {}.)"
.format(priv, ppriv, arg, channel))
value = mapping.get(mode[1])
if value is not None:
if mode[0] == '+':
priv = priv | value
else:
priv = priv & ~value
bot.privileges[channel][arg] = priv
bot.channels[channel].privileges[arg] = priv
示例4: votemode
# 需要导入模块: from sopel.tools import Identifier [as 别名]
# 或者: from sopel.tools.Identifier import is_nick [as 别名]
def votemode(bot, trigger, mode):
make_user_active(bot, trigger)
channel = trigger.sender
account = trigger.account
if account is None:
bot.say("You must be authed to use this command")
return
if bot.privileges[trigger.sender][bot.nick] < OP:
return bot.reply("I'm not a channel operator!")
quota = calculate_quota(bot, trigger, bot.memory['mode_threshold'][mode])
# This isn't per user but it's probably an OK heuristic
if datetime.now() - bot.memory['last_vote'] > timedelta(minutes=5):
clear_votes(bot)
# Quota is 50% of active users plus one
if trigger.group(2):
target = Identifier(str(trigger.group(2)).split()[0].strip().lower())
if not target.is_nick():
return bot.reply("That is not a valid nick")
if target not in bot.privileges[channel]:
return bot.reply("I don't see %s." % target)
target_privs = bot.privileges[channel][target]
if target_privs > 0:
return bot.reply("You cannot vote" + mode + " privileged users")
if target in bot.memory['votes'][mode]:
if str(account) not in bot.memory['votes'][mode][target]:
bot.memory['votes'][mode][target].append(str(account))
else:
bot.memory['votes'][mode][target] = [str(account)]
bot.reply("Vote recorded. (%s more votes for action)" % str(max(0, quota - len(bot.memory['votes'][mode][target])+1)))
if len(bot.memory['votes'][mode][target]) > quota:
bot.memory['vote_methods'][mode](bot, channel, target)
bot.memory['last_vote'] = datetime.now()
elif mode == "registered" or mode == "moderated":
if str(account) not in bot.memory['votes'][mode]:
bot.memory['votes'][mode].append(str(account))
else:
bot.memory['votes'][mode] = [str(account)]
bot.reply("Vote recorded. (%s more votes for action)" % str(max(0, quota - len(bot.memory['votes'][mode])+1)))
if len(bot.memory['votes'][mode]) > quota:
bot.memory['vote_methods'][mode](bot, channel)
bot.memory['last_vote'] = datetime.now()
else:
bot.say("Current active vote%s (%s needed to %s): " % (mode, str(quota + 1), mode))
for ballot in bot.memory['votes'][mode]:
bot.say("%s has %s %s votes." % (ballot, len(bot.memory['votes'][mode][ballot]), mode))
return
示例5: write_log
# 需要导入模块: from sopel.tools import Identifier [as 别名]
# 或者: from sopel.tools.Identifier import is_nick [as 别名]
def write_log(bot, event, channel):
if bot.config.chanlogs2.allow_toggle:
if not bot.db.get_channel_value(channel, 'logging'):
return
if not isinstance(channel, Identifier):
channel = Identifier(channel)
if channel.is_nick() and not bot.config.chanlogs2.privmsg:
return # Don't log if we are configured not to log PMs
if bot.config.chanlogs2.backend == 'postgres':
write_db_line(bot, event, channel)
else:
write_log_line(bot, event, channel)
示例6: track_modes
# 需要导入模块: from sopel.tools import Identifier [as 别名]
# 或者: from sopel.tools.Identifier import is_nick [as 别名]
def track_modes(bot, trigger):
"""Track usermode changes and keep our lists of ops up to date."""
# Mode message format: <channel> *( ( "-" / "+" ) *<modes> *<modeparams> )
channel = Identifier(trigger.args[0])
line = trigger.args[1:]
# If the first character of where the mode is being set isn't a #
# then it's a user mode, not a channel mode, so we'll ignore it.
if channel.is_nick():
return
mapping = {
"v": sopel.module.VOICE,
"h": sopel.module.HALFOP,
"o": sopel.module.OP,
"a": sopel.module.ADMIN,
"q": sopel.module.OWNER,
}
modes = []
for arg in line:
if len(arg) == 0:
continue
if arg[0] in "+-":
# There was a comment claiming IRC allows e.g. MODE +aB-c foo, but
# I don't see it in any RFCs. Leaving in the extra parsing for now.
sign = ""
modes = []
for char in arg:
if char == "+" or char == "-":
sign = char
else:
modes.append(sign + char)
else:
arg = Identifier(arg)
for mode in modes:
priv = bot.privileges[channel].get(arg, 0)
value = mapping.get(mode[1])
if value is not None:
if mode[0] == "+":
priv = priv | value
else:
priv = priv & ~value
bot.privileges[channel][arg] = priv
示例7: kick
# 需要导入模块: from sopel.tools import Identifier [as 别名]
# 或者: from sopel.tools.Identifier import is_nick [as 别名]
def kick(bot, trigger):
"""
Kick a user from the channel.
"""
if bot.privileges[trigger.sender][bot.nick] < HALFOP:
return bot.reply("I'm not a channel operator!")
text = trigger.group().split()
argc = len(text)
if argc < 2:
return
opt = Identifier(text[1])
nick = opt
channel = trigger.sender
reasonidx = 2
if not opt.is_nick():
if argc < 3:
return
nick = text[2]
channel = opt
reasonidx = 3
reason = ' '.join(text[reasonidx:])
if nick != bot.config.core.nick:
bot.write(['KICK', channel, nick], reason)
示例8: unquiet
# 需要导入模块: from sopel.tools import Identifier [as 别名]
# 或者: from sopel.tools.Identifier import is_nick [as 别名]
def unquiet(bot, trigger):
"""
This gives admins the ability to unquiet a user.
The bot must be a Channel Operator for this command to work.
"""
if bot.privileges[trigger.sender][bot.nick] < OP:
return bot.reply("I'm not a channel operator!")
text = trigger.group().split()
argc = len(text)
if argc < 2:
return
opt = Identifier(text[1])
quietmask = opt
channel = trigger.sender
if not opt.is_nick():
if argc < 3:
return
quietmask = text[2]
channel = opt
quietmask = configureHostMask(quietmask)
if quietmask == '':
return
bot.write(['MODE', channel, '-q', quietmask])
示例9: track_modes
# 需要导入模块: from sopel.tools import Identifier [as 别名]
# 或者: from sopel.tools.Identifier import is_nick [as 别名]
def track_modes(bot, trigger):
"""Track usermode changes and keep our lists of ops up to date."""
# Mode message format: <channel> *( ( "-" / "+" ) *<modes> *<modeparams> )
if len(trigger.args) < 3:
# We need at least [channel, mode, nickname] to do anything useful
# MODE messages with fewer args won't help us
LOGGER.info("Received an apparently useless MODE message: {}"
.format(trigger.raw))
return
# Our old MODE parsing code checked if any of the args was empty.
# Somewhere around here would be a good place to re-implement that if it's
# actually necessary to guard against some non-compliant IRCd. But for now
# let's just log malformed lines to the debug log.
if not all(trigger.args):
LOGGER.debug("The server sent a possibly malformed MODE message: {}"
.format(trigger.raw))
# From here on, we will make a (possibly dangerous) assumption that the
# received MODE message is more-or-less compliant
channel = Identifier(trigger.args[0])
# If the first character of where the mode is being set isn't a #
# then it's a user mode, not a channel mode, so we'll ignore it.
# TODO: Handle CHANTYPES from ISUPPORT numeric (005)
# (Actually, most of this function should be rewritten again when we parse
# ISUPPORT...)
if channel.is_nick():
return
modestring = trigger.args[1]
nicks = [Identifier(nick) for nick in trigger.args[2:]]
mapping = {'v': sopel.module.VOICE,
'h': sopel.module.HALFOP,
'o': sopel.module.OP,
'a': sopel.module.ADMIN,
'q': sopel.module.OWNER}
# Parse modes before doing anything else
modes = []
sign = ''
for char in modestring:
# There was a comment claiming IRC allows e.g. MODE +aB-c foo, but it
# doesn't seem to appear in any RFCs. But modern.ircdocs.horse shows
# it, so we'll leave in the extra parsing for now.
if char in '+-':
sign = char
elif char in mapping:
# Filter out unexpected modes and hope they don't have parameters
modes.append(sign + char)
# Try to map modes to arguments, after sanity-checking
if len(modes) != len(nicks) or not all([nick.is_nick() for nick in nicks]):
# Something fucky happening, like unusual batching of non-privilege
# modes together with the ones we expect. Way easier to just re-WHO
# than try to account for non-standard parameter-taking modes.
_send_who(bot, channel)
return
pairs = dict(zip(modes, nicks))
for (mode, nick) in pairs.items():
priv = bot.channels[channel].privileges.get(nick, 0)
# Log a warning if the two privilege-tracking data structures
# get out of sync. That should never happen.
# This is a good place to verify that bot.channels is doing
# what it's supposed to do before ultimately removing the old,
# deprecated bot.privileges structure completely.
ppriv = bot.privileges[channel].get(nick, 0)
if priv != ppriv:
LOGGER.warning("Privilege data error! Please share Sopel's"
"raw log with the developers, if enabled. "
"(Expected {} == {} for {} in {}.)"
.format(priv, ppriv, nick, channel))
value = mapping.get(mode[1])
if value is not None:
if mode[0] == '+':
priv = priv | value
else:
priv = priv & ~value
bot.privileges[channel][nick] = priv
bot.channels[channel].privileges[nick] = priv