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


Python UtilBot.text_to_segments方法代码示例

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


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

示例1: flip

# 需要导入模块: from Core.Util import UtilBot [as 别名]
# 或者: from Core.Util.UtilBot import text_to_segments [as 别名]
def flip(bot, event, *args):
    if ''.join(args) == '?':
        segments = UtilBot.text_to_segments("""\
*Flip*
Usage: /flip <optional: number of times to flip>
Purpose: Flips a coin.
""")
        bot.send_message_segments(event.conv, segments)
    else:
        times = 1
        if len(args) > 0 and args[-1].isdigit():
            times = int(args[-1]) if int(args[-1]) < 1000000 else 1000000
        heads, tails = 0, 0
        for x in range(0, times):
            n = random.randint(0, 1)
            if n == 1:
                heads += 1
            else:
                tails += 1
        if times == 1:
            bot.send_message(event.conv, "Heads!" if heads > tails else "Tails!")
        else:
            bot.send_message(event.conv,
                             "Winner: " + (
                                 "Heads!" if heads > tails else "Tails!" if tails > heads else "Tie!") + " Heads: " + str(
                                 heads) + " Tails: " + str(tails) + " Ratio: " + (str(
                                 Fraction(heads, tails)) if heads > 0 and tails > 0 else str(heads) + '/' + str(tails)))
开发者ID:RockyTV,项目名称:HangoutsBot,代码行数:29,代码来源:ExtraCommands.py

示例2: config

# 需要导入模块: from Core.Util import UtilBot [as 别名]
# 或者: from Core.Util.UtilBot import text_to_segments [as 别名]
def config(bot, event, cmd=None, *args):
    if cmd == 'get' or cmd is None:
        config_args = list(args)
        value = bot.config.get_by_path(config_args) if config_args else dict(bot.config)
    elif cmd == 'set':
        config_args = list(args[:-1])
        if len(args) >= 2:
            bot.config.set_by_path(config_args, json.loads(args[-1]))
            bot.config.save()
            value = bot.config.get_by_path(config_args)
        else:
            yield from DispatcherSingleton.unknown_command(bot, event)
            return
    else:
        yield from DispatcherSingleton.unknown_command(bot, event)
        return

    if value is None:
        value = 'Parameter does not exist!'

    config_path = ' '.join(k for k in ['config'] + config_args)
    segments = [hangups.ChatMessageSegment('{}:'.format(config_path),
                                           is_bold=True),
                hangups.ChatMessageSegment('\n', hangups.SegmentType.LINE_BREAK)]
    segments.extend(UtilBot.text_to_segments(json.dumps(value, indent=2, sort_keys=True)))
    bot.send_message_segments(event.conv, segments)
开发者ID:busterkieton,项目名称:HangoutsBot,代码行数:28,代码来源:DefaultCommands.py

示例3: roulette

# 需要导入模块: from Core.Util import UtilBot [as 别名]
# 或者: from Core.Util.UtilBot import text_to_segments [as 别名]
def roulette(bot, event, *args):
    if ''.join(args) == '?':
        segments = UtilBot.text_to_segments("""\
**Roulette**
Usage: /roulette
Purpose: Spins the chamber and tries to shoot you in the head
""")
        bot.send_message_segments(event.conv, segments)
    else:
        #static variables
        if not hasattr(roulette, "_rouletteChamber"):
            roulette._rouletteChamber = random.randrange(0, 6)
        if not hasattr(roulette, "_rouletteBullet"):
            roulette._rouletteBullet = random.randrange(0, 6)

        if len(args) > 0 and args[0] == 'spin':
            roulette._rouletteBullet = random.randrange(0, 6)
            bot.send_message(event.conv, '*SPIN* Are you feeling lucky?')
            return
        if roulette._rouletteChamber == roulette._rouletteBullet:
            roulette._rouletteBullet = random.randrange(0, 6)
            roulette._rouletteChamber = random.randrange(0, 6)
            bot.send_message(event.conv, '*BANG*')
        else:
            bot.send_message(event.conv, '*click*')
            roulette._rouletteChamber += 1
            roulette._rouletteChamber %= 6
开发者ID:gamecheet,项目名称:HangoutsBot,代码行数:29,代码来源:CustomCommands.py

示例4: rate

# 需要导入模块: from Core.Util import UtilBot [as 别名]
# 或者: from Core.Util.UtilBot import text_to_segments [as 别名]
def rate(bot, event, *args):
    ratings = dict(
                   agree      ="\u2714"
                  ,disagree   ="\u274c"
                  ,funny      ="\U0001f604"
                  ,winner     ="\U0001f31f"
                  ,zing       ="\u26a1"
                  ,informative="\u2139"
                  ,friendly   ="\u2764"
                  ,useful     ="\U0001f527"
                  ,optimistic ="\U0001f308"
                  ,artistic   ="\U0001f3a8"
                  ,late       ="\u23f0"
                  ,dumb       ="\U0001f4e6"
                  ,box        ="\U0001f4e6"
                  )
    if ''.join(args) == '?':
        segments = UtilBot.text_to_segments("""\
**Rate**
Usage: /rate <rating>
Purpose: Responds to your rating, ratings are agree, disagree, funny, winner, zing, informative, friendly, optimistic, artistic, late, dumb and box.
""")
        bot.send_message_segments(event.conv, segments)
    else:
        try:
            bot.send_message(event.conv, ratings[args[0]])
        except KeyError:
            bot.send_message(event.conv, "That's not a valid rating. You are \U0001f4e6 x 1")
开发者ID:gamecheet,项目名称:HangoutsBot,代码行数:30,代码来源:CustomCommands.py

示例5: navyseals

# 需要导入模块: from Core.Util import UtilBot [as 别名]
# 或者: from Core.Util.UtilBot import text_to_segments [as 别名]
def navyseals(bot, event, *args):
     if ''.join(args) == '?':
        segments = UtilBot.text_to_segments("""\
**Navy Seals**
Usage: /navyseals
Purpose: Shits fury all over you.
""")
        bot.send_message_segments(event.conv, segments)
     else:
        bot.send_message(event.conv,
'''What the fuck did you just fucking say about me, you little bitch? \
I'll have you know I graduated top of my class in the Navy Seals, and \
I've been involved in numerous secret raids on Al-Quaeda, and I have over \
300 confirmed kills. I am trained in gorilla warfare and I'm the top sniper \
in the entire US armed forces. You are nothing to me but just another target. \
I will wipe you the fuck out with precision the likes of which has never \
been seen before on this Earth, mark my fucking words. You think you can \
get away with saying that shit to me over the Internet? Think again, fucker. \
As we speak I am contacting my secret network of spies across the USA and \
your IP is being traced right now so you better prepare for the storm, \
maggot. The storm that wipes out the pathetic little thing you call your \
life. You're fucking dead, kid. I can be anywhere, anytime, and I can kill \
you in over seven hundred ways, and that's just with my bare hands. Not only \
am I extensively trained in unarmed combat, but I have access to the entire \
arsenal of the United States Marine Corps and I will use it to its full \
extent to wipe your miserable ass off the face of the continent, you little \
shit. If only you could have known what unholy retribution your little \
"clever" comment was about to bring down upon you, maybe you would have held \
your fucking tongue. But you couldn't, you didn't, and now you're paying the \
price, you goddamn idiot. I will shit fury all over you and you will drown in \
it. You're fucking dead, kiddo.''')
开发者ID:gamecheet,项目名称:HangoutsBot,代码行数:33,代码来源:CustomCommands.py

示例6: xfiles

# 需要导入模块: from Core.Util import UtilBot [as 别名]
# 或者: from Core.Util.UtilBot import text_to_segments [as 别名]
def xfiles(bot, event, *args):
    if ''.join(args) == '?':
        segments = UtilBot.text_to_segments("""\
**Xfiles**
Usage: /xfiles
Purpose: but what if bot is not kill
""")
        bot.send_message_segments(event.conv, segments)
    else:
        args = ['xfiles','theme']
        youtube(bot, event, *args)
开发者ID:gamecheet,项目名称:HangoutsBot,代码行数:13,代码来源:CustomCommands.py

示例7: run

# 需要导入模块: from Core.Util import UtilBot [as 别名]
# 或者: from Core.Util.UtilBot import text_to_segments [as 别名]
    def run(self, bot, event, bot_command_char, *args, **kwds):

        bot_command_char = bot_command_char.strip()  # For cases like "/bot " or " / "

        if args[0] == bot_command_char:  # Either the command char is like "/bot" or the user did "/ ping"
            args = list(args[1:])
        if args[0].startswith(bot_command_char):
            command = args[0][len(bot_command_char):]
        else:
            command = args[0]
        if command[:2] == 'r/':
            command = 'subreddit'
            args = list(args)
            print(args)
            args.insert(1, args[0][3:])
        elif command[:2] == 'v/':
            command = 'subverse'
            args = list(args)
            print(args)
            args.insert(1, args[0][3:])
        try:
            func = self.commands[command]
        except KeyError:
            try:
                if event.user.is_self:
                    func = self.hidden_commands[command]
                else:
                    raise KeyError
            except KeyError:
                if self.unknown_command:
                    func = self.unknown_command
                else:
                    raise NoCommandFoundError(
                        "Command {} is not registered. Furthermore, no command found to handle unknown commands.".format
                        (command))

        func = asyncio.coroutine(func)

        args = list(args[1:])

        # For help cases.
        if len(args) > 0 and args[0] == '?':
            if func.__doc__:
                bot.send_message_segments(event.conv, UtilBot.text_to_segments(func.__doc__))
                return

        try:
            asyncio.async(func(bot, event, *args, **kwds))
        except Exception as e:
            log = open('log.txt', 'a+')
            log.writelines(str(datetime.now()) + ":\n " + traceback.format_exc() + "\n\n")
            log.close()
            print(traceback.format_exc())
开发者ID:gamecheet,项目名称:HangoutsBot,代码行数:55,代码来源:Dispatcher.py

示例8: help

# 需要导入模块: from Core.Util import UtilBot [as 别名]
# 或者: from Core.Util.UtilBot import text_to_segments [as 别名]
def help(bot, event, command=None, *args):
    valid_user_commands = []
    for command_test in sorted(DispatcherSingleton.commands.keys()):
        if UtilBot.check_if_can_run_command(bot, event, command_test):
            valid_user_commands.append(command_test)
    docstring = """
    **Current Implemented Commands:**
    {}
    Use: /<command name> ? or /help <command name> to find more information about the command.
    """.format(', '.join(valid_user_commands))
    if command == '?' or command is None:
        bot.send_message_segments(event.conv, UtilBot.text_to_segments(docstring))
    else:
        if command in DispatcherSingleton.commands.keys():
            func = DispatcherSingleton.commands[command]
            if func.__doc__:
                bot.send_message_segments(event.conv, UtilBot.text_to_segments(func.__doc__))
            else:  # Compatibility purposes for the old way of showing help text.
                args = ['?']
                func(bot, event, *args)
        else:
            bot.send_message("The command {} is not registered.".format(command))
开发者ID:busterkieton,项目名称:HangoutsBot,代码行数:24,代码来源:DefaultCommands.py

示例9: fliptext

# 需要导入模块: from Core.Util import UtilBot [as 别名]
# 或者: from Core.Util.UtilBot import text_to_segments [as 别名]
def fliptext(bot, event, *args):
    if ''.join(args) == '?':
        segments = UtilBot.text_to_segments("""\
**Flip Text**
Usage: /fliptext <text>
Purpose: Flips your message 180 degrees
""")
        bot.send_message_segments(event.conv, segments)
    else:
        args = ' '.join(args)
        output = ''.join([fliptextdict.get(letter, letter) for letter in args])
        output = output[::-1]
        bot.send_message(event.conv, output)
开发者ID:gamecheet,项目名称:HangoutsBot,代码行数:15,代码来源:CustomCommands.py

示例10: eightball

# 需要导入模块: from Core.Util import UtilBot [as 别名]
# 或者: from Core.Util.UtilBot import text_to_segments [as 别名]
def eightball(bot, event, *args):
    if ''.join(args) == '?':
        segments = UtilBot.text_to_segments("""\
**Eightball**
Usage: /eightball
Purpose: Tells fortunes!
""")
        bot.send_message_segments(event.conv, segments)
    else:
        if len(args) > 0:
            bot.send_message(event.conv, _checkTheBall(len(' '.join(args))))
        else:
            bot.send_message(event.conv, _checkTheBall(random.randint(0, 2)))
开发者ID:gamecheet,项目名称:HangoutsBot,代码行数:15,代码来源:CustomCommands.py

示例11: udefine

# 需要导入模块: from Core.Util import UtilBot [as 别名]
# 或者: from Core.Util.UtilBot import text_to_segments [as 别名]
def udefine(bot, event, *args):
    if ''.join(args) == '?':
        segments = UtilBot.text_to_segments("""\
*Urbanly Define*
Usage: /udefine <word to search for> \
<optional: definition number [defaults to 1st]>
Purpose: Define a word.
""")
        bot.send_message_segments(event.conv, segments)
    else:
        api_host = 'http://urbanscraper.herokuapp.com/search/'
        num_requested = 0
        returnall = False
        if len(args) == 0:
            bot.send_message(event.conv, "Invalid usage of /udefine.")
            return
        else:
            if args[-1] == '*':
                args = args[:-1]
                returnall = True
            if args[-1].isdigit():
                # we subtract one here because def #1 is the 0 item in the list
                num_requested = int(args[-1]) - 1
                args = args[:-1]

            term = parse.quote('.'.join(args))
            response = requests.get(api_host + term)
            error_response = 'No definition found for \"{}\".'.format(' '.join(args))
            if response.status_code != 200:
                bot.send_message(event.conv, error_response)
            result = response.content.decode()
            result_list = json.loads(result)
            if len(result_list) == 0:
                bot.send_message(event.conv, error_response)
                return
            num_requested = min(num_requested, len(result_list) - 1)
            num_requested = max(0, num_requested)
            result = result_list[num_requested].get(
                'definition', error_response)
            if returnall:
                segments = []
                for string in result_list:
                    segments.append(hangups.ChatMessageSegment(string))
                    segments.append(hangups.ChatMessageSegment('\n', hangups.SegmentType.LINE_BREAK))
                bot.send_message_segments(event.conv, segments)
            else:
                segments = [hangups.ChatMessageSegment(' '.join(args), is_bold=True),
                            hangups.ChatMessageSegment('\n', hangups.SegmentType.LINE_BREAK),
                            hangups.ChatMessageSegment(result + ' [{0} of {1}]'.format(
                                num_requested + 1, len(result_list)))]
                bot.send_message_segments(event.conv, segments)
开发者ID:RockyTV,项目名称:HangoutsBot,代码行数:53,代码来源:ExtraCommands.py

示例12: source

# 需要导入模块: from Core.Util import UtilBot [as 别名]
# 或者: from Core.Util.UtilBot import text_to_segments [as 别名]
def source(bot, event, *args):
    if ''.join(args) == '?':
        segments = UtilBot.text_to_segments("""\
**Source**
Usage: /source
Purpose: Links to the GitHub
""")
        bot.send_message_segments(event.conv, segments)
    else:
        url = 'https://github.com/ShaunOfTheLive/HangoutsBot'
        segments = [hangups.ChatMessageSegment(url,
                                               hangups.SegmentType.LINK,
                                               link_target=url)]
        bot.send_message_segments(event.conv, segments)
开发者ID:gamecheet,项目名称:HangoutsBot,代码行数:16,代码来源:CustomCommands.py

示例13: log

# 需要导入模块: from Core.Util import UtilBot [as 别名]
# 或者: from Core.Util.UtilBot import text_to_segments [as 别名]
def log(bot, event, *args):
    if ''.join(args) == '?':
        segments = UtilBot.text_to_segments("""\
**Log**
Usage: /log <text>
Purpose: Logs text to the log.txt file.
""")
        bot.send_message_segments(event.conv, segments)
    else:
        msg = ' '.join(args)
        log = open('log.txt', 'a+')
        log.writelines(msg + "\n")
        for c in msg: log.writelines(hex(ord(c)) + " ")
        log.writelines("\n")
        log.close()
开发者ID:gamecheet,项目名称:HangoutsBot,代码行数:17,代码来源:CustomCommands.py

示例14: spoof

# 需要导入模块: from Core.Util import UtilBot [as 别名]
# 或者: from Core.Util.UtilBot import text_to_segments [as 别名]
def spoof(bot, event, *args):
    if ''.join(args) == '?':
        segments = UtilBot.text_to_segments("""\
*Spoof*
Usage: /spoof
Purpose: Who knows...
""")
        bot.send_message_segments(event.conv, segments)
    else:
        segments = [hangups.ChatMessageSegment('!!! CAUTION !!!', is_bold=True),
                    hangups.ChatMessageSegment('\n', hangups.SegmentType.LINE_BREAK),
                    hangups.ChatMessageSegment('User ')]
        link = 'https://plus.google.com/u/0/{}/about'.format(event.user.id_.chat_id)
        segments.append(hangups.ChatMessageSegment(event.user.full_name, hangups.SegmentType.LINK,
                                                   link_target=link))
        segments.append(hangups.ChatMessageSegment(' has just been reporting to the NSA for attempted spoofing!'))
        bot.send_message_segments(event.conv, segments)
开发者ID:RockyTV,项目名称:HangoutsBot,代码行数:19,代码来源:ExtraCommands.py

示例15: latex

# 需要导入模块: from Core.Util import UtilBot [as 别名]
# 或者: from Core.Util.UtilBot import text_to_segments [as 别名]
def latex(bot, event, *args):
    if ''.join(args) == '?':
        segments = UtilBot.text_to_segments("""\
**LaTeX**
Usage: /latex <LaTeX code>
Purpose: Renders LaTeX code to an image and sends it
""")
        bot.send_message_segments(event.conv, segments)
    else:
        cmd = "texvc /tmp images '" + \
              ' '.join(args).replace("'", "'\\''") + \
              "' utf-8 'rgb 1.0 1.0 1.0'"
        print('args: ')
        print(cmd)
        output = subprocess.check_output(cmd, shell=True)
        output = output.decode(encoding='UTF-8')
        print(output)
        filename = output[1:33] + '.png'
        filename = os.path.join('images', filename)
        image_id = yield from UtilBot.upload_image(bot, filename)
        send_image(bot, event, image_id)
开发者ID:gamecheet,项目名称:HangoutsBot,代码行数:23,代码来源:CustomCommands.py


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