3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-05-21 16:55:03 +00:00

!timezone: add fuzzy matching for timezone name; add reset

This commit is contained in:
Dragory 2020-08-19 00:47:31 +03:00
parent 6ba56a3f12
commit a39bdb559f
6 changed files with 90 additions and 7 deletions

View file

@ -1,17 +1,34 @@
import { timeAndDateCmd } from "../types";
import { commandTypeHelpers as ct } from "../../../commandTypes";
import { sendSuccessMessage } from "../../../pluginUtils";
import { sendErrorMessage, sendSuccessMessage } from "../../../pluginUtils";
import { isValidTimezone } from "../../../utils/isValidTimezone";
import { disableInlineCode, trimLines } from "../../../utils";
import { parseFuzzyTimezone } from "../../../utils/parseFuzzyTimezone";
export const SetTimezoneCmd = timeAndDateCmd({
trigger: "timezone",
permission: "can_set_timezone",
signature: {
timezone: ct.timezone(),
timezone: ct.string(),
},
async run({ pluginData, message, args }) {
await pluginData.state.memberTimezones.set(message.author.id, args.timezone);
sendSuccessMessage(pluginData, message.channel, `Your timezone is now set to **${args.timezone}**`);
const parsedTz = parseFuzzyTimezone(args.timezone);
if (!parsedTz) {
sendErrorMessage(
pluginData,
message.channel,
trimLines(`
Invalid timezone: \`${disableInlineCode(args.timezone)}\`
Zeppelin uses timezone locations rather than specific timezone names.
See the **TZ database name** column at <https://en.wikipedia.org/wiki/List_of_tz_database_time_zones> for a list of valid options.
`),
);
return;
}
await pluginData.state.memberTimezones.set(message.author.id, parsedTz);
sendSuccessMessage(pluginData, message.channel, `Your timezone is now set to **${parsedTz}**`);
},
});