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


Python Writer.get_writing方法代码示例

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


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

示例1: handle_command

# 需要导入模块: from writer import Writer [as 别名]
# 或者: from writer.Writer import get_writing [as 别名]
def handle_command(command, details, channel, respond = True):
    """
        Receives commands directed at the bot and determines if they
        are valid commands. If so, then acts on the commands. If not,
        returns back what it needs for clarification.
    """
    response = False
    if command == "learn":
        learner = Learner()
        response = learner.learn(details[0], " ".join(details[1:]))
    elif command == "unlearn":
        learner = Learner()
        content = None
        if len(details) > 1:
            content = " ".join(details[1:])    
        response = learner.unlearn(details[0], content)
    elif command == "commands":
        learner = Learner()
        response = learner.list_commands()
    elif command == "list":
        learner = Learner()
        response = learner.list(details[0])
    elif command == "cowsay":
        out = subprocess.check_output(['cowsay', " ".join(details)])
        response = "```" + out + "```"
    elif command == "meme":
        memer = Memer()
        if not details or len(details) == 0:
            response = memer.list_templates()
        else:
            template = details.pop(0).strip()
            parts = [x.strip() for x in " ".join(details).split(",")]
            top = parts[0] if len(parts) > 0 else None
            bottom = parts[1] if len(parts) > 1 else None

            response = memer.get_meme(template, top, bottom)
            
    elif command == "hostname":
        response = "slurms coming to you live from: `%s (%s)`" % (subprocess.check_output("hostname -A",  shell=True).strip(), subprocess.check_output("hostname -i",  shell=True).strip())
    elif command == "write":
        writer = Writer()
        response = writer.get_writing(" ".join(details))
    elif command == "imglearn":
        learner = Learner()
        imgur = Imgur()
        image_url = imgur.save_from_url(" ".join(details[1:]))
        response = learner.learn(details[0], image_url)

    elif command == "++" or command == "endorse":
        plusser = Plusser()
        reason = ""
        if len(details) > 1:
            reason = " ".join(details[1:])

        response = plusser.plus(details[0], reason)
    elif command == "plusses":
        plusser = Plusser()
        response = plusser.get(details[0])
        
    elif command == "leaders" or command == "leader_board":
        plusser = Plusser()
        response = plusser.leader_board()

    elif command == "monthly_leaders" or command == "monthly_leader_board":
        plusser = Plusser()
        months_ago = 0
        if details and len(details) > 0:
            months_ago = details[0]
        response = plusser.monthly_leader_board(months_ago)

    elif command == "youtube":
        query = " ".join(details)
        videos = youtube.youtube_search(query)
        if len(videos) > 0:
            response = videos[-1]
        else:
            response = "sorry, couldnt find any videos for %s" % query
    elif command == "echo":
        response = " ".join(details)
    elif command == "pipe":
        pipe(command, details, channel)
    elif command == "doom":
        doom = Doom()
        response = doom.doom(details)
    else:
        """
          see if a randomly entered command is something that was previously learned
        """
        learner = Learner()
        response = learner.get(command)
    
    if response and respond:
        slack_client.api_call("chat.postMessage", channel=channel,
                              text=response, as_user=True)
    elif not respond:
        return response
开发者ID:detectica,项目名称:slurm,代码行数:98,代码来源:slurmsbot.py


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