Skip to content

Fix defcon having wrong text when disabling.#541

Merged
sco1 merged 7 commits into
python-discord:masterfrom
ikuyarihS:master
Oct 21, 2019
Merged

Fix defcon having wrong text when disabling.#541
sco1 merged 7 commits into
python-discord:masterfrom
ikuyarihS:master

Conversation

@ikuyarihS
Copy link
Copy Markdown
Contributor

@ikuyarihS ikuyarihS commented Oct 17, 2019

Closes #539

This pull request fixes the issue for wrong status in the embed, as well as unifying certains if else to prevent similar future errors.

Most notable code is here:

log_msg = f"**Staffer:** {actor} (`{actor.id}`)\n"

if change.lower() == "enabled":
    icon = Icons.defcon_enabled
    color = Colours.soft_green
    status_msg = "DEFCON enabled"
    log_msg += f"**Days:** {self.days.days}\n\n"
elif change.lower() == "disabled":
    icon = Icons.defcon_disabled
    color = Colours.soft_red
    status_msg = "DEFCON enabled"
elif change.lower() == "updated":
    icon = Icons.defcon_updated
    color = Colour.blurple()
    status_msg = "DEFCON updated"
    log_msg += f"**Days:** {self.days.days}\n\n"

To remedy this issue, the class will now have a private class variable Enum ( Thanks to @MarkKoz for the suggestions )

class Action(Enum):
    """Defcon Action."""

    ActionInfo = namedtuple('LogInfoDetails', ['icon', 'color', 'template'])

    ENABLED = ActionInfo(Icons.defcon_enabled, Colours.soft_green, "**Days:** {days}\n\n")
    DISABLED = ActionInfo(Icons.defcon_disabled, Colours.soft_red, "")
    UPDATED = ActionInfo(Icons.defcon_updated, Colour.blurple(), "**Days:** {days}\n\n")

Another big change is the introduction of _defcon_action to unify the process all defcon actions has to go through:

  • Try to do the action.
  • Log error if there is any.
  • Send log message.

#### Closes python-discord#539

This pull request fixes the issue for wrong status in the embed, as well as unifying certains if else to prevent similar future errors.

Most notable code is here:

```python
log_msg = f"**Staffer:** {actor} (`{actor.id}`)\n"

if change.lower() == "enabled":
    icon = Icons.defcon_enabled
    color = Colours.soft_green
    status_msg = "DEFCON enabled"
    log_msg += f"**Days:** {self.days.days}\n\n"
elif change.lower() == "disabled":
    icon = Icons.defcon_disabled
    color = Colours.soft_red
    status_msg = "DEFCON enabled"
elif change.lower() == "updated":
    icon = Icons.defcon_updated
    color = Colour.blurple()
    status_msg = "DEFCON updated"
    log_msg += f"**Days:** {self.days.days}\n\n"
```

To remedy this issue, the class will now have a private class variable

```py
_defcon_log_info: Dict[str, Tuple] = {
    'enabled': (Icons.defcon_enabled, Colours.soft_green, "**Days:** {days}\n\n"),
    'disabled': (Icons.defcon_disabled, Colours.soft_red, ""),
    'updated': (Icons.defcon_updated, Colour.blurple(), "**Days:** {days}\n\n"),
}
```

Another big change is the introduction of `_defcon_action` to unify the process all defcon actions has to go through:
- Try to do the action.
- Log error if there is any.
- Send log message.
@ikuyarihS ikuyarihS added t: bug Something isn't working area: cogs p: 3 - low Low Priority labels Oct 17, 2019
@ikuyarihS ikuyarihS requested review from eivl and kosayoda October 17, 2019 06:20
@ikuyarihS ikuyarihS self-assigned this Oct 17, 2019
Comment thread bot/cogs/defcon.py Outdated
Comment thread bot/cogs/defcon.py Outdated
- Further unify defcon actions in `_defcon_action` - Thanks to Mark's suggestions.
- Changed from a Dict to an Enum for defcon log info.
Comment thread bot/cogs/defcon.py Outdated
Comment thread bot/cogs/defcon.py Outdated
Comment thread bot/cogs/defcon.py Outdated
- Renamed `DefconInfoLog` to `Action`
- Added `ActionInfo` namedtuple.
- Use `Action` consistently for `_defcon_action()` and `send_defcon_log()`
Comment thread bot/cogs/defcon.py Outdated
- Remove the unneccessary `get_info()` method of Enum `Action`.
- Pass Enum `Action` directly to `build_defcon_msg()` and `send_defcon_log()` - Right now, only `_defcon_action()` is using them.
Comment thread bot/cogs/defcon.py Outdated
Comment thread bot/cogs/defcon.py Outdated
- Update docstrings for `build_defcon_msg()` and `send_defcon_log()` - It is now taking in an `Action` directly instead of a string.
Comment thread bot/cogs/defcon.py Outdated
@ikuyarihS ikuyarihS removed request for eivl and kosayoda October 21, 2019 06:44
- Now it will only show the amount of days.
- Quality of Life: Also show `day` instead of `days` when it's just 1 day.
@sco1 sco1 merged commit 0f85f2a into python-discord:master Oct 21, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

p: 3 - low Low Priority t: bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Defcon have wrong text in #mod-log when you disable it.

3 participants