Selaa lähdekoodia

Cleanup

pull/13/head
Rocketsoup 2 kuukautta sitten
vanhempi
commit
3a46c90bc3
3 muutettua tiedostoa jossa 45 lisäystä ja 48 poistoa
  1. 3
    2
      rocketbot/cogs/autokickcog.py
  2. 3
    3
      rocketbot/cogs/basecog.py
  3. 39
    43
      rocketbot/cogs/configcog.py

+ 3
- 2
rocketbot/cogs/autokickcog.py Näytä tiedosto

@@ -1,7 +1,8 @@
1 1
 from datetime import datetime, timedelta
2 2
 
3 3
 from discord import Guild, Member, Status
4
-from discord.ext import commands, tasks
4
+from discord.ext import tasks
5
+from discord.ext.commands import Cog
5 6
 from discord.ext.tasks import Loop
6 7
 
7 8
 from config import CONFIG
@@ -66,7 +67,7 @@ class AutoKickCog(BaseCog, name='Auto Kick'):
66 67
 		timer: Loop = self.status_check_timer
67 68
 		timer.start()
68 69
 
69
-	@commands.Cog.listener()
70
+	@Cog.listener()
70 71
 	async def on_member_join(self, member: Member) -> None:
71 72
 		"""Event handler"""
72 73
 		guild: Guild = member.guild

+ 3
- 3
rocketbot/cogs/basecog.py Näytä tiedosto

@@ -2,7 +2,7 @@
2 2
 Base cog class and helper classes.
3 3
 """
4 4
 from datetime import datetime, timedelta, timezone
5
-from typing import Optional, ForwardRef
5
+from typing import Optional
6 6
 
7 7
 import discord
8 8
 from discord import Guild, Interaction, Member, Message, RawReactionActionEvent, TextChannel
@@ -18,7 +18,7 @@ from rocketbot.collections import AgeBoundDict
18 18
 from rocketbot.storage import Storage
19 19
 from rocketbot.utils import bot_log, dump_stacktrace
20 20
 
21
-Rocketbot = ForwardRef('rocketbot.bot.Rocketbot')
21
+Rocketbot = 'rocketbot.bot.Rocketbot'
22 22
 
23 23
 class WarningContext:
24 24
 	def __init__(self, member: Member, warn_time: datetime):
@@ -176,7 +176,7 @@ class BaseCog(Cog):
176 176
 			BaseCog.STATE_KEY_RECENT_WARNINGS)
177 177
 		if recent_warns is None:
178 178
 			recent_warns = AgeBoundDict(timedelta(seconds=CONFIG['squelch_warning_seconds']),
179
-				lambda i, context : context.last_warned)
179
+				lambda i, context0 : context0.last_warned)
180 180
 			Storage.set_state_value(member.guild, BaseCog.STATE_KEY_RECENT_WARNINGS, recent_warns)
181 181
 		context: WarningContext = recent_warns.get(member.id)
182 182
 		if context is None:

+ 39
- 43
rocketbot/cogs/configcog.py Näytä tiedosto

@@ -31,18 +31,16 @@ class ConfigCog(BaseCog, name='Configuration'):
31 31
 		default_permissions=Permissions(Permissions.manage_messages.flag)
32 32
 	)
33 33
 
34
-	@config.command(
35
-		description='Sets the mod warning channel',
36
-		extras={
37
-			'long_description': 'Run this command in the channel where bot messages ' +
38
-				'intended for server moderators should be sent. Other bot ' +
39
-				'messages may still be posted in the channel a command was ' +
40
-				'invoked in. If no output channel is set, mod-related messages ' +
41
-				'will not be posted!',
42
-		}
43
-	)
44
-	async def setwarningchannel(self, interaction: Interaction) -> None:
45
-		"""Command handler"""
34
+	@config.command()
35
+	async def set_warning_channel(self, interaction: Interaction) -> None:
36
+		"""
37
+		Sets mod warnings to post in the current channel.
38
+
39
+		Run this command in the channel where bot messages intended for server
40
+		moderators should be sent. Other bot messages may still be posted in
41
+		the channel a command was invoked in. If no output channel is set,
42
+		mod-related messages will not be posted!
43
+		"""
46 44
 		guild: Guild = interaction.guild
47 45
 		channel: TextChannel = interaction.channel
48 46
 		Storage.set_config_value(guild, ConfigKey.WARNING_CHANNEL_ID,
@@ -52,15 +50,14 @@ class ConfigCog(BaseCog, name='Configuration'):
52 50
 			ephemeral=True,
53 51
 		)
54 52
 
55
-	@config.command(
56
-		description='Shows the mod warning channel',
57
-		extras={
58
-			'long_description': 'Shows the configured channel (if any) where mod ' + \
59
-				'warnings will be posted.',
60
-		},
61
-	)
62
-	async def getwarningchannel(self, interaction: Interaction) -> None:
63
-		"""Command handler"""
53
+	@config.command()
54
+	async def get_warning_channel(self, interaction: Interaction) -> None:
55
+		"""
56
+		Shows the mod warning channel, if any.
57
+
58
+		Shows the configured channel (if any) where mod warnings and other bot
59
+		output will be posted.
60
+		"""
64 61
 		guild: Guild = interaction.guild
65 62
 		channel_id = Storage.get_config_value(guild, ConfigKey.WARNING_CHANNEL_ID)
66 63
 		if channel_id is None:
@@ -75,20 +72,23 @@ class ConfigCog(BaseCog, name='Configuration'):
75 72
 				ephemeral=True,
76 73
 			)
77 74
 
78
-	@config.command(
79
-		description='Sets a user/role to mention in warning messages',
80
-		extras={
81
-			'usage': '<@user|@role>',
82
-			'long_description': 'Configures an role or other prefix to include at the ' +
83
-				'beginning of warning messages. If the intent is to get the ' +
84
-				'attention of certain users, be sure to specify a properly ' +
85
-				'formed @ tag, not just the name of the user/role.',
86
-		},
87
-	)
88
-	async def setwarningmention(self,
75
+	@config.command()
76
+	async def set_warning_mention(self,
89 77
 			interaction: Interaction,
90 78
 			mention: Optional[Union[User, Role]] = None) -> None:
91
-		"""Command handler"""
79
+		"""
80
+		Sets a user/role to mention in warning messages.
81
+
82
+		Configures an role or other prefix to include at the beginning of
83
+		warning messages. The intent is to get the attention of certain users
84
+		in case action is needed. Leave blank to tag no one.
85
+
86
+		Parameters
87
+		----------
88
+		interaction: Interaction
89
+		mention: User or Role
90
+			The user or role to mention in warning messages
91
+		"""
92 92
 		guild: Guild = interaction.guild
93 93
 		Storage.set_config_value(guild, ConfigKey.WARNING_MENTION, mention.mention if mention else None)
94 94
 		if mention is None:
@@ -98,19 +98,15 @@ class ConfigCog(BaseCog, name='Configuration'):
98 98
 			)
99 99
 		else:
100 100
 			await interaction.response.send_message(
101
-				f'{CONFIG["success_emoji"]} Warning messages will now tag {mention}.',
101
+				f'{CONFIG["success_emoji"]} Warning messages will now tag {mention.mention}.',
102 102
 				ephemeral=True,
103 103
 			)
104 104
 
105
-	@config.command(
106
-		description='Shows the user/role to mention in warning messages',
107
-		extras={
108
-			'long_description': 'Shows the text, if any, that will be prefixed on any ' +
109
-				'warning messages.',
110
-		},
111
-	)
112
-	async def getwarningmention(self, interaction: Interaction) -> None:
113
-		"""Command handler"""
105
+	@config.command()
106
+	async def get_warning_mention(self, interaction: Interaction) -> None:
107
+		"""
108
+		Shows the configured user/role to mention in warning messages.
109
+		"""
114 110
 		guild: Guild = interaction.guild
115 111
 		mention: str = Storage.get_config_value(guild, ConfigKey.WARNING_MENTION)
116 112
 		if mention is None:

Loading…
Peruuta
Tallenna