回答編集履歴

1

もう一つのファイルについて修正点を追記

2020/04/16 23:31

投稿

teamikl
teamikl

スコア8664

test CHANGED
@@ -75,3 +75,75 @@
75
75
  コードの修正箇所を少なくする為。_send_raw内のを変更しましたが、
76
76
 
77
77
  呼び出し側で追加するか、_send_raw内で追加するか、どちらか片方で良いです。
78
+
79
+
80
+
81
+ ----
82
+
83
+ 追記
84
+
85
+
86
+
87
+ ```python
88
+
89
+
90
+
91
+ from irc import *
92
+
93
+ import os
94
+
95
+ import random
96
+
97
+
98
+
99
+ channel = "#testit"
100
+
101
+ server = "irc.freenode.net"
102
+
103
+ botnick = "reddity"
104
+
105
+
106
+
107
+ irc = IRC()
108
+
109
+ irc.connect(server, channel, botnick)
110
+
111
+
112
+
113
+ while 1:
114
+
115
+ text = irc.get_text().decode("utf-8")
116
+
117
+ print(text)
118
+
119
+
120
+
121
+ if "PRIVMSG" in text and channel in text and "hello" in text:
122
+
123
+ irc.send(channel, "HEllo!")
124
+
125
+
126
+
127
+ ```
128
+
129
+
130
+
131
+ 変更点:
132
+
133
+ `text = irc.get_text().decode("utf-8")`
134
+
135
+
136
+
137
+ text がバイト型の場合
138
+
139
+
140
+
141
+ - b"PRIVMSG" in text
142
+
143
+ - b"hello" in text
144
+
145
+ - とできますが、 `channel in text` の channel は 文字列なので変換が必要
146
+
147
+ 但し、irc.send は文字列を要求されるので。元のtextを文字列に変換するようにしました。
148
+
149
+ エンコードは固定で utf-8 としてます。