Skip to content

Commit

Permalink
Die Itemvariable "Zugriff" wurde hinzugefügt und eingebaut.
Browse files Browse the repository at this point in the history
  • Loading branch information
LuminatiHD committed Nov 1, 2021
1 parent 3e0c641 commit e90af7f
Show file tree
Hide file tree
Showing 5 changed files with 114 additions and 16 deletions.
63 changes: 62 additions & 1 deletion Buttons.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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):
Expand All @@ -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):
Expand All @@ -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()
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()

2 changes: 1 addition & 1 deletion Husi_Bot_Discord.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down
Binary file modified ItemFiles.db
Binary file not shown.
20 changes: 17 additions & 3 deletions cogs/newItem.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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()

Expand Down
45 changes: 34 additions & 11 deletions cogs/searchItem.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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):
Expand All @@ -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(", "):
Expand All @@ -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")

Expand All @@ -137,15 +146,14 @@ 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")

elif selectbtn.edit:
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)
Expand All @@ -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)
Expand All @@ -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
Expand All @@ -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:
Expand All @@ -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()

Expand Down

0 comments on commit e90af7f

Please sign in to comment.