99KEY_PATH = "D:\Coding\Discord bots\python-windows-bot\key.txt"
1010CONFIG_PATH = "D:\Coding\Discord bots\python-windows-bot\config.json"
1111
12-
1312def is_connected ():
1413 try :
15- # Try to resolve a common domain to check if network is available
14+ # Try to resolve a common domain to check if the network is available
1615 socket .create_connection (("www.google.com" , 80 ))
1716 return True
1817 except OSError :
1918 pass
2019 return False
2120
22-
2321def load_config ():
2422 print ("Loading configuration file..." )
2523 with open (CONFIG_PATH , "r" ) as config_file :
2624 config = json .load (config_file )
2725 return config
2826
29-
30- async def main ():
27+ async def network_monitor ():
3128 while True :
32- if is_connected ():
33- break
34- print ("Waiting for network..." )
35- await asyncio .sleep (5 ) # Wait for 5 seconds before checking again
29+ if not is_connected ():
30+ print ("Network connection lost. Waiting for network..." )
31+ while not is_connected ():
32+ await asyncio .sleep (5 ) # Wait for 5 seconds before checking again
33+ print ("Network has been restored." )
34+ await asyncio .sleep (60 ) # Check network status every 60 seconds
3635
36+ async def main ():
3737 if os .path .exists (KEY_PATH ):
3838 with open (KEY_PATH , "r" ) as f :
3939 TOKEN = f .read ()
@@ -46,6 +46,9 @@ async def main():
4646
4747 client = discord .Client (intents = intents )
4848
49+ # Start the network monitoring task in the background
50+ asyncio .create_task (network_monitor ())
51+
4952 @client .event
5053 async def on_ready ():
5154 print (f"We have logged in as { client .user } " )
@@ -56,7 +59,8 @@ async def on_ready():
5659
5760 @client .event
5861 async def on_message (message ):
59- msg = str (message .content ).lower ()
62+ msg = str (message .content ).lower ().split (' ' )[0 ]
63+ args = message .content .split (" " )[1 :]
6064
6165 if (
6266 message .author == client .user
@@ -66,7 +70,7 @@ async def on_message(message):
6670
6771 if message .author .bot or message .author .id != config ["author_id" ]:
6872 return
69-
73+
7074 if str (message .attachments ) != "[]" :
7175 from commands .file_save import execute_file_save
7276
@@ -81,8 +85,11 @@ async def on_message(message):
8185 from commands .ping_command import execute_ping_command
8286
8387 await execute_ping_command (client , message , config )
88+
89+ if msg == "ss" or msg == "screenshot" :
90+ from commands .screenshot_command import execute_screenshot_command
91+ await execute_screenshot_command (message , args )
8492
8593 await client .start (TOKEN )
8694
87-
8895asyncio .run (main ())
0 commit comments