From adf654a68983dd7fd04b367535029760fd6998ff Mon Sep 17 00:00:00 2001 From: LuminatiHD Date: Sun, 31 Oct 2021 11:06:48 +0100 Subject: [PATCH] =?UTF-8?q?Man=20kann=20jetzt=20items=20l=C3=B6schen.=20Ed?= =?UTF-8?q?itieren=20k=C3=B6nnen=20w=C3=A4re=20das=20n=C3=A4chste=20Ziel?= =?UTF-8?q?=20(+bissl=20cleanup=20beim=20readme)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Buttons.py | 80 +++++++++++++++++++++++++++++++++++++++++++++ ItemFiles.db | Bin 12288 -> 12288 bytes README.md | 10 +++--- cogs/searchItem.py | 68 ++++++++++++++++++-------------------- 4 files changed, 118 insertions(+), 40 deletions(-) create mode 100644 Buttons.py 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 69cb9bc270d5cb1b19d3e1040f56f62fda150805..1c77ffe57732d78a40e1578854834d925c277db9 100644 GIT binary patch delta 71 zcmZojXh@hK&6qz?#+fmHW5ObNu?hwjeqAR12mA~8z4>+dSwWER>1IKJ3w)Db=*hD1 WS1@QyuF+SStgG+M!hZ+-Ymv+_ONEGTe+Z}JO0 YSr#=8R>jFR`YMxk^}SitSizhY0NVKzR{#J2 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.")