-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy path__init__.py
More file actions
97 lines (82 loc) · 2.71 KB
/
__init__.py
File metadata and controls
97 lines (82 loc) · 2.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
"""Utility classes & functions provided for use across the whole of the project."""
import asyncio
import ssl
from typing import TYPE_CHECKING
import certifi
import discord
from .command_checks import CommandChecks
from .message_sender_components import MessageSavingSenderComponent
from .suppress_traceback import SuppressTraceback
from .tex_bot import TeXBot
from .tex_bot_base_cog import TeXBotBaseCog
from .tex_bot_contexts import TeXBotApplicationContext, TeXBotAutocompleteContext
if TYPE_CHECKING:
from collections.abc import Sequence
from typing import Final
__all__: "Sequence[str]" = (
"GLOBAL_SSL_CONTEXT",
"AllChannelTypes",
"CommandChecks",
"MessageSavingSenderComponent",
"SuppressTraceback",
"TeXBot",
"TeXBotApplicationContext",
"TeXBotAutocompleteContext",
"TeXBotBaseCog",
"generate_invite_url",
"is_member_inducted",
"is_running_in_async",
)
if TYPE_CHECKING:
type AllChannelTypes = (
discord.VoiceChannel
| discord.StageChannel
| discord.TextChannel
| discord.ForumChannel
| discord.CategoryChannel
| None
)
GLOBAL_SSL_CONTEXT: "Final[ssl.SSLContext]" = ssl.create_default_context(
cafile=certifi.where()
)
def generate_invite_url(discord_bot_application_id: int, discord_guild_id: int) -> str:
"""Execute the logic that this util function provides."""
return discord.utils.oauth_url(
client_id=discord_bot_application_id,
permissions=discord.Permissions(
manage_roles=True,
read_messages=True,
send_messages=True,
manage_messages=True,
embed_links=True,
read_message_history=True,
mention_everyone=True,
add_reactions=True,
use_slash_commands=True,
kick_members=True,
ban_members=True,
manage_channels=True,
view_audit_log=True,
moderate_members=True,
),
guild=discord.Object(id=discord_guild_id),
scopes=("bot", "applications.commands"),
disable_guild_select=True,
)
def is_member_inducted(member: discord.Member) -> bool:
"""
Util method to check if the supplied member has been inducted.
Returns True if the member has any role other than "@News".
The set of ignored roles is a tuple to make the set easily expandable.
"""
return any(
role.name.lower().strip("@ \n\t") not in ("news", "everyone") for role in member.roles
)
def is_running_in_async() -> bool:
"""Determine whether the current context is asynchronous or not."""
try:
asyncio.get_running_loop()
except RuntimeError:
return False
else:
return True