def __countdown_cmd_change(self, ctx: commands.Context, cd_name: str, cd_time: str): result_str = "" try: pend_test_convert = pendulum.from_format( cd_time, self.pend_format) # check that the format is correct except ValueError as error: expected = "ERROR: inputted time does not match expected format `month/day/year @ hour:minute AM/PM UTC_offset`\n" result_str = expected + " ex. `5/17/20 @ 1:00 PM -06:00`" BOT_ERROR.output_debug(result_str, self.logger) return result_str query_get_timer_by_name = f"SELECT * FROM {self.__get_cd_table_name(ctx.guild.id)} WHERE name=\'{cd_name}\';" query_result = self.sqlhelp.execute_read_query(query_get_timer_by_name) if (query_result != None): if (len(query_result) > 0): (query_id, query_name, query_time, query_user_id) = query_result[0] if (ctx.author.id == query_user_id): if (self.sqlhelp.execute_update_query( self.__get_cd_table_name(ctx.guild.id), f"time=\'{cd_time}\'", f"id={query_id}")): diff_str = self.__find_pend_diff_str(pend_test_convert) result_str = f"Updated countdown for {cd_name}. Now set for {diff_str}" else: result_str = BOT_ERROR.INVALID_COUNTDOWN_NAME(cd_name) else: cd_owner = ctx.guild.get_member(query_user_id) result_str = BOT_ERROR.CANNOT_CHANGE_COUNTDOWN( cd_owner.name) else: result_str = BOT_ERROR.INVALID_COUNTDOWN_NAME(cd_name) return result_str
def __countdown_cmd_remove(self, ctx: commands.Context, cd_name: str): result_str = "" query_get_timer_by_name = f"SELECT * FROM {self.__get_cd_table_name(ctx.guild.id)} WHERE name=\'{cd_name}\';" query_result = self.sqlhelp.execute_read_query(query_get_timer_by_name) if (query_result != None): (query_id, query_name, query_time, query_user_id) = query_result[0] if (query_user_id == ctx.author.id): if (self.sqlhelp.execute_delete_query( self.__get_cd_table_name(ctx.guild.id), f"id={query_id}")): result_str = f"Countdown timer `{query_name}` removed." else: result_str = BOT_ERROR.INVALID_COUNTDOWN_NAME(cd_name) else: cd_owner = ctx.guild.get_member(query_user_id) result_str = BOT_ERROR.CANNOT_CHANGE_COUNTDOWN(cd_owner.name) else: result_str = BOT_ERROR.INVALID_COUNTDOWN_NAME(cd_name) return result_str