-
Notifications
You must be signed in to change notification settings - Fork 0
/
BotClient.py
executable file
·98 lines (83 loc) · 3.4 KB
/
BotClient.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
import discord
import decky_plugin
class BotClient(discord.Client):
def __init__(self):
intents = discord.Intents.default()
intents.members = True
intents.presences = True
super().__init__(intents=intents)
self.dms = {}
self.chat_channel = {}
async def on_ready(self):
decky_plugin.logger.info(f'Logged in as {self.user.name}')
def get_user_name(self):
return self.user.name
def get_server_name(self):
server_name = "Not in a guild!"
for guild in self.guilds:
server_name = guild.name
break
return server_name
async def send_message_to_user(self, user_id, msg):
user = self.get_user(user_id)
if user:
await user.send(msg)
else:
decky_plugin.logger.info("Usuario not found")
async def send_message_to_channel(self, channel_name, msg):
for guild in self.guilds:
channel = discord.utils.get(guild.text_channels, name=channel_name)
if channel:
await channel.send(msg)
else:
decky_plugin.logger.info("Channel not found in the guild.")
break
async def close_session(self):
await self.close()
async def get_dms_specific_user(self, username):
counter = 100
user = discord.utils.get(self.get_all_members(), name=username)
if user is not None:
private_channel = await user.create_dm()
async for message in private_channel.history(limit=100):
self.dms[counter] = str(message.author.name) + ";" + str(message.content)
counter -= 1
else:
decky_plugin.logger.info("Usuario not found")
async def get_messages_from_channel(self, channel_name):
counter = 100
for guild in self.guilds:
for channel in guild.channels:
if str(channel.name) == channel_name:
async for message in channel.history(limit=100):
self.chat_channel[counter] = str(message.author.name) + ";" + str(message.content)
counter -= 1
break
def get_channels(self):
channels = {}
for guild in self.guilds:
for channel in guild.channels:
if str(channel.type) == "text":
channels[channel.id] = channel.name
return channels
def get_online_members(self):
online_members = {}
for guild in self.guilds:
for member in guild.members:
if str(self.user.name) != member.name and str(member.status) != "offline":
status = str(member.status)
if status == "dnd":
status = "Do Not Disturb"
elif status == "idle":
status = "Idle"
elif status == "online":
status = "Online"
online_members[member.id] = str(member.name) + ";" + status
return online_members
def get_offline_members(self):
offline_members = {}
for guild in self.guilds:
for member in guild.members:
if str(self.user.name) != member.name and str(member.status) == "offline":
offline_members[member.id] = str(member.name)
return offline_members