-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
171 lines (134 loc) · 6.34 KB
/
main.py
File metadata and controls
171 lines (134 loc) · 6.34 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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
import conifg
import asyncio
from disnake import *
from commands import *
from aioconsole import ainput
from log import log, user_message, event, error
from utils import SelectUtils, prepare_message, show_history, GuildMute, ChannelMute, MuteUtils, draw_message_attachments
log("SpyAgent-DiscordBotClient 3.4.1, 2026, progame1201")
client = Client(intents=Intents.all())
mutes = MuteUtils.get_mutes()
guild_mutes = []
channel_mutes = []
vc_clients = []
guild: Guild | None = None
channel: TextChannel | None = None
for mute in mutes.channels:
channel_mutes.append(mute.id)
for mute in mutes.guilds:
guild_mutes.append(mute.id)
log(f"Loaded mutes: {channel_mutes}, {guild_mutes}")
@client.event
async def on_ready():
global guild, channel
log(f"Logged in as {client.user.name}", show_time=True)
select_utils = SelectUtils(client)
guild = await select_utils.select_guild()
channel = await select_utils.select_channel(guild)
await show_history(channel, draw_images=conifg.DRAW_IMAGES)
asyncio.run_coroutine_threadsafe(message_sender(), client.loop)
@client.event
async def on_message(message: Message):
if conifg.WRITE_MSGS_FROM_SEL_CH and message.channel != channel:
return
if message.channel in channel_mutes or message.guild in guild_mutes and message.channel != channel:
return
user_message(await prepare_message(message, conifg.WRITE_MSGS_FROM_SEL_CH))
if conifg.DRAW_IMAGES:
await draw_message_attachments(message)
@client.event
async def on_reaction_add(reaction, user):
if channel.id == reaction.message.channel.id:
event(
f"Reaction {reaction.emoji} | was added to: {reaction.message.author}: "
f"{reaction.message.content if len(reaction.message.content) < 40 else f"{reaction.message.content[:40]}..."} | by {user.name}\n")
@client.event
async def on_reaction_remove(reaction, *args):
if channel.id == reaction.message.channel.id:
event(
f"Reaction {reaction.emoji} | was removed from: {reaction.message.author}: "
f"{reaction.message.content if len(reaction.message.content) < 40 else f"{reaction.message.content[:40]}..."}\n")
@client.event
async def on_message_delete(message: Message):
if channel.id == message.channel.id:
event(f"Message removed {message.author}: {message.content} \n")
@client.event
async def on_message_edit(before, after):
if channel.id == after.channel.id:
event(f"Message: {after.author}: {before.content} | has been changed to: {after.content}\n")
@client.event
async def on_guild_channel_delete(channel: TextChannel):
if channel.guild.id == guild.id:
event(f"channel {channel.name} has been deleted\n")
@client.event
async def on_guild_channel_create(channel: TextChannel):
if channel.guild.id == guild.id:
event(f"channel {channel.name} has been created | id: {channel.id}\n")
@client.event
async def on_guild_join(guild):
event(f"Client was joined to the {guild.name} guild")
@client.event
async def on_guild_remove(guild):
event(
f"The guild: {guild.name} has been removed from the guild list (this could be due to: "
f"The bot has been banned. The bot was kicked out. The guild owner deleted the guild. "
f"Or you just left the guild)\n")
@client.event
async def on_voice_state_update(member: Member, before, after):
if member.guild.id == guild.id:
if before.channel is None and after.channel is not None:
event(f'{member.name} joined voice channel {after.channel}')
elif before.channel is not None and after.channel is None:
event(f'{member.name} left voice channel {before.channel}')
async def message_sender():
global guild, channel
while True:
message: str = await ainput("")
if message.lower().startswith(conifg.COMMAND_PREFIX):
message = message.replace(conifg.COMMAND_PREFIX, "").lower()
if message == "help":
print()
log("HELP:")
for command in get_commands(guild, channel, client):
log(command.description)
print()
for command in get_commands(guild, channel, client):
if message.split(" ")[0] != command.name:
continue
if command.name == "mute" or command.name == "unmute": # I tried to use isinstance, but it froze. Idk what the problem is.
command.channel_mutes = channel_mutes
command.guild_mutes = guild_mutes
output: CommandOutput = await command.execute(message.split(" ")[1:])
elif command.name == "vcdisconnect" or command.name == "vcplay" or command.name == "vcstop":
command.vc_clients = vc_clients
output: CommandOutput = await command.execute(message.split(" ")[1:])
else:
output: CommandOutput = await command.execute(message.split(" ")[1:])
if isinstance(output, ResetOutput):
guild = output.guild
channel = output.channel
if isinstance(output, SetOutput):
channel = output.channel
if isinstance(output, VcDisconnectOutput):
vc_clients.remove(output.vc_client)
if isinstance(output, VcConnectOutput):
vc_clients.append(output.vc_client)
if isinstance(output, MuteOutput):
if isinstance(output.mute_object, ChannelMute):
channel_mutes.append(output.mute_object.id)
if isinstance(output.mute_object, GuildMute):
guild_mutes.append(output.mute_object.id)
if isinstance(output, UnmuteOutput):
if isinstance(output.mute_object, ChannelMute):
channel_mutes.remove(output.mute_object.id)
if isinstance(output.mute_object, GuildMute):
guild_mutes.remove(output.mute_object.id)
if isinstance(output, GuildLeaveOutput):
guild = output.guild
channel = output.channel
continue
try:
await channel.send(message)
except Forbidden:
error(f"It's impossible to send: Forbidden.")
client.run(conifg.TOKEN)