当前位置: 首页>>代码示例>>Python>>正文


Python Identifier.lower方法代码示例

本文整理汇总了Python中sopel.tools.Identifier.lower方法的典型用法代码示例。如果您正苦于以下问题:Python Identifier.lower方法的具体用法?Python Identifier.lower怎么用?Python Identifier.lower使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在sopel.tools.Identifier的用法示例。


在下文中一共展示了Identifier.lower方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: cutwire

# 需要导入模块: from sopel.tools import Identifier [as 别名]
# 或者: from sopel.tools.Identifier import lower [as 别名]
def cutwire(bot, trigger):
    """
    Tells sopel to cut a wire when you've been bombed.
    """
    global bombs, colors
    target = Identifier(trigger.nick)
    if target.lower() != bot.nick.lower() and target.lower() not in bombs:
        bot.say('You can\'t cut a wire till someone bombs you')
        return
    if not trigger.group(2):
        bot.say('You have to choose a wire to cut.')
        return
    color, code = bombs.pop(target.lower())  # remove target from bomb list
    wirecut = trigger.group(2).rstrip(' ')
    if wirecut.lower() in ('all', 'all!'):
        sch.cancel(code)  # defuse timer, execute premature detonation
        kmsg = ('KICK %s %s : Cutting ALL the wires! *boom* (You should\'ve picked the %s wire.)'
                % (trigger.sender, target, color))
        bot.write([kmsg])
    elif wirecut.capitalize() not in colors:
        bot.say('I can\'t seem to find that wire, ' + target + '! You sure you\'re picking the right one? It\'s not here!')
        bombs[target.lower()] = (color, code)  # Add the target back onto the bomb list,
    elif wirecut.capitalize() == color:
        bot.say('You did it, ' + target + '! I\'ll be honest, I thought you were dead. But nope, you did it. You picked the right one. Well done.')
        sch.cancel(code)  # defuse bomb
    else:
        sch.cancel(code)  # defuse timer, execute premature detonation
        kmsg = 'KICK ' + trigger.sender + ' ' + target + \
               ' : No! No, that\'s the wrong one. Aww, you\'ve gone and killed yourself. Oh, that\'s... that\'s not good. No good at all, really. Wow. Sorry. (You should\'ve picked the ' + color + ' wire.)'
        bot.write([kmsg])
开发者ID:johnlage,项目名称:BombBot,代码行数:32,代码来源:bomb.py

示例2: start

# 需要导入模块: from sopel.tools import Identifier [as 别名]
# 或者: from sopel.tools.Identifier import lower [as 别名]
def start(bot, trigger):
    """
    Put a bomb in the specified user's pants. They will be kicked if they
     don't guess the right wire fast enough.
    """
    if not trigger.group(3):
        bot.say('Who do you want to Bomb?')
        return
    if not trigger.sender.startswith('#'):
        bot.say('Tell me this in a channel')
        return
    global bombs
    global sch
    target = Identifier(trigger.group(3))
    if target == bot.nick:
        bot.say('I will NOT BOMB MYSELF!')
        return
    if target.lower() in bombs:
        bot.say('I can\'t fit another bomb in ' + target + '\'s pants!')
        return
    if target == trigger.nick:
        bot.say('I will not LET YOU BOMB YOURSELF!')
        return
    if target.lower() not in bot.privileges[trigger.sender.lower()]:
        bot.say('Please Bomb someone WHO IS HERE!')
        return
    message = 'Hey, ' + target + '! Don\'t look but, I think there\'s a bomb in your pants. 2 minute timer, 5 wires: Red, Yellow, Blue, White and Black. Which wire should I cut? Don\'t worry, I know what I\'m doing! (respond with .cutwire color)'
    bot.say(message)
    color = choice(colors)
    bot.msg(trigger.nick,
               "Hey, don\'t tell %s, but the %s wire? Yeah, that\'s the one."
               " But shh! Don\'t say anything!" % (target, color))
    code = sch.enter(fuse, 1, explode, (bot, trigger))
    bombs[target.lower()] = (color, code)
    sch.run()
开发者ID:johnlage,项目名称:BombBot,代码行数:37,代码来源:bomb.py

示例3: cancel_bomb

# 需要导入模块: from sopel.tools import Identifier [as 别名]
# 或者: from sopel.tools.Identifier import lower [as 别名]
def cancel_bomb(bot, trigger):
    """
    Lets a bomber disarm the bomb they set on the specified user. Does not reset the cooldown timer.
    (Bot admins can cancel bombs on any player in the channel.)
    """
    target = trigger.group(3) or None
    if not target:
        for bomb in BOMBS:
            if trigger.nick == BOMBS[bomb]['bomber']:
                target = BOMBS[bomb]['target']
                break
        if not target:
            return bot.reply(STRINGS['CANCEL_WHOM'])
    target = Identifier(target)  # issue #24
    with lock:
        if target.lower() not in BOMBS:
            bot.reply(STRINGS['CANCEL_NO_BOMB'] % target)
            return
        if trigger.nick != BOMBS[target.lower()]['bomber'] and not trigger.admin:
            bot.reply(STRINGS['CANCEL_NO_PERMISSION'] % target)
            return
        bomber = BOMBS[target.lower()]['bomber']
        bombs_planted = bot.db.get_nick_value(bomber, 'bombs_planted') or 0
        bot.db.set_nick_value(bomber, 'bombs_planted', bombs_planted - 1)
        BOMBS.pop(target.lower())['timer'].cancel()
        bot.say(STRINGS['CANCEL_DONE'] % target)
开发者ID:dgw,项目名称:sopel-BombBot,代码行数:28,代码来源:bombbot.py

示例4: explode

# 需要导入模块: from sopel.tools import Identifier [as 别名]
# 或者: from sopel.tools.Identifier import lower [as 别名]
def explode(bot, trigger):
    target = Identifier(trigger.group(3))
    orig_target = target
    with lock:
        if target.lower() not in BOMBS:  # nick change happened
            for nick in BOMBS.keys():
                if BOMBS[nick]['target'] == target:
                    target = Identifier(nick)
                    break
        bot.say(STRINGS['NEVER_TRIED'] % (target, BOMBS[target.lower()]['color']))
        kickboom(bot, trigger, target)
        BOMBS.pop(target.lower())
    timeouts = bot.db.get_nick_value(orig_target, 'bomb_timeouts') or 0
    bot.db.set_nick_value(orig_target, 'bomb_timeouts', timeouts + 1)
开发者ID:piagetbot,项目名称:sopel,代码行数:16,代码来源:bombbot.py

示例5: bomb_glue

# 需要导入模块: from sopel.tools import Identifier [as 别名]
# 或者: from sopel.tools.Identifier import lower [as 别名]
def bomb_glue(bot, trigger):
    old = trigger.nick
    new = Identifier(trigger)
    with lock:
        if old.lower() in BOMBS:
            BOMBS[new.lower()] = BOMBS.pop(old.lower())
            bot.notice(STRINGS['BOMB_STILL'] % new, new)
开发者ID:piagetbot,项目名称:sopel,代码行数:9,代码来源:bombbot.py

示例6: get_nick_value

# 需要导入模块: from sopel.tools import Identifier [as 别名]
# 或者: from sopel.tools.Identifier import lower [as 别名]
 def get_nick_value(self, nick, key):
     """Retrieves the value for a given key associated with a nick."""
     nick = Identifier(nick)
     result = self.execute(
         'SELECT value FROM nicknames JOIN nick_values '
         'ON nicknames.nick_id = nick_values.nick_id '
         'WHERE slug = ? AND key = ?',
         [nick.lower(), key]
     ).fetchone()
     if result is not None:
         result = result[0]
     return _deserialize(result)
开发者ID:daniellawrence,项目名称:sopel,代码行数:14,代码来源:db.py

示例7: cancel_bomb

# 需要导入模块: from sopel.tools import Identifier [as 别名]
# 或者: from sopel.tools.Identifier import lower [as 别名]
def cancel_bomb(bot, trigger):
    """
    Cancel the bomb placed on the specified player (can also be used by admins).
    """
    target = trigger.group(3) or None
    if not target:
        bot.reply(STRINGS['CANCEL_WHOM'])
        return
    target = Identifier(target)  # issue #24
    with lock:
        if target.lower() not in BOMBS:
            bot.reply(STRINGS['CANCEL_NO_BOMB'] % target)
            return
        if trigger.nick != BOMBS[target.lower()]['bomber'] and not trigger.admin:
            bot.reply(STRINGS['CANCEL_NO_PERMISSION'] % target)
            return
        bomber = BOMBS[target.lower()]['bomber']
        bombs_planted = bot.db.get_nick_value(bomber, 'bombs_planted') or 0
        bot.db.set_nick_value(bomber, 'bombs_planted', bombs_planted - 1)
        BOMBS.pop(target.lower())['timer'].cancel()
        bot.say(STRINGS['CANCEL_DONE'] % target)
开发者ID:piagetbot,项目名称:sopel,代码行数:23,代码来源:bombbot.py

示例8: unalias_nick

# 需要导入模块: from sopel.tools import Identifier [as 别名]
# 或者: from sopel.tools.Identifier import lower [as 别名]
    def unalias_nick(self, alias):
        """Removes an alias.

        Raises ValueError if there is not at least one other nick in the group.
        To delete an entire group, use `delete_group`.
        """
        alias = Identifier(alias)
        nick_id = self.get_nick_id(alias, False)
        count = self.execute('SELECT COUNT(*) FROM nicknames WHERE nick_id = ?',
                             [nick_id]).fetchone()[0]
        if count == 0:
            raise ValueError('Given alias is the only entry in its group.')
        self.execute('DELETE FROM nicknames WHERE slug = ?', [alias.lower()])
开发者ID:daniellawrence,项目名称:sopel,代码行数:15,代码来源:db.py

示例9: cutwire

# 需要导入模块: from sopel.tools import Identifier [as 别名]
# 或者: from sopel.tools.Identifier import lower [as 别名]
def cutwire(bot, trigger):
    """
    Tells sopel to cut a wire when you've been bombed.
    """
    global BOMBS
    target = Identifier(trigger.nick)
    if target == bot.nick:  # a parallel bot behind a bouncer (e.g. Bucket) can trigger this function (see #16)
        return
    with lock:
        if target.lower() != bot.nick.lower() and target.lower() not in BOMBS:
            bot.say(STRINGS['CUT_NO_BOMB'] % target)
            return
        if not trigger.group(3):
            bot.say(STRINGS['CUT_NO_WIRE'])
            return
        # Remove target from bomb list temporarily
        bomb = BOMBS.pop(target.lower())
        wirecut = trigger.group(3)
        if wirecut.lower() in ('all', 'all!'):
            bomb['timer'].cancel()  # defuse timer, execute premature detonation
            bot.say(STRINGS['CUT_ALL_WIRES'] % bomb['color'])
            kickboom(bot, trigger, target)
            alls = bot.db.get_nick_value(bomb['target'], 'bomb_alls') or 0
            bot.db.set_nick_value(bomb['target'], 'bomb_alls', alls + 1)
        elif wirecut.capitalize() not in bomb['wires']:
            bot.say(STRINGS['CUT_IMAGINARY'] % target)
            # Add the target back onto the bomb list
            BOMBS[target.lower()] = bomb
        elif wirecut.capitalize() == bomb['color']:
            bot.say(STRINGS['CUT_CORRECT'] % target)
            bomb['timer'].cancel()  # defuse bomb
            defuses = bot.db.get_nick_value(bomb['target'], 'bomb_defuses') or 0
            bot.db.set_nick_value(bomb['target'], 'bomb_defuses', defuses + 1)
        else:
            bomb['timer'].cancel()  # defuse timer, execute premature detonation
            bot.say(STRINGS['CUT_WRONG'] % bomb['color'])
            kickboom(bot, trigger, target)
            wrongs = bot.db.get_nick_value(bomb['target'], 'bomb_wrongs') or 0
            bot.db.set_nick_value(bomb['target'], 'bomb_wrongs', wrongs + 1)
开发者ID:piagetbot,项目名称:sopel,代码行数:41,代码来源:bombbot.py

示例10: alias_nick

# 需要导入模块: from sopel.tools import Identifier [as 别名]
# 或者: from sopel.tools.Identifier import lower [as 别名]
    def alias_nick(self, nick, alias):
        """Create an alias for a nick.

        Raises ValueError if the alias already exists. If nick does not already
        exist, it will be added along with the alias."""
        nick = Identifier(nick)
        alias = Identifier(alias)
        nick_id = self.get_nick_id(nick)
        sql = 'INSERT INTO nicknames (nick_id, slug, canonical) VALUES (?, ?, ?)'
        values = [nick_id, alias.lower(), alias]
        try:
            self.execute(sql, values)
        except sqlite3.IntegrityError as e:
            raise ValueError('Alias already exists. {0}'.format(e))
开发者ID:daniellawrence,项目名称:sopel,代码行数:16,代码来源:db.py

示例11: alias_nick

# 需要导入模块: from sopel.tools import Identifier [as 别名]
# 或者: from sopel.tools.Identifier import lower [as 别名]
    def alias_nick(self, nick, alias):
        """Create an alias for a nick.

        Raises ValueError if the alias already exists. If nick does not already
        exist, it will be added along with the alias."""
        nick = Identifier(nick)
        alias = Identifier(alias)
        nick_id = self.get_nick_id(nick)
        session = self.ssession()
        try:
            result = session.query(Nicknames) \
                .filter(Nicknames.slug == alias.lower()) \
                .filter(Nicknames.canonical == alias) \
                .one_or_none()
            if result:
                raise ValueError('Given alias is the only entry in its group.')
            nickname = Nicknames(nick_id=nick_id, slug=alias.lower(), canonical=alias)
            session.add(nickname)
            session.commit()
        except SQLAlchemyError:
            session.rollback()
            raise
        finally:
            session.close()
开发者ID:sopel-irc,项目名称:sopel,代码行数:26,代码来源:db.py

示例12: get_nick_value

# 需要导入模块: from sopel.tools import Identifier [as 别名]
# 或者: from sopel.tools.Identifier import lower [as 别名]
 def get_nick_value(self, nick, key):
     """Retrieves the value for a given key associated with a nick."""
     nick = Identifier(nick)
     session = self.ssession()
     try:
         result = session.query(NickValues) \
             .filter(Nicknames.nick_id == NickValues.nick_id) \
             .filter(Nicknames.slug == nick.lower()) \
             .filter(NickValues.key == key) \
             .one_or_none()
         if result is not None:
             result = result.value
         return _deserialize(result)
     except SQLAlchemyError:
         session.rollback()
         raise
     finally:
         session.close()
开发者ID:sopel-irc,项目名称:sopel,代码行数:20,代码来源:db.py

示例13: unalias_nick

# 需要导入模块: from sopel.tools import Identifier [as 别名]
# 或者: from sopel.tools.Identifier import lower [as 别名]
    def unalias_nick(self, alias):
        """Removes an alias.

        Raises ValueError if there is not at least one other nick in the group.
        To delete an entire group, use `delete_group`.
        """
        alias = Identifier(alias)
        nick_id = self.get_nick_id(alias, False)
        session = self.ssession()
        try:
            count = session.query(Nicknames) \
                .filter(Nicknames.nick_id == nick_id) \
                .count()
            if count <= 1:
                raise ValueError('Given alias is the only entry in its group.')
            session.query(Nicknames).filter(Nicknames.slug == alias.lower()).delete()
            session.commit()
        except SQLAlchemyError:
            session.rollback()
            raise
        finally:
            session.close()
开发者ID:sopel-irc,项目名称:sopel,代码行数:24,代码来源:db.py

示例14: luv_h8

# 需要导入模块: from sopel.tools import Identifier [as 别名]
# 或者: from sopel.tools.Identifier import lower [as 别名]
def luv_h8(bot, trigger, target, which, warn_nonexistent=True):
    target = Identifier(target)
    which = which.lower()  # issue #18
    pfx = change = selfreply = None  # keep PyCharm & other linters happy
    if target.lower() not in bot.privileges[trigger.sender.lower()]:
        if warn_nonexistent:
            bot.reply("You can only %s someone who is here." % which)
        return
    if rep_too_soon(bot, trigger.nick):
        return
    if which == 'luv':
        selfreply = "No narcissism allowed!"
        pfx, change = 'in', 1
    if which == 'h8':
        selfreply = "Go to 4chan if you really hate yourself!"
        pfx, change = 'de', -1
    if not (pfx and change and selfreply):  # safeguard against leaving something in the above mass-None assignment
        bot.say("Logic error! Please report this to %s." % bot.config.core.owner)
        return
    if is_self(bot, trigger.nick, target):
        bot.reply(selfreply)
        return
    rep = mod_rep(bot, trigger.nick, target, change)
    bot.say("%s has %screased %s's reputation score to %d" % (trigger.nick, pfx, target, rep))
开发者ID:dgw,项目名称:sopel-rep,代码行数:26,代码来源:rep.py

示例15: start

# 需要导入模块: from sopel.tools import Identifier [as 别名]
# 或者: from sopel.tools.Identifier import lower [as 别名]
def start(bot, trigger):
    """
    Put a bomb in the specified user's pants. If they take too long or guess wrong,
     they die (and get kicked from the channel, if enabled).
    """
    if not trigger.group(3):
        bot.say(STRINGS['TARGET_MISSING'])
        return NOLIMIT
    if bot.db.get_channel_value(trigger.sender, 'bombs_disabled'):
        bot.notice(STRINGS['CHANNEL_DISABLED'] % trigger.sender, trigger.nick)
        return NOLIMIT
    since_last = time_since_bomb(bot, trigger.nick)
    if since_last < TIMEOUT and not trigger.admin:
        bot.notice(STRINGS['TIMEOUT_REMAINING'] % (TIMEOUT - since_last),
                   trigger.nick)
        return
    global BOMBS
    target = Identifier(trigger.group(3))
    target_unbombable = bot.db.get_nick_value(target, 'unbombable')
    if target == bot.nick:
        bot.say(STRINGS['TARGET_BOT'])
        return NOLIMIT
    if is_self(bot, trigger.nick, target):
        bot.say(STRINGS['TARGET_SELF'] % trigger.nick)
        return NOLIMIT
    if target.lower() not in bot.privileges[trigger.sender.lower()]:
        bot.say(STRINGS['TARGET_IMAGINARY'])
        return NOLIMIT
    if target_unbombable and not trigger.admin:
        bot.say(STRINGS['TARGET_DISABLED'] % target)
        return NOLIMIT
    if bot.db.get_nick_value(trigger.nick, 'unbombable'):
        bot.say(STRINGS['NOT_WHILE_DISABLED'] % trigger.nick)
        return NOLIMIT
    with lock:
        if target.lower() in BOMBS:
            bot.say(STRINGS['TARGET_FULL'] % target)
            return NOLIMIT
        wires = [COLORS[i] for i in sorted(sample(xrange(len(COLORS)), randrange(3, 5)))]
        num_wires = len(wires)
        wires_list = [formatting.color(str(wire), str(wire)) for wire in wires]
        wires_list = ", ".join(wires_list[:-2] + [" and ".join(wires_list[-2:])]).replace('Light_', '')
        wires = [wire.replace('Light_', '') for wire in wires]
        color = choice(wires)
        bot.say(
                choice(STRINGS['BOMB_PLANTED']) % {'target':           target,
                                                   'fuse_time': STRINGS['FUSE'],
                                                   'wire_num':         num_wires,
                                                   'wire_list':        wires_list,
                                                   'prefix':           bot.config.core.help_prefix or '.'
                                                   })
        bot.notice(STRINGS['BOMB_ANSWER'] % (target, color), trigger.nick)
        if target_unbombable:
            bot.notice(STRINGS['TARGET_DISABLED_FYI'] % target, trigger.nick)
        timer = Timer(FUSE, explode, (bot, trigger))
        BOMBS[target.lower()] = {'wires':  wires,
                                 'color':  color,
                                 'timer':  timer,
                                 'target': target,
                                 'bomber': trigger.nick
                                 }
        timer.start()
    bombs_planted = bot.db.get_nick_value(trigger.nick, 'bombs_planted') or 0
    bot.db.set_nick_value(trigger.nick, 'bombs_planted', bombs_planted + 1)
    bot.db.set_nick_value(trigger.nick, 'bomb_last_planted', time.time())
开发者ID:piagetbot,项目名称:sopel,代码行数:67,代码来源:bombbot.py


注:本文中的sopel.tools.Identifier.lower方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。