New per-server logging and config
This commit is contained in:
parent
a4ee53c4c8
commit
4aa0526826
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
.env
|
27
commands/log.py
Normal file
27
commands/log.py
Normal 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))
|
@ -1,24 +1,32 @@
|
|||||||
import nextcord
|
import nextcord
|
||||||
from nextcord.ext import commands
|
from nextcord.ext import commands
|
||||||
|
|
||||||
|
from userinfo import parsedinfo
|
||||||
|
|
||||||
class Logger(commands.Cog):
|
class Logger(commands.Cog):
|
||||||
def __init__(self, bot):
|
def __init__(self, bot):
|
||||||
|
self.mod = None
|
||||||
self.client = bot
|
self.client = bot
|
||||||
|
|
||||||
@commands.Cog.listener()
|
@commands.Cog.listener()
|
||||||
async def on_message_delete(self, msg: nextcord.Message):
|
async def on_message_delete(self, ctx: nextcord.Message):
|
||||||
embedlist = []
|
embedlist = [nextcord.Embed(
|
||||||
embedlist.append(nextcord.Embed(
|
|
||||||
title="Message delete",
|
title="Message delete",
|
||||||
description=msg.content,
|
description=ctx.content,
|
||||||
url="https://entarapi.xyz"
|
url="https://git.squog.ru/entar/SquogBot"
|
||||||
))
|
)]
|
||||||
embedlist[0].set_author(name=msg.author.name, icon_url=msg.author.avatar.url)
|
embedlist[0].set_author(name=ctx.author.name, icon_url=ctx.author.avatar.url)
|
||||||
for image in msg.attachments:
|
|
||||||
|
for image in ctx.attachments:
|
||||||
newembed = nextcord.Embed(url="https://entarapi.xyz")
|
newembed = nextcord.Embed(url="https://entarapi.xyz")
|
||||||
newembed.set_image(image.url) # Unfortunately i cant add multiple images.
|
newembed.set_image(image.url) # Unfortunately i cant add multiple images.
|
||||||
embedlist.append(newembed)
|
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()
|
@commands.Cog.listener()
|
||||||
async def on_command(self, ctx: commands.Context):
|
async def on_command(self, ctx: commands.Context):
|
||||||
@ -27,15 +35,19 @@ class Logger(commands.Cog):
|
|||||||
description=ctx.message.content
|
description=ctx.message.content
|
||||||
)
|
)
|
||||||
embed.set_author(name=ctx.author.name, icon_url=ctx.author.avatar.url)
|
embed.set_author(name=ctx.author.name, icon_url=ctx.author.avatar.url)
|
||||||
field = embed.add_field(name="Channel", value=ctx.channel.name)
|
embed.add_field(name="Channel", value=ctx.channel.name)
|
||||||
await SquogMod.send(embed=embed)
|
|
||||||
|
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()
|
@commands.Cog.listener()
|
||||||
async def on_ready(self):
|
async def on_ready(self):
|
||||||
global SquogMod
|
|
||||||
print("Bot logged")
|
print("Bot logged")
|
||||||
SquogMod = self.client.get_channel(1356577069068324986)
|
# self.mod = self.client.get_channel(1356577069068324986)
|
||||||
print(SquogMod)
|
|
||||||
|
|
||||||
def setup(bot):
|
def setup(bot):
|
||||||
bot.add_cog(Logger(bot))
|
bot.add_cog(Logger(bot))
|
2
main.py
2
main.py
@ -6,10 +6,10 @@ from dotenv import load_dotenv
|
|||||||
load_dotenv()
|
load_dotenv()
|
||||||
|
|
||||||
#Defining the basic stuff here
|
#Defining the basic stuff here
|
||||||
SquogServer = 1356433463854497944
|
|
||||||
SquogToken = os.environ.get("TOKEN")
|
SquogToken = os.environ.get("TOKEN")
|
||||||
|
|
||||||
client = commands.Bot(command_prefix="!", intents=nextcord.Intents.all())
|
client = commands.Bot(command_prefix="!", intents=nextcord.Intents.all())
|
||||||
|
|
||||||
#Removing the default help command because no
|
#Removing the default help command because no
|
||||||
client.remove_command("help")
|
client.remove_command("help")
|
||||||
|
|
||||||
|
1
userinfo/guildinfo.json
Normal file
1
userinfo/guildinfo.json
Normal file
@ -0,0 +1 @@
|
|||||||
|
[{"id": 10000, "log-channel": 1356577069068324986}, {"id": 1356433463854497944, "log-channel": 1356577069068324986}]
|
30
userinfo/parsedinfo.py
Normal file
30
userinfo/parsedinfo.py
Normal 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
|
Loading…
x
Reference in New Issue
Block a user