私はファイルか何かから正規表現を生成し、それが@re_botcmdErrbotダイナミック正規表現
に必要がありますが、私はエラーを取得します:「定義されていません」発見されre_botcmd変数を定義しない方法はありますか?ログファイルから
from errbot import BotPlugin, re_botcmd
from pathlib import Path
import re
class ModHelper(BotPlugin):
"""Help Mods Warning User and kick/ban them"""
def activate(self):
self.my_file = Path("./filter.txt")
if not self.my_file.is_file():
return
self.filter = open('filter.txt', 'r')
for self.tmp in self.filter:
if not self['reg']:
self['reg'] = '(',self.tmp,')'
else:
self['reg'] = self['reg'],'|(',self.tmp,')'
return super().activate()
@re_botcmd(pattern=self['reg'], prefixed=False, flags=re.IGNORECASE)
def test_warn(self, msg, match):
"""Test"""
return "Warn User"
エラー:
Errbot: File "<frozen importlib._bootstrap_external>", line 678, in exec_module
File "<frozen importlib._bootstrap>", line 205, in _call_with_frames_removed
File "/home/errbot/errbot-root/plugins/err-modhelper/modhelper.py", line 5, in <module>
class ModHelper(BotPlugin):
File "/home/errbot/errbot-root/plugins/err-modhelper/modhelper.py", line 23, in ModHelper
@re_botcmd(pattern=self['reg'], prefixed=False, flags=re.IGNORECASE)
NameError: name 'self' is not defined
感謝〜
エラーが発生しました。完全なエラースタックを指定してください。 – Kishan
は、より良い表示のために投稿にエラーを追加しました –
この行に自分をどのように指定できますか? '@re_botcmd(pattern = self ['reg']、prefixed = False、flags = re.IGNORECASE)'できません。 PLZはクラスの__init__メソッドに登録してからself.regを使ってアクセスします – Kishan