async def whatdidimiss(self, ctx): try: # Checking cooldown: if cooldown.cooldown_in_effect(ctx): raise UserError("Please wait for cooldown.") cooldown.add_cooldown( ctx, CONFIG["commands"]["whatdidimiss"]["cooldown"]) # Checking for appropriate permissions check_cmd_perms(ctx) timestamp = datetime.datetime.utcnow() - datetime.timedelta( seconds=utils.parse_time_to_seconds( CONFIG["commands"]["whatdidimiss"]["max-lookback-time"])) with ctx.typing(): (words, msg_time) = await utils.collect_messages( ctx, True, timestamp, CONFIG["commands"]["whatdidimiss"]["stopwords"], True, True) with concurrent.futures.ProcessPoolExecutor() as pool: image = await asyncio.get_event_loop().run_in_executor( pool, create_wordcloud, words) if msg_time.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(msg_time.total_seconds())) await ctx.send( f"Here are the messages since your last post: ({time_diff})", file=discord.File(fp=image, filename="wordcloud.png")) cooldown.add_cooldown( ctx, CONFIG["commands"]["whatdidimiss"]["cooldown"]) except UserError as e: await ctx.send(f"Invalid input: {e.message}")
async def wordcloud( self, ctx, in_time=CONFIG["commands"]["whatdidimiss"]["defaulttime"], one_channel="True", case_insensitive="True"): try: # Checking cooldown: if cooldown.cooldown_in_effect(ctx): raise UserError("Please wait for cooldown.") cooldown.add_cooldown( ctx, CONFIG["commands"]["whatdidimiss"]["cooldown"]) # Checking for appropriate permissions check_cmd_perms(ctx) seconds = utils.parse_time_to_seconds(in_time) if seconds > utils.parse_time_to_seconds( CONFIG["commands"]["whatdidimiss"] ["maxtime"]) or seconds < 1: raise UserError("Time outside of allowed range") one_channel = utils.parse_bool(one_channel) case_insensitive = utils.parse_bool(case_insensitive) # 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 words = await utils.collect_messages( ctx, one_channel, timestamp, CONFIG["commands"]["whatdidimiss"]["stopwords"], case_insensitive) with concurrent.futures.ProcessPoolExecutor() as pool: image = await asyncio.get_event_loop().run_in_executor( pool, create_wordcloud, words) await ctx.send(f"Messages over: {in_time}", file=discord.File(fp=image, filename="wordcloud.png")) except UserError as e: await ctx.send(f"Invalid Input: {e.message}") # Removing the cooldown as an act of mercy if e.no_cooldown: cooldown.remove_cooldown(ctx)
async def check_cooldown(self, ctx): c, t = cooldown.cooldown_in_effect(ctx) if c: t = utils.parse_seconds_to_time(t) raise UserError(f"Relax. Your cooldown expires in {t}!") cooldown.add_cooldown(ctx, CONFIG["commands"]["whatdidimiss"]["cooldown"])