def message(self, breadcrumbs): if self.__status is pulp.LpStatusOptimal: return self.__solution_message(breadcrumbs) message = ResultMessage() message.embed = Embed(title=str(self)) message.content = str(breadcrumbs) return message
def _get_info_page(self, breadcrumbs): var_names = [var.human_readable_name() for var in self._vars] start_index = (breadcrumbs.page() - 1) * InfoResult.num_on_page last_index = start_index + InfoResult.num_on_page vars_on_page = var_names[start_index:last_index] out = [] message = ResultMessage() for i, var_ in enumerate(vars_on_page): prefix = "" if self._add_reaction_selectors: prefix = ada.emoji.NUM_EMOJI[i + 1] message.reactions.append(prefix) out.append("- " + prefix + var_) if not self._add_reaction_selectors: message.reactions = [] if breadcrumbs.page() > 1: message.reactions.append(ada.emoji.PREVIOUS_PAGE) message.reactions.append(ada.emoji.INFO) if breadcrumbs.page() < self._num_pages(): message.reactions.append(ada.emoji.NEXT_PAGE) message.embed = Embed(title="Found " + str(len(self._vars)) + " matches:") message.embed.description = "\n".join(out) message.embed.set_footer(text=self._footer(breadcrumbs.page())) message.content = str(breadcrumbs) return message
def message(self, breadcrumbs): if len(self._vars) == 0: message = ResultMessage() message.embed = Embed(title="No matches found") message.content = str(breadcrumbs) return message if len(self._vars) > 1: return self._get_info_page(breadcrumbs) message = ResultMessage() message.embed = self._vars[0].embed() message.content = str(breadcrumbs) message.reactions = [ada.emoji.PREVIOUS_PAGE] return message
def __solution_messages(self, breadcrumbs): message = ResultMessage() message.embed = Embed(title="Optimization Query") sections = [str(self.__query)] inputs = self.__get_vars(self.__db.items().values(), check_value=lambda val: val < 0, suffix="/m") if len(inputs) > 0: sections.append("**Inputs**\n" + "\n".join(inputs)) outputs = self.__get_vars(self.__db.items().values(), check_value=lambda val: val > 0, suffix="/m") if len(outputs) > 0: sections.append("**Outputs**\n" + "\n".join(outputs)) recipes = self.__get_vars(self.__db.recipes().values()) if len(recipes) > 0: sections.append("**Recipes**\n" + "\n".join(recipes)) buildings = self.__get_vars(self.__db.crafters().values()) buildings.extend(self.__get_vars(self.__db.generators().values())) if len(buildings) > 0: sections.append("**Buildings**\n" + "\n".join(buildings)) descriptions = [] curr_description = "" for section in sections: if len(curr_description) + len(section) >= 4096: descriptions.append(curr_description) curr_description = "" curr_description += section + "\n\n" descriptions.append(curr_description) message.embed.description = descriptions[0] filename = 'output.gv' filepath = 'output/' + filename self.generate_graph_viz(filepath) file = File(filepath + '.png') # The image already shows up from the attached file, so no need to place it in the embed as well. # message.embed.set_image(url="attachment://" + filename + ".png") message.file = file message.content = str(breadcrumbs) messages = [message] if len(descriptions) > 1: for i in range(1, len(descriptions)): next_message = ResultMessage() next_message.embed = Embed() next_message.embed.description = descriptions[i] messages.append(next_message) return messages
def message(self, breadcrumbs): message = ResultMessage() # message.embed = Embed(title="Error") # message.embed.description = "hello" # "```{}```".format(str(self)) product_name = self.__stats.query.product_item.human_readable_name() out = [] out.append("All recipes that produce " + product_name) out.append("```\n{}```".format( tabulate(self.__overall_stats, headers="keys", tablefmt="simple"))) out.append("Raw Inputs for 1/m " + product_name) out.append("```\n{}```".format( tabulate(self.__input_stats, headers="keys", tablefmt="simple"))) message.content = "{}\n{}".format(str(breadcrumbs), '\n'.join(out)) if len(message.content) > 2000: message.content = "Output was too long" return message
def __solution_message(self, breadcrumbs): message = ResultMessage() message.embed = Embed(title="Optimization Query") # We don't include the parsed query in case this puts the embed over the character limit # message.embed.description = str(self.__query) message.embed.description = " " inputs = self.__get_vars(self.__db.items().values(), check_value=lambda val: val < 0, suffix="/m") if len(inputs) > 0: message.embed.add_field(name="Inputs", value="\n".join(inputs), inline=True) outputs = self.__get_vars(self.__db.items().values(), check_value=lambda val: val > 0, suffix="/m") if len(outputs) > 0: message.embed.add_field(name="Outputs", value="\n".join(outputs), inline=True) recipes = self.__get_vars(self.__db.recipes().values()) if len(recipes) > 0: message.embed.add_field(name="Recipes", value="\n".join(recipes), inline=False) buildings = self.__get_vars(self.__db.crafters().values()) buildings.extend(self.__get_vars(self.__db.generators().values())) if len(buildings) > 0: message.embed.add_field(name="Buildings", value="\n".join(buildings), inline=True) filename = 'output.gv' filepath = 'output/' + filename self.generate_graph_viz(filepath) file = File(filepath + '.png') # The image already shows up from the attached file, so no need to place it in the embed as well. # message.embed.set_image(url="attachment://" + filename + ".png") message.file = file message.content = breadcrumbs return message
def message(self, breadcrumbs): message = ResultMessage() message.embed = Embed(title="Error") message.embed.description = self.__msg message.content = str(breadcrumbs) return message
def message(self, breadcrumbs): message = ResultMessage() message.embed = Embed(title="Help") message.embed.description = str(self) message.content = str(breadcrumbs) return message