Skip to content

Commit

Permalink
Allow the use of custom names instead of "System" for system messages
Browse files Browse the repository at this point in the history
  • Loading branch information
DarkView committed Aug 11, 2021
1 parent 40e8a44 commit 488ba6a
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 9 deletions.
17 changes: 13 additions & 4 deletions CONFIG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,27 @@ Below you can find the default options:

em.systemStaffEnabled = on
em.systemStaffColor = "#1AA4BC"

# Miscellaneous Settings
em.systemName = "System"
```
If you want to change an option, simply copy and paste the corresponding line into your config and change the value.

## Valid values
### Toggles
# Valid values
## Toggles
Any setting that ends in `Enabled` is a toggle.
Like regular on/off settings, these take any truthy or falsy values.
Truthy: `on`, `1`, `true`
Falsy: `off`, `0`, `false`, `null`

### Colors
## Colors
Any option that ends in `Color` takes a color value.
Valid color formats are:
- HEX (e.g. "#7289DA") | These must start with a `#` and be in quotes
- RGB (e.g. 114, 137, 218) | Any three numbers delimited with any non-number
- RGB (e.g. 114, 137, 218) | Any three numbers delimited with any non-number

## Miscellaneous Settings
These all accept different values. All misc. settings and their types are listed here:
### systemName
This accepts any string. Said string will then be used in the embed instead of `System` when a system message is sent.
Setting this to `$botname` will automatically use the Bots username (as it was when the plugin was loaded - later changes are not reflected until the bot restarts).
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
## A plugin for [Dragory's ModMail](https://github.com/dragory/modmailbot) that changes messages to embeds
**Currently on Version 1.1.1**
**Currently on Version 1.1.2**
Plugin written and maintained by [DarkView](https://github.com/DarkView) (Dark#1010 on Discord)

## Setup
Expand Down
19 changes: 15 additions & 4 deletions embedMessages.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module.exports = async function ({ config, bot, formats }) {
const moment = require("moment");
const pluginVersion = "1.1.1";
const pluginVersion = "1.1.2";
const KEY = "em";
const truthyValues = ["on", "1", "true"];
const falsyValues = ["off", "0", "false", "null"];
Expand Down Expand Up @@ -99,6 +99,9 @@ module.exports = async function ({ config, bot, formats }) {
SYSTEM_USER_THREAD_COLOR: "systemReplyThreadColor",
SYSTEM_STAFF_ENABLED: "systemStaffEnabled",
SYSTEM_STAFF_COLOR: "systemStaffColor",

// Miscellaneous Settings
CUSTOM_SYSTEM_NAME: "systemName",
});

// Init with defaults
Expand All @@ -121,6 +124,9 @@ module.exports = async function ({ config, bot, formats }) {
[SETTING_NAMES.SYSTEM_USER_THREAD_COLOR, parseColor("#5865F2")],
[SETTING_NAMES.SYSTEM_STAFF_ENABLED, true],
[SETTING_NAMES.SYSTEM_STAFF_COLOR, parseColor("#1AA4BC")],

// Miscellaneous Settings
[SETTING_NAMES.CUSTOM_SYSTEM_NAME, "System"],
]);

// Load config settings
Expand All @@ -144,9 +150,14 @@ module.exports = async function ({ config, bot, formats }) {
} else {
settings.set(name, parsedColor);
}
} else {
settings.set(name, override);
}
}
}

// Do auto-value checks on boot instead of once every message
const systemName = settings.get(SETTING_NAMES.CUSTOM_SYSTEM_NAME).toLowerCase() === "$botname" ? bot.user.username : settings.get(SETTING_NAMES.CUSTOM_SYSTEM_NAME);

/**
* Returns pfp url for userId
Expand Down Expand Up @@ -296,7 +307,7 @@ module.exports = async function ({ config, bot, formats }) {
const embed = { description: threadMessage.body, color: settings.get(SETTING_NAMES.SYSTEM_USER_DM_COLOR) };

embed.author = {
name: "System",
name: systemName,
icon_url: bot.user.avatarURL,
};

Expand Down Expand Up @@ -329,7 +340,7 @@ module.exports = async function ({ config, bot, formats }) {
const embed = { description: threadMessage.body, color: settings.get(SETTING_NAMES.SYSTEM_USER_THREAD_COLOR) };

embed.author = {
name: "System",
name: systemName,
icon_url: bot.user.avatarURL,
};

Expand Down Expand Up @@ -362,7 +373,7 @@ module.exports = async function ({ config, bot, formats }) {
const embed = { description: threadMessage.body, color: settings.get(SETTING_NAMES.SYSTEM_STAFF_COLOR) };

embed.author = {
name: "System",
name: systemName,
icon_url: bot.user.avatarURL,
};

Expand Down

0 comments on commit 488ba6a

Please sign in to comment.