diff --git a/Buttons.py b/Buttons.py index 49f3b97..6a25f8c 100644 --- a/Buttons.py +++ b/Buttons.py @@ -150,6 +150,7 @@ def __init__(self, ctx): self.edit = [] self.goback = False self.ctx = ctx + @nextcord.ui.button(label="Kategorie", style=nextcord.ButtonStyle.primary) async def kategorie(self, button: nextcord.ui.Button, interaction: nextcord.Interaction): if await testinter(ctx=self.ctx, interaction=interaction): @@ -174,6 +175,12 @@ async def fach(self, button: nextcord.ui.Button, interaction: nextcord.Interacti self.edit.append("fach") self.stop() + @nextcord.ui.button(label="Zugriff", style=nextcord.ButtonStyle.primary) + async def access(self, button: nextcord.ui.Button, interaction: nextcord.Interaction): + if await testinter(ctx=self.ctx, interaction=interaction): + self.edit.append("access") + self.stop() + @nextcord.ui.button(label="Zurück", style=nextcord.ButtonStyle.gray) async def goback(self, button: nextcord.ui.Button, interaction: nextcord.Interaction): if await testinter(ctx=self.ctx, interaction=interaction): @@ -189,6 +196,7 @@ def __init__(self, ctx): super().__init__(timeout=120.0) self.choice = "Hausaufgabe" self.ctx = ctx + @nextcord.ui.button(label="A", style=nextcord.ButtonStyle.primary) async def Hausaufgabe(self, button: nextcord.ui.Button, interaction: nextcord.Interaction): if await testinter(ctx=self.ctx, interaction=interaction): @@ -199,4 +207,57 @@ async def Hausaufgabe(self, button: nextcord.ui.Button, interaction: nextcord.In async def Test(self, button: nextcord.ui.Button, interaction: nextcord.Interaction): if await testinter(ctx=self.ctx, interaction=interaction): self.choice = "Test" - self.stop() \ No newline at end of file + self.stop() + + +class ManageItemAccess(nextcord.ui.View): + """Wird geregelt wer dieses Item sehen kann, aka ob es privat ist, + für alle, oder nur für die jeweiligen SF oder EF.""" + + def __init__(self, ctx): + super().__init__(timeout=120.0) + self.ctx = ctx + self.access = "all" + + # wede diräkt mitem bot redisch, de chaner d ufgab nid uf SF oder EF restricte wöuer d serverdate nid het. + if self.ctx.channel.__str__().startswith("Direct Message"): + self.OnlyEF.disabled = True + self.OnlySF.disabled = True + + @nextcord.ui.button(label="Für Alle", style=nextcord.ButtonStyle.primary) + async def All(self, button: nextcord.ui.Button, interaction: nextcord.Interaction): + if await testinter(ctx=self.ctx, interaction=interaction): + self.access = "all" + self.stop() + + @nextcord.ui.button(label="Für mein SF", style=nextcord.ButtonStyle.primary) + async def OnlySF(self, button: nextcord.ui.Button, interaction: nextcord.Interaction): + if await testinter(ctx=self.ctx, interaction=interaction): + SF = "all" + for role in self.ctx.author.roles: + if role.name.lower().startswith("sf"): + SF = role.name + + self.access = SF + self.stop() + + @nextcord.ui.button(label="Für mein EF", style=nextcord.ButtonStyle.primary) + async def OnlyEF(self, button: nextcord.ui.Button, interaction: nextcord.Interaction): + if await testinter(ctx=self.ctx, interaction=interaction): + EF = "all" + for role in self.ctx.author.roles: + if role.name.lower().startswith("ef"): + EF = role.name + + self.access = EF + self.stop() + + self.access = EF + self.stop() + + @nextcord.ui.button(label="Nur für mich", style=nextcord.ButtonStyle.primary) + async def Private(self, button: nextcord.ui.Button, interaction: nextcord.Interaction): + if await testinter(ctx=self.ctx, interaction=interaction): + self.access = "private" + self.stop() + diff --git a/Husi_Bot_Discord.py b/Husi_Bot_Discord.py index 268a6fa..cb60814 100644 --- a/Husi_Bot_Discord.py +++ b/Husi_Bot_Discord.py @@ -4,7 +4,7 @@ Itemfile = "ItemFiles.db" Alltables = "testitems", "items" Itemtable = "testitems" -tablecategories = ("datum", "kagegorie", "fach", "aufgabe") +tablecategories = ("datum", "kategorie", "fach", "aufgabe", "access") database = sqlite3.connect(Itemfile) diff --git a/ItemFiles.db b/ItemFiles.db index 4174f50..cf2ab1b 100644 Binary files a/ItemFiles.db and b/ItemFiles.db differ diff --git a/cogs/newItem.py b/cogs/newItem.py index 91ca9a7..86a5be5 100644 --- a/cogs/newItem.py +++ b/cogs/newItem.py @@ -6,8 +6,8 @@ import Buttons Itemfile = "ItemFiles.db" Alltables = "testitems", "items" -Itemtable = "testitems" -tablecategories = ("datum", "kagegorie", "fach", "aufgabe") +Itemtable = "items" +tablecategories = ("datum", "kagegorie", "fach", "aufgabe", "access") weekdays = ["Montag", "Dienstag", @@ -110,7 +110,21 @@ async def new(self, ctx:Context): aufgabe = None if not exitcommand: - database.cursor().execute(f"INSERT INTO {Itemtable} VALUES ('{date}', '{category}', '{fach}', '{aufgabe}')") + manageaccess = Buttons.ManageItemAccess(ctx) + await ctx.reply("Für wen soll dieses Item sichtbar sein?", view=manageaccess) + await manageaccess.wait() + if manageaccess.access == "all": + access = "all" + elif manageaccess.access == "private": + access = ctx.author.id + + else: + access = manageaccess + + + + if not exitcommand: + database.cursor().execute(f"INSERT INTO {Itemtable} VALUES ('{date}', '{category}', '{fach}', '{aufgabe}', '{access}')") await ctx.channel.send(f"{category} wurde eingetragen") database.commit() diff --git a/cogs/searchItem.py b/cogs/searchItem.py index cfe7247..e8c6fe7 100644 --- a/cogs/searchItem.py +++ b/cogs/searchItem.py @@ -8,8 +8,8 @@ Itemfile = "ItemFiles.db" Alltables = "testitems", "items" -Itemtable = "testitems" -tablecategories = ("datum", "kategorie", "fach", "aufgabe") +Itemtable = "items" +tablecategories = ("datum", "kategorie", "fach", "aufgabe", "access", ("rowid")) Itemkategorien = ("Test", "Aufgabe") weekdays = ["Montag", @@ -81,7 +81,7 @@ def changefachname(fach): # so isches übersichtlecher class Itemsearch(commands.Cog): for item in database.cursor().execute( f"SELECT datum, rowid FROM {Itemtable}"): # aui elemänt lösche wo scho düre si if str(date.today()) > item[0]: - database.cursor().execute(f"DELETE FROM {Itemtable} WHERE rowid = {item[1]}") + database.cursor().execute(f"DELETE FROM {Itemtable} WHERE rowid = {item[5]}") database.commit() def __init__(self, bot: commands.Bot): @@ -90,10 +90,18 @@ def __init__(self, bot: commands.Bot): @commands.command() async def outlook(self, ctx: Context): if self.bot.user != ctx.author: + EF = "all" + SF = "all" + for role in ctx.author.roles: + if role.name.lower().startswith("ef"): + EF = role.name + elif role.name.lower().startswith("sf"): + SF = role.name + search = ctx.message.content[9:] if search == "": search = None - items = database.cursor().execute(f"SELECT *, rowid FROM {Itemtable} ORDER BY datum").fetchall() + items = database.cursor().execute(f"SELECT *, rowid FROM {Itemtable} WHERE access = 'all' OR access = '{ctx.author.id}' OR access = '{SF}' OR access = '{EF}' ORDER BY datum").fetchall() results = [i for i in items] # weme ds nid macht de tuetses bi results.remove ds elemänt bi items ou remove ka werum if search is not None: for keyword in search.split(", "): @@ -120,7 +128,8 @@ async def outlook(self, ctx: Context): else: selecteditem = selection[buttons.select] selected = nextcord.Embed(title=f"{selecteditem[1]} {selecteditem[2]} ") - selected.add_field(name="Aufgabe:", value=selecteditem[3]) + selected.add_field(name="Aufgabe:", value=selecteditem[3], inline=True) + selected.add_field(name="Zugriff: ", value=selecteditem[4], inline=True) (year, month, day) = selecteditem[0].split("-") selected.set_footer(text=f"Fällig bis: {str(weekdays[date(int(year), int(month), int(day)).weekday()])}, {day}.{month}.{year}\n") @@ -137,7 +146,7 @@ async def outlook(self, ctx: Context): await ctx.reply(content="Willst du wirklich das Item löschen?", view=confirm) await confirm.wait() if confirm.confirm: - database.cursor().execute(f"DELETE FROM {Itemtable} WHERE rowid = {selecteditem[4]}") + database.cursor().execute(f"DELETE FROM {Itemtable} WHERE rowid = {selecteditem[5]}") database.commit() await ctx.reply("Item wurde gelöscht") @@ -145,7 +154,6 @@ async def outlook(self, ctx: Context): editor = await ctx.reply("Was genau möchtest du editieren?") editorbtn = Buttons.EditButtons(ctx) await editor.edit(view=editorbtn) - await editorbtn.wait() if "kategorie" in editorbtn.edit: confirm = Buttons.Confirm(ctx) @@ -154,7 +162,7 @@ async def outlook(self, ctx: Context): view=confirm) await confirm.wait() if confirm.confirm: - database.cursor().execute(f"UPDATE {Itemtable} SET kategorie = '{Itemkategorien[Itemkategorien.index(selecteditem[1]) - 1]}'WHERE rowid = {selecteditem[4]}") + database.cursor().execute(f"UPDATE {Itemtable} SET kategorie = '{Itemkategorien[Itemkategorien.index(selecteditem[1]) - 1]}'WHERE rowid = {selecteditem[5]}") if "aufgabe" in editorbtn.edit: confirm = Buttons.Confirm(ctx) @@ -164,7 +172,7 @@ async def outlook(self, ctx: Context): newaufg = await self.bot.wait_for("message", check = lambda msg: msg.author == ctx.author) await newaufg.reply(f"Alte Aufgabe: {selecteditem[3]}\nNeue Aufgabe: {newaufg.content}.\nBestätigen?", view = confirm) await confirm.wait() - database.cursor().execute(f"UPDATE {Itemtable} SET aufgabe = '{newaufg.content}' WHERE rowid = {selecteditem[4]}") + database.cursor().execute(f"UPDATE {Itemtable} SET aufgabe = '{newaufg.content}' WHERE rowid = {selecteditem[5]}") if "datum" in editorbtn.edit: error = True @@ -185,7 +193,7 @@ async def outlook(self, ctx: Context): except: await ctx.reply("ungültiges Datum") continue - database.cursor().execute(f"UPDATE {Itemtable} SET datum = '{datum}' WHERE rowid = {selecteditem[4]}") + database.cursor().execute(f"UPDATE {Itemtable} SET datum = '{datum}' WHERE rowid = {selecteditem[5]}") if "fach" in editorbtn.edit: confirm = Buttons.Confirm(ctx) while not confirm.confirm: @@ -197,7 +205,22 @@ async def outlook(self, ctx: Context): f"{changefachname(newfach.content)}.\nBestätigen?", view=confirm) await confirm.wait() database.cursor().execute( - f"UPDATE {Itemtable} SET fach = '{changefachname(newfach.content)}' WHERE rowid = {selecteditem[4]}") + f"UPDATE {Itemtable} SET fach = '{changefachname(newfach.content)}' WHERE rowid = {selecteditem[5]}") + + if "access" in editorbtn.edit: + confirm = Buttons.Confirm(ctx) + newacc = Buttons.ManageItemAccess(ctx) + while not confirm.confirm: + confirm = Buttons.Confirm(ctx) + await editor.reply("Zugriff: ", view=newacc) + await newacc.wait() + + await editor.reply(f"Alter Zugriff: {selecteditem[4]}\nNeuer Zugriff: " + f"{newacc.access}.\nBestätigen?", view=confirm) + await confirm.wait() + database.cursor().execute( + f"UPDATE {Itemtable} SET access = '{newacc.access}' WHERE rowid = {selecteditem[5]}") + await ctx.channel.send("Änderungen wurden vorgenommen") database.commit()