Просмотр исходного кода

Bang commands ignore suffixes after the command name to allow tagging users or other commentary

tags/2.0.0
Rocketsoup 1 месяц назад
Родитель
Сommit
60b6c0224c
1 измененных файлов: 9 добавлений и 4 удалений
  1. 9
    4
      rocketbot/cogs/bangcommandcog.py

+ 9
- 4
rocketbot/cogs/bangcommandcog.py Просмотреть файл

@@ -238,9 +238,9 @@ class BangCommandCog(BaseCog, name='Bang Commands'):
238 238
 		if message.guild is None or message.channel is None or not isinstance(message.channel, TextChannel):
239 239
 			return
240 240
 		content = message.content
241
-		if content is None or not content.startswith('!') or not BangCommandCog._is_valid_name(content):
241
+		name = BangCommandCog._name_from_command_message(content)
242
+		if name is None:
242 243
 			return
243
-		name = BangCommandCog._normalize_name(content)
244 244
 		cmd = self.get_saved_command(message.guild, name)
245 245
 		if cmd is None:
246 246
 			return
@@ -261,9 +261,14 @@ class BangCommandCog(BaseCog, name='Bang Commands'):
261 261
 
262 262
 	@staticmethod
263 263
 	def _is_valid_name(name: Optional[str]) -> bool:
264
+		return name is not None and re.match(r'^!?([a-z]+)([_-][a-z]+)*$', name) is not None
265
+
266
+	@staticmethod
267
+	def _name_from_command_message(name: Optional[str]) -> Optional[str]:
264 268
 		if name is None:
265
-			return False
266
-		return re.match(r'^!?([a-z]+)([_-][a-z]+)*$', name) is not None
269
+			return None
270
+		match = re.match(r'^!?((?:[a-z]+)(?:[_-][a-z]+)*)\b.*$', name)
271
+		return BangCommandCog._normalize_name(match.group(1)) if match else None
267 272
 
268 273
 class _EditModal(Modal, title='Edit Command'):
269 274
 	name_label = Label(

Загрузка…
Отмена
Сохранить