単純な IRC ボットを作成するというアイデアで遊んでいます。この目的のために書かれたさまざまな Python ソフトウェアがあり、さまざまな機能セットとさまざまな複雑さがあるようです。かなりユーザーフレンドリーなインターフェースを持っていると思われるこのパッケージを見つけて、インストールしました。
最初に、パッケージが Python 3 を考慮せずに作成されたように見えるという問題に遭遇しました。その上で 2to3 コンバーター ツールを実行したところ、その後パッケージをインポートできました。ただし、ドキュメントから例を複製しようとすると、質問のタイトルにエラーが表示されます。チャンネルの名前が削除された私のスクリプトは次のとおりです。
from ircutils import bot
class hambot (bot.SimpleBot):
def on_channel_message (self, event):
if event.message == 'go away hambot':
self.quit('Goodbye.')
def main ():
hb = hambot('hambot')
hb.connect('irc.synirc.org', channel = '(channel name removed)')
hb.start()
if __name__ == '__main__': main()
実行しようとすると、次の結果が得られます。asynchat.py
最初の例外は、IRCUtils パッケージの一部ではなく、Python 自体の一部のように見えるというスクリプトのみを参照しているため、何が問題なのか少しわかりません。
Python 3.2.3 (default, Apr 11 2012, 07:15:24) [MSC v.1500 32 bit (Intel)] on win
32
Type "help", "copyright", "credits" or "license" for more information.
>>> import hambot
>>> hambot.main()
Traceback (most recent call last):
File "C:\Python32\lib\asynchat.py", line 243, in initiate_send
data = buffer(first, 0, obs)
File "C:\Python32\lib\asynchat.py", line 56, in buffer
memoryview(obj)
TypeError: cannot make memory view because object does not have the buffer inter
face
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "D:\Docs\programs\python\hambot\hambot.py", line 11, in main
hb.start()
File "C:\Python32\lib\site-packages\ircutils\client.py", line 271, in start
self.conn.start()
File "C:\Python32\lib\site-packages\ircutils\connection.py", line 115, in star
t
asyncore.loop(map=self._map)
File "C:\Python32\lib\asyncore.py", line 216, in loop
poll_fun(timeout, map)
File "C:\Python32\lib\asyncore.py", line 162, in poll
write(obj)
File "C:\Python32\lib\asyncore.py", line 95, in write
obj.handle_error()
File "C:\Python32\lib\asyncore.py", line 91, in write
obj.handle_write_event()
File "C:\Python32\lib\asyncore.py", line 466, in handle_write_event
self.handle_write()
File "C:\Python32\lib\asynchat.py", line 194, in handle_write
self.initiate_send()
File "C:\Python32\lib\asynchat.py", line 245, in initiate_send
data = first.more()
AttributeError: 'str' object has no attribute 'more'
>>>
このエラー メッセージに関連する StackOverflow には既に 1 つの質問がありますが、受け入れられた回答では、「gevent」というパッケージに関連していると述べられています。これに関係するとは思わない。