本文整理汇总了Python中brain.Brain.respond方法的典型用法代码示例。如果您正苦于以下问题:Python Brain.respond方法的具体用法?Python Brain.respond怎么用?Python Brain.respond使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类brain.Brain
的用法示例。
在下文中一共展示了Brain.respond方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: RelayToIRC
# 需要导入模块: from brain import Brain [as 别名]
# 或者: from brain.Brain import respond [as 别名]
class RelayToIRC(irc.IRCClient):
"""
Wire bot brain, job queue, and config into a Twisted IRC client
"""
timestamp = None
def connectionMade(self):
self.config = self.factory.config
self.nickname = self.config["irc"]["nick"]
self.realname = self.config["irc"]["realname"]
self.channel = self.config["irc"]["channel"]
if "maxlen" in self.config["irc"]:
text.maxlen = self.config["irc"]["maxlen"]
self.sourceURL = self.config["source_url"]
irc.IRCClient.connectionMade(self)
if "pass" in self.config["irc"]:
if "ownermail" in self.config["irc"]:
self.msg("NickServ", "REGISTER %s %s" % (self.config["irc"]["pass"], self.config["irc"]["ownermail"]))
elif "regverify" in self.config["irc"]:
self.msg("NickServ", "VERIFY REGISTER %s %s" % (self.config["irc"]["nick"], self.config["irc"]["regverify"]))
self.msg("NickServ", "IDENTIFY %s" % self.config["irc"]["pass"])
def signedOn(self):
self.join(self.channel)
def joined(self, channel):
print "Joined channel %s as %s" % (channel, self.nickname)
self.brain = Brain(self.config, sink=self)
#XXX get outta here:
source = JobQueue(
definition=self.config["jobs"],
sink=self,
interval=self.config["poll_interval"]
)
source.run()
def privmsg(self, user, channel, message):
if message.find(self.nickname) >= 0:
self.brain.respond(user, message)
def write(self, data):
if isinstance(data, list):
for line in data:
self.write(line)
return
self.say(self.channel, data.encode('ascii', 'replace'))
self.timestamp = datetime.datetime.utcnow()
@staticmethod
def run(config):
factory = ReconnectingClientFactory()
factory.protocol = RelayToIRC
factory.config = config
reactor.connectTCP(config["irc"]["host"], config["irc"]["port"], factory)
reactor.run()