我将从文件或其他东西生成正则表达式,并在 @re_botcmd 中需要它
但我收到错误:“未定义”有没有办法定义 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
谢谢~