Skip to content

Commit 8a3bc9a

Browse files
committed
Implement better variable response matching
With more time to consider, I realized I can do this a much better way.
1 parent b3a4574 commit 8a3bc9a

File tree

2 files changed

+4
-6
lines changed

2 files changed

+4
-6
lines changed

bot/exts/smart_eval/_cog.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -129,11 +129,11 @@ async def smart_eval(self, ctx: commands.Context, *, code: str) -> None:
129129
match = re.search(pattern, code)
130130
if match:
131131
for response in responses:
132-
try:
133-
matching_responses.append(response.format(match.group("content")))
134-
except IndexError:
132+
matches = match.groups()
133+
if len(matches) > 0:
134+
matching_responses.append(response.format(*matches))
135+
else:
135136
matching_responses.append(response)
136-
137137
if not matching_responses:
138138
matching_responses = DEFAULT_RESPONSES
139139
final_response = random.choice(matching_responses)

bot/exts/smart_eval/_smart_eval_rules.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
from bot.exts.miscellaneous import ZEN_OF_PYTHON
22

3-
# If you want to capture something that will be used in the response, capture it with a named group called "content"
4-
53
RULES = {
64
r"(?i:ignore all previous instructions)": [ # Ignoring previous instructions capture
75
"Excuse you, you really think I follow any instructions?",

0 commit comments

Comments
 (0)