I will generate the regex from a file or something and need it in the @re_botcmd
but i get the error: "not defined" is there a way do define a variable that re_botcmd is finding?
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"
Error from Log file:
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
Thanks ~
I had a similar problem when recognizing mentions of Jira issues in chat; the recognizer needed to know the list of Jira projects. I solved it by getting that list at compile time in a small utility class and then having the recognizer pick up the list at run time: