diff --git a/Buttons.py b/Buttons.py new file mode 100644 index 0000000..f79a68d --- /dev/null +++ b/Buttons.py @@ -0,0 +1,80 @@ +import nextcord + +class PageButtons(nextcord.ui.View): # buttons für d siitene + def __init__(self, results, currentpage): + super().__init__(timeout=120.0) # timeout macht eifach das d buttons nach 2 minute nümme chöi drückt wärde. + self.currentpage = currentpage + self.results = results + self.left = False + self.right = False + self.select = 0 + + @nextcord.ui.button(label="1", style=nextcord.ButtonStyle.primary) + async def Select1(self, button: nextcord.ui.Button, interaction: nextcord.Interaction): + self.select = 0 + self.stop() + + @nextcord.ui.button(label="2", style=nextcord.ButtonStyle.primary) + async def Select2(self, button: nextcord.ui.Button, interaction: nextcord.Interaction): + self.select = 1 + self.stop() + + @nextcord.ui.button(label="3", style=nextcord.ButtonStyle.primary) + async def Select3(self, button: nextcord.ui.Button, interaction: nextcord.Interaction): + self.select = 2 + self.stop() + + @nextcord.ui.button(label="4", style=nextcord.ButtonStyle.primary) + async def Select4(self, button: nextcord.ui.Button, interaction: nextcord.Interaction): + self.select = 3 + self.stop() + + @nextcord.ui.button(label="5", style=nextcord.ButtonStyle.primary) + async def Select5(self, button: nextcord.ui.Button, interaction: nextcord.Interaction): + self.select = 4 + self.stop() + + @nextcord.ui.button(label="<", style=nextcord.ButtonStyle.primary) + async def leftbutton(self, button: nextcord.ui.Button, interaction: nextcord.Interaction): + self.currentpage -= 1 + self.left = True + self.stop() + + @nextcord.ui.button(label=">", style=nextcord.ButtonStyle.primary) + async def rightbutton(self, button: nextcord.ui.Button, interaction: nextcord.Interaction): + self.currentpage += 1 + self.right = True + self.stop() + + +class Selectionmode(nextcord.ui.View): + def __init__(self): + super().__init__(timeout=120.0) + self.edit = False + self.delete = False + + @nextcord.ui.button(label="Edit", style=nextcord.ButtonStyle.primary, disabled=True) + async def edit(self, button: nextcord.ui.Button, interaction: nextcord.Interaction): + self.edit = True + self.stop() + + @nextcord.ui.button(label="Delete", style=nextcord.ButtonStyle.red) + async def delete(self, button: nextcord.ui.Button, interaction: nextcord.Interaction): + self.delete = True + self.stop() + + +class Confirmdelete(nextcord.ui.View): + def __init__(self): + super().__init__(timeout=120.0) + self.delete = False + + @nextcord.ui.button(label="Yes", style=nextcord.ButtonStyle.red) + async def confirm(self, button: nextcord.ui.Button, interaction: nextcord.Interaction): + self.delete = True + self.stop() + + @nextcord.ui.button(label="No", style=nextcord.ButtonStyle.green) + async def cancel(self, button: nextcord.ui.Button, interaction: nextcord.Interaction): + self.delete = False + self.stop() \ No newline at end of file diff --git a/ItemFiles.db b/ItemFiles.db index 69cb9bc..1c77ffe 100644 Binary files a/ItemFiles.db and b/ItemFiles.db differ diff --git a/README.md b/README.md index 693a071..c5b4471 100644 --- a/README.md +++ b/README.md @@ -11,17 +11,19 @@ https://www.youtube.com/watch?v=byHcYRpMgI4 für Integration mit Discord: Discord.py wird nümme aktualisiert, drum bruche mir nextcord. -Nextcord isch ä fork vo discord.py. Ds heisst, me cha drmit +Nextcord isch ä fork vo discord.py, heisst, me cha drmit genau ds gliiche mache wie mit discord.py, me muess eifach bines paar sache statt discord nextcord häreschriibe. nextcord.py isch aber nid compatible mit discord.py, aso weder scho discord.py heit, -de düet ds bitte deinstallliere. Weder nextcord no nid heit, -de chöiter ses eifach mit +de müestme ds deinstallliere. Weder nextcord no nid heit, +de chöiter des eifach mit `python3 -m pip install -U nextcord` -installiere. schüschtigi informatione zu nextcord finget dir hie: https://nextcord.readthedocs.io/en/latest/ +mache. schüschtigi informatione zu nextcord finget dir hie: https://nextcord.readthedocs.io/en/latest/ und hie: https://github.com/nextcord/nextcord +hie isch ou no dr discord-server vo Nextcord, dört chöiter ou frage steue und so: +https://discord.com/invite/ZebatWssCB diff --git a/cogs/searchItem.py b/cogs/searchItem.py index d654171..187c79a 100644 --- a/cogs/searchItem.py +++ b/cogs/searchItem.py @@ -20,34 +20,6 @@ database = sqlite3.connect(Itemfile) - -class PageButtons(nextcord.ui.View): # buttons für d siitene - def __init__(self, results, currentpage): - super().__init__(timeout=120.0) # timeout macht eifach das d buttons nach 2 minute nümme chöi drückt wärde. - self.currentpage = currentpage - self.results = results - self.left = False - self.right = False - - @nextcord.ui.button(label="<", style=nextcord.ButtonStyle.primary) - async def leftbutton(self, button: nextcord.ui.Button, interaction: nextcord.Interaction): - self.currentpage -= 1 - self.left = True - self.stop() - - @nextcord.ui.button(label=">", style=nextcord.ButtonStyle.primary) - async def rightbutton(self, button: nextcord.ui.Button, interaction: nextcord.Interaction): - self.currentpage += 1 - self.right = True - self.stop() - - # was hie no chli es problem isch, isch wieme dr button tuet disable, aso weme uf dr site 0 isch sött me nid - # chönne witer nach links gah. Mä cha dr button Disable, aso so mache, das dr button nid drück wird, indäm - # me bim button-invoke-decorator (da @nextcord.ui.button) tuet aus argumänt no "disabled" häretue. mä cha - # aber nid argumänt usem __init__ oder so dritue. ds eizige wone chönnt mache wär mit if-else-statements, - # aber da wäri z fuu grad + i bimer sicher dases ä bessere wäg git. - - def layout(items, footer): week_1 = False week_2 = False @@ -114,7 +86,7 @@ async def outlook(self, ctx:Context): search = ctx.message.content[9:] if search == "": search=None - items = database.cursor().execute(f"SELECT * FROM {Itemtable} ORDER BY datum").fetchall() + items = database.cursor().execute(f"SELECT *, rowid FROM {Itemtable} 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(", "): @@ -124,17 +96,41 @@ async def outlook(self, ctx:Context): results.remove(item) if results: # aaschiinend giut ä lääri lischte aus ä boolean, ka bro begin = datetime.datetime.now() - buttons = PageButtons(results, 0) + buttons = Buttons.PageButtons(results, 0) + currentpage = 1 buttons.leftbutton.disabled = True buttons.rightbutton.disabled = 1 >= len(results) / 5 # mit [BUTTON].disabled chame d disability vomne button wächsle. det machi hie für dasme nit cha out of bounds gah. - outputmsg = await ctx.reply(embed=layout(results[:5], footer=f"Seite {1}/{len(results) // 5 + 1}"), view=buttons) + selection = results[:5] + outputmsg = await ctx.reply(embed=layout(selection, footer=f"Seite {1}/{len(results) // 5 + 1}"), view=buttons) while datetime.datetime.now() < begin+datetime.timedelta(minutes=2): await buttons.wait() # ds wartet druf das öppis drücket wird. ds geit bim Button mitem self.stop(). Problem isch aber, dass me dr button när nümme cha bruuche, auso muesme ä neue generiere. - currentpage = buttons.currentpage - buttons = PageButtons(results, currentpage) - buttons.leftbutton.disabled = currentpage==0 - buttons.rightbutton.disabled = (currentpage+1) >= len(results)/5 - await outputmsg.edit(embed=layout(results[currentpage*5:(currentpage+1)*5], footer=f"Seite {currentpage+1}/{len(results)//5+1}"), view=buttons) # es isch übersichtlecher, d message ds editiere aus se neu d schicke. + if buttons.left or buttons.right: # luegt öb d pagetaschte si drücket worde. schüsch weiser dasme möcht selecte. + currentpage = buttons.currentpage + selection = results[currentpage*5:(currentpage+1)*5] + buttons = Buttons.PageButtons(results, currentpage) + buttons.leftbutton.disabled = currentpage==0 + buttons.rightbutton.disabled = (currentpage+1) >= len(results)/5 + await outputmsg.edit(embed=layout(selection, footer=f"Seite {currentpage+1}/{len(results)//5+1}"), view=buttons) # es isch übersichtlecher, d message ds editiere aus se neu d schicke. + + else: + selecteditem = selection[buttons.select] + selected = nextcord.Embed(title = f"{selecteditem[1]} {selecteditem[2]} ") + selected.add_field(name="Aufgabe:", value=selecteditem[3]) + (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") + + selectbtn = Buttons.Selectionmode() + await outputmsg.edit(embed=selected, view=selectbtn) + await selectbtn.wait() # button.wait() wartet druf dasme öppis het drückt + + if selectbtn.delete: + confirm = Buttons.Confirmdelete() + await ctx.reply(content="Willst du wirklich das Item löschen?", view=confirm) + await confirm.wait() + if confirm.delete: + database.cursor().execute(f"DELETE FROM {Itemtable} WHERE rowid = {selecteditem[4]}") + database.commit() + await ctx.reply("Item wurde gelöscht") else: await ctx.reply("Keine Resultate gefunden.")