mirror of
https://github.com/Vendicated/Vencord.git
synced 2025-02-25 07:48:32 +00:00
Migrated to DataStore
This commit is contained in:
parent
365ca0ef57
commit
0d656f5e00
3 changed files with 405 additions and 27 deletions
|
@ -18,31 +18,37 @@
|
||||||
|
|
||||||
const PreloadedUserSettings = findLazy(m => m.ProtoClass?.typeName === "discord_protos.discord_users.v1.PreloadedUserSettings");
|
const PreloadedUserSettings = findLazy(m => m.ProtoClass?.typeName === "discord_protos.discord_users.v1.PreloadedUserSettings");
|
||||||
|
|
||||||
|
import * as DataStore from "@api/DataStore";
|
||||||
import { findLazy } from "@webpack";
|
import { findLazy } from "@webpack";
|
||||||
|
export const DATASTORE_KEY = "plugins.Timezones.savedTimezones";
|
||||||
|
import type { timezones } from "./all_timezones";
|
||||||
|
|
||||||
|
|
||||||
|
export interface TimezoneDB {
|
||||||
|
[userId: string]: typeof timezones[number];
|
||||||
|
}
|
||||||
|
|
||||||
const API_URL = "https://timezonedb.catvibers.me/";
|
const API_URL = "https://timezonedb.catvibers.me/";
|
||||||
const Cache = new Map<string, string | null>();
|
const Cache = new Map<string, string | null>();
|
||||||
|
|
||||||
const getSettings = () => Vencord.Settings.plugins.Timezones;
|
|
||||||
|
|
||||||
export async function getUserTimezone(discordID: string): Promise<string | null> {
|
export async function getUserTimezone(discordID: string): Promise<string | null> {
|
||||||
|
const timezone = (await DataStore.get(DATASTORE_KEY) as TimezoneDB | undefined)?.[discordID];
|
||||||
if (getSettings()[`timezones.${discordID}`])
|
if (timezone) return timezone;
|
||||||
return getSettings()[`timezones.${discordID}`];
|
|
||||||
|
|
||||||
if (Cache.has(discordID)) {
|
if (Cache.has(discordID)) {
|
||||||
return Cache.get(discordID) as string | null;
|
return Cache.get(discordID) as string | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
const response = await fetch(API_URL + "api/user/" + discordID);
|
const response = await fetch(API_URL + "api/user/" + discordID);
|
||||||
const timezone = await response.json();
|
const timezone_res = await response.json();
|
||||||
|
|
||||||
if (response.status !== 200) {
|
if (response.status !== 200) {
|
||||||
Cache.set(discordID, null);
|
Cache.set(discordID, null);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
Cache.set(discordID, timezone.timezoneId);
|
|
||||||
return timezone.timezoneId;
|
Cache.set(discordID, timezone_res.timezoneId);
|
||||||
|
return timezone_res.timezoneId;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getTimeString(timezone: string, timestamp = new Date()): string {
|
export function getTimeString(timezone: string, timestamp = new Date()): string {
|
||||||
|
|
324
src/plugins/Timezones/all_timezones.ts
Normal file
324
src/plugins/Timezones/all_timezones.ts
Normal file
|
@ -0,0 +1,324 @@
|
||||||
|
/*
|
||||||
|
* Vencord, a modification for Discord's desktop app
|
||||||
|
* Copyright (c) 2023 Vendicated and contributors
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
export const timezones = [
|
||||||
|
"Africa/Abidjan",
|
||||||
|
"Africa/Accra",
|
||||||
|
"Africa/Addis_Ababa",
|
||||||
|
"Africa/Algiers",
|
||||||
|
"Africa/Asmara",
|
||||||
|
"Africa/Bamako",
|
||||||
|
"Africa/Bangui",
|
||||||
|
"Africa/Banjul",
|
||||||
|
"Africa/Bissau",
|
||||||
|
"Africa/Blantyre",
|
||||||
|
"Africa/Brazzaville",
|
||||||
|
"Africa/Bujumbura",
|
||||||
|
"Africa/Cairo",
|
||||||
|
"Africa/Casablanca",
|
||||||
|
"Africa/Conakry",
|
||||||
|
"Africa/Dakar",
|
||||||
|
"Africa/Dar_es_Salaam",
|
||||||
|
"Africa/Djibouti",
|
||||||
|
"Africa/Douala",
|
||||||
|
"Africa/El_Aaiun",
|
||||||
|
"Africa/Freetown",
|
||||||
|
"Africa/Gaborone",
|
||||||
|
"Africa/Harare",
|
||||||
|
"Africa/Johannesburg",
|
||||||
|
"Africa/Juba",
|
||||||
|
"Africa/Kampala",
|
||||||
|
"Africa/Khartoum",
|
||||||
|
"Africa/Kigali",
|
||||||
|
"Africa/Kinshasa",
|
||||||
|
"Africa/Lagos",
|
||||||
|
"Africa/Libreville",
|
||||||
|
"Africa/Lome",
|
||||||
|
"Africa/Luanda",
|
||||||
|
"Africa/Lubumbashi",
|
||||||
|
"Africa/Lusaka",
|
||||||
|
"Africa/Malabo",
|
||||||
|
"Africa/Maputo",
|
||||||
|
"Africa/Maseru",
|
||||||
|
"Africa/Mbabane",
|
||||||
|
"Africa/Mogadishu",
|
||||||
|
"Africa/Monrovia",
|
||||||
|
"Africa/Nairobi",
|
||||||
|
"Africa/Ndjamena",
|
||||||
|
"Africa/Niamey",
|
||||||
|
"Africa/Nouakchott",
|
||||||
|
"Africa/Ouagadougou",
|
||||||
|
"Africa/Porto-Novo",
|
||||||
|
"Africa/Sao_Tome",
|
||||||
|
"Africa/Timbuktu",
|
||||||
|
"Africa/Tripoli",
|
||||||
|
"Africa/Tunis",
|
||||||
|
"Africa/Windhoek",
|
||||||
|
"America/Adak",
|
||||||
|
"America/Anchorage",
|
||||||
|
"America/Anguilla",
|
||||||
|
"America/Antigua",
|
||||||
|
"America/Araguaina",
|
||||||
|
"America/Argentina/Buenos_Aires",
|
||||||
|
"America/Argentina/Catamarca",
|
||||||
|
"America/Argentina/ComodRivadavia",
|
||||||
|
"America/Argentina/Cordoba",
|
||||||
|
"America/Argentina/Jujuy",
|
||||||
|
"America/Argentina/La_Rioja",
|
||||||
|
"America/Argentina/Mendoza",
|
||||||
|
"America/Argentina/Rio_Gallegos",
|
||||||
|
"America/Argentina/Salta",
|
||||||
|
"America/Argentina/San_Juan",
|
||||||
|
"America/Argentina/San_Luis",
|
||||||
|
"America/Argentina/Tucuman",
|
||||||
|
"America/Argentina/Ushuaia",
|
||||||
|
"America/Aruba",
|
||||||
|
"America/Asuncion",
|
||||||
|
"America/Atikokan",
|
||||||
|
"America/Bahia",
|
||||||
|
"America/Bahia_Banderas",
|
||||||
|
"America/Barbados",
|
||||||
|
"America/Belem",
|
||||||
|
"America/Belize",
|
||||||
|
"America/Blanc-Sablon",
|
||||||
|
"America/Boa_Vista",
|
||||||
|
"America/Bogota",
|
||||||
|
"America/Boise",
|
||||||
|
"America/Cambridge_Bay",
|
||||||
|
"America/Campo_Grande",
|
||||||
|
"America/Cancun",
|
||||||
|
"America/Caracas",
|
||||||
|
"America/Cayenne",
|
||||||
|
"America/Cayman",
|
||||||
|
"America/Chicago",
|
||||||
|
"America/Chihuahua",
|
||||||
|
"America/Ciudad_Juarez",
|
||||||
|
"America/Coral_Harbour",
|
||||||
|
"America/Costa_Rica",
|
||||||
|
"America/Creston",
|
||||||
|
"America/Cuiaba",
|
||||||
|
"America/Curacao",
|
||||||
|
"America/Dawson",
|
||||||
|
"America/Dawson_Creek",
|
||||||
|
"America/Denver",
|
||||||
|
"America/Detroit",
|
||||||
|
"America/Dominica",
|
||||||
|
"America/Edmonton",
|
||||||
|
"America/Eirunepe",
|
||||||
|
"America/El_Salvador",
|
||||||
|
"America/Ensenada",
|
||||||
|
"America/Fort_Nelson",
|
||||||
|
"America/Fortaleza",
|
||||||
|
"America/Glace_Bay",
|
||||||
|
"America/Goose_Bay",
|
||||||
|
"America/Grand_Turk",
|
||||||
|
"America/Grenada",
|
||||||
|
"America/Guadeloupe",
|
||||||
|
"America/Guatemala",
|
||||||
|
"America/Guayaquil",
|
||||||
|
"America/Guyana",
|
||||||
|
"America/Halifax",
|
||||||
|
"America/Havana",
|
||||||
|
"America/Hermosillo",
|
||||||
|
"America/Indiana/Indianapolis",
|
||||||
|
"America/Indiana/Knox",
|
||||||
|
"America/Indiana/Marengo",
|
||||||
|
"America/Indiana/Petersburg",
|
||||||
|
"America/Indiana/Tell_City",
|
||||||
|
"America/Indiana/Vevay",
|
||||||
|
"America/Indiana/Vincennes",
|
||||||
|
"America/Indiana/Winamac",
|
||||||
|
"America/Inuvik",
|
||||||
|
"America/Iqaluit",
|
||||||
|
"America/Jamaica",
|
||||||
|
"America/Juneau",
|
||||||
|
"America/Kentucky/Louisville",
|
||||||
|
"America/Kentucky/Monticello",
|
||||||
|
"America/La_Paz",
|
||||||
|
"America/Lima",
|
||||||
|
"America/Los_Angeles",
|
||||||
|
"America/Maceio",
|
||||||
|
"America/Managua",
|
||||||
|
"America/Manaus",
|
||||||
|
"America/Martinique",
|
||||||
|
"America/Matamoros",
|
||||||
|
"America/Mazatlan",
|
||||||
|
"America/Menominee",
|
||||||
|
"America/Merida",
|
||||||
|
"America/Metlakatla",
|
||||||
|
"America/Mexico_City",
|
||||||
|
"America/Miquelon",
|
||||||
|
"America/Moncton",
|
||||||
|
"America/Monterrey",
|
||||||
|
"America/Montevideo",
|
||||||
|
"America/Montreal",
|
||||||
|
"America/Montserrat",
|
||||||
|
"America/Nassau",
|
||||||
|
"America/New_York",
|
||||||
|
"America/Nipigon",
|
||||||
|
"America/Nome",
|
||||||
|
"America/Noronha",
|
||||||
|
"America/North_Dakota/Beulah",
|
||||||
|
"America/North_Dakota/Center",
|
||||||
|
"America/North_Dakota/New_Salem",
|
||||||
|
"America/Ojinaga",
|
||||||
|
"America/Panama",
|
||||||
|
"America/Pangnirtung",
|
||||||
|
"America/Paramaribo",
|
||||||
|
"America/Phoenix",
|
||||||
|
"America/Port-au-Prince",
|
||||||
|
"America/Port_of_Spain",
|
||||||
|
"America/Porto_Velho",
|
||||||
|
"America/Puerto_Rico",
|
||||||
|
"America/Punta_Arenas",
|
||||||
|
"America/Rainy_River",
|
||||||
|
"America/Rankin_Inlet",
|
||||||
|
"America/Recife",
|
||||||
|
"America/Regina",
|
||||||
|
"America/Resolute",
|
||||||
|
"America/Rio_Branco",
|
||||||
|
"America/Rosario",
|
||||||
|
"America/Santarem",
|
||||||
|
"America/Santiago",
|
||||||
|
"America/Santo_Domingo",
|
||||||
|
"America/Sao_Paulo",
|
||||||
|
"America/Sitka",
|
||||||
|
"America/St_Johns",
|
||||||
|
"America/St_Kitts",
|
||||||
|
"America/St_Lucia",
|
||||||
|
"America/St_Thomas",
|
||||||
|
"America/St_Vincent",
|
||||||
|
"America/Swift_Current",
|
||||||
|
"America/Tegucigalpa",
|
||||||
|
"America/Thunder_Bay",
|
||||||
|
"America/Tijuana",
|
||||||
|
"America/Toronto",
|
||||||
|
"America/Tortola",
|
||||||
|
"America/Vancouver",
|
||||||
|
"America/Whitehorse",
|
||||||
|
"America/Winnipeg",
|
||||||
|
"America/Yakutat",
|
||||||
|
"America/Yellowknife",
|
||||||
|
"Antarctica/Casey",
|
||||||
|
"Antarctica/Davis",
|
||||||
|
"Antarctica/DumontDUrville",
|
||||||
|
"Antarctica/Mawson",
|
||||||
|
"Antarctica/McMurdo",
|
||||||
|
"Antarctica/Palmer",
|
||||||
|
"Antarctica/Rothera",
|
||||||
|
"Antarctica/Syowa",
|
||||||
|
"Antarctica/Troll",
|
||||||
|
"Antarctica/Vostok",
|
||||||
|
"Asia/Aden",
|
||||||
|
"Asia/Bahrain",
|
||||||
|
"Asia/Brunei",
|
||||||
|
"Asia/Chongqing",
|
||||||
|
"Asia/Hanoi",
|
||||||
|
"Asia/Harbin",
|
||||||
|
"Asia/Kashgar",
|
||||||
|
"Asia/Kuala_Lumpur",
|
||||||
|
"Asia/Kuwait",
|
||||||
|
"Asia/Muscat",
|
||||||
|
"Asia/Phnom_Penh",
|
||||||
|
"Asia/Tel_Aviv",
|
||||||
|
"Asia/Vientiane",
|
||||||
|
"Atlantic/Bermuda",
|
||||||
|
"Atlantic/Cape_Verde",
|
||||||
|
"Atlantic/Jan_Mayen",
|
||||||
|
"Atlantic/Reykjavik",
|
||||||
|
"Atlantic/South_Georgia",
|
||||||
|
"Atlantic/St_Helena",
|
||||||
|
"Atlantic/Stanley",
|
||||||
|
"Australia/Currie",
|
||||||
|
"CST6CDT",
|
||||||
|
"EST",
|
||||||
|
"EST5EDT",
|
||||||
|
"Etc/GMT",
|
||||||
|
"Etc/GMT+1",
|
||||||
|
"Etc/GMT+10",
|
||||||
|
"Etc/GMT+11",
|
||||||
|
"Etc/GMT+12",
|
||||||
|
"Etc/GMT+2",
|
||||||
|
"Etc/GMT+3",
|
||||||
|
"Etc/GMT+4",
|
||||||
|
"Etc/GMT+5",
|
||||||
|
"Etc/GMT+6",
|
||||||
|
"Etc/GMT+7",
|
||||||
|
"Etc/GMT+8",
|
||||||
|
"Etc/GMT+9",
|
||||||
|
"Etc/GMT-1",
|
||||||
|
"Etc/GMT-10",
|
||||||
|
"Etc/GMT-11",
|
||||||
|
"Etc/GMT-12",
|
||||||
|
"Etc/GMT-13",
|
||||||
|
"Etc/GMT-14",
|
||||||
|
"Etc/GMT-2",
|
||||||
|
"Etc/GMT-3",
|
||||||
|
"Etc/GMT-4",
|
||||||
|
"Etc/GMT-5",
|
||||||
|
"Etc/GMT-6",
|
||||||
|
"Etc/GMT-7",
|
||||||
|
"Etc/GMT-8",
|
||||||
|
"Etc/GMT-9",
|
||||||
|
"Etc/UTC",
|
||||||
|
"Europe/Amsterdam",
|
||||||
|
"Europe/Belfast",
|
||||||
|
"Europe/Copenhagen",
|
||||||
|
"Europe/Guernsey",
|
||||||
|
"Europe/Isle_of_Man",
|
||||||
|
"Europe/Jersey",
|
||||||
|
"Europe/Ljubljana",
|
||||||
|
"Europe/Luxembourg",
|
||||||
|
"Europe/Monaco",
|
||||||
|
"Europe/Oslo",
|
||||||
|
"Europe/Sarajevo",
|
||||||
|
"Europe/Skopje",
|
||||||
|
"Europe/Stockholm",
|
||||||
|
"Europe/Tiraspol",
|
||||||
|
"Europe/Uzhgorod",
|
||||||
|
"Europe/Vaduz",
|
||||||
|
"Europe/Zagreb",
|
||||||
|
"Europe/Zaporozhye",
|
||||||
|
"Factory",
|
||||||
|
"HST",
|
||||||
|
"Indian/Antananarivo",
|
||||||
|
"Indian/Christmas",
|
||||||
|
"Indian/Cocos",
|
||||||
|
"Indian/Comoro",
|
||||||
|
"Indian/Kerguelen",
|
||||||
|
"Indian/Mahe",
|
||||||
|
"Indian/Mauritius",
|
||||||
|
"Indian/Mayotte",
|
||||||
|
"Indian/Reunion",
|
||||||
|
"MST",
|
||||||
|
"MST7MDT",
|
||||||
|
"PST8PDT",
|
||||||
|
"Pacific/Chuuk",
|
||||||
|
"Pacific/Easter",
|
||||||
|
"Pacific/Enderbury",
|
||||||
|
"Pacific/Funafuti",
|
||||||
|
"Pacific/Galapagos",
|
||||||
|
"Pacific/Honolulu",
|
||||||
|
"Pacific/Johnston",
|
||||||
|
"Pacific/Majuro",
|
||||||
|
"Pacific/Midway",
|
||||||
|
"Pacific/Pohnpei",
|
||||||
|
"Pacific/Saipan",
|
||||||
|
"Pacific/Wake",
|
||||||
|
"Pacific/Wallis"
|
||||||
|
] as const;
|
|
@ -18,18 +18,24 @@
|
||||||
|
|
||||||
|
|
||||||
import { ApplicationCommandInputType, ApplicationCommandOptionType, findOption, sendBotMessage } from "@api/Commands";
|
import { ApplicationCommandInputType, ApplicationCommandOptionType, findOption, sendBotMessage } from "@api/Commands";
|
||||||
|
import * as DataStore from "@api/DataStore";
|
||||||
import { Devs } from "@utils/constants";
|
import { Devs } from "@utils/constants";
|
||||||
import { classes } from "@utils/misc";
|
import { classes } from "@utils/misc";
|
||||||
import definePlugin, { OptionType } from "@utils/types";
|
import definePlugin, { OptionType } from "@utils/types";
|
||||||
import { findByCodeLazy, findByPropsLazy } from "@webpack";
|
import { findByCodeLazy, findByPropsLazy } from "@webpack";
|
||||||
import { React, Text, UserStore } from "@webpack/common";
|
import { React, Text, UserStore } from "@webpack/common";
|
||||||
import { Message, User } from "discord-types/general";
|
import { Message, User } from "discord-types/general";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const EditIcon = findByCodeLazy("M19.2929 9.8299L19.9409 9.18278C21.353 7.77064 21.353 5.47197 19.9409");
|
const EditIcon = findByCodeLazy("M19.2929 9.8299L19.9409 9.18278C21.353 7.77064 21.353 5.47197 19.9409");
|
||||||
const classNames = findByPropsLazy("customStatusSection");
|
const classNames = findByPropsLazy("customStatusSection");
|
||||||
|
import { timezones } from "./all_timezones";
|
||||||
import { getTimeString, getUserTimezone } from "./Utils";
|
import { DATASTORE_KEY, getTimeString, getUserTimezone, TimezoneDB } from "./Utils";
|
||||||
const styles = findByPropsLazy("timestampInline");
|
const styles = findByPropsLazy("timestampInline");
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
export default definePlugin({
|
export default definePlugin({
|
||||||
name: "Timezones",
|
name: "Timezones",
|
||||||
description: "Shows the timezones of users",
|
description: "Shows the timezones of users",
|
||||||
|
@ -58,20 +64,42 @@ export default definePlugin({
|
||||||
name: "user",
|
name: "user",
|
||||||
description: "User to set timezone for",
|
description: "User to set timezone for",
|
||||||
type: ApplicationCommandOptionType.USER,
|
type: ApplicationCommandOptionType.USER,
|
||||||
|
required: true
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "timezone",
|
name: "timezone",
|
||||||
description: "Timezone id to set (see https://en.wikipedia.org/wiki/List_of_tz_database_time_zones)",
|
description: "Timezone id to set (see https://en.wikipedia.org/wiki/List_of_tz_database_time_zones)",
|
||||||
type: ApplicationCommandOptionType.STRING,
|
type: ApplicationCommandOptionType.STRING,
|
||||||
|
required: true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
],
|
],
|
||||||
execute(args, ctx) {
|
execute(args, ctx) {
|
||||||
const user = findOption(args, "user");
|
const user: string | undefined = findOption(args, "user");
|
||||||
const timezone = findOption(args, "timezone");
|
const timezone = (findOption(args, "timezone", timezones[timezones.indexOf("Etc/UTC")])?.trim() as typeof timezones[number] | undefined);
|
||||||
Vencord.Settings.plugins.Timezones[`timezones.${user}`] = timezone;
|
|
||||||
sendBotMessage(ctx.channel.id, { content: "Timezone set" });
|
|
||||||
|
// Kinda hard to happen, but just to be safe...
|
||||||
|
if (!user || !timezone) return sendBotMessage(ctx.channel.id, { content: "PLease provider both a user and a timezone." });
|
||||||
|
|
||||||
|
|
||||||
|
if (timezone && !timezones.includes(timezone)) {
|
||||||
|
sendBotMessage(ctx.channel.id, { content: "Invalid timezone.\nPlease look at https://en.wikipedia.org/wiki/List_of_tz_database_time_zones" });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
DataStore.update(DATASTORE_KEY, (oldValue: TimezoneDB | undefined) => {
|
||||||
|
oldValue = oldValue || {};
|
||||||
|
|
||||||
|
oldValue[user] = timezone;
|
||||||
|
return oldValue;
|
||||||
|
}).then(() => {
|
||||||
|
sendBotMessage(ctx.channel.id, { content: "Timezone set!" });
|
||||||
|
}).catch(err => {
|
||||||
|
console.error(err);
|
||||||
|
sendBotMessage(ctx.channel.id, { content: "Something went wrong, please try again later." });
|
||||||
|
});
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -83,16 +111,28 @@ export default definePlugin({
|
||||||
name: "user",
|
name: "user",
|
||||||
description: "User to delete timezone for",
|
description: "User to delete timezone for",
|
||||||
type: ApplicationCommandOptionType.USER,
|
type: ApplicationCommandOptionType.USER,
|
||||||
|
required: true
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
execute(args, ctx) {
|
execute(args, ctx) {
|
||||||
const user = findOption(args, "user");
|
const user: string | undefined = findOption(args, "user");
|
||||||
if (!Vencord.Settings.plugins.Timezones[`timezones.${user}`]) {
|
if (!user) return sendBotMessage(ctx.channel.id, { content: "Please provide a user." }) && undefined;
|
||||||
sendBotMessage(ctx.channel.id, { content: "No timezone" });
|
|
||||||
return;
|
DataStore.update(DATASTORE_KEY, (oldValue: TimezoneDB | undefined) => {
|
||||||
}
|
oldValue = oldValue || {};
|
||||||
delete Vencord.Settings.plugins.Timezones[`timezones.${user}`];
|
|
||||||
sendBotMessage(ctx.channel.id, { content: "Timezone deleted" });
|
if (!Object.prototype.hasOwnProperty.call(oldValue, user))
|
||||||
|
sendBotMessage(ctx.channel.id, { content: "No timezones were set for this user." });
|
||||||
|
else {
|
||||||
|
delete oldValue[user];
|
||||||
|
sendBotMessage(ctx.channel.id, { content: "Timezone removed!." });
|
||||||
|
}
|
||||||
|
|
||||||
|
return oldValue;
|
||||||
|
}).catch(err => {
|
||||||
|
console.error(err);
|
||||||
|
sendBotMessage(ctx.channel.id, { content: "Something went wrong, please try again later." });
|
||||||
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -100,13 +140,21 @@ export default definePlugin({
|
||||||
description: "Get all timezones",
|
description: "Get all timezones",
|
||||||
inputType: ApplicationCommandInputType.BUILT_IN,
|
inputType: ApplicationCommandInputType.BUILT_IN,
|
||||||
execute(args, ctx) {
|
execute(args, ctx) {
|
||||||
const timezones = Vencord.Settings.plugins.Timezones;
|
DataStore.get(DATASTORE_KEY).then((timezones: TimezoneDB | undefined) => {
|
||||||
let str = Object.entries(timezones).filter(t => t.toString().startsWith("timezones.")).map(([user, timezone]) => `<@${user.slice(10)}>: ${timezone}`).join("\n");
|
if (!timezones || Object.keys(timezones).length === 0) {
|
||||||
|
sendBotMessage(ctx.channel.id, { content: "No timezones are set." });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (str.length === 0) {
|
sendBotMessage(ctx.channel.id, {
|
||||||
str = "No timezones set";
|
content: "Timezones for " + Object.keys(timezones).length + " users:\n" + Object.keys(timezones).map(user => {
|
||||||
}
|
return `<@${user}> - ${timezones[user]}`;
|
||||||
sendBotMessage(ctx.channel.id, { content: str });
|
}).join("\n")
|
||||||
|
});
|
||||||
|
}).catch(err => {
|
||||||
|
console.error(err);
|
||||||
|
sendBotMessage(ctx.channel.id, { content: "Something went wrong, please try again later." });
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
|
Loading…
Add table
Reference in a new issue