async def wordcloud(self, ctx, in_time = CONFIG["commands"]["whatdidimiss"]["defaulttime"], one_channel = "True", case_insensitive = "True" ): try: await self.check_cooldown(ctx) # 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(f'Thats too much time! {CONFIG["commands"]["whatdidimiss"]["maxtime"]} Maximum!', True) 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"Heres what happened in the past: {in_time}", 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)
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 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 add_cooldown(ctx, down_time): "Adds a cooldown for the given amount of time (in the bots text time format) for the current context." cooldown_id = get_cooldown_id(ctx) cooldown_list[cooldown_id] = datetime.datetime.utcnow( ) + datetime.timedelta(seconds=utils.parse_time_to_seconds(down_time))