From 07d74a4ef40056cecb875a3f6884f8c0477aac1f Mon Sep 17 00:00:00 2001 From: Zomatree Date: Sat, 17 May 2025 12:59:39 +0100 Subject: [PATCH 1/2] feat: reset bot token button --- external/lang | 2 +- src/controllers/modals/ModalController.tsx | 1 + .../modals/components/Confirmation.tsx | 8 +++++ src/controllers/modals/types.ts | 5 +++ src/pages/settings/panes/MyBots.tsx | 34 +++++++++++++++---- 5 files changed, 43 insertions(+), 7 deletions(-) diff --git a/external/lang b/external/lang index e5413325..4ec2f998 160000 --- a/external/lang +++ b/external/lang @@ -1 +1 @@ -Subproject commit e54133252e834299a23e759b7cda2cf2b2447279 +Subproject commit 4ec2f99855825743f65eabd715ec77f61c28c5d8 diff --git a/src/controllers/modals/ModalController.tsx b/src/controllers/modals/ModalController.tsx index 62ed8073..ebed19c6 100644 --- a/src/controllers/modals/ModalController.tsx +++ b/src/controllers/modals/ModalController.tsx @@ -297,4 +297,5 @@ export const modalController = new ModalControllerExtended({ report_success: ReportSuccess, modify_displayname: ModifyDisplayname, changelog_usernames: ChangelogUsernames, + reset_bot_token: Confirmation }); diff --git a/src/controllers/modals/components/Confirmation.tsx b/src/controllers/modals/components/Confirmation.tsx index 179a8b43..8fbed7e4 100644 --- a/src/controllers/modals/components/Confirmation.tsx +++ b/src/controllers/modals/components/Confirmation.tsx @@ -20,6 +20,7 @@ export default function Confirmation( | "delete_bot" | "block_user" | "unfriend_user" + | "reset_bot_token" >, ) { const history = useHistory(); @@ -31,6 +32,7 @@ export default function Confirmation( delete_bot: ["confirm_delete", "delete"], unfriend_user: ["unfriend_user", "remove"], block_user: ["block_user", "block"], + reset_bot_token: ["reset_bot_token", "reset"], }; const event = EVENTS[props.type]; @@ -88,6 +90,12 @@ export default function Confirmation( .bots.delete(props.target); props.cb?.(); break; + case "reset_bot_token": + clientController + .getAvailableClient() + .bots + .edit(props.target.id, { remove: ["Token"] }) + .then(props.callback) } }} submit={{ diff --git a/src/controllers/modals/types.ts b/src/controllers/modals/types.ts index 752c22d5..9255d173 100644 --- a/src/controllers/modals/types.ts +++ b/src/controllers/modals/types.ts @@ -190,6 +190,11 @@ export type Modal = { type: "report_success"; user?: User; } + | { + type: "reset_bot_token"; + target: { name: string, id: string }, + callback: () => Promise; + } ); export type ModalProps = Modal & { type: T } & { diff --git a/src/pages/settings/panes/MyBots.tsx b/src/pages/settings/panes/MyBots.tsx index 03af49c0..52e8c052 100644 --- a/src/pages/settings/panes/MyBots.tsx +++ b/src/pages/settings/panes/MyBots.tsx @@ -35,6 +35,7 @@ import { modalController } from "../../../controllers/modals/ModalController"; interface Data { _id: string; + token: string; username: string; public: boolean; interactions_url?: string; @@ -74,6 +75,7 @@ function BotCard({ bot, onDelete, onUpdate }: Props) { const [user, setUser] = useState(client.users.get(bot._id)!); const [data, setData] = useState({ _id: bot._id, + token: bot.token, username: user.username, public: bot.public, interactions_url: bot.interactions_url as any, @@ -94,7 +96,7 @@ function BotCard({ bot, onDelete, onUpdate }: Props) { const refreshProfile = useCallback(() => { client.api .get(`/users/${bot._id as ""}/profile`, undefined, { - headers: { "x-bot-token": bot.token }, + headers: { "x-bot-token": data.token }, }) .then((profile) => setProfile(profile ?? {})); // eslint-disable-next-line react-hooks/exhaustive-deps @@ -149,7 +151,7 @@ function BotCard({ bot, onDelete, onUpdate }: Props) { "/users/@me", avatar ? { avatar } : { remove: ["Avatar"] }, { - headers: { "x-bot-token": bot.token }, + headers: { "x-bot-token": data.token }, }, ); @@ -168,7 +170,7 @@ function BotCard({ bot, onDelete, onUpdate }: Props) { ? { profile: { background } } : { remove: ["ProfileBackground"] }, { - headers: { "x-bot-token": bot.token }, + headers: { "x-bot-token": data.token }, }, ); @@ -184,7 +186,7 @@ function BotCard({ bot, onDelete, onUpdate }: Props) { "/users/@me", content ? { profile: { content } } : { remove: ["ProfileContent"] }, { - headers: { "x-bot-token": bot.token }, + headers: { "x-bot-token": data.token }, }, ); @@ -312,6 +314,7 @@ function BotCard({ bot, onDelete, onUpdate }: Props) { if (editMode) { setData({ _id: bot._id, + token: data.token, username: user!.username, public: bot.public, interactions_url: bot.interactions_url as any, @@ -334,7 +337,7 @@ function BotCard({ bot, onDelete, onUpdate }: Props) { } - onClick={() => modalController.writeText(bot.token)} + onClick={() => modalController.writeText(data.token)} description={ <> {"••••• "} @@ -344,7 +347,7 @@ function BotCard({ bot, onDelete, onUpdate }: Props) { ev, modalController.push({ type: "show_token", - token: bot.token, + token: data.token, name: user!.username, }), ) @@ -490,6 +493,25 @@ function BotCard({ bot, onDelete, onUpdate }: Props) { }> + )} From 0a8b70c8ed963490d7967ec65920f4923037fafc Mon Sep 17 00:00:00 2001 From: Zomatree Date: Sat, 17 May 2025 13:10:11 +0100 Subject: [PATCH 2/2] chore: update submodule --- external/lang | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/external/lang b/external/lang index 4ec2f998..bb4bfcfd 160000 --- a/external/lang +++ b/external/lang @@ -1 +1 @@ -Subproject commit 4ec2f99855825743f65eabd715ec77f61c28c5d8 +Subproject commit bb4bfcfd5a22dfc84a1a9f797a43af6804d96b93