From 9a2eb08992d13ab0d694bf5add84b8b3a7cc6879 Mon Sep 17 00:00:00 2001 From: Vortex <75498823+hypervortex@users.noreply.github.com> Date: Wed, 21 Feb 2024 19:12:17 +0530 Subject: [PATCH] Add files via upload --- dist/ba_root/mods/features/dccmdlogs.py | 38 +++++++++++++++ dist/ba_root/mods/features/discord_bot.py | 56 ++--------------------- 2 files changed, 43 insertions(+), 51 deletions(-) create mode 100644 dist/ba_root/mods/features/dccmdlogs.py diff --git a/dist/ba_root/mods/features/dccmdlogs.py b/dist/ba_root/mods/features/dccmdlogs.py new file mode 100644 index 0000000..23c134b --- /dev/null +++ b/dist/ba_root/mods/features/dccmdlogs.py @@ -0,0 +1,38 @@ +import json +from datetime import datetime +import os +import _ba + +# Define the directory path using the playerData variable +directory_path = os.path.join(_ba.env()["python_directory_user"], "playersData") + +# Create the directory if it doesn't exist +if not os.path.exists(directory_path): + os.makedirs(directory_path) + +# Define the file path within the directory +file_path = os.path.join(directory_path, "discord_command_logs.json") # Adjust the file name as needed + +def log_command(user_id, user_name, command): + timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S") + + # Create or load logs data + logs_data = [] + if os.path.exists(file_path): + with open(file_path, "r") as f: + logs_data = json.load(f) + + # Append new log entry + logs_data.append({ + "user_id": user_id, + "user_name": user_name, + "command": command, + "timestamp": timestamp + }) + + # Write logs data to JSON file + with open(file_path, "w") as f: + json.dump(logs_data, f, indent=4) + + print("Command logged successfully.") + diff --git a/dist/ba_root/mods/features/discord_bot.py b/dist/ba_root/mods/features/discord_bot.py index e4e75a8..809e261 100644 --- a/dist/ba_root/mods/features/discord_bot.py +++ b/dist/ba_root/mods/features/discord_bot.py @@ -117,21 +117,7 @@ async def joined_player(pbid, devices_string, time): await channel.send(message) #print(f"{devices_string}... Notification send Successfully!") -def log_command(user_id, user_name, command): - timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S") - - logs_data = pdata.get_DiscordCmds() - - logs_data.append([ - f"user_id - {user_id}", - f"user_name - {user_name}", - f"command - {command}", - f"timestamp - {timestamp}" - ]) - - # Update logs data - pdata.update_DiscordCmdLogs() - +from features import dccmdlogs as dcl @client.event async def on_message(message): global channel @@ -161,10 +147,10 @@ async def on_message(message): cmd = commands_prefix servers = _ba.app.server._config.party_name m = message.content[2:].split() - command = m[0:] + command = message.content userid = message.author.id username = message.author.name - log_command(userid, username, command) + dcl.log_command(userid, username, command) if m[0] == 'bsunban': #unban in all server xD if len(m) == 2: pb_id_to_unban = m[1] @@ -1899,40 +1885,7 @@ async def on_message(message): await message.channel.send(f">>> :arrow_right:**{m[1]} Not played in {servers} yet**") else: await message.channel.send(">>> :arrow_right:**:x:Invalid Format! Use `{0}{1}dinfodata `**".format(prefix, commands_prefix)) - - #bandata cmd to check all ids - elif m[0] == 'bandata': - player_info = mongo.playerinfo.find_one() or {'pinfo': {'pbid': [], 'name': [], 'deviceid': [], 'ip': [], 'linkedaccount': [], 'accountage': []}} - if player_info and 'pinfo' in player_info: - p_ids = player_info['pinfo']['pbid'] - p_name = player_info['pinfo']['name'] - p_deviceid = player_info['pinfo']['deviceid'] - p_ip = player_info['pinfo']['ip'] - p_linkedaccount = player_info['pinfo']['linkedaccount'] - p_account_age = player_info['pinfo']['accountage'] - - if len(m) == 2: - pb_id_to_check = m[1] - if pb_id_to_check in p_ids: - index = p_ids.index(pb_id_to_check) - name = p_name[index] - deviceid = p_deviceid[index] - ip = p_ip[index] - linkedaccount = p_linkedaccount[index] - accountage = p_account_age[index] - player_message = ( - f">>> :arrow_right:**:reminder_ribbon:|| Name: {name} **\n" - f":arrow_right:**:reminder_ribbon:|| Account ID: {pb_id_to_check} **\n" - f":arrow_right:**:reminder_ribbon:|| IP: {ip} \n**" - f":arrow_right:**:reminder_ribbon:|| Device-id: {deviceid} **\n" - f":arrow_right:**:reminder_ribbon:|| Linked Account: {linkedaccount} **\n" - f":arrow_right:**:reminder_ribbon:|| Account-Age: {accountage} **" - ) - await message.channel.send(player_message) - else: - await message.channel.send(f">>> :arrow_right:**{m[1]} Not played in {servers} yet**") - else: - await message.channel.send(">>> :arrow_right:**:x:Invalid Format! Use `{0}bandata `**".format(prefix)) + # get top 10 player list xD elif m[0] == (cmd +'top10'): @@ -2003,6 +1956,7 @@ async def on_message(message): await message.channel.send(">>> :arrow_right:**:x:Invalid Format! Use `{0}userremove `**".format(prefix)) +