From 67ced4e7bfaefd5b361530d19e2ab9fea6e80a09 Mon Sep 17 00:00:00 2001
From: swee <meow@swee.codes>
Date: Tue, 11 Mar 2025 15:40:46 -0700
Subject: [PATCH] Update sweebot.py

---
 sweebot.py | 32 +++++++++++++++++++++++++++++---
 1 file changed, 29 insertions(+), 3 deletions(-)

diff --git a/sweebot.py b/sweebot.py
index 9afe719..e506ab7 100644
--- a/sweebot.py
+++ b/sweebot.py
@@ -1,4 +1,4 @@
-__version__ = "1.0.1 AI update" + ". https://git.swee.codes/swee/MeowNex"
+__version__ = "1.0.2 DOcker-SHELL update" + ". https://git.swee.codes/swee/MeowNex"
 import socket
 import subprocess
 from time import sleep, time, ctime
@@ -17,6 +17,8 @@ from googleapiclient.discovery import build
 import uuid
 import ssl
 import requests
+import docker
+dock = docker.from_env()
 global lastquery
 AIurl = environ["AIurl"]
 AIsession = requests.Session()
@@ -60,7 +62,7 @@ def ai_response_truncate(uuidd):
     else:
         abrt(404)
 threading.Thread(target=app.run, daemon=True, kwargs={"port": 2005}).start()
-
+cntr = None
 # YouTube API
 DEVELOPER_KEY = environ["ytapi"]
 headers = {
@@ -663,7 +665,31 @@ while True:
                             irc.send_irc(channel, nick + ": Permission denied.")
                             block+=1
                             run-=1
-                            
+
+                    elif command[0] == "$dopull":
+                        irc.send_irc(channel, nick + ":[...] Please wait, pulling docker image...")
+                        image = dock.images.pull('alpine')
+                        irc.send_irc(channel, nick + ":[OK] Pulled docker image, running command now.")
+                    elif command[0] == "$doshell":
+                        if len(command) > 1:
+                            try:
+                                if cntr == None:
+                                    cntr = dock.containers.run('alpine', "/bin/ash", detach=True, tty=True)
+                                _, stream = cntr.exec_run(cmd=" ".join(command[1:]))
+                                multiline(stream, channel)
+                            except Exception as ex:
+                                irc.send_irc(channel, nick + ":[ERR] Traceback:")
+                                multiline(traceback.format_exc(), channel)
+                        else:
+                            irc.send_irc(channel, nick + ":[ERR] ")
+                    elif command[0] == "$doreset":
+                        if cntr == None:
+                            irc.send_irc(channel, nick + ":[OK] No container is loaded yet.")
+                        else:
+                            cntr.remove()
+                            cntr = None
+                            irc.send_irc(channel, nick + ":[OK] Done.")
+                        
 
                     elif command[0] == "$version":
                         irc.send_irc(channel, "This is MeowNexUS IRC " + __version__)