コード例 #1
0
    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
コード例 #2
0
 def __countdown_cmd_set(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
         if (self.sqlhelp.insert_records(
                 self.__get_cd_table_name(ctx.guild.id),
                 "(name, time, user_id)",
             [f"('{cd_name}', '{cd_time}', {ctx.author.id})"])):
             diff_str = self.__find_pend_diff_str(pend_test_convert)
             result_str = f"{cd_name} countdown set for {cd_time} ({diff_str})"
         else:
             result_str = BOT_ERROR.COUNTDOWN_NAME_TAKEN
     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)
     finally:
         return result_str