Browse Source

Adding syntax cheat sheet to pattern

pull/13/head
Rocketsoup 2 months ago
parent
commit
e5716dce5a
1 changed files with 32 additions and 8 deletions
  1. 32
    8
      rocketbot/cogs/patterncog.py

+ 32
- 8
rocketbot/cogs/patterncog.py View File

6
 from datetime import datetime
6
 from datetime import datetime
7
 from typing import Optional
7
 from typing import Optional
8
 
8
 
9
-from discord import Guild, Member, Message, utils as discordutils, Permissions, Interaction
10
-from discord.app_commands import Choice, Group, autocomplete, rename
9
+from discord import Guild, Member, Message, utils as discordutils, Interaction
10
+from discord.app_commands import Choice, Group, autocomplete
11
 from discord.ext.commands import Cog
11
 from discord.ext.commands import Cog
12
 
12
 
13
 from config import CONFIG
13
 from config import CONFIG
85
 		Choice(name='very high (150)', value=150),
85
 		Choice(name='very high (150)', value=150),
86
 	]
86
 	]
87
 
87
 
88
+_long_help = \
89
+"""Patterns are a powerful but complex topic. See <https://git.rixafrix.com/ialbert/python-app-rocketbot/src/branch/main/docs/patterns.md> for full documentation.
90
+
91
+### Quick cheat sheet
92
+
93
+> `/pattern add` _pattern\\_name_ _action\\_list_ `if` _expression_
94
+
95
+- _pattern\\_name_ is a brief name for identifying the pattern later (not shown to user)
96
+- _action\\_list_ is a comma-delimited list of actions to take on matching messages and is any of:
97
+   - `ban`
98
+   - `delete`
99
+   - `kick`
100
+   - `modinfo` - logs a message but doesn't tag mods
101
+   - `modwarn` - tags mods
102
+   - `reply` "message text"
103
+- _expression_ determines which messages match, of the form _field_ _op_ _value_.
104
+   - Fields:
105
+      - `content.markdown`: string
106
+      - `content.plain`: string
107
+      - `author`: user
108
+      - `author.id`: id
109
+      - `author.joinage`: timespan
110
+      - `author.name`: string
111
+      - `lastmatched`: timespan
112
+   - Operators: `==`, `!=`, `<`, `>`, `<=`, `>=`, `contains`, `!contains`, `matches`, `!matches`, `containsword`, `!containsword`
113
+   - Can combine multiple expressions with `!`, `and`, `or`, and parentheses."""
114
+
88
 class PatternCog(BaseCog, name='Pattern Matching'):
115
 class PatternCog(BaseCog, name='Pattern Matching'):
89
 	"""
116
 	"""
90
 	Highly flexible cog for performing various actions on messages that match
117
 	Highly flexible cog for performing various actions on messages that match
100
 			bot,
127
 			bot,
101
 			config_prefix='patterns',
128
 			config_prefix='patterns',
102
 			short_description='Manages message pattern matching.',
129
 			short_description='Manages message pattern matching.',
103
-			long_description='Patterns are a powerful but complex topic. See <https://git.rixafrix.com/ialbert/python-app-rocketbot/src/branch/main/docs/patterns.md> for full documentation.'
130
+			long_description=_long_help
104
 		)
131
 		)
105
 		PatternCog.shared = self
132
 		PatternCog.shared = self
106
 
133
 
264
 		guild_only=True,
291
 		guild_only=True,
265
 		default_permissions=MOD_PERMISSIONS,
292
 		default_permissions=MOD_PERMISSIONS,
266
 		extras={
293
 		extras={
267
-			'long_description': 'Patterns are a powerful but complex topic. '
268
-								'See <https://git.rixafrix.com/ialbert/python-app-rocketbot/src/branch/main/docs/patterns.md> for full documentation.'
294
+			'long_description': _long_help,
269
 		},
295
 		},
270
 	)
296
 	)
271
 
297
 
272
 	@pattern.command(
298
 	@pattern.command(
273
 		description='Adds or updates a custom pattern.',
299
 		description='Adds or updates a custom pattern.',
274
 		extras={
300
 		extras={
275
-			'long_description': 'Patterns use a simplified expression language. Full '
276
-								'documentation found here: '
277
-								'<https://git.rixafrix.com/ialbert/python-app-rocketbot/src/branch/main/docs/patterns.md>',
301
+			'long_description': _long_help,
278
 		},
302
 		},
279
 	)
303
 	)
280
 	@autocomplete(
304
 	@autocomplete(

Loading…
Cancel
Save