0

假设您正在远程登录 IRC 以了解它是如何工作的。当您发出命令时,IRC 服务器会返回数据,告诉您它在做什么。一旦我创建了一个默认脚本,它基本上就是服务器和客户端之间正常 IRC 连接的发生方式,如果它偏离了它,它不会告诉我出了什么问题。我需要能够根据服务器返回给我的内容抛出异常。我如何在 python 中做到这一点?

4

2 回答 2

1

这是一个教程,它几乎可以引导您完成在 Python 中使用套接字的 IRC 客户端:

于 2009-07-13T18:14:26.977 回答
0

Twisted是一个用 Python 编写的事件驱动的网络引擎,包括对IRC协议的支持。要访问IRC功能,请将其导入:

from twisted.words.protocols import irc

在此处查看示例:ircLogBot.py - 连接到 IRC 服务器并记录所有消息。例子__doc__

"""An example IRC log bot - logs a channel's events to a file.

If someone says the bot's name in the channel followed by a ':',
e.g.

  <foo> logbot: hello!

    the bot will reply:

  <logbot> foo: I am a log bot

Run this script with two arguments, the channel name the bot should
connect to, and file to log to, e.g.:

  $ python ircLogBot.py test test.log

will log channel #test to the file 'test.log'.
"""
于 2009-07-13T17:57:27.243 回答