def check_cmd_perms(ctx): # Checking for appropriate permissions # Only check if the bot type is a member of a server if not utils.check_perms(ctx, discord.Permissions( read_message_history = True, attach_files = True, send_messages = True )): raise UserError("`read_message_history`, `attach_files`, and `send_messages` permissions required.", True)
async def remove_invocation(cog, ctx): if CONFIG["commands"]["hug"]["delete-message"] and check_perms(ctx, discord.Permissions( manage_messages = True )): try: await ctx.message.delete() except discord.Forbidden: print("Invalid permissions: Bot needs manage_messages to delete user messages.") except discord.NotFound: print("Message not found. Something went wrong during command invocation.") except discord.HTTPException as e: print(f"HTTP Exception: {e}")
async def find_wordcloud(self, ctx, in_time, one_channel=True, case_insensitive=True, stop_after_usermsg=False): try: await self.check_cooldown(ctx) if not utils.check_perms(ctx, discord.Permissions( read_message_history = True, attach_files = True, send_messages = True )): raise UserError("`read_message_history`, `attach_files`, and `send_messages` permissions required.", True) seconds = utils.parse_time_to_seconds(in_time) if seconds > utils.parse_time_to_seconds(CONFIG["commands"]["whatdidimiss"]["maxtime"]) or seconds < 1: raise UserError(f'Thats too much time! {CONFIG["commands"]["whatdidimiss"]["maxtime"]} Maximum!', True) # Getting the earliest time that should be used timestamp = datetime.datetime.utcnow() - datetime.timedelta(seconds=seconds) # And now for the slow stuff with ctx.typing(): # Next, recursively grabbing messages and appending them to a long ass string result = await utils.collect_messages( ctx, one_channel, timestamp, CONFIG["commands"]["whatdidimiss"]["stopwords"], case_insensitive, stop_after_usermsg ) # Depending on if stop_after_usermsg is set, it'll either just return the frequency dict, or a tuple with more information words = result[0] msg_count = result[1] if stop_after_usermsg: if result[2].total_seconds() == 0: time_diff = f'Hit max time of {CONFIG["commands"]["whatdidimiss"]["max-lookback-time"]}' else: time_diff = utils.parse_seconds_to_time(int(result[2].total_seconds())) with concurrent.futures.ProcessPoolExecutor() as pool: image = await asyncio.get_event_loop().run_in_executor(pool, create_wordcloud, words) if stop_after_usermsg: await ctx.send(f"Heres what happened since your last post {time_diff} ago ({msg_count} messages)", file=discord.File(fp=image, filename="wordcloud.png")) else: await ctx.send(f"Heres what happened in the past {utils.prettify_time(in_time)} ({msg_count} messages)", file=discord.File(fp=image, filename="wordcloud.png")) except UserError as e: await ctx.send(f":warning: {e.message}") # Removing the cooldown as an act of mercy if e.no_cooldown: cooldown.remove_cooldown(ctx)
def server_admin_check(ctx): "Checks if the command caller is a server admin." # Defining a discord server admin as someone with administrator permissions for that server return check_perms(ctx, Permissions(administrator=True), ctx.author)