本文整理汇总了Python中EventDispatcher.EventDispatcher.dispatch方法的典型用法代码示例。如果您正苦于以下问题:Python EventDispatcher.dispatch方法的具体用法?Python EventDispatcher.dispatch怎么用?Python EventDispatcher.dispatch使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类EventDispatcher.EventDispatcher
的用法示例。
在下文中一共展示了EventDispatcher.dispatch方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from EventDispatcher import EventDispatcher [as 别名]
# 或者: from EventDispatcher.EventDispatcher import dispatch [as 别名]
class IRCBot:
def __init__(self, configname):
self.config = ConfigLoader(configname)
self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.irc = IRCInterface(self.socket)
self.plugins = {}
self.dispatcher = EventDispatcher(self.irc)
def rise(self):
self.loadAllPlugins()
self.connect()
def loadPlugin(self, pluginName):
plugin = importlib.import_module("plugins." + pluginName)
for name in dir(plugin):
local = getattr(plugin, name)
if hasattr(local, "_ircEvent"):
self.dispatcher.hookEvent(getattr(local, "_ircEvent"), local)
def loadAllPlugins(self):
for m in self.config.get("plugins"):
self.loadPlugin(m)
def connect(self):
self.socket.connect( (self.config.get("server"), int(self.config.get("port"))) )
self.handshake()
self.loop()
def handshake(self):
self.irc.nick(self.config.get("nick"))
self.irc.user(self.config.get("nick"), "...", "...", "...")
for channel in self.config.get("channels"):
self.irc.join(channel)
def loop(self):
buffer = ""
while True:
data = self.irc.read()
for cmd in data:
if cmd["command"] == "PING":
self.irc.pong(cmd["params"][0])
self.dispatcher.dispatch(cmd)