Rocketsoup 2 месяцев назад
Родитель
Сommit
3a46c90bc3
3 измененных файлов: 45 добавлений и 48 удалений
  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 Просмотреть файл

1
 from datetime import datetime, timedelta
1
 from datetime import datetime, timedelta
2
 
2
 
3
 from discord import Guild, Member, Status
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
 from discord.ext.tasks import Loop
6
 from discord.ext.tasks import Loop
6
 
7
 
7
 from config import CONFIG
8
 from config import CONFIG
66
 		timer: Loop = self.status_check_timer
67
 		timer: Loop = self.status_check_timer
67
 		timer.start()
68
 		timer.start()
68
 
69
 
69
-	@commands.Cog.listener()
70
+	@Cog.listener()
70
 	async def on_member_join(self, member: Member) -> None:
71
 	async def on_member_join(self, member: Member) -> None:
71
 		"""Event handler"""
72
 		"""Event handler"""
72
 		guild: Guild = member.guild
73
 		guild: Guild = member.guild

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

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

+ 39
- 43
rocketbot/cogs/configcog.py Просмотреть файл

31
 		default_permissions=Permissions(Permissions.manage_messages.flag)
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
 		guild: Guild = interaction.guild
44
 		guild: Guild = interaction.guild
47
 		channel: TextChannel = interaction.channel
45
 		channel: TextChannel = interaction.channel
48
 		Storage.set_config_value(guild, ConfigKey.WARNING_CHANNEL_ID,
46
 		Storage.set_config_value(guild, ConfigKey.WARNING_CHANNEL_ID,
52
 			ephemeral=True,
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
 		guild: Guild = interaction.guild
61
 		guild: Guild = interaction.guild
65
 		channel_id = Storage.get_config_value(guild, ConfigKey.WARNING_CHANNEL_ID)
62
 		channel_id = Storage.get_config_value(guild, ConfigKey.WARNING_CHANNEL_ID)
66
 		if channel_id is None:
63
 		if channel_id is None:
75
 				ephemeral=True,
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
 			interaction: Interaction,
77
 			interaction: Interaction,
90
 			mention: Optional[Union[User, Role]] = None) -> None:
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
 		guild: Guild = interaction.guild
92
 		guild: Guild = interaction.guild
93
 		Storage.set_config_value(guild, ConfigKey.WARNING_MENTION, mention.mention if mention else None)
93
 		Storage.set_config_value(guild, ConfigKey.WARNING_MENTION, mention.mention if mention else None)
94
 		if mention is None:
94
 		if mention is None:
98
 			)
98
 			)
99
 		else:
99
 		else:
100
 			await interaction.response.send_message(
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
 				ephemeral=True,
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
 		guild: Guild = interaction.guild
110
 		guild: Guild = interaction.guild
115
 		mention: str = Storage.get_config_value(guild, ConfigKey.WARNING_MENTION)
111
 		mention: str = Storage.get_config_value(guild, ConfigKey.WARNING_MENTION)
116
 		if mention is None:
112
 		if mention is None:

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