switch to commands bot

This commit is contained in:
2025-06-07 17:52:20 -05:00
parent aa3996bbd9
commit 97f90e3814
4 changed files with 140 additions and 117 deletions

View File

@ -1,7 +1,6 @@
import discord
import ipaddress
import subprocess
from garfpy import logger
class IPUtils:
@ -23,63 +22,52 @@ class IPUtils:
return True
return False
async def scan(self, message, user, guild, query):
split = query.split()
target = split[-1]
async def ping(self, ctx, target):
if self.is_private(target):
return
try:
await ctx.send(f"`Pinging {target}...`")
result = subprocess.run(
["ping", "-c", "4", target], capture_output=True, text=True
)
embed = discord.Embed(
title=f"Ping result: {target}",
color=discord.Color.light_gray(),
description=f"```{result.stdout}```",
)
await ctx.send(embed=embed)
except Exception as e:
await ctx.send(f"`GarfBot Error: {str(e)}`")
if query.startswith("garfping "):
try:
logger.info(
f"Ping Request - User: {user}, Server: {guild}, Target: {target}"
)
await message.channel.send(f"`Pinging {target}...`")
result = subprocess.run(
["ping", "-c", "4", target], capture_output=True, text=True
)
embed = discord.Embed(
title=f"Ping result: {target}",
color=0x4D4D4D,
description=f"```{result.stdout}```",
)
await message.channel.send(embed=embed)
except Exception as e:
await message.channel.send(f"`GarfBot Error: {str(e)}`")
async def dns(self, ctx, target):
if self.is_private(target):
return
try:
await ctx.send(f"`Requesting {target}...`")
result = subprocess.run(
["nslookup", target], capture_output=True, text=True
)
embed = discord.Embed(
title=f"NSLookup result: {target}",
color=discord.Color.light_gray(),
description=f"```{result.stdout}```",
)
await ctx.send(embed=embed)
except Exception as e:
await ctx.send(f"`GarfBot Error: {str(e)}`")
if query.startswith("garfdns "):
try:
logger.info(
f"NSLookup Request - User: {user}, Server: {guild}, Target: {target}"
)
await message.channel.send(f"`Requesting {target}...`")
result = subprocess.run(
["nslookup", target], capture_output=True, text=True
)
embed = discord.Embed(
title=f"NSLookup result: {target}",
color=0x4D4D4D,
description=f"```{result.stdout}```",
)
await message.channel.send(embed=embed)
except Exception as e:
await message.channel.send(f"`GarfBot Error: {str(e)}`")
if query.startswith("garfhack "):
try:
logger.info(
f"Nmap Request - User: {user}, Server: {guild}, Target: {target}"
)
await message.channel.send(f"`Scanning {target}...`")
result = subprocess.run(
["nmap", "-Pn", "-O", "-v", target], capture_output=True, text=True
)
embed = discord.Embed(
title=f"Nmap scan result: {target}",
color=0x4D4D4D,
description=f"```{result.stdout}```",
)
embed.set_footer(text="https://nmap.org/")
await message.channel.send(embed=embed)
except Exception as e:
await message.channel.send(f"`GarfBot Error: {str(e)}`")
async def scan(self, ctx, target):
try:
await ctx.send(f"`Scanning {target}...`")
result = subprocess.run(
["nmap", "-Pn", "-O", "-v", target], capture_output=True, text=True
)
embed = discord.Embed(
title=f"Nmap scan result: {target}",
color=discord.Color.light_gray(),
description=f"```{result.stdout}```",
)
embed.set_footer(text="https://nmap.org/")
await ctx.send(embed=embed)
except Exception as e:
await ctx.send(f"`GarfBot Error: {str(e)}`")

View File

@ -47,7 +47,7 @@ async def generate_qr(text):
qr = qrcode.QRCode(
version=version,
error_correction=qrcode.constants.ERROR_CORRECT_L,
error_correction=qrcode.constants.ERROR_CORRECT_L, # type: ignore
box_size=box_size,
border=4,
)
@ -58,7 +58,7 @@ async def generate_qr(text):
qr_image = qr.make_image(fill_color="black", back_color="white")
img_buffer = BytesIO()
qr_image.save(img_buffer, format="PNG")
qr_image.save(img_buffer, format="PNG") # type: ignore
img_buffer.seek(0)
return img_buffer

View File

@ -18,13 +18,13 @@ class WeatherAPI:
else:
return {"zip": location}
parts = location.split()
params = location.split()
if len(parts) == 1:
return {"q": f"{parts[0]},US"}
if len(params) == 1:
return {"q": f"{params[0]},US"}
elif len(parts) == 2:
city, second = parts
elif len(params) == 2:
city, second = params
if len(second) == 2 and second.upper() not in [
"AK",
@ -88,26 +88,26 @@ class WeatherAPI:
else:
return {"q": f"{city},{second},US"}
elif len(parts) == 3:
city, state, country = parts
elif len(params) == 3:
city, state, country = params
return {"q": f"{city},{state},{country.upper()}"}
else:
if len(parts[-1]) == 2:
city_parts = parts[:-1]
country = parts[-1]
if len(params[-1]) == 2:
city_parts = params[:-1]
country = params[-1]
city_name = " ".join(city_parts)
return {"q": f"{city_name},{country.upper()}"}
elif len(parts) >= 2 and len(parts[-1]) == 2 and len(parts[-2]) <= 2:
city_parts = parts[:-2]
state = parts[-2]
country = parts[-1]
elif len(params) >= 2 and len(params[-1]) == 2 and len(params[-2]) <= 2:
city_parts = params[:-2]
state = params[-2]
country = params[-1]
city_name = " ".join(city_parts)
return {"q": f"{city_name},{state},{country.upper()}"}
else:
city_name = " ".join(parts)
city_name = " ".join(params)
return {"q": f"{city_name},US"}
async def get_weather(self, location, units="metric"):