Skip to content

Commit

Permalink
SpyAgent 2.8.0
Browse files Browse the repository at this point in the history
Several commands have been added:
***reply -  reply to a message
***vcplay - turns on music in any voice channel
***vcstop - turns off the music where it is on (you can enable it in the config)

Support for displaying replies to message has been added
  • Loading branch information
progame1201 committed Jan 16, 2024
1 parent 1b0801a commit e737393
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 25 deletions.
102 changes: 84 additions & 18 deletions SpyBot20/Commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
from colorama import Fore, init

class Commands:
'''All commands of SpyAgent 2.6.0+
most of the commands were taken from version 1.0.0, which is why their code maybe bad.
'''All commands of SpyAgent 2.8.0+
most of the commands were taken from version 1.0.0-2.0.0, which is why their code maybe bad.
'''
def __init__(self, client=None, guild=None, channel=None):
self.client:Client = client
Expand Down Expand Up @@ -41,17 +41,21 @@ def getmutes(self):
return [channels_mute_list, guild_mute_list]
async def async_input(self, prompt):
return await asyncio.to_thread(input, prompt)

async def get_history(self):
async def raw_history(self):
messages = []
try:
async for message in self.channel.history(limit=config.history_size, oldest_first=False):
messages.append(message)
except Forbidden:
print(f"{Fore.RED}It's impossible to get: Forbidden.")
return False
messages.reverse()
return messages
async def get_history(self):
messages = await self.raw_history()
if messages == False:
return
print("Channel history:\n#####################")
messages.reverse()
for message in messages:
rounded_date_string = message.created_at.astimezone(pytz.timezone('Europe/Moscow')).strftime('%Y-%m-%d %H:%M')
attachment_list = []
Expand All @@ -66,6 +70,10 @@ async def get_history(self):
for reaction in message.reactions:
reactions_list.append(reaction.emoji)
msg += f" | reactions: {reactions_list}"
if config.allow_reference_display:
if message.reference and message.reference.message_id:
reference = await message.channel.fetch_message(message.reference.message_id)
msg += f" | reference: reply: {reference.author.name}: {reference.content}"
print(msg)

print("#####################")
Expand Down Expand Up @@ -105,11 +113,10 @@ async def unmutechannel(self):
except Exception as e:
print(f"index not found\n{e}")
async def delete(self):
messages = []
messages = await self.raw_history()
if messages == False:
return
yourmessages: dict[int:Message] = {}
async for message in self.channel.history(limit=config.history_size, oldest_first=False):
messages.append(message)
messages.reverse()

for i, message in enumerate(messages):
if message.author.id == self.client.user.id:
Expand Down Expand Up @@ -234,10 +241,9 @@ async def reaction(self):
print("2 - message list")
messageinput = await self.async_input("type number:")
if messageinput == "2":
messages = []
async for message in self.channel.history(limit=50, oldest_first=False):
messages.append(message)
messages.reverse()
messages = await self.raw_history()
if messages == False:
return
for i, message in enumerate(messages):
print(f"{i}: {message.author}: {message.content}")
messageindex = await self.async_input("message index:")
Expand All @@ -259,15 +265,28 @@ async def privatemsg(self):

async def setuser(self):
usrid = int(await self.async_input("user id:"))
print("checking availability...")
sure = False
for user in self.client.users:
if user.id == usrid:
sure = True
break
if sure == False:
allowed = await self.async_input("the user was not found in the list of users. Continue? [y / n]")
if allowed.lower() != "y":
return
else:
print("User has been found")
user: User = self.client.get_user(usrid)
self.channel = user
return {"channel":user, "guild":None}
await self.get_history()
return {"channel":user}
async def edit(self):
messages = []
messages = await self.raw_history()
if messages == False:
return
yourmessages: dict[int:Message] = {}
async for message in self.channel.history(limit=config.history_size, oldest_first=False):
messages.append(message)
messages.reverse()

for i, message in enumerate(messages):
if message.author.id == self.client.user.id:
yourmessages[i] = message
Expand All @@ -287,3 +306,50 @@ async def set(self):
self.channel = self.client.get_channel(int(id))
await self.get_history()
return {"channel": self.channel}
async def reply(self):
messages = await self.raw_history()
replymessages:dict[int,Message] = {}
if messages == False:
return
for i, msg in enumerate(messages):
replymessages[i] = msg
print(f"{i}: {msg.channel}: {msg.author}: {msg.content}")
id = int(await self.async_input("message index:"))
if id < 0:
return
await replymessages[id].reply(await self.async_input("message:"))
async def vcpaly(self):
print("Choose a channel:")
channels: dict[int, dict[str:int]] = {}
for i, channel in enumerate(self.guild.voice_channels):
channels.update({i: {channel.name: channel.id}})
print(f"{i}: {channel.name}")
data = await self.async_input("channel index:")
if data == "" or data == None:
return
try:
vcchannel:VoiceChannel = self.client.get_channel(list(channels.get(int(data)).values())[0])
for client in self.client.voice_clients:
if client.guild.id == vcchannel.guild.id:
await client.disconnect()
logger.success(f"channel assigned! channel name {channel.name}, channel id: {channel.id}")
vcch:VoiceClient = await vcchannel.connect(timeout=5)
except Forbidden:
logger.error(f"{Fore.RED}It's impossible to connect: Forbidden.")
return
path = filedialog.askopenfilename()
if path == "" or path == None or path == " ":
return
source = FFmpegPCMAudio(path)
vcch.play(source)
logger.success("Audio playback has started")
async def VC_play(self, source, vcch):
vcch.play(source)
async def vcstop(self):
for i, client in enumerate(self.client.voice_clients):
print(f"{i}:{client.channel.name}")
id = await self.async_input("channel index:")
await self.client.voice_clients[int(id)].disconnect()
logger.success("Disconnected")


24 changes: 17 additions & 7 deletions SpyBot20/SpyAgent.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from colorama import Fore, init
import Commands
import LocalCommandManager
logger.info("Spy Agent 2.7.0, 2024, progame1201")
logger.info("Spy Agent 2.8.0, 2024, progame1201")
logger.info("Running...")
client:Client = Client(intents=Intents.all())
init(autoreset=True)
Expand Down Expand Up @@ -109,7 +109,7 @@ async def message_edit():
while True:
before, after = await client.wait_for("message_edit")
if channel.id == after.channel.id:
print(f"Message: {before.content} | has been changed to: {after.content} |in: {after.guild}: {after.channel}: {after.author}\n")
print(f"Message: {before.content} | has been changed to: {after.content} | in: {after.guild}: {after.channel}: {after.author}\n")

async def guild_remove():
while True:
Expand Down Expand Up @@ -166,13 +166,16 @@ async def receive_messages():
for attachment in message.attachments:
attachment_list.append(attachment.url)
msg += f" | attachments: {attachment_list}"
if message.reference:
if config.allow_reference_display:
reference = await message.channel.fetch_message(message.reference.message_id)
msg += f" | reference: {reference.author.name}: {reference.content}"

print(f"{msg}\n")
if config.notification == True:
if message.author.id != client.user.id:
winsound.Beep(500, 100)
winsound.Beep(1000, 100)

winsound.Beep(500, 100)
winsound.Beep(1000, 100)
async def chatting():
global guild
global channel
Expand All @@ -195,6 +198,9 @@ async def chatting():
cm.new(command_name="***into", func=cmnds.into)
cm.new(command_name="***set", func=cmnds.set)
cm.new(command_name="***setuser", func=cmnds.setuser)
cm.new(command_name="***reply", func=cmnds.reply)
cm.new(command_name="***vcplay", func=cmnds.vcpaly)
cm.new(command_name="***vcstop", func=cmnds.vcstop)
print(f"\n{Fore.YELLOW}List of loaded commands:\n{cm.get_keys()}\n{Fore.CYAN}type ***help to get more info!")
logger.success("Command manager started!")
await sleep(2)
Expand All @@ -213,8 +219,7 @@ async def chatting():
if "channel" in list(cmresult.keys()):
channel = cmresult["channel"]
if "guild" in list(cmresult.keys()):
if cmresult["guild"] != None:
guild = cmresult["guild"]
guild = cmresult["guild"]
continue

try:
Expand Down Expand Up @@ -247,10 +252,15 @@ async def get_history(channel:TextChannel):
for reaction in message.reactions:
reactions_list.append(reaction.emoji)
msg += f" | reactions: {reactions_list}"
if config.allow_reference_display:
if message.reference and message.reference.message_id:
reference = await message.channel.fetch_message(message.reference.message_id)
msg += f" | reference: reply: {reference.author.name}: {reference.content}"
print(msg)

print("#####################")
async def async_input(prompt):
return await asyncio.to_thread(input, prompt)


client.run(config.Token)
1 change: 1 addition & 0 deletions SpyBot20/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
notification = False # default == False
allow_private_messages = True # default == True
display_users_avatars_urls = False # default == False it may break the display of messages if the user does not have his own avatar
allow_reference_display = False # default == False Displays replies to messages. It can greatly slow down the receipt of messages and message history
#event detector:
'''it serves to indicate that an event has occurred'''
detector = True # default == True
Expand Down

0 comments on commit e737393

Please sign in to comment.