本文整理汇总了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())
示例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)