Pārlūkot izejas kodu

Better number formatting

pull/35/head
Rocketsoup 1 nedēļu atpakaļ
vecāks
revīzija
1284e62832
1 mainītis faili ar 30 papildinājumiem un 26 dzēšanām
  1. 30
    26
      rocketbot/cogs/kickstartercog.py

+ 30
- 26
rocketbot/cogs/kickstartercog.py Parādīt failu

@@ -161,15 +161,16 @@ class KickstarterCog(BaseCog):
161 161
 		else:
162 162
 			lines.append(f"- Backer role configured as `{backer_role.name}`")
163 163
 		if stats.username_count > 0:
164
-			lines.append(f"- **{stats.username_count}** Discord usernames imported")
165
-			lines.append(f"- Last new import at <t:{stats.username_last_imported_at}:f>")
166
-			lines.append(f"- **{stats.username_found_count}** members linked successfully")
164
+			lines.append(f"- **{stats.username_count:,}** Discord usernames imported")
165
+			lines.append("- Last import with new records on " \
166
+				f"<t:{stats.username_last_imported_at}:f>")
167
+			lines.append(f"- **{stats.username_found_count:,}** members linked successfully")
167 168
 			if stats.username_not_found_count > 0:
168
-				lines.append(f"- **{stats.username_not_found_count}** imported " \
169
+				lines.append(f"- **{stats.username_not_found_count:,}** imported " \
169 170
 					"usernames not yet linked to Discord members")
170 171
 			if stats.username_unprocessed_count > 0:
171
-				lines.append(f"- **{stats.username_unprocessed_count}** " \
172
-					"usernames not yet attempted to sync")
172
+				lines.append(f"- **{stats.username_unprocessed_count:,}** " \
173
+					"usernames added since last sync")
173 174
 		else:
174 175
 			lines.append("- No Discord usernames imported yet. Use " \
175 176
 				f"`/{KickstarterCog.kickstarter.name} {KickstarterCog.upload.name}`")
@@ -324,10 +325,10 @@ class KickstarterCog(BaseCog):
324 325
 		text = f"{CONFIG['success_emoji']} Record for `@{normal_username}` reset. " \
325 326
 			"(No roles removed from member.)"
326 327
 		if old_member_id is not None:
327
-			text += f"\n- member_id: `{old_member_id}` --> `{record.discord_member_id}`"
328
+			text += f"\n- `discord_member_id` changed from `{old_member_id}` to `{record.discord_member_id}`"
328 329
 		if old_lookup_status is not None:
329
-			text += f"\n- lookup_status: `{_describe_lookup_status(old_lookup_status)}`" \
330
-				f" --> `{_describe_lookup_status(record.lookup_status)}`"
330
+			text += f"\n- `lookup_status` changed from `{_describe_lookup_status(old_lookup_status)}`" \
331
+				f" to `{_describe_lookup_status(record.lookup_status)}`"
331 332
 		await interaction.response.send_message(text, ephemeral=True)
332 333
 
333 334
 	@kickstarter.command(
@@ -339,6 +340,7 @@ class KickstarterCog(BaseCog):
339 340
 
340 341
 		await interaction.response.send_modal(_UploadUsernamesModal())
341 342
 
343
+	# @override
342 344
 	async def interaction_check(self, interaction: Interaction) -> bool:
343 345
 		if interaction.command is not None:
344 346
 			self.__trace(interaction.guild, f"@{interaction.user.name} used " \
@@ -406,7 +408,7 @@ class KickstarterCog(BaseCog):
406 408
 	) -> '_ImportResult':
407 409
 		"""Imports Discord usernames from an upload attachment."""
408 410
 		self.__trace(guild, f"Download - start - {attachment.filename} " \
409
-			f"({attachment.size} bytes, {attachment.content_type})")
411
+			f"({attachment.size:,} bytes, {attachment.content_type})")
410 412
 		file_bytes = await attachment.read()
411 413
 		file_str = file_bytes.decode('utf-8')
412 414
 		self.__trace(guild, "Download - complete")
@@ -430,12 +432,12 @@ class KickstarterCog(BaseCog):
430 432
 				self.__trace(guild, f"Not a Discord username: \"{line}\"")
431 433
 				malformed_usernames.append(line)
432 434
 				malformed_count += 1
433
-		self.__trace(guild, f"Parse - complete - {len(lines)} lines, {len(usernames)} " \
434
-			f"valid usernames, {malformed_count} malformed usernames")
435
+		self.__trace(guild, f"Parse - complete - {len(lines):,} lines, {len(usernames):,} " \
436
+			f"valid usernames, {malformed_count:,} malformed usernames")
435 437
 
436
-		self.__trace(guild, f"Storing - start - {len(usernames)} usernames")
438
+		self.__trace(guild, f"Storing - start - {len(usernames):,} usernames")
437 439
 		new_username_count = self.__store_kickstarter_usernames(guild.id, usernames)
438
-		self.__trace(guild, f"Storing - complete - {new_username_count} unique " \
440
+		self.__trace(guild, f"Storing - complete - {new_username_count:,} unique " \
439 441
 			"usernames stored")
440 442
 
441 443
 		return _ImportResult(
@@ -459,14 +461,14 @@ class KickstarterCog(BaseCog):
459 461
 					_LookupStatus.unprocessed,
460 462
 					_LookupStatus.username_not_found
461 463
 				})
462
-		self.__trace(guild, f"Fetch usernames - complete - found {len(usernames)}")
464
+		self.__trace(guild, f"Fetch usernames - complete - found {len(usernames):,}")
463 465
 		username_to_member_id: dict[str, int] = {}
464 466
 		if self.bot.intents.members:
465 467
 			self.__trace(guild, "Fetching guild members from API - start")
466 468
 			async for member in guild.fetch_members(limit=None):
467 469
 				username_to_member_id[member.name] = member.id
468 470
 			self.__trace(guild, "Fetching guild members from API - complete - " \
469
-				f"got {len(username_to_member_id)}")
471
+				f"got {len(username_to_member_id):,}")
470 472
 		async def username_loop_handler(username: _KickstarterDiscordUser):
471 473
 			nonlocal complete_count
472 474
 			nonlocal not_found_count
@@ -491,8 +493,8 @@ class KickstarterCog(BaseCog):
491 493
 		self.__trace(guild, "Sync loop - start")
492 494
 		failure_count = await self.__throttled_loop(guild, usernames,
493 495
 			username_loop_handler, update_seconds=10.0)
494
-		self.__trace(guild, f"Sync loop - complete - {complete_count} completed, " \
495
-			f"{not_found_count} not found")
496
+		self.__trace(guild, f"Sync loop - complete - {complete_count:,} completed, " \
497
+			f"{not_found_count:,} not found")
496 498
 		return _SyncUsernamesResult(complete_count, not_found_count, failure_count)
497 499
 
498 500
 	async def __throttled_loop(self,
@@ -523,7 +525,7 @@ class KickstarterCog(BaseCog):
523 525
 							f"retry_after={retry_header_value}")
524 526
 						await sleep(retry_after_millis / 1000.0)
525 527
 						sleep_length = 1.0 if sleep_length == 0.0 else sleep_length * 2.0
526
-						self.__trace(guild, f"Sleep increased to {sleep_length}s " \
528
+						self.__trace(guild, f"Sleep increased to {sleep_length:,}s " \
527 529
 							"due to rate limiting")
528 530
 					else:
529 531
 						dump_stacktrace(ex)
@@ -532,7 +534,7 @@ class KickstarterCog(BaseCog):
532 534
 			if not complete:
533 535
 				failure_count += 1
534 536
 			if update_seconds is not None and now_timestamp() - last_update_time >= update_seconds:
535
-				self.__trace(guild, f"Completed {iter_count + 1} iterations")
537
+				self.__trace(guild, f"Completed {iter_count + 1:,} iterations")
536 538
 				last_update_time = now_timestamp()
537 539
 		return failure_count
538 540
 
@@ -827,13 +829,13 @@ class _ImportResult:
827 829
 	def summary_markdown(self) -> str:
828 830
 		lines: list[str] = []
829 831
 		if self.valid_record_count > 0:
830
-			lines.append(f"- Read {self.valid_record_count} valid records")
832
+			lines.append(f"- Read {self.valid_record_count:,} valid records")
831 833
 		else:
832 834
 			lines.append("- Upload contained **no valid records**")
833 835
 		if self.malformed_record_count > 0:
834
-			lines.append(f"- Read **{self.malformed_record_count} malformed records**")
836
+			lines.append(f"- Read **{self.malformed_record_count:,} malformed records**")
835 837
 		if self.new_record_count > 0:
836
-			lines.append(f"- Imported {self.new_record_count} new unique records")
838
+			lines.append(f"- Imported {self.new_record_count:,} new unique records")
837 839
 		else:
838 840
 			lines.append("- No new unique records (all previously imported)")
839 841
 		return "\n".join(lines)
@@ -852,14 +854,14 @@ class _SyncUsernamesResult:
852 854
 	def summary_markdown(self) -> str:
853 855
 		lines: list[str] = []
854 856
 		if self.complete_count > 0:
855
-			lines.append(f"- Gave backer role to {self.complete_count} new members")
857
+			lines.append(f"- Gave backer role to {self.complete_count:,} new members")
856 858
 		else:
857 859
 			lines.append("- No new members found")
858 860
 		if self.not_found_count > 0:
859
-			lines.append(f"- {self.not_found_count} members could not be found " \
861
+			lines.append(f"- {self.not_found_count:,} members could not be found " \
860 862
 				"by the provided username")
861 863
 		if self.failure_count > 0:
862
-			lines.append(f"- Failed to link {self.failure_count} members")
864
+			lines.append(f"- Failed to link {self.failure_count:,} members")
863 865
 		return "\n".join(lines)
864 866
 
865 867
 class _UploadUsernamesModal(Modal):
@@ -875,6 +877,7 @@ class _UploadUsernamesModal(Modal):
875 877
 	def __init__(self):
876 878
 		super().__init__(title='Upload Discord Usernames', timeout=None)
877 879
 
880
+	# @override
878 881
 	async def on_submit(self, interaction: Interaction) -> None:
879 882
 		# noinspection PyTypeChecker
880 883
 		upload_input: FileUpload = self.upload_label.component
@@ -885,6 +888,7 @@ class _UploadUsernamesModal(Modal):
885 888
 		attachment = upload_input.values[0]
886 889
 		await KickstarterCog.shared.on_username_upload_submit(interaction, attachment)
887 890
 
891
+	# @override
888 892
 	async def on_error(self, interaction: Interaction, error: Exception) -> None:
889 893
 		dump_stacktrace(error)
890 894
 		try:

Notiek ielāde…
Atcelt
Saglabāt