diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..2eea525 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.env \ No newline at end of file diff --git a/commands/log.py b/commands/log.py new file mode 100644 index 0000000..afaafb9 --- /dev/null +++ b/commands/log.py @@ -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)) \ No newline at end of file diff --git a/events/log.py b/events/log.py index 8a213dd..c6d938a 100644 --- a/events/log.py +++ b/events/log.py @@ -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)) \ No newline at end of file diff --git a/main.py b/main.py index 63d0509..c281534 100644 --- a/main.py +++ b/main.py @@ -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") diff --git a/userinfo/guildinfo.json b/userinfo/guildinfo.json new file mode 100644 index 0000000..632b5ff --- /dev/null +++ b/userinfo/guildinfo.json @@ -0,0 +1 @@ +[{"id": 10000, "log-channel": 1356577069068324986}, {"id": 1356433463854497944, "log-channel": 1356577069068324986}] \ No newline at end of file diff --git a/userinfo/parsedinfo.py b/userinfo/parsedinfo.py new file mode 100644 index 0000000..3e85fac --- /dev/null +++ b/userinfo/parsedinfo.py @@ -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 \ No newline at end of file diff --git a/userinfo/userinfo.json b/userinfo/userinfo.json index b5b0ec0..f981cf7 100644 --- a/userinfo/userinfo.json +++ b/userinfo/userinfo.json @@ -1 +1 @@ -[{"id": 999, "messages": []}] \ No newline at end of file +[{"id": 999, "messages": []}] \ No newline at end of file