Skip to content

Commit 3dce957

Browse files
committed
Added Bat file to be accessible from anywhere
1 parent cb467fe commit 3dce957

File tree

7 files changed

+20
-11
lines changed

7 files changed

+20
-11
lines changed

bot.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
import pyautogui
77
from commands.mouse_movement import monitor_mouse_movement
88

9+
KEY_PATH = "D:\Coding\Discord bots\python-windows-bot\key.txt"
10+
CONFIG_PATH = "D:\Coding\Discord bots\python-windows-bot\config.json"
11+
912

1013
def is_connected():
1114
try:
@@ -19,7 +22,7 @@ def is_connected():
1922

2023
def load_config():
2124
print("Loading configuration file...")
22-
with open("config.json", "r") as config_file:
25+
with open(CONFIG_PATH, "r") as config_file:
2326
config = json.load(config_file)
2427
return config
2528

@@ -31,8 +34,8 @@ async def main():
3134
print("Waiting for network...")
3235
await asyncio.sleep(5) # Wait for 5 seconds before checking again
3336

34-
if os.path.exists("key.txt"):
35-
with open("key.txt", "r") as f:
37+
if os.path.exists(KEY_PATH):
38+
with open(KEY_PATH, "r") as f:
3639
TOKEN = f.read()
3740
else:
3841
TOKEN = ""
180 Bytes
Binary file not shown.

commands/file_save.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ async def execute_file_save(client, message, config):
66
await message.guild.get_channel(LOG_CHANNEL_ID).send(f"File Detected: {filename}")
77
try:
88
await message.attachments[0].save(
9-
fp="files/{}".format(filename)
9+
fp="D:/Coding\Discord bots/python-windows-bot/files/{}".format(filename)
1010
) # saves the file
1111
await message.guild.get_channel(LOG_CHANNEL_ID).send("File Sucessfully saved")
1212
print(f"[file_save_LOG] - File Sucessfully saved.")

commands/mouse_movement.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
import datetime
88
from PIL import ImageGrab
99

10+
DATA_JSON_PATH = "D:\Coding\Discord bots\python-windows-bot\data\data.json"
11+
SCREENSHOT_PATH = "D:\Coding\Discord bots\python-windows-bot\data\screenshot.png"
12+
1013

1114
async def monitor_mouse_movement(client, config, starting_mouse_position):
1215
log_channel_id = config["mouse_log_channel_id"]
@@ -19,7 +22,7 @@ async def monitor_mouse_movement(client, config, starting_mouse_position):
1922
previous_mouse_position = starting_mouse_position
2023

2124
try:
22-
with open("data/data.json", "r") as data_file:
25+
with open(DATA_JSON_PATH, "r") as data_file:
2326
data = json.load(data_file)
2427
last_message_id = data.get("last_message_id")
2528
image_message_id = data.get("image_message_id")
@@ -61,7 +64,7 @@ async def monitor_mouse_movement(client, config, starting_mouse_position):
6164
)
6265
)
6366

64-
screenshot.save("data/screenshot.png")
67+
screenshot.save(SCREENSHOT_PATH)
6568

6669
# Check if image_message is not None and attempt to delete it if it exists
6770
if image_message:
@@ -71,7 +74,7 @@ async def monitor_mouse_movement(client, config, starting_mouse_position):
7174
pass # Message already deleted or not found
7275

7376
image_message = await log_channel.send(
74-
message, file=discord.File("data/screenshot.png")
77+
message, file=discord.File(SCREENSHOT_PATH)
7578
)
7679

7780
print(f"[mouse_movement_LOG] - {last_movement_time} : Mouse SS sent.")
@@ -81,7 +84,7 @@ async def monitor_mouse_movement(client, config, starting_mouse_position):
8184
else:
8285
last_message = await log_channel.send(message)
8386

84-
with open("data/data.json", "w") as data_file:
87+
with open(DATA_JSON_PATH, "w") as data_file:
8588
json.dump(
8689
{
8790
"last_message_id": last_message.id,

data/data.json.example

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"last_message_id": 1148276847387274799, "image_message_id": 1155463340493231465, "last_movement_time": "24-09-2023 16:48:48"}

start_bot.bat

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1+
cd "D:\Coding\Discord bots\python-windows-bot"
12
powershell -ExecutionPolicy Bypass -File "D:\Coding\Discord bots\python-windows-bot\start_bot.ps1"
3+
pause

start_bot.ps1

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
$venvScript = "d:/Coding/Discord bots/python-windows-bot/.venv/Scripts/Activate.ps1"
2-
$botScript = "d:/Coding/Discord bots/python-windows-bot/bot.py"
1+
$venvScript = "D:\Coding\Discord bots\python-windows-bot\.venv\Scripts\Activate.ps1"
2+
$botScript = "D:\Coding\Discord bots\python-windows-bot\bot.py"
33

44
# Activate the virtual environment
5-
. $venvScript
5+
& $venvScript
66

77
# Run the bot script
88
python $botScript

0 commit comments

Comments
 (0)