Skip to content

Commit

Permalink
SpyAgent 2.10.0
Browse files Browse the repository at this point in the history
Improvements in working with voice chats:
Now, when logging into any of the voice chats, the number of people in this channel is written after the channel name
A new event detector has been added: on_voice_state_update, which notifies when someone entered or exited the voice chat

A new command has been added: ***guildleave Allows you to exit the guild you are in
  • Loading branch information
progame1201 committed Feb 21, 2024
1 parent 02925c7 commit 035c49b
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 13 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ __All commands work with the prefix ***<br>__
+ vcconnect - connect to any voice channel<br>
+ vcdisconnect - disconnect from voice channel
+ vctts - use tts in voice chat<br>
+ guildleave - allows you to exit the guild you are in<br>

### **commands in private messages:** work in SpyAgentPM<br>

+ reset - Gives you the opportunity to re-select the channel and server <br>
Expand Down
10 changes: 8 additions & 2 deletions SpyBot20/Commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class Commands:
def __init__(self, client=None, guild=None, channel=None):
self.client:Client = client
self.channel:TextChannel = channel
self.guild = guild
self.guild:Guild = guild
self.vcchlients:list[VoiceClient] = []
init(autoreset=True)
def getmutes(self):
Expand Down Expand Up @@ -361,7 +361,7 @@ async def vcconnect(self):
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}")
print(f"{i}: {channel.name} {[member.name for member in channel.members]}")
data = await self.async_input("channel index:")
if data == "" or data == None:
return
Expand Down Expand Up @@ -412,5 +412,11 @@ async def vcstop(self):
except:
pass
logger.success("Stoped playing.")
async def leave(self):
print(f"Do you really want to quit from {self.guild.name}?")
confirmation = input("yes or no: ").lower()
if confirmation == "yes" or confirmation == "y":
await self.guild.leave()
logger.success("I'm leaving the current guild.")


24 changes: 14 additions & 10 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.9.1, 2024, progame1201")
logger.info("Spy Agent 2.10.0, 2024, progame1201")
logger.info("Running...")
client:Client = Client(intents=Intents.all())
init(autoreset=True)
Expand All @@ -39,8 +39,7 @@ async def getmutes():
def calculate_file_hash(file_path):
sha256_hash = hashlib.sha256()
with open(file_path, "rb") as file:
for byte_block in iter(lambda: file.read(), b""):
sha256_hash.update(byte_block)
sha256_hash.update(file.read())
return sha256_hash.hexdigest()
def check_file_integrity(file_path):
global hashes
Expand All @@ -56,18 +55,14 @@ async def on_ready():
global guild
global channel
logger.info(f"Welcome {client.user.name}! Bot ID: {client.user.id}")

await sleep(1)

print("Choose a server:")
for i, guild in enumerate(client.guilds):
print(f"{i}: {guild.name}")
data = await async_input("server index:")
guild = client.guilds[int(data)]
logger.success(f"guild assigned! guild name: {guild.name}, guild owner: {guild.owner}, guild id: {guild.id} guild icon url: {guild.icon.url}")

await sleep(1)

print("Choose channel:")
channels: dict[int, dict[str:int]] = {}
for i, channel in enumerate(guild.text_channels):
Expand Down Expand Up @@ -109,8 +104,14 @@ async def on_guild_channel_create(cchannel:channel):
async def on_guild_join(jguild):
print(f"Client was joined to the {jguild.name} guild")
async def on_guild_remove(rguild):
print(f"The guild: {rguild.name} | has been removed from the guild list (this could be due to: The client has been banned. The client was kicked out. The guild owner deleted the guild.\n")
print(f"The guild: {rguild.name} | has been removed from the guild list (this could be due to: The client has been banned. The client was kicked out. The guild owner deleted the guild. Or did you just quit the guild)\n")

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:
print(f'{member.name} joined voice channel {after.channel}')
elif before.channel is not None and after.channel is None:
print(f'{member.name} left voice channel {before.channel}')
if config.detector:
if config.on_reaction_add:
client.event(on_reaction_add)
Expand All @@ -128,6 +129,8 @@ async def on_guild_remove(rguild):
client.event(on_guild_channel_create)
if config.on_guild_channel_delete:
client.event(on_guild_channel_delete)
if config.on_voice_state_update:
client.event(on_voice_state_update)
async def receive_messages():
global channel
global guild
Expand All @@ -141,11 +144,11 @@ async def receive_messages():
rounded_date_string = message.created_at.astimezone(pytz.timezone('Europe/Moscow')).strftime('%Y-%m-%d %H:%M')
if isinstance(message.channel, DMChannel):
if config.allow_private_messages:
msg = f"Private message: {message.channel}: {rounded_date_string} ({message.author.id})"
msg = f"Private message: {message.channel}: {rounded_date_string} (user id: {message.author.id})"
else:
continue
else:
msg = f"{message.guild}: {message.channel} ({message.channel.id}): {rounded_date_string}"
msg = f"{message.guild}: {message.channel} (channel id: {message.channel.id}): {rounded_date_string}"
if check_file_integrity("guildmutes") or check_file_integrity("channelmutes"):
lastmutes = await getmutes()
channels_mute_list = lastmutes[0]
Expand Down Expand Up @@ -206,6 +209,7 @@ async def chatting():
cm.new(command_name="***vcdisconnect", func=cmnds.vcdisconnect)
cm.new(command_name="***activity", func=cmnds.activity)
cm.new(command_name="***vctts", func=cmnds.vctts)
cm.new(command_name="***guildleave", func=cmnds.leave)
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 Down
3 changes: 2 additions & 1 deletion SpyBot20/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@
on_guild_remove = True # default == True
on_guild_join = True # default == True
on_guild_channel_create = True # default == True it only works if it happened in the guild you selected
on_guild_channel_delete = True # default == True it only works if it happened in the guild you selected
on_guild_channel_delete = True # default == True it only works if it happened in the guild you selected
on_voice_state_update = True # default == True it only works if it happened in the guild you selected

0 comments on commit 035c49b

Please sign in to comment.