소스 검색

Doc tweaks

tags/1.0.2
Rocketsoup 4 년 전
부모
커밋
f96ee6284d
2개의 변경된 파일51개의 추가작업 그리고 13개의 파일을 삭제
  1. 11
    9
      cogs/patterncog.py
  2. 40
    4
      patterns.md

+ 11
- 9
cogs/patterncog.py 파일 보기

@@ -136,10 +136,10 @@ class PatternCog(BaseCog):
136 136
 	# 	return patterns
137 137
 
138 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 140
 		if patterns is None:
141 141
 			patterns = {}
142
-			patterns_encoded = Storage.get_config_value(guild, 'PatternsCog.patterns')
142
+			patterns_encoded = Storage.get_config_value(guild, 'PatternCog.patterns')
143 143
 			if patterns_encoded:
144 144
 				for pe in patterns_encoded:
145 145
 					name = pe.get('name')
@@ -149,7 +149,7 @@ class PatternCog(BaseCog):
149 149
 						patterns[name] = ps
150 150
 					except RuntimeError as e:
151 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 153
 		return patterns
154 154
 
155 155
 	def __save_patterns(self, guild: Guild, patterns: dict) -> None:
@@ -159,7 +159,7 @@ class PatternCog(BaseCog):
159 159
 				'name': name,
160 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 164
 	@commands.Cog.listener()
165 165
 	async def on_message(self, message: Message) -> None:
@@ -258,14 +258,16 @@ class PatternCog(BaseCog):
258 258
 	)
259 259
 	@commands.has_permissions(ban_members=True)
260 260
 	@commands.guild_only()
261
-	async def patterns(self, context: commands.Context):
261
+	async def pattern(self, context: commands.Context):
262 262
 		'Message pattern matching'
263 263
 		if context.invoked_subcommand is None:
264 264
 			await context.send_help()
265 265
 
266
-	@patterns.command(
266
+	@pattern.command(
267 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 271
 		usage='<pattern_name> <expression...>',
270 272
 		ignore_extra=True
271 273
 	)
@@ -284,7 +286,7 @@ class PatternCog(BaseCog):
284 286
 				f'{CONFIG["failure_emoji"]} Error parsing statement. {e}',
285 287
 				mention_author=False)
286 288
 
287
-	@patterns.command(
289
+	@pattern.command(
288 290
 		brief='Removes a custom pattern',
289 291
 		usage='<pattern_name>'
290 292
 	)
@@ -301,7 +303,7 @@ class PatternCog(BaseCog):
301 303
 				f'{CONFIG["failure_emoji"]} No pattern named `{name}`.',
302 304
 				mention_author=False)
303 305
 
304
-	@patterns.command(
306
+	@pattern.command(
305 307
 		brief='Lists all patterns'
306 308
 	)
307 309
 	async def list(self, context: commands.Context) -> None:

+ 40
- 4
patterns.md 파일 보기

@@ -2,18 +2,32 @@
2 2
 
3 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 9
 The pattern `<name>` can be anything. If it contains spaces, enclose it in double quotes, e.g. `"my filter"`.
10 10
 
11 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 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 31
 Available actions:
18 32
 
19 33
 * `ban` - Bans the user. The "reason" in the audit log will reference the pattern name.
@@ -91,6 +105,28 @@ Lastly, expressions can be inverted by prefixing a `!`. For example:
91 105
 
92 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 130
 ## Grammar
95 131
 
96 132
 `<statement>` ::= `<actions>` " if " `<expression>`

Loading…
취소
저장