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

Better config.py organization for cog defaults. All emoji come from config.

tags/1.0.1
Rocketsoup 4 лет назад
Родитель
Сommit
76d6ebcfd2
7 измененных файлов: 133 добавлений и 76 удалений
  1. 12
    0
      cogs/basecog.py
  2. 9
    7
      cogs/configcog.py
  3. 61
    38
      cogs/crosspostcog.py
  4. 26
    19
      cogs/joinraidcog.py
  5. 22
    9
      config.py.sample
  6. 2
    2
      rocketbot.py
  7. 1
    1
      storage.py

+ 12
- 0
cogs/basecog.py Просмотреть файл

11
 		self.bot = bot
11
 		self.bot = bot
12
 		self.listened_mod_react_message_ids = AgeBoundDict(timedelta(minutes=5), lambda message_id, tpl : tpl[0])
12
 		self.listened_mod_react_message_ids = AgeBoundDict(timedelta(minutes=5), lambda message_id, tpl : tpl[0])
13
 
13
 
14
+	@classmethod
15
+	def get_cog_default(cls, key: str):
16
+		"""
17
+		Convenience method for getting a cog configuration default from
18
+		`CONFIG['cogs'][<cogname>][<key>]`.
19
+		"""
20
+		cogs: dict = CONFIG['cog_defaults']
21
+		cog = cogs.get(cls.__name__)
22
+		if cog is None:
23
+			return None
24
+		return cog.get(key)
25
+
14
 	def listen_for_reactions_to(self, message: Message, context = None) -> None:
26
 	def listen_for_reactions_to(self, message: Message, context = None) -> None:
15
 		"""
27
 		"""
16
 		Registers a warning message as something a mod may react to to enact
28
 		Registers a warning message as something a mod may react to to enact

+ 9
- 7
cogs/configcog.py Просмотреть файл

1
 from discord import Guild, TextChannel
1
 from discord import Guild, TextChannel
2
 from discord.ext import commands
2
 from discord.ext import commands
3
+
4
+from config import CONFIG
3
 from storage import ConfigKey, Storage
5
 from storage import ConfigKey, Storage
4
 from cogs.basecog import BaseCog
6
 from cogs.basecog import BaseCog
5
 
7
 
35
 		Storage.set_config_value(guild, ConfigKey.WARNING_CHANNEL_ID,
37
 		Storage.set_config_value(guild, ConfigKey.WARNING_CHANNEL_ID,
36
 			context.channel.id)
38
 			context.channel.id)
37
 		await context.message.reply(
39
 		await context.message.reply(
38
-			f'Warning channel updated to {channel.mention}.',
40
+			f'{CONFIG["success_emoji"]} Warning channel updated to {channel.mention}.',
39
 			mention_author=False)
41
 			mention_author=False)
40
 
42
 
41
 	@config.command(
43
 	@config.command(
48
 		channel_id = Storage.get_config_value(guild, ConfigKey.WARNING_CHANNEL_ID)
50
 		channel_id = Storage.get_config_value(guild, ConfigKey.WARNING_CHANNEL_ID)
49
 		if channel_id is None:
51
 		if channel_id is None:
50
 			await context.message.reply(
52
 			await context.message.reply(
51
-				'No warning channel is configured.',
53
+				f'{CONFIG["info_emoji"]} No warning channel is configured.',
52
 				mention_author=False)
54
 				mention_author=False)
53
 		else:
55
 		else:
54
 			channel = guild.get_channel(channel_id)
56
 			channel = guild.get_channel(channel_id)
55
 			await context.message.reply(
57
 			await context.message.reply(
56
-				f'Warning channel is configured as {channel.mention}.',
58
+				f'{CONFIG["info_emoji"]} Warning channel is configured as {channel.mention}.',
57
 				mention_author=False)
59
 				mention_author=False)
58
 
60
 
59
 	@config.command(
61
 	@config.command(
70
 		Storage.set_config_value(guild, ConfigKey.WARNING_MENTION, mention)
72
 		Storage.set_config_value(guild, ConfigKey.WARNING_MENTION, mention)
71
 		if mention is None:
73
 		if mention is None:
72
 			await context.message.reply(
74
 			await context.message.reply(
73
-				'Warning messages will not tag anyone.',
75
+				f'{CONFIG["success_emoji"]} Warning messages will not tag anyone.',
74
 				mention_author=False)
76
 				mention_author=False)
75
 		else:
77
 		else:
76
 			await context.message.reply(
78
 			await context.message.reply(
77
-				f'Warning messages will now tag {mention}.',
79
+				f'{CONFIG["success_emoji"]} Warning messages will now tag {mention}.',
78
 				mention_author=False)
80
 				mention_author=False)
79
 
81
 
80
 	@config.command(
82
 	@config.command(
88
 		mention: str = Storage.get_config_value(guild, ConfigKey.WARNING_MENTION)
90
 		mention: str = Storage.get_config_value(guild, ConfigKey.WARNING_MENTION)
89
 		if mention is None:
91
 		if mention is None:
90
 			await context.message.reply(
92
 			await context.message.reply(
91
-				'No warning mention configured.',
93
+				f'{CONFIG["info_emoji"]} No warning mention configured.',
92
 				mention_author=False)
94
 				mention_author=False)
93
 		else:
95
 		else:
94
 			await context.message.reply(
96
 			await context.message.reply(
95
-				f'Warning messages will tag {mention}',
97
+				f'{CONFIG["info_emoji"]} Warning messages will tag {mention}',
96
 				mention_author=False)
98
 				mention_author=False)

+ 61
- 38
cogs/crosspostcog.py Просмотреть файл

3
 from datetime import datetime, timedelta
3
 from datetime import datetime, timedelta
4
 import math
4
 import math
5
 
5
 
6
+from config import CONFIG
6
 from rscollections import AgeBoundList, SizeBoundDict
7
 from rscollections import AgeBoundList, SizeBoundDict
7
 from cogs.basecog import BaseCog
8
 from cogs.basecog import BaseCog
8
 from storage import Storage
9
 from storage import Storage
39
 	# Config
40
 	# Config
40
 
41
 
41
 	def __warn_count(self, guild: Guild) -> int:
42
 	def __warn_count(self, guild: Guild) -> int:
42
-		return Storage.get_config_value(guild, self.CONFIG_KEY_WARN_COUNT) or 3
43
+		return Storage.get_config_value(guild, self.CONFIG_KEY_WARN_COUNT) or \
44
+			self.get_cog_default('warn_message_count')
43
 
45
 
44
 	def __ban_count(self, guild: Guild) -> int:
46
 	def __ban_count(self, guild: Guild) -> int:
45
-		return Storage.get_config_value(guild, self.CONFIG_KEY_BAN_COUNT) or 9999
47
+		return Storage.get_config_value(guild, self.CONFIG_KEY_BAN_COUNT) or \
48
+			self.get_cog_default('ban_message_count')
46
 
49
 
47
 	def __min_message_length(self, guild: Guild) -> int:
50
 	def __min_message_length(self, guild: Guild) -> int:
48
-		return Storage.get_config_value(guild, self.CONFIG_KEY_MIN_MESSAGE_LENGTH) or 0
51
+		return Storage.get_config_value(guild, self.CONFIG_KEY_MIN_MESSAGE_LENGTH) or \
52
+			self.get_cog_default('min_message_length')
49
 
53
 
50
 	def __message_age_seconds(self, guild: Guild) -> int:
54
 	def __message_age_seconds(self, guild: Guild) -> int:
51
-		return Storage.get_config_value(guild, self.CONFIG_KEY_MESSAGE_AGE) or 120
55
+		return Storage.get_config_value(guild, self.CONFIG_KEY_MESSAGE_AGE) or \
56
+			self.get_cog_default('time_window_seconds')
52
 
57
 
53
 	async def __record_message(self, message: Message) -> None:
58
 	async def __record_message(self, message: Message) -> None:
54
 		if message.author.permissions_in(message.channel).ban_members:
59
 		if message.author.permissions_in(message.channel).ban_members:
109
 					f'> {content}'
114
 					f'> {content}'
110
 				if context.warning_message:
115
 				if context.warning_message:
111
 					await self.update_warn(context.warning_message, msg)
116
 					await self.update_warn(context.warning_message, msg)
112
-					await context.warning_message.clear_reaction('🗑')
113
-					await context.warning_message.clear_reaction('👢')
114
-					await context.warning_message.clear_reaction('🚫')
117
+					await context.warning_message.clear_reaction(CONFIG['trash_emoji'])
118
+					await context.warning_message.clear_reaction(CONFIG['kick_emoji'])
119
+					await context.warning_message.clear_reaction(CONFIG['ban_emoji'])
115
 				else:
120
 				else:
116
 					context.warning_message = await self.warn(context.member.guild, msg)
121
 					context.warning_message = await self.warn(context.member.guild, msg)
117
 		elif len(context.messages) >= self.__warn_count(context.member.guild):
122
 		elif len(context.messages) >= self.__warn_count(context.member.guild):
122
 				'\n'
127
 				'\n'
123
 			can_delete = len(context.messages) > len(context.deleted_messages)
128
 			can_delete = len(context.messages) > len(context.deleted_messages)
124
 			if can_delete:
129
 			if can_delete:
125
-				msg += '\n🗑 to delete messages'
130
+				msg += f'\n{CONFIG["trash_emoji"]} to delete messages'
126
 			else:
131
 			else:
127
 				msg += '\nAll messages deleted'
132
 				msg += '\nAll messages deleted'
128
 			if not context.is_kicked:
133
 			if not context.is_kicked:
129
-				msg += '\n👢 to kick user'
134
+				msg += f'\n{CONFIG["kick_emoji"]} to kick user'
130
 			elif not context.is_banned:
135
 			elif not context.is_banned:
131
 				msg += '\nUser kicked'
136
 				msg += '\nUser kicked'
132
 			if context.is_banned:
137
 			if context.is_banned:
133
 				msg += '\nUser banned'
138
 				msg += '\nUser banned'
134
 			else:
139
 			else:
135
-				msg += '\n🚫 to ban user'
140
+				msg += '\n{CONFIG["ban_emoji"]} to ban user'
136
 			if context.warning_message:
141
 			if context.warning_message:
137
 				await self.update_warn(context.warning_message, msg)
142
 				await self.update_warn(context.warning_message, msg)
138
 			else:
143
 			else:
139
 				context.warning_message = await self.warn(context.member.guild, msg)
144
 				context.warning_message = await self.warn(context.member.guild, msg)
140
 				self.listen_for_reactions_to(context.warning_message, context)
145
 				self.listen_for_reactions_to(context.warning_message, context)
141
 			if can_delete:
146
 			if can_delete:
142
-				await context.warning_message.add_reaction('🗑')
147
+				await context.warning_message.add_reaction(CONFIG['trash_emoji'])
143
 			else:
148
 			else:
144
-				await context.warning_message.clear_reaction('🗑')
149
+				await context.warning_message.clear_reaction(CONFIG['trash_emoji'])
145
 			if not context.is_kicked:
150
 			if not context.is_kicked:
146
-				await context.warning_message.add_reaction('👢')
151
+				await context.warning_message.add_reaction(CONFIG['kick_emoji'])
147
 			else:
152
 			else:
148
-				await context.warning_message.clear_reaction('👢')
153
+				await context.warning_message.clear_reaction(CONFIG['kick_emoji'])
149
 			if not context.is_banned:
154
 			if not context.is_banned:
150
-				await context.warning_message.add_reaction('🚫')
155
+				await context.warning_message.add_reaction(CONFIG['ban_emoji'])
151
 			else:
156
 			else:
152
-				await context.warning_message.clear_reaction('🚫')
157
+				await context.warning_message.clear_reaction(CONFIG['ban_emoji'])
153
 
158
 
154
 	async def __delete_messages(self, context: SpamContext) -> None:
159
 	async def __delete_messages(self, context: SpamContext) -> None:
155
 		for message in context.messages - context.deleted_messages:
160
 		for message in context.messages - context.deleted_messages:
173
 		if context is None:
178
 		if context is None:
174
 			return
179
 			return
175
 
180
 
176
-		if emoji.name == '🗑':
181
+		if emoji.name == CONFIG['trash_emoji']:
177
 			await self.__delete_messages(context)
182
 			await self.__delete_messages(context)
178
-		elif emoji.name == '👢':
183
+		elif emoji.name == CONFIG['kick_emoji']:
179
 			await self.__kick(context)
184
 			await self.__kick(context)
180
-		elif emoji.name == '🚫':
185
+		elif emoji.name == CONFIG['ban_emoji']:
181
 			await self.__ban(context)
186
 			await self.__ban(context)
182
 
187
 
183
 	@commands.Cog.listener()
188
 	@commands.Cog.listener()
210
 			allowed_types=(int, ), min_value=self.MIN_WARN_COUNT):
215
 			allowed_types=(int, ), min_value=self.MIN_WARN_COUNT):
211
 			return
216
 			return
212
 		Storage.set_config_value(context.guild, self.CONFIG_KEY_WARN_COUNT, warn_count)
217
 		Storage.set_config_value(context.guild, self.CONFIG_KEY_WARN_COUNT, warn_count)
213
-		await context.message.reply(f'✅ Mods will be warned if a user posts ' +
214
-			f'the exact same message {warn_count} or more times within ' +
218
+		await context.message.reply(
219
+			CONFIG['success_emoji'] + ' ' +
220
+			'Mods will be warned if a user posts the exact same message ' +
221
+			f'{warn_count} or more times within ' +
215
 			f'{self.__message_age_seconds(context.guild)} seconds.',
222
 			f'{self.__message_age_seconds(context.guild)} seconds.',
216
 			mention_author=False)
223
 			mention_author=False)
217
 
224
 
239
 			allowed_types=(int, ), min_value=self.MIN_BAN_COUNT):
246
 			allowed_types=(int, ), min_value=self.MIN_BAN_COUNT):
240
 			return
247
 			return
241
 		Storage.set_config_value(context.guild, self.CONFIG_KEY_BAN_COUNT, ban_count)
248
 		Storage.set_config_value(context.guild, self.CONFIG_KEY_BAN_COUNT, ban_count)
242
-		await context.message.reply(f'✅ Users will be banned if they post ' +
243
-			f'the exact same message {ban_count} or more times within ' +
249
+		await context.message.reply(
250
+			CONFIG['success_emoji'] + ' ' +
251
+			'Users will be banned if they post the exact same message ' +
252
+			f'{ban_count} or more times within ' +
244
 			f'{self.__message_age_seconds(context.guild)} seconds.',
253
 			f'{self.__message_age_seconds(context.guild)} seconds.',
245
 			mention_author=False)
254
 			mention_author=False)
246
 
255
 
249
 		brief='Returns the number of duplicate messages to trigger an automatic ban',
258
 		brief='Returns the number of duplicate messages to trigger an automatic ban',
250
 	)
259
 	)
251
 	async def joinraid_getbancount(self, context: commands.Context):
260
 	async def joinraid_getbancount(self, context: commands.Context):
252
-		await context.message.reply(f'ℹ️ Users will be banned if they post ' +
253
-			f'the exact same message {self.__ban_count(context.guild)} or more ' +
254
-			f'times within {self.__message_age_seconds(context.guild)} seconds.',
261
+		await context.message.reply(
262
+			CONFIG['info_emoji'] + ' ' +
263
+			'Users will be banned if they post the exact same message ' +
264
+			f'{self.__ban_count(context.guild)} or more times within ' +
265
+			f'{self.__message_age_seconds(context.guild)} seconds.',
255
 			mention_author=False)
266
 			mention_author=False)
256
 
267
 
257
 	@crosspost.command(
268
 	@crosspost.command(
269
 			return
280
 			return
270
 		Storage.set_config_value(context.guild, self.CONFIG_KEY_MIN_MESSAGE_LENGTH, min_length)
281
 		Storage.set_config_value(context.guild, self.CONFIG_KEY_MIN_MESSAGE_LENGTH, min_length)
271
 		if min_length == 0:
282
 		if min_length == 0:
272
-			await context.message.reply(f'✅ All messages will count against ' +
273
-				'spam counts, regardless of length.', mention_author=False)
283
+			await context.message.reply(
284
+				CONFIG['success_emoji'] + ' ' +
285
+				f'All messages will count against spam counts, regardless ' +
286
+				'of length.', mention_author=False)
274
 		else:
287
 		else:
275
-			await context.message.reply(f'✅ Only messages {min_length} ' +
276
-				f'characters or longer will count against spam counts.',
288
+			await context.message.reply(
289
+				CONFIG['success_emoji'] + ' ' +
290
+				f'Only messages {min_length} characters or longer will ' +
291
+				'count against spam counts.',
277
 				mention_author=False)
292
 				mention_author=False)
278
 
293
 
279
 	@crosspost.command(
294
 	@crosspost.command(
283
 	async def joinraid_getminlength(self, context: commands.Context):
298
 	async def joinraid_getminlength(self, context: commands.Context):
284
 		min_length = self.__min_message_length(context.guild)
299
 		min_length = self.__min_message_length(context.guild)
285
 		if min_length == 0:
300
 		if min_length == 0:
286
-			await context.message.reply(f'ℹ️ All messages will count against ' +
287
-				'spam counts, regardless of length.', mention_author=False)
301
+			await context.message.reply(
302
+				CONFIG['info_emoji'] + ' ' +
303
+				f'All messages will count against spam counts, regardless ' +
304
+				'of length.', mention_author=False)
288
 		else:
305
 		else:
289
-			await context.message.reply(f'ℹ️ Only messages {min_length} ' +
290
-				f'characters or longer will count against spam counts.',
306
+			await context.message.reply(
307
+				CONFIG['info_emoji'] + ' ' +
308
+				f'Only messages {min_length} characters or longer will ' +
309
+				'count against spam counts.',
291
 				mention_author=False)
310
 				mention_author=False)
292
 
311
 
293
 	@crosspost.command(
312
 	@crosspost.command(
304
 			allowed_types=(int, ), min_value=self.MIN_TIME_SPAN):
323
 			allowed_types=(int, ), min_value=self.MIN_TIME_SPAN):
305
 			return
324
 			return
306
 		Storage.set_config_value(context.guild, self.CONFIG_KEY_MESSAGE_AGE, seconds)
325
 		Storage.set_config_value(context.guild, self.CONFIG_KEY_MESSAGE_AGE, seconds)
307
-		await context.message.reply(f'✅ Only messages in the past {seconds} ' +
308
-			f'seconds will be checked for duplicates.',
326
+		await context.message.reply(
327
+			CONFIG['success_emoji'] + ' ' +
328
+			f'Only messages in the past {seconds} seconds will be checked ' +
329
+			'for duplicates.',
309
 			mention_author=False)
330
 			mention_author=False)
310
 
331
 
311
 	@crosspost.command(
332
 	@crosspost.command(
314
 	)
335
 	)
315
 	async def joinraid_gettimewindow(self, context: commands.Context):
336
 	async def joinraid_gettimewindow(self, context: commands.Context):
316
 		seconds = self.__message_age_seconds(context.guild)
337
 		seconds = self.__message_age_seconds(context.guild)
317
-		await context.message.reply(f'ℹ️ Only messages in the past {seconds} ' +
318
-			'seconds will be checked for duplicates.',
338
+		await context.message.reply(
339
+			CONFIG['info_emoji'] + ' ' +
340
+			f'Only messages in the past {seconds} seconds will be checked ' +
341
+			'for duplicates.',
319
 			mention_author=False)
342
 			mention_author=False)

+ 26
- 19
cogs/joinraidcog.py Просмотреть файл

162
 	"""
162
 	"""
163
 	def __init__(self, guild_id: int):
163
 	def __init__(self, guild_id: int):
164
 		self.guild_id = guild_id
164
 		self.guild_id = guild_id
165
-		self.join_warning_count = CONFIG['joinWarningCount']
166
-		self.join_warning_seconds = CONFIG['joinWarningSeconds']
165
+		self.join_warning_count = self.get_cog_default('warning_count')
166
+		self.join_warning_seconds = self.get_cog_default('warning_seconds')
167
 		# Non-persisted runtime state
167
 		# Non-persisted runtime state
168
 		self.current_raid = JoinRaidRecord()
168
 		self.current_raid = JoinRaidRecord()
169
 		self.all_raids = [ self.current_raid ] # periodically culled of old ones
169
 		self.all_raids = [ self.current_raid ] # periodically culled of old ones
254
 		Returns the join rate configured for this guild.
254
 		Returns the join rate configured for this guild.
255
 		"""
255
 		"""
256
 		count: int = Storage.get_config_value(guild, self.STATE_KEY_RAID_COUNT) \
256
 		count: int = Storage.get_config_value(guild, self.STATE_KEY_RAID_COUNT) \
257
-			or CONFIG['joinWarningCount']
257
+			or self.get_cog_default('warning_count')
258
 		seconds: float = Storage.get_config_value(guild, self.STATE_KEY_RAID_SECONDS) \
258
 		seconds: float = Storage.get_config_value(guild, self.STATE_KEY_RAID_SECONDS) \
259
-			or CONFIG['joinWarningSeconds']
259
+			or self.get_cog_default('warning_seconds')
260
 		return (count, seconds)
260
 		return (count, seconds)
261
 
261
 
262
 	def __is_enabled(self, guild: Guild) -> bool:
262
 	def __is_enabled(self, guild: Guild) -> bool:
263
 		"""
263
 		"""
264
 		Returns whether join raid detection is enabled in this guild.
264
 		Returns whether join raid detection is enabled in this guild.
265
 		"""
265
 		"""
266
-		return Storage.get_config_value(guild, self.STATE_KEY_ENABLED) or False
266
+		return Storage.get_config_value(guild, self.STATE_KEY_ENABLED) \
267
+			or self.get_cog_default('enabled')
267
 
268
 
268
 	# -- Commands -----------------------------------------------------------
269
 	# -- Commands -----------------------------------------------------------
269
 
270
 
288
 		Storage.set_config_value(guild, self.STATE_KEY_ENABLED, True)
289
 		Storage.set_config_value(guild, self.STATE_KEY_ENABLED, True)
289
 		# TODO: Startup tracking if necessary
290
 		# TODO: Startup tracking if necessary
290
 		await context.message.reply(
291
 		await context.message.reply(
291
-			'✅ ' + self.__describe_raid_settings(guild, force_enabled_status=True),
292
+			CONFIG['success_emoji'] + ' ' +
293
+			self.__describe_raid_settings(guild, force_enabled_status=True),
292
 			mention_author=False)
294
 			mention_author=False)
293
 
295
 
294
 	@joinraid.command(
296
 	@joinraid.command(
302
 		Storage.set_config_value(guild, self.STATE_KEY_ENABLED, False)
304
 		Storage.set_config_value(guild, self.STATE_KEY_ENABLED, False)
303
 		# TODO: Tear down tracking if necessary
305
 		# TODO: Tear down tracking if necessary
304
 		await context.message.reply(
306
 		await context.message.reply(
305
-			'✅ ' + self.__describe_raid_settings(guild, force_enabled_status=True),
307
+			CONFIG['success_emoji'] + ' ' +
308
+			self.__describe_raid_settings(guild, force_enabled_status=True),
306
 			mention_author=False)
309
 			mention_author=False)
307
 
310
 
308
 	@joinraid.command(
311
 	@joinraid.command(
322
 		guild = context.guild
325
 		guild = context.guild
323
 		if join_count < self.MIN_JOIN_COUNT:
326
 		if join_count < self.MIN_JOIN_COUNT:
324
 			await context.message.reply(
327
 			await context.message.reply(
325
-				f'⚠️ `join_count` must be >= {self.MIN_JOIN_COUNT}',
328
+				CONFIG['warning_emoji'] + ' ' +
329
+				f'`join_count` must be >= {self.MIN_JOIN_COUNT}',
326
 				mention_author=False)
330
 				mention_author=False)
327
 			return
331
 			return
328
 		if seconds <= 0:
332
 		if seconds <= 0:
329
 			await context.message.reply(
333
 			await context.message.reply(
330
-				f'⚠️ `seconds` must be > 0',
334
+				CONFIG['warning_emoji'] + ' ' +
335
+				f'`seconds` must be > 0',
331
 				mention_author=False)
336
 				mention_author=False)
332
 			return
337
 			return
333
 		Storage.set_config_values(guild, {
338
 		Storage.set_config_values(guild, {
336
 		})
341
 		})
337
 
342
 
338
 		await context.message.reply(
343
 		await context.message.reply(
339
-			'✅ ' + self.__describe_raid_settings(guild, force_rate_status=True),
344
+			CONFIG['success_emoji'] + ' ' +
345
+			self.__describe_raid_settings(guild, force_rate_status=True),
340
 			mention_author=False)
346
 			mention_author=False)
341
 
347
 
342
 	@joinraid.command(
348
 	@joinraid.command(
346
 	async def joinraid_getrate(self, context: commands.Context):
352
 	async def joinraid_getrate(self, context: commands.Context):
347
 		'Command handler'
353
 		'Command handler'
348
 		await context.message.reply(
354
 		await context.message.reply(
349
-			'ℹ️ ' + self.__describe_raid_settings(context.guild, force_rate_status=True),
355
+			CONFIG['info_emoji'] + ' ' +
356
+			self.__describe_raid_settings(context.guild, force_rate_status=True),
350
 			mention_author=False)
357
 			mention_author=False)
351
 
358
 
352
 	# -- Listeners ----------------------------------------------------------
359
 	# -- Listeners ----------------------------------------------------------
385
 			# Either not a warning message or one we stopped tracking
392
 			# Either not a warning message or one we stopped tracking
386
 			return
393
 			return
387
 		emoji: PartialEmoji = payload.emoji
394
 		emoji: PartialEmoji = payload.emoji
388
-		if emoji.name == CONFIG['kickEmoji']:
395
+		if emoji.name == CONFIG['kick_emoji']:
389
 			await raid.kick_all()
396
 			await raid.kick_all()
390
 			gc.reset_raid(message.created_at)
397
 			gc.reset_raid(message.created_at)
391
 			await self.__update_raid_warning(guild, raid)
398
 			await self.__update_raid_warning(guild, raid)
392
-		elif emoji.name == CONFIG['banEmoji']:
399
+		elif emoji.name == CONFIG['ban_emoji']:
393
 			await raid.ban_all()
400
 			await raid.ban_all()
394
 			gc.reset_raid(message.created_at)
401
 			gc.reset_raid(message.created_at)
395
 			await self.__update_raid_warning(guild, raid)
402
 			await self.__update_raid_warning(guild, raid)
470
 		(message, can_kick, can_ban) = self.__describe_raid(raid)
477
 		(message, can_kick, can_ban) = self.__describe_raid(raid)
471
 		raid.warning_message = await self.warn(guild, message)
478
 		raid.warning_message = await self.warn(guild, message)
472
 		if can_kick:
479
 		if can_kick:
473
-			await raid.warning_message.add_reaction(CONFIG['kickEmoji'])
480
+			await raid.warning_message.add_reaction(CONFIG['kick_emoji'])
474
 		if can_ban:
481
 		if can_ban:
475
-			await raid.warning_message.add_reaction(CONFIG['banEmoji'])
482
+			await raid.warning_message.add_reaction(CONFIG['ban_emoji'])
476
 
483
 
477
 	async def __update_raid_warning(self, guild: Guild, raid: JoinRaidRecord) -> None:
484
 	async def __update_raid_warning(self, guild: Guild, raid: JoinRaidRecord) -> None:
478
 		"""
485
 		"""
483
 		(message, can_kick, can_ban) = self.__describe_raid(raid)
490
 		(message, can_kick, can_ban) = self.__describe_raid(raid)
484
 		await self.update_warn(raid.warning_message, message)
491
 		await self.update_warn(raid.warning_message, message)
485
 		if not can_kick:
492
 		if not can_kick:
486
-			await raid.warning_message.clear_reaction(CONFIG['kickEmoji'])
493
+			await raid.warning_message.clear_reaction(CONFIG['kick_emoji'])
487
 		if not can_ban:
494
 		if not can_ban:
488
-			await raid.warning_message.clear_reaction(CONFIG['banEmoji'])
495
+			await raid.warning_message.clear_reaction(CONFIG['ban_emoji'])
489
 
496
 
490
 	def __describe_raid(self, raid: JoinRaidRecord) -> tuple:
497
 	def __describe_raid(self, raid: JoinRaidRecord) -> tuple:
491
 		"""
498
 		"""
512
 
519
 
513
 		message += '\n'
520
 		message += '\n'
514
 		if any_kickable:
521
 		if any_kickable:
515
-			message += f'\nReact to this message with {CONFIG["kickEmoji"]} to kick all these users.'
522
+			message += f'\nReact to this message with {CONFIG["kick_emoji"]} to kick all these users.'
516
 		else:
523
 		else:
517
 			message += '\nNo users left to kick.'
524
 			message += '\nNo users left to kick.'
518
 		if any_bannable:
525
 		if any_bannable:
519
-			message += f'\nReact to this message with {CONFIG["banEmoji"]} to ban all these users.'
526
+			message += f'\nReact to this message with {CONFIG["ban_emoji"]} to ban all these users.'
520
 		else:
527
 		else:
521
 			message += '\nNo users left to ban.'
528
 			message += '\nNo users left to ban.'
522
 
529
 

+ 22
- 9
config.py.sample Просмотреть файл

1
 # Copy this file to config.py and fill in necessary values
1
 # Copy this file to config.py and fill in necessary values
2
 CONFIG = {
2
 CONFIG = {
3
-	'clientToken': 'token',
4
-	'joinWarningCount': 5,
5
-	'joinWarningSeconds': 5,
6
-	'commandPrefix': '$rb_',
7
-	'kickEmojiName': 'boot',
8
-	'kickEmoji': '👢',
9
-	'banEmojiName': 'no_entry_sign',
10
-	'banEmoji': '🚫',
11
-	'configPath': 'config/',
3
+	'client_token': 'token',
4
+	'command_prefix': '$rb_',
5
+	'kick_emoji': '👢',
6
+	'ban_emoji': '🚫',
7
+	'trash_emoji': '🗑',
8
+	'success_emoji': '✅',
9
+	'warning_emoji': '⚠️',
10
+	'info_emoji': 'ℹ️',
11
+	'config_path': 'config/',
12
+	'cog_defaults': {
13
+		'JoinRaidCog': {
14
+			'enabled': False,
15
+			'warning_count': 5,
16
+			'warning_seconds': 5,
17
+		},
18
+		'CrossPostCog': {
19
+			'warn_message_count': 3,
20
+			'ban_message_count': 9999,
21
+			'time_window_seconds': 120,
22
+			'min_message_length': 0,
23
+		},
24
+	},
12
 }
25
 }

+ 2
- 2
rocketbot.py Просмотреть файл

21
 intents = Intents.default()
21
 intents = Intents.default()
22
 intents.messages = True
22
 intents.messages = True
23
 intents.members = True # To get join/leave events
23
 intents.members = True # To get join/leave events
24
-bot = Rocketbot(command_prefix=CONFIG['commandPrefix'], intents=intents)
24
+bot = Rocketbot(command_prefix=CONFIG['command_prefix'], intents=intents)
25
 bot.add_cog(GeneralCog(bot))
25
 bot.add_cog(GeneralCog(bot))
26
 bot.add_cog(ConfigCog(bot))
26
 bot.add_cog(ConfigCog(bot))
27
 bot.add_cog(JoinRaidCog(bot))
27
 bot.add_cog(JoinRaidCog(bot))
28
 bot.add_cog(CrossPostCog(bot))
28
 bot.add_cog(CrossPostCog(bot))
29
-bot.run(CONFIG['clientToken'], bot=True, reconnect=True)
29
+bot.run(CONFIG['client_token'], bot=True, reconnect=True)
30
 print('\nBot aborted')
30
 print('\nBot aborted')

+ 1
- 1
storage.py Просмотреть файл

161
 		"""
161
 		"""
162
 		Returns the JSON file path where guild config should be written.
162
 		Returns the JSON file path where guild config should be written.
163
 		"""
163
 		"""
164
-		config_value: str = CONFIG['configPath']
164
+		config_value: str = CONFIG['config_path']
165
 		path: str = config_value if config_value.endswith('/') else f'{config_value}/'
165
 		path: str = config_value if config_value.endswith('/') else f'{config_value}/'
166
 		return f'{path}guild_{guild.id}.json'
166
 		return f'{path}guild_{guild.id}.json'
167
 
167
 

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