Skip to content
This repository was archived by the owner on Sep 9, 2024. It is now read-only.

Commit 7b358bf

Browse files
committed
Fix cog
1 parent 648a989 commit 7b358bf

File tree

7 files changed

+85
-26
lines changed

7 files changed

+85
-26
lines changed

_orangcbot/__main__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ def convert_none_to_0(key: Optional[ConvertibleToInt] = None) -> int:
9292
# WARNING: Do not remove this if!
9393
if nextcord.version_info < (3, 0, 0):
9494
bot.load_extension("onami")
95-
bot.load_extension("extensions.antihoist")
95+
# bot.load_extension("extensions.antihoist")
9696

9797
bot.load_extension("extensions.fun")
9898
bot.load_extension("extensions.faq")

_orangcbot/extensions/antihoist.py

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
from __future__ import annotations
22

3+
from datetime import datetime
34
import logging
45
from string import ascii_letters
56
from typing import TYPE_CHECKING, Final
67

7-
from nextcord.ext import commands
8+
from nextcord import HTTPException, Permissions, user_command, Interaction, Member
9+
from nextcord.ext import commands, application_checks as ac
810

911
if TYPE_CHECKING:
1012
import nextcord
13+
from nextcord import AutoModerationActionExecution
14+
1115

1216
NUMBERS: Final[str] = "1234567890"
1317
normal_characters: Final[str] = ascii_letters + NUMBERS
@@ -39,6 +43,33 @@ async def check_nickname_on_edit(
3943
nick="kid", reason="having a strong craving to be a discord ecelebrity"
4044
)
4145

46+
# @commands.Cog.listener("on_auto_moderation_action_execution")
47+
# async def check_nword_pass(self, execution: AutoModerationActionExecution):
48+
# if execution.rule_id == 1196650528889905305: # racial slur N word automod rule
49+
# try:
50+
# await execution.member.send(
51+
# f"seriously? you think you are better just because you were born in somewhere rather than Africa? you're banned from is-a.dev now. oh yes, if you're looking for an appeal form, sorry, no, cuz we are so disgusted at you. it's {datetime.now().year}, get some braincells rather than spamming your keyboard online like that!"
52+
# )
53+
# except HTTPException:
54+
# pass
55+
# await execution.member.ban(
56+
# reason="thought that they are better just because they weren't born in somewhere rather than Africa"
57+
# )
58+
59+
@user_command(
60+
dm_permission=False, name="Cleanse Nickname", default_member_permissions=8
61+
)
62+
@ac.has_role(830875873027817484)
63+
async def cleanse_nickname(self, interaction: Interaction, member: Member) -> None:
64+
previous_display_name = member.display_name
65+
await member.edit(
66+
nick="kid",
67+
reason=f"nickname cleansing requested by {interaction.user.display_name}",
68+
)
69+
await interaction.send(
70+
f"Nickname of {previous_display_name} has been cleansed to `kid`."
71+
)
72+
4273

4374
def setup(bot: commands.Bot) -> None:
4475
bot.add_cog(AutoMod(bot))

_orangcbot/extensions/converters.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,39 +10,40 @@
1010
"SlashSubdomainNameConverter",
1111
"EnsureHTTPConverter",
1212
"SlashEnsureHTTPConverter",
13+
"RGBColorTupleConverter",
1314
)
1415

1516

1617
class SubdomainNameConverter(commands.Converter):
17-
async def convert(self, ctx: commands.Context, argument: str) -> str:
18+
async def convert(self, ctx: commands.Context, argument: str) -> str: # type: ignore
1819
argument = argument.lower()
1920
if argument.endswith(".is-a.dev"):
2021
return argument[:-9]
2122
return argument
2223

2324

2425
class RGBColorTupleConverter(commands.Converter):
25-
async def convert(self, ctx: commands.Context, argument: str) -> Tuple[str]:
26+
async def convert(self, ctx: commands.Context, argument: str) -> Tuple[str]: # type: ignore
2627
return argument.split("-") # type: ignore[reportReturnType]
2728

2829

2930
class SlashSubdomainNameConverter(OptionConverter):
30-
async def convert(self, interaction: Interaction, value: str) -> str:
31+
async def convert(self, interaction: Interaction, value: str) -> str: # type: ignore
3132
value = value.lower()
3233
if value.endswith(".is-a.dev"):
3334
return value[:-9]
3435
return value
3536

3637

3738
class SlashEnsureHTTPConverter(OptionConverter):
38-
async def convert(self, interaction: Interaction, value: str) -> str:
39+
async def convert(self, interaction: Interaction, value: str) -> str: # type: ignore
3940
if value.startswith("https://") or value.startswith("http://"):
4041
return value
4142
return "http://" + value
4243

4344

4445
class EnsureHTTPConverter(commands.Converter):
45-
async def convert(self, ctx: commands.Context, argument: str) -> str:
46+
async def convert(self, ctx: commands.Context, argument: str) -> str: # type: ignore
4647
if argument.startswith("https://") or argument.startswith("http://"):
4748
return argument
4849
return "http://" + argument
@@ -60,7 +61,7 @@ async def convert(self, ctx: commands.Context, argument: str) -> str: # type: i
6061

6162

6263
class SlashEnsureNoHTTPConverter(commands.Converter):
63-
async def convert(self, ctx: commands.Context, argument: str) -> str: # type: ignore[reportUnusedArgument]
64+
async def convert(self, interaction: Interaction, argument: str) -> str: # type: ignore[reportUnusedArgument]
6465
if argument.startswith("https://"):
6566
return argument[len("https://") - 1 :]
6667

_orangcbot/extensions/dns.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def construct_embed(url: str, answer: str, record_type: str):
4040

4141
class DigDropdown(nextcord.ui.Select):
4242
if TYPE_CHECKING:
43-
_message: nextcord.Message
43+
_message: nextcord.Message | nextcord.PartialInteractionMessage
4444

4545
def __init__(self, url: str):
4646
options = [
@@ -53,21 +53,24 @@ def __init__(self, url: str):
5353
DigSelectOption("PTR"),
5454
]
5555
self._url: str = url
56-
super().__init__(options=options, placeholder="What records do you want?")
56+
super().__init__(options=options, placeholder="What records do you want?") # type: ignore -- perfectly compatible!
5757

5858
async def callback(self, interaction: nextcord.Interaction):
5959
await interaction.response.defer()
60+
61+
assert interaction.data is not None
62+
assert "values" in interaction.data
6063
try:
6164
answers = _dnsresolver.resolve(self._url, interaction.data["values"][0])
62-
answer = "\n".join([str(ans) for ans in answers])
65+
answer = "\n".join([str(ans) for ans in answers]) # type: ignore
6366
except _dnsresolver.NoAnswer:
6467
answer = "NOT FOUND"
6568
await self._message.edit(
6669
embed=construct_embed(self._url, answer, interaction.data["values"][0])
6770
)
6871

6972
def update_msg(self, msg: nextcord.Message):
70-
self._message: nextcord.Message = msg
73+
self._message: nextcord.Message | nextcord.PartialInteractionMessage = msg
7174

7275

7376
class DNSView(nextcord.ui.View):
@@ -91,10 +94,11 @@ def update_msg(
9194
self, msg: nextcord.Message | nextcord.PartialInteractionMessage
9295
) -> None:
9396
self._message = msg
94-
self.dropdown.update_msg(msg)
97+
self.dropdown.update_msg(msg) # type: ignore
9598

9699
async def on_timeout(self):
97100
for child in self.children:
101+
assert isinstance(child, nextcord.ui.Button)
98102
child.disabled = True
99103
await self._message.edit(view=self)
100104

@@ -108,7 +112,7 @@ async def dig(self, ctx: commands.Context, url: str):
108112
"""Dig an URL for its DNS records. Default to CNAME, if you want other then select in the dropdown."""
109113
try:
110114
answers = _dnsresolver.resolve(url, "CNAME")
111-
answer = "\n".join([str(ans) for ans in answers])
115+
answer = "\n".join([str(ans) for ans in answers]) # type: ignore -- those are subscriptable
112116
except _dnsresolver.NoAnswer:
113117
answer = "NOT FOUND"
114118
except _dnsresolver.NXDOMAIN:
@@ -130,7 +134,7 @@ async def dig_(
130134
"""Dig an URL for its DNS records. Default to CNAME, if you want other things then please choose in the dropdown provided later."""
131135
try:
132136
answers = _dnsresolver.resolve(url, "CNAME")
133-
answer = "\n".join([str(ans) for ans in answers])
137+
answer = "\n".join([str(ans) for ans in answers]) # type: ignore -- those are subscriptible
134138
except _dnsresolver.NoAnswer:
135139
answer = "NOT FOUND"
136140
except _dnsresolver.NXDOMAIN:

_orangcbot/extensions/faq.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from __future__ import annotations
22

3-
from typing import Dict, List
3+
from typing import TYPE_CHECKING, Dict, List
44

55
import nextcord
66
from nextcord.ext import commands
@@ -57,6 +57,9 @@ def __init__(self, question: str, answer: str) -> None:
5757

5858

5959
class FAQDropdown(nextcord.ui.Select):
60+
if TYPE_CHECKING:
61+
_message: nextcord.Message | nextcord.PartialInteractionMessage
62+
6063
def __init__(self):
6164
options: List[nextcord.SelectOption] = [
6265
nextcord.SelectOption(
@@ -94,10 +97,11 @@ def __init__(self):
9497
),
9598
]
9699
super().__init__(placeholder="Select your question.", options=options)
97-
self._message: nextcord.Message = None
98100

99-
def update_msg(self, message: nextcord.Message | nextcord.InteractionMessage):
100-
self._message: nextcord.Message | nextcord.InteractionMessage = message
101+
def update_msg(
102+
self, message: nextcord.Message | nextcord.PartialInteractionMessage
103+
):
104+
self._message: nextcord.Message | nextcord.PartialInteractionMessage = message
101105

102106
async def callback(self, interaction: nextcord.Interaction):
103107
await interaction.response.defer()

_orangcbot/extensions/suggestions.py

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
from __future__ import annotations
22

33
from contextlib import suppress
4-
from typing import TYPE_CHECKING
4+
from typing import TYPE_CHECKING, Literal, cast
55

66
from nextcord import (
77
Colour,
88
Embed,
99
Interaction,
1010
Message,
1111
SlashOption,
12+
TextChannel,
1213
TextInputStyle,
1314
message_command,
1415
slash_command,
@@ -41,7 +42,7 @@ def __init__(self, mode: bool, message: Message) -> None:
4142
async def callback(self, interaction: Interaction) -> None:
4243
embed = self._suggestion_msg.embeds[0]
4344
embed.add_field(
44-
name=f"{'Approved by' if self._mode else 'Denied by'} {interaction.user.display_name}",
45+
name=f"{'Approved by' if self._mode else 'Denied by'} {interaction.user.name}",
4546
value=self.reas.value,
4647
)
4748
await self._suggestion_msg.edit(embed=embed)
@@ -75,7 +76,7 @@ async def deny_suggestion_msg(
7576
await interaction.response.send_modal(ApproveOrDeny(False, message))
7677

7778
@slash_command(name="suggestion")
78-
async def _suggestion(self, interaction: Interaction):
79+
async def _suggestion(self, interaction: Interaction): # type: ignore[reportUnusedVariable]
7980
pass
8081

8182
@_suggestion.subcommand(
@@ -91,6 +92,9 @@ async def _suggest(
9192
name="suggestion", description="Write your suggestion here.", required=True
9293
),
9394
):
95+
embed: Embed
96+
97+
for_ = cast(Literal["the server", "the service"], for_)
9498
if for_ == "the server":
9599
embed = Embed(
96100
title="Server Suggestion", description=suggestion, colour=Colour.red()
@@ -99,19 +103,26 @@ async def _suggest(
99103
text=f"By {str(interaction.user)} (ID {interaction.user.id})"
100104
)
101105

102-
if for_ == "the service":
106+
elif for_ == "the service":
103107
embed = Embed(
104108
title="Service Suggestion", description=suggestion, colour=Colour.red()
105109
)
106110
embed.set_footer(
107111
text=f"By {str(interaction.user)} (ID {interaction.user.id})"
108112
)
109113

114+
else:
115+
await interaction.send(
116+
"Well, what do you want to suggest for? Use your brain and let autocomplete guide you."
117+
)
118+
110119
channel = interaction.guild.get_channel(self.suggestion_channel)
111-
message = await channel.send(embed=embed)
120+
channel = cast(TextChannel, channel)
121+
message = await channel.send(embed=embed) # type: ignore
112122
await message.add_reaction("✅")
113123
await message.add_reaction("❌")
114124
log_channel = self.bot.get_channel(955105139461607444)
125+
log_channel = cast(TextChannel, log_channel)
115126
await log_channel.send(f"{str(interaction.user)} has suggested {suggestion}.")
116127
await interaction.send(
117128
f"You can now see your suggestion in {channel.mention}.",
@@ -146,6 +157,7 @@ async def _deny(
146157
),
147158
):
148159
channel = interaction.guild.get_channel(self.suggestion_channel)
160+
channel = cast(TextChannel, channel)
149161
message = await channel.fetch_message(int(messageId))
150162
embed = message.embeds[0]
151163
new_embed = embed.add_field(
@@ -171,6 +183,7 @@ async def _approve(
171183
if not why:
172184
why = "No reason provided"
173185
channel = self.bot.get_channel(self.suggestion_channel)
186+
channel = cast(TextChannel, channel)
174187
message = await channel.fetch_message(int(messageId))
175188
embed = message.embeds[0]
176189
new_embed = embed.add_field(

_orangcbot/extensions/types.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,20 @@ class _OwnerObject(TypedDict):
1616
twitter: NotRequired[str]
1717

1818

19-
class _RecordObject(TypedDict, total=False):
19+
class _OtherRecordObject(TypedDict, total=False):
2020
A: List[str]
21-
CNAME: str
2221
URL: str
2322
TXT: Union[str, List[str]]
2423
MX: List[str]
2524

2625

26+
class _CNAMERecordObject(TypedDict):
27+
CNAME: str
28+
29+
30+
_RecordObject = Union[_OtherRecordObject, _CNAMERecordObject]
31+
32+
2733
class Domain(TypedDict):
2834
description: NotRequired[str]
2935
repo: NotRequired[str]

0 commit comments

Comments
 (0)