async def setpingable(self, ctx: commands.Context, *, role: discord.Role): """Make a role pingable""" bot = self.bot pred_yn = MessagePredicate.yes_or_no(ctx) pred_c = MessagePredicate.valid_text_channel(ctx) await self.config.role(role).pingable.set(True) await ctx.send("Do you want it to work only in one channel?") try: await bot.wait_for("message", timeout=120, check=pred_yn) except asyncio.TimeoutError: await ctx.send("You took too long. Try again, please.") return if pred_yn.result is True: await ctx.send("What channel?") try: await bot.wait_for("message", timeout=120, check=pred_c) except asyncio.TimeoutError: await ctx.send("You took too long. Try again, please.") return channel = pred_c.result await self.config.role(role).channel.set(channel.id) await ctx.send( f'{role.name} set as pingable. You can now set an alias for `{ctx.clean_prefix}pingable "{role.name}"` for users to use.' )
async def notice(self, ctx, message, *pingRole: discord.Role): """Sends a notice to a text channel and pings the specified role(s). Channel will be set through a prompt Arguments: message -- The message to be posted. Must have quotes around it if it's more than one word pingRole -- Can be 1 or more roles that you want to ping in the notice Notice will be in this format: @role(s) [message]""" try: await ctx.send("**Which channel do you want to post the notice in?**\nYou have {} seconds to respond before this times out".format(verify_timeout)) pred = MessagePredicate.valid_text_channel(ctx) await ctx.bot.wait_for("message", check=pred, timeout=verify_timeout) channel = pred.result formatted_message = "```@{0}\n\n{1}```".format(" @".join([role.name for role in pingRole]), message) notice_check = await ctx.send(formatted_message) react_msg = await ctx.send("**Are you ready to send this notice now?**") start_adding_reactions(react_msg, ReactionPredicate.YES_OR_NO_EMOJIS) pred = ReactionPredicate.yes_or_no(react_msg, ctx.author) await ctx.bot.wait_for("reaction_add", check=pred, timeout=verify_timeout) if pred.result is True: #make all the roles in pingRoles mentionable and save their original state mentionable = [] for role in pingRole: mentionable.append(role.mentionable) if not role.mentionable: await role.edit(mentionable=True) final_notice = "{0}\n\n{1}".format(" ".join([role.mention for role in pingRole]), message) await channel.send(final_notice) await ctx.channel.delete_messages([notice_check, react_msg]) #reset roles back to their original state index = 0 for role in pingRole: await role.edit(mentionable=mentionable[index]) index += 1 await ctx.send("Done") else: await ctx.send("Notice not sent") except asyncio.TimeoutError: await ctx.send("Response timed out. Notice not sent.")
async def setsuggest_setup(self, ctx: commands.Context): """ Go through the initial setup process. """ await self.config.guild(ctx.guild).same.set(False) await self.config.guild(ctx.guild).suggest_id.set(None) await self.config.guild(ctx.guild).approve_id.set(None) await self.config.guild(ctx.guild).reject_id.set(None) predchan = MessagePredicate.valid_text_channel(ctx) overwrites = { ctx.guild.default_role: discord.PermissionOverwrite(send_messages=False), ctx.guild.me: discord.PermissionOverwrite(send_messages=True), } msg = await ctx.send("Do you already have your channel(s) done?") start_adding_reactions(msg, ReactionPredicate.YES_OR_NO_EMOJIS) pred = ReactionPredicate.yes_or_no(msg, ctx.author) try: await self.bot.wait_for("reaction_add", timeout=30, check=pred) except asyncio.TimeoutError: await msg.delete() return await ctx.send("You took too long. Try again, please.") if not pred.result: await msg.delete() suggestions = get(ctx.guild.text_channels, name="suggestions") if not suggestions: suggestions = await ctx.guild.create_text_channel( "suggestions", overwrites=overwrites, reason="Suggestion cog setup") await self.config.guild(ctx.guild).suggest_id.set(suggestions.id) msg = await ctx.send( "Do you want to use the same channel for approved and rejected suggestions? (If yes, they won't be reposted anywhere, only their title will change accordingly.)" ) start_adding_reactions(msg, ReactionPredicate.YES_OR_NO_EMOJIS) pred = ReactionPredicate.yes_or_no(msg, ctx.author) try: await self.bot.wait_for("reaction_add", timeout=30, check=pred) except asyncio.TimeoutError: await msg.delete() return await ctx.send("You took too long. Try again, please.") if pred.result: await msg.delete() await self.config.guild(ctx.guild).same.set(True) else: await msg.delete() approved = get(ctx.guild.text_channels, name="approved-suggestions") if not approved: msg = await ctx.send( "Do you want to have an approved suggestions channel?") start_adding_reactions(msg, ReactionPredicate.YES_OR_NO_EMOJIS) pred = ReactionPredicate.yes_or_no(msg, ctx.author) try: await self.bot.wait_for("reaction_add", timeout=30, check=pred) except asyncio.TimeoutError: await msg.delete() return await ctx.send( "You took too long. Try again, please.") if pred.result: approved = await ctx.guild.create_text_channel( "approved-suggestions", overwrites=overwrites, reason="Suggestion cog setup", ) await self.config.guild(ctx.guild ).approve_id.set(approved.id) await msg.delete() else: await self.config.guild(ctx.guild ).approve_id.set(approved.id) rejected = get(ctx.guild.text_channels, name="rejected-suggestions") if not rejected: msg = await ctx.send( "Do you want to have a rejected suggestions channel?") start_adding_reactions(msg, ReactionPredicate.YES_OR_NO_EMOJIS) pred = ReactionPredicate.yes_or_no(msg, ctx.author) try: await self.bot.wait_for("reaction_add", timeout=30, check=pred) except asyncio.TimeoutError: await msg.delete() return await ctx.send( "You took too long. Try again, please.") if pred.result: rejected = await ctx.guild.create_text_channel( "rejected-suggestions", overwrites=overwrites, reason="Suggestion cog setup", ) await self.config.guild(ctx.guild ).reject_id.set(rejected.id) await msg.delete() else: await self.config.guild(ctx.guild ).reject_id.set(rejected.id) else: await msg.delete() msg = await ctx.send( "Mention the channel where you want me to post new suggestions." ) try: await self.bot.wait_for("message", timeout=30, check=predchan) except asyncio.TimeoutError: await msg.delete() return await ctx.send("You took too long. Try again, please.") suggestion = predchan.result await self.config.guild(ctx.guild).suggest_id.set(suggestion.id) await msg.delete() msg = await ctx.send( "Do you want to use the same channel for approved and rejected suggestions? (If yes, they won't be reposted anywhere, only their title will change accordingly.)" ) start_adding_reactions(msg, ReactionPredicate.YES_OR_NO_EMOJIS) pred = ReactionPredicate.yes_or_no(msg, ctx.author) try: await self.bot.wait_for("reaction_add", timeout=30, check=pred) except asyncio.TimeoutError: await msg.delete() return await ctx.send("You took too long. Try again, please.") if pred.result: await msg.delete() await self.config.guild(ctx.guild).same.set(True) else: await msg.delete() msg = await ctx.send( "Do you want to have an approved suggestions channel?") start_adding_reactions(msg, ReactionPredicate.YES_OR_NO_EMOJIS) pred = ReactionPredicate.yes_or_no(msg, ctx.author) try: await self.bot.wait_for("reaction_add", timeout=30, check=pred) except asyncio.TimeoutError: await msg.delete() return await ctx.send( "You took too long. Try again, please.") if pred.result: await msg.delete() msg = await ctx.send( "Mention the channel where you want me to post approved suggestions." ) try: await self.bot.wait_for("message", timeout=30, check=predchan) except asyncio.TimeoutError: await msg.delete() return await ctx.send( "You took too long. Try again, please.") approved = predchan.result await self.config.guild(ctx.guild ).approve_id.set(approved.id) await msg.delete() msg = await ctx.send( "Do you want to have a rejected suggestions channel?") start_adding_reactions(msg, ReactionPredicate.YES_OR_NO_EMOJIS) pred = ReactionPredicate.yes_or_no(msg, ctx.author) try: await self.bot.wait_for("reaction_add", timeout=30, check=pred) except asyncio.TimeoutError: await msg.delete() return await ctx.send( "You took too long. Try again, please.") if pred.result: await msg.delete() msg = await ctx.send( "Mention the channel where you want me to post rejected suggestions." ) try: await self.bot.wait_for("message", timeout=30, check=predchan) except asyncio.TimeoutError: await msg.delete() return await ctx.send( "You took too long. Try again, please.") rejected = predchan.result await self.config.guild(ctx.guild ).reject_id.set(rejected.id) await msg.delete() await ctx.send( "You have finished the setup! Please, move your channels to the category you want them in." )
async def interactive(self, ctx: commands.Context): """Start interactive setup""" # group has guild check if TYPE_CHECKING: assert ctx.guild is not None assert isinstance(ctx.me, discord.Member) m: discord.Message = await ctx.send( "Just a heads up, you'll be asked for a message for when the user provided their birth" " year, a message for when they didn't, the channel to sent notifications, the role," " and the time of day to send them.\n\nWhen you're ready, press the tick." ) start_adding_reactions(m, ReactionPredicate.YES_OR_NO_EMOJIS) pred = ReactionPredicate.yes_or_no(m, ctx.author) # type:ignore try: await self.bot.wait_for("reaction_add", check=pred, timeout=300) except asyncio.TimeoutError: await m.edit(content=( f"Took too long to react, cancelling setup. Run `{ctx.clean_prefix}bdset" " interactive` to start again.")) if pred.result is not True: await ctx.send("Okay, I'll cancel setup.") return # ============================== MSG WITH YEAR ============================== m = await ctx.send( "What message should I send if the user provided their birth year?\n\nYou can use the" " following variables: `mention`, `name`, `new_age`. Put curly brackets `{}` around" " them, for example: {mention} is now {new_age} years old!\n\nYou have 5 minutes." ) try: pred = MessagePredicate.same_context(ctx) message = await self.bot.wait_for("message", check=pred, timeout=300) except asyncio.TimeoutError: await ctx.send( f"Took too long to react, cancelling setup. Run `{ctx.clean_prefix}bdset" " interactive` to start again.") return message_w_year = message.content if len(message_w_year) > MAX_BDAY_MSG_LEN: await ctx.send("That message is too long, please try again.") return # ============================== MSG WITHOUT YEAR ============================== m = await ctx.send( "What message should I send if the user didn't provide their birth year?\n\nYou can" " use the following variables: `mention`, `name`. Put curly brackets `{}` around them," " for example: {mention}'s birthday is today! Happy birthday {name}\n\nYou have 5" " minutes.") try: pred = MessagePredicate.same_context(ctx) message = await self.bot.wait_for("message", check=pred, timeout=300) except asyncio.TimeoutError: await ctx.send( f"Took too long to react, cancelling setup. Run `{ctx.clean_prefix}bdset" " interactive` to start again.") return message_wo_year = message.content if len(message_wo_year) > MAX_BDAY_MSG_LEN: await ctx.send("That message is too long, please try again.") return # ============================== CHANNEL ============================== m = await ctx.send( "Where would you like to send notifications? I will ignore any message with an invalid" " channel.\n\nYou have 5 minutes.") try: pred = MessagePredicate.valid_text_channel(ctx) await self.bot.wait_for("message", check=pred, timeout=300) except asyncio.TimeoutError: await ctx.send( f"Took too long to react, cancelling setup. Run `{ctx.clean_prefix}bdset" " interactive` to start again.") channel: discord.TextChannel = pred.result if error := channel_perm_check(ctx.me, channel): await ctx.send( warning( f"{error} Please make sure" " you rectify this as soon as possible, but I'll let you continue the setup." ))