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


Python Commands.parse方法代码示例

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


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

示例1: on_publicmsg

# 需要导入模块: from commands import Commands [as 别名]
# 或者: from commands.Commands import parse [as 别名]
  def on_publicmsg(self, connection, event):
    if connection != self.connection:
      self.log.info("IRC: Incorrect connection in on_publicmsg")
      return

    incoming_message = event.arguments()[0].lstrip()

    if len(incoming_message) < 1:
        return

    cmd = incoming_message.partition(" ")[0][1:]
    args = incoming_message.partition(" ")[2]
    src = event.source()

    if incoming_message[0] == "!":
        self.log.info("Command: \"%s\" Args: \"%s\" From: \"%s\"" % (cmd, args, src))
        command = Commands(event.target(), self.command_info, self.command_callback)
        command.parse(cmd, args, src)
    else:
        inc_msg = incoming_message.strip(" \t\n\r").lower()
        origin = src.partition("!")[0]
        if (not inc_msg.find("morning") == -1) and (not inc_msg.find(self.config.nick) == -1):
            self.command_callback("Morning %s" % origin, event.target())
        elif (not inc_msg.find("afternoon") == -1) and (not inc_msg.find(self.config.nick) == -1):
            self.command_callback("Afternoon %s" % origin, event.target())
        elif (not inc_msg.find("evening") == -1) and (not inc_msg.find(self.config.nick) == -1):
            self.command_callback("Evening %s" % origin, event.target())
        elif (not inc_msg.find("night") == -1) and (not inc_msg.find(self.config.nick) == -1):
            self.command_callback("Good night %s" % origin, event.target())
开发者ID:fone4u,项目名称:apexbot,代码行数:31,代码来源:bot.py

示例2: Bot

# 需要导入模块: from commands import Commands [as 别名]
# 或者: from commands.Commands import parse [as 别名]
class Bot(irc.IRCClient):
    """Core Bot events, subclassed from Twisted's IRCClient

    Respond to privmsgs in channels and wrap self.msg to delegate replies
    based on the context (query versus public channel). This also maintains
    the Redis and last.fm connections while creating contacts as users talk.
    """

    def __init__(self, nickname, chans, fact):
        """initialize the Bot info, Redis client, and last.fm connection"""
        self.nickname = nickname
        self.chans = chans
        self.factory = fact
        self.db = Contacts()
        self.youtube = Youtube(secrets.YOUTUBE_API_KEY)
        self.commands = Commands(self)
        self.last = pylast.LastFMNetwork(api_key=secrets.LAST_API_KEY,
                                         api_secret=secrets.LAST_API_SECRET,
                                         username=secrets.LAST_USER,
                                         password_hash=secrets.LAST_PASS_HASH)

    def _isPrivate(self, nick, channel):
        """sets the private context based on channel or user"""
        return (channel == self.nickname and nick != self.nickname)

    def signedOn(self):
        for chan in self.chans:
            self.join(chan)

    def msg(self, contact, message):
        """wraps self.msg to delegate the reply"""
        channel = contact.nick if contact.private else contact.channel
        irc.IRCClient.msg(self, channel, message)

    def privmsg(self, user, channel, message):
        """manages contacts based on message and dispatches it to Commands

        Interface with Redis for getting, or creating, the Contact and setting
        its context, then passing it off to be parsed.
        """
        contact = self.db.get(user)

        # update private context for replies to existing contact
        if contact:
            private = self._isPrivate(contact.nick, channel)
            contact.channel = channel
            contact.private = private
        # if new contact, create and set private context
        else:
            contact = Contact(user, channel)
            contact.private = self._isPrivate(contact.nick, channel)
            self.db.set(contact.user, contact)

        # only respond if it's properly said
        if contact.private or message.startswith("!"):
            self.commands.parse(contact, message)
开发者ID:rattboi,项目名称:last,代码行数:58,代码来源:bot.py


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