-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBotBase.py
79 lines (64 loc) · 2.24 KB
/
BotBase.py
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
from nextcord.abc import GuildChannel
from nextcord.ext import commands
from nextcord import Guild, Member, User, DMChannel
from nextcord.ext import commands
class BotBaseBot(commands.Bot):
async def get_or_fetch_guild(self, guild_id: int) -> Guild:
"""Looks up a guild in cache or fetches if not found."""
guild = self.get_guild(guild_id)
if guild:
return guild
try:
guild = await self.fetch_guild(guild_id)
except:
return False
return guild
async def get_or_fetch_user(self, user_id: int) -> User:
"""Looks up a user in cache or fetches if not found."""
user = self.get_user(user_id)
if user:
return user
try:
user = await self.fetch_user(user_id)
except:
return False
return user
async def get_or_fetch_member(self, guild_id: int, member_id: int) -> Member:
"""Looks up a member in cache or fetches if not found."""
guild = await self.get_or_fetch_guild(guild_id)
if not guild:
return await self.get_or_fetch_user(member_id)
member = guild.get_member(member_id)
if member is not None:
return member
try:
member = await guild.fetch_member(member_id)
except:
member = await self.get_or_fetch_user(member_id)
return member
async def get_or_fetch_channel(self, channel_id: int) -> GuildChannel:
"""Looks up a channel in cache or fetches if not found."""
channel = self.get_channel(channel_id)
if channel:
return channel
try:
channel = await self.fetch_channel(channel_id)
except:
return False
return channel
async def get_user_dm(self, user_id: int, *args, **kwargs) -> DMChannel:
try:
user = await self.bot.get_or_fetc_user(user_id)
if user:
try:
await user.send(
*args, **kwargs
)
return True
except:
return False
except:
return False
return False
async def WrapStuff(self, stuff):
pass