Skip to content
This repository was archived by the owner on May 3, 2021. It is now read-only.

Commit 830cc1a

Browse files
committed
Bug fix: #6
using deepcopy with the discord.Message object causes an unforseen crash where serialization of the object with pickle by deepcopy causes the method call to crash, which leads to a halt in the async job. This is fixed by moving the only temporary stripping of characters for identifying a callback bind to the method "matches" in the class Callback itself. It resolves the previous bug (5) as well as this resulting bug.
1 parent b702923 commit 830cc1a

2 files changed

Lines changed: 3 additions & 6 deletions

File tree

baseclasses/baseclasses.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
from datetime import datetime, timedelta, time
1111
from enum import Enum, auto
1212
from abc import ABC, abstractmethod
13-
from copy import deepcopy
1413

1514
from ..core.callback import Callback
1615
from ..core.internals import _cim
@@ -161,11 +160,8 @@ def get_callback(self, message: Message) -> Callback:
161160
should be overloaded if a different return behavior
162161
in a no-match-found scenario is desired.
163162
"""
164-
message_copy = deepcopy(message)
165-
message_copy.content = [i.strip(FeatureCommandParserBase.IGNORED_CHARS) for i in message_copy.content]
166-
167163
for cb in self._callbacks:
168-
match = cb.matches(message_copy)
164+
match = cb.matches(Message)
169165
if match: return cb
170166
return None
171167

core/callback.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ class Callback:
3838
(bool) whether the order of items in the
3939
lead or trail property is trivial or not
4040
"""
41+
IGNORED_CHARS = '?=)(/&%¤#"!,.-;:_^*`´><|'
4142

4243
__slots__ = ('_lead', '_trail', '_func', '_bindings',
4344
'_interactive', '_ordered', '_intact_lead',
@@ -90,7 +91,7 @@ def matches(self, message: Message) -> bool:
9091
Bool, True if self matches command
9192
"""
9293
match_trail = False
93-
lowered = [i.lower() for i in message.content]
94+
lowered = [i.lower().strip(Callback.IGNORED_CHARS) for i in message.content]
9495

9596
if not (match_lead := [i for i in self._lead if i in lowered]):
9697
return None

0 commit comments

Comments
 (0)