async def announce_category_del(self, msg, category_id: int): """Check if any messages are still assigned to this category, and refuse to delete if so""" category_id = int(category_id) # Quick fail if trying to delete default if category_id == 1: await msg.reply(f"{bot.msg_prefix}Default category will not be deleted.") return # Grab the category category = self.get_announcements_category(category_id) if category is None: await msg.reply(f"{bot.msg_prefix} Category id {category_id} does not exist.") return # Check to see if there are announcements still assigned to this category announcement_count = session.query(Announcements).filter(Announcements.category == category_id).count() if announcement_count > 0: await msg.reply(f"{bot.msg_prefix}{category.name} is not an empty category, aborting. 🚨🚨") return session.delete(category) session.commit() await msg.reply(f"{bot.msg_prefix}{category.name} ({category.id}) has been deleted.")
async def announce_del(self, msg, *args): try: id = args[0] id = int(id) except IndexError: print("Invalid Announcement delete value not provided") return except ValueError: print("Invalid Announcement delete ID passed, must be an integer") return except Exception as e: print(e) return announcement = self.get_announcement(id) if announcement is None: print("Invalid Announcement delete ID, 0 rows deleted.") else: session.delete(announcement) print(f"Announcement id {announcement.id} deleted.") await msg.reply(f"{bot.msg_prefix}Announcement {id=} deleted.") count = session.query(Announcements).filter(Announcements.category == announcement.id).count() if count == 0 and announcement.id != 1: await msg.reply(f"{bot.msg_prefix}Resetting category to Default") session.query(Settings).filter(Settings.key == self.current_category_setting).update({Settings.value: 1}) session.commit()
async def wig_del(self, msg: Message, id: int): """Delete a wig by ID""" id = int(id) wig: Wigs = session.query(Wigs).filter(Wigs.id == id).first() if wig is not None: session.delete(wig) session.commit() await msg.reply(f"{bot.msg_prefix}{wig.wig_name} deleted.")
async def allow_user(self, msg: Message, user: str): query = ( session.query(LinksToDiscordIgnoreList).filter(LinksToDiscordIgnoreList.username == user.lower()).one_or_none() ) if query: session.delete(query) session.commit() await msg.reply(f"{bot.msg_prefix}I will now allow links from {user}") else: await msg.reply(f"{bot.msg_prefix}{user} wasn't on my ignore list.")
async def ignore_del(self, msg: Message, id: int): id = int(id) # Library may not actually convert to an integer query = session.query(IgnoreList).filter( IgnoreList.id == id).one_or_none() if query: session.delete(query) session.commit() await msg.reply( f"{bot.msg_prefix}I will no longer ignore {query.pattern}") del bot.ignore_list_patterns[id] else: await msg.reply(f"{bot.msg_prefix}ID:{id} doesn't exist.")