New per-server logging and config

This commit is contained in:
Entarno54 2025-05-11 17:25:31 +07:00
parent a4ee53c4c8
commit 4aa0526826
7 changed files with 87 additions and 16 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
.env

27
commands/log.py Normal file
View File

@ -0,0 +1,27 @@
import nextcord
from nextcord.ext import commands
from userinfo import parsedinfo
class LogCommands(commands.Cog):
def __init__(self, bot):
self.client = bot
@commands.command()
@commands.has_permissions(administrator = True)
async def setlogchannel(self, ctx: nextcord.Message, channel: nextcord.TextChannel):
print(ctx.author, channel)
guildInfo = await parsedinfo.find("guild", "id", ctx.guild.id)
if not guildInfo:
info = await parsedinfo.get("guild")
info.append({"id": ctx.guild.id, "log-channel": 0})
guildInfo = await parsedinfo.find("guild", "id", ctx.guild.id)
guildInfo["log-channel"] = channel.id
await parsedinfo.flush() # Yes
def setup(bot):
bot.add_cog(LogCommands(bot))

View File

@ -1,24 +1,32 @@
import nextcord
from nextcord.ext import commands
from userinfo import parsedinfo
class Logger(commands.Cog):
def __init__(self, bot):
self.mod = None
self.client = bot
@commands.Cog.listener()
async def on_message_delete(self, msg: nextcord.Message):
embedlist = []
embedlist.append(nextcord.Embed(
async def on_message_delete(self, ctx: nextcord.Message):
embedlist = [nextcord.Embed(
title="Message delete",
description=msg.content,
url="https://entarapi.xyz"
))
embedlist[0].set_author(name=msg.author.name, icon_url=msg.author.avatar.url)
for image in msg.attachments:
description=ctx.content,
url="https://git.squog.ru/entar/SquogBot"
)]
embedlist[0].set_author(name=ctx.author.name, icon_url=ctx.author.avatar.url)
for image in ctx.attachments:
newembed = nextcord.Embed(url="https://entarapi.xyz")
newembed.set_image(image.url) # Unfortunately i cant add multiple images.
embedlist.append(newembed)
await SquogMod.send(embeds=embedlist)
guild = await parsedinfo.find("guild", "id", ctx.guild.id)
if guild and guild["log-channel"] != 0:
channel = ctx.guild.get_channel(guild["log-channel"])
await channel.send(embeds=embedlist)
@commands.Cog.listener()
async def on_command(self, ctx: commands.Context):
@ -27,15 +35,19 @@ class Logger(commands.Cog):
description=ctx.message.content
)
embed.set_author(name=ctx.author.name, icon_url=ctx.author.avatar.url)
field = embed.add_field(name="Channel", value=ctx.channel.name)
await SquogMod.send(embed=embed)
embed.add_field(name="Channel", value=ctx.channel.name)
guild = await parsedinfo.find("guild", "id", ctx.guild.id)
if guild and guild["log-channel"] != 0:
channel = ctx.guild.get_channel(guild["log-channel"])
await channel.send(embed=embed)
@commands.Cog.listener()
async def on_ready(self):
global SquogMod
print("Bot logged")
SquogMod = self.client.get_channel(1356577069068324986)
print(SquogMod)
# self.mod = self.client.get_channel(1356577069068324986)
def setup(bot):
bot.add_cog(Logger(bot))

View File

@ -6,10 +6,10 @@ from dotenv import load_dotenv
load_dotenv()
#Defining the basic stuff here
SquogServer = 1356433463854497944
SquogToken = os.environ.get("TOKEN")
client = commands.Bot(command_prefix="!", intents=nextcord.Intents.all())
#Removing the default help command because no
client.remove_command("help")

1
userinfo/guildinfo.json Normal file
View File

@ -0,0 +1 @@
[{"id": 10000, "log-channel": 1356577069068324986}, {"id": 1356433463854497944, "log-channel": 1356577069068324986}]

30
userinfo/parsedinfo.py Normal file
View File

@ -0,0 +1,30 @@
import json
openGuild = open("./userinfo/guildinfo.json", "r")
parsedGuild = json.loads(openGuild.read())
openUser = open("./userinfo/userinfo.json", "r")
parsedUser = json.loads(openUser.read())
parsed = {
"guild": parsedGuild,
"user": parsedUser
}
async def flush():
writeUser = open("./userinfo/userinfo.json", "w")
writeUser.write(json.dumps(parsed["user"]))
writeUser.close()
writeGuild = open("./userinfo/guildinfo.json", "w")
writeGuild.write(json.dumps(parsed["guild"]))
writeGuild.close()
async def get(file):
return parsed[file]
async def find(file, index, value):
for Info in parsed[file]:
if Info[index] == value:
return Info
return None

View File

@ -1 +1 @@
[{"id": 999, "messages": []}]
[{"id": 999, "messages": []}]