Merge branch 'test' into 'main'

Test merge

See merge request crate/garfbot!1
This commit is contained in:
crate 2024-09-30 21:36:00 +00:00
commit 16222c99ae
3 changed files with 66 additions and 5 deletions

View File

@ -1,10 +1,17 @@
FROM python:3.13.0rc2-bookworm FROM python:3.11.10-bookworm
WORKDIR /usr/src/app WORKDIR /usr/src/app
COPY ./requirements.txt . COPY ./requirements.txt .
RUN apt update RUN apt update
RUN apt install nmap -y RUN apt install -y iputils-ping
RUN pip install --no-cache-dir -r requirements.txt -vvv RUN apt install -y dnsutils
RUN apt install -y nmap
RUN apt install -y python3
RUN apt install -y python3-pip
RUN pip3 install discord
RUN pip3 install openai
RUN pip3 install aiohttp
RUN pip3 install requests
CMD [ "python", "./garfbot.py" ] CMD [ "python", "./garfbot.py" ]

View File

@ -8,6 +8,7 @@ import aiohttp
import asyncio import asyncio
import discord import discord
import requests import requests
import ipaddress
import subprocess import subprocess
from base64 import b64encode from base64 import b64encode
from openai import AsyncOpenAI from openai import AsyncOpenAI
@ -49,6 +50,18 @@ intents.message_content = True
garfbot = discord.Client(intents=intents) garfbot = discord.Client(intents=intents)
# Network Utils Setup
def is_private(target):
try:
ip_obj = ipaddress.ip_address(target)
if ip_obj.is_private:
return True
except ValueError:
if "crate.lan" in target.lower():
return True
return False
# Kroger Setup # Kroger Setup
client_id = config.CLIENT_ID client_id = config.CLIENT_ID
client_secret = config.CLIENT_SECRET client_secret = config.CLIENT_SECRET
@ -224,9 +237,49 @@ async def on_message(message):
if message.content.lower().startswith("garfping "): if message.content.lower().startswith("garfping "):
try: try:
query = message.content.split() query = message.content.split()
user = message.author.name
server = message.guild.name if message.guild else "Direct Message"
target = query[-1] target = query[-1]
result = subprocess.run(['ping', '-c', '1', target], capture_output=True, text=True) print(f"Ping Request - User: {user}, Server: {server}, Target: {target}", flush=True)
await message.channel.send(f"`Ping result for {target}: {result.stdout}`") if is_private(target):
rejection = await generate_chat_response("Hey Garfield, explain to me why I am dumb for trying to hack your private computer network.")
await message.channel.send(rejection)
else:
result = subprocess.run(['ping', '-c', '4', target], capture_output=True, text=True)
await message.channel.send(f"`Ping result for {target}: {result.stdout}`")
except Exception as e:
await message.channel.send(f"`GarfBot Error: {str(e)}`")
if message.content.lower().startswith("garfdns "):
try:
query = message.content.split()
user = message.author.name
server = message.guild.name if message.guild else "Direct Message"
target = query[-1]
print(f"NSLookup Request - User: {user}, Server: {server}, Target: {target}", flush=True)
if is_private(target):
rejection = await generate_chat_response("Hey Garfield, explain to me why I am dumb for trying to hack your private computer network.")
await message.channel.send(rejection)
else:
result = subprocess.run(['nslookup', target], capture_output=True, text=True)
await message.channel.send(f"`NSLookup result for {target}: {result.stdout}`")
except Exception as e:
await message.channel.send(f"`GarfBot Error: {str(e)}`")
if message.content.lower().startswith("garfhack "):
try:
query = message.content.split()
user = message.author.name
server = message.guild.name if message.guild else "Direct Message"
target = query[-1]
print(f"Nmap Request - User: {user}, Server: {server}, Target: {target}", flush=True)
if is_private(target):
rejection = await generate_chat_response("Hey Garfield, explain to me why I am dumb for trying to hack your private computer network.")
await message.channel.send(rejection)
else:
await message.channel.send(f"`Scanning {target}...`")
result = subprocess.run(['nmap', '-Pn', '-O', '-v', target], capture_output=True, text=True)
await message.channel.send(f"`Ping result for {target}: {result.stdout}`")
except Exception as e: except Exception as e:
await message.channel.send(f"`GarfBot Error: {str(e)}`") await message.channel.send(f"`GarfBot Error: {str(e)}`")

1
garfbot.sh Normal file
View File

@ -0,0 +1 @@
docker run -d --restart always -v $PWD:/usr/src/app --name garfbot garfbot