Przeglądaj źródła

Doc tweaks

tags/1.0.2
Rocketsoup 4 lat temu
rodzic
commit
f96ee6284d
2 zmienionych plików z 51 dodań i 13 usunięć
  1. 11
    9
      cogs/patterncog.py
  2. 40
    4
      patterns.md

+ 11
- 9
cogs/patterncog.py Wyświetl plik

136
 	# 	return patterns
136
 	# 	return patterns
137
 
137
 
138
 	def __get_patterns(self, guild: Guild) -> dict:
138
 	def __get_patterns(self, guild: Guild) -> dict:
139
-		patterns = Storage.get_state_value(guild, 'PatternsCog.patterns')
139
+		patterns = Storage.get_state_value(guild, 'PatternCog.patterns')
140
 		if patterns is None:
140
 		if patterns is None:
141
 			patterns = {}
141
 			patterns = {}
142
-			patterns_encoded = Storage.get_config_value(guild, 'PatternsCog.patterns')
142
+			patterns_encoded = Storage.get_config_value(guild, 'PatternCog.patterns')
143
 			if patterns_encoded:
143
 			if patterns_encoded:
144
 				for pe in patterns_encoded:
144
 				for pe in patterns_encoded:
145
 					name = pe.get('name')
145
 					name = pe.get('name')
149
 						patterns[name] = ps
149
 						patterns[name] = ps
150
 					except RuntimeError as e:
150
 					except RuntimeError as e:
151
 						self.log(guild, f'Error parsing saved statement "{name}". Skipping: {statement}')
151
 						self.log(guild, f'Error parsing saved statement "{name}". Skipping: {statement}')
152
-			Storage.set_state_value(guild, 'PatternsCog.patterns', patterns)
152
+			Storage.set_state_value(guild, 'PatternCog.patterns', patterns)
153
 		return patterns
153
 		return patterns
154
 
154
 
155
 	def __save_patterns(self, guild: Guild, patterns: dict) -> None:
155
 	def __save_patterns(self, guild: Guild, patterns: dict) -> None:
159
 				'name': name,
159
 				'name': name,
160
 				'statement': statement.original,
160
 				'statement': statement.original,
161
 			})
161
 			})
162
-		Storage.set_config_value(guild, 'PatternsCog.patterns', to_save)
162
+		Storage.set_config_value(guild, 'PatternCog.patterns', to_save)
163
 
163
 
164
 	@commands.Cog.listener()
164
 	@commands.Cog.listener()
165
 	async def on_message(self, message: Message) -> None:
165
 	async def on_message(self, message: Message) -> None:
258
 	)
258
 	)
259
 	@commands.has_permissions(ban_members=True)
259
 	@commands.has_permissions(ban_members=True)
260
 	@commands.guild_only()
260
 	@commands.guild_only()
261
-	async def patterns(self, context: commands.Context):
261
+	async def pattern(self, context: commands.Context):
262
 		'Message pattern matching'
262
 		'Message pattern matching'
263
 		if context.invoked_subcommand is None:
263
 		if context.invoked_subcommand is None:
264
 			await context.send_help()
264
 			await context.send_help()
265
 
265
 
266
-	@patterns.command(
266
+	@pattern.command(
267
 		brief='Adds a custom pattern',
267
 		brief='Adds a custom pattern',
268
-		description='Adds a custom pattern. Patterns use a simplified expression language. Full documentation found here: https://git.rixafrix.com/ialbert/python-app-rocketbot/src/branch/master/patterns.md',
268
+		description='Adds a custom pattern. Patterns use a simplified ' + \
269
+			'expression language. Full documentation found here: ' + \
270
+			'https://git.rixafrix.com/ialbert/python-app-rocketbot/src/branch/master/patterns.md',
269
 		usage='<pattern_name> <expression...>',
271
 		usage='<pattern_name> <expression...>',
270
 		ignore_extra=True
272
 		ignore_extra=True
271
 	)
273
 	)
284
 				f'{CONFIG["failure_emoji"]} Error parsing statement. {e}',
286
 				f'{CONFIG["failure_emoji"]} Error parsing statement. {e}',
285
 				mention_author=False)
287
 				mention_author=False)
286
 
288
 
287
-	@patterns.command(
289
+	@pattern.command(
288
 		brief='Removes a custom pattern',
290
 		brief='Removes a custom pattern',
289
 		usage='<pattern_name>'
291
 		usage='<pattern_name>'
290
 	)
292
 	)
301
 				f'{CONFIG["failure_emoji"]} No pattern named `{name}`.',
303
 				f'{CONFIG["failure_emoji"]} No pattern named `{name}`.',
302
 				mention_author=False)
304
 				mention_author=False)
303
 
305
 
304
-	@patterns.command(
306
+	@pattern.command(
305
 		brief='Lists all patterns'
307
 		brief='Lists all patterns'
306
 	)
308
 	)
307
 	async def list(self, context: commands.Context) -> None:
309
 	async def list(self, context: commands.Context) -> None:

+ 40
- 4
patterns.md Wyświetl plik

2
 
2
 
3
 The PatternCog offers a way of creating custom message filters of moderate complexity without needing to make code changes in the bot and redeploy it. A guild can have any number of custom patterns. The commands are:
3
 The PatternCog offers a way of creating custom message filters of moderate complexity without needing to make code changes in the bot and redeploy it. A guild can have any number of custom patterns. The commands are:
4
 
4
 
5
-`$rb_patterns add <name> <statement>` - Add a new named pattern
6
-`$rb_patterns remove <name>` - Remove a named pattern
7
-`$rb_patterns list` - List all named patterns
5
+* `$rb_pattern add <name> <statement>` - Add a new named pattern
6
+* `$rb_pattern remove <name>` - Remove a named pattern
7
+* `$rb_pattern list` - List all named patterns
8
 
8
 
9
 The pattern `<name>` can be anything. If it contains spaces, enclose it in double quotes, e.g. `"my filter"`.
9
 The pattern `<name>` can be anything. If it contains spaces, enclose it in double quotes, e.g. `"my filter"`.
10
 
10
 
11
 ## Statements
11
 ## Statements
12
 
12
 
13
-A statement consists of one or more actions to take on a message followed by an expression defining the criteria for which messages match.
13
+A statement consists of one or more actions to take on a message followed by an expression defining the criteria for which messages match. For example:
14
+
15
+```
16
+reply "You can't say that word!", delete if message contains "heck"
17
+```
18
+
19
+This statement has two actions: replying, then deleting the original message. It will match any word that contains the word "heck".
20
+
21
+The list of actions and the matching expression are separated by the word "if", which must be present in every statement.
14
 
22
 
15
 ### Actions
23
 ### Actions
16
 
24
 
25
+One or more actions can be added to the statement. If there is more than one, they are separated with commas. Example:
26
+
27
+```
28
+delete, kick, modwarn
29
+```
30
+
17
 Available actions:
31
 Available actions:
18
 
32
 
19
 * `ban` - Bans the user. The "reason" in the audit log will reference the pattern name.
33
 * `ban` - Bans the user. The "reason" in the audit log will reference the pattern name.
91
 
105
 
92
 This will only match messages that do not contain both "me" and "you". If it contains just "me" or just "you" or neither word then it will match. If both are present it will not match.
106
 This will only match messages that do not contain both "me" and "you". If it contains just "me" or just "you" or neither word then it will match. If both are present it will not match.
93
 
107
 
108
+## Examples
109
+
110
+Here are examples of `add` commands:
111
+
112
+Automatically delete a banned word:
113
+
114
+```
115
+$rb_pattern add "bad word" delete if content contains "darn"
116
+```
117
+
118
+Ban anyone who posts a URL within the first 30 minutes of joining the server.
119
+
120
+```
121
+$rb_pattern add "url spam" ban if author.joinage < 30m and (content contains "http://" or content contains "https://")
122
+```
123
+
124
+Automatically reply to anyone asking when lunch is.
125
+
126
+```
127
+$rb_pattern add "lunch" reply "Lunch is at noon." if content == "When is lunch?"
128
+```
129
+
94
 ## Grammar
130
 ## Grammar
95
 
131
 
96
 `<statement>` ::= `<actions>` " if " `<expression>`
132
 `<statement>` ::= `<actions>` " if " `<expression>`

Ładowanie…
Anuluj
Zapisz