forked from abner/for-legacy-web
feat: reset bot token button
parent
bccf1eebae
commit
07d74a4ef4
|
|
@ -1 +1 @@
|
||||||
Subproject commit e54133252e834299a23e759b7cda2cf2b2447279
|
Subproject commit 4ec2f99855825743f65eabd715ec77f61c28c5d8
|
||||||
|
|
@ -297,4 +297,5 @@ export const modalController = new ModalControllerExtended({
|
||||||
report_success: ReportSuccess,
|
report_success: ReportSuccess,
|
||||||
modify_displayname: ModifyDisplayname,
|
modify_displayname: ModifyDisplayname,
|
||||||
changelog_usernames: ChangelogUsernames,
|
changelog_usernames: ChangelogUsernames,
|
||||||
|
reset_bot_token: Confirmation
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,7 @@ export default function Confirmation(
|
||||||
| "delete_bot"
|
| "delete_bot"
|
||||||
| "block_user"
|
| "block_user"
|
||||||
| "unfriend_user"
|
| "unfriend_user"
|
||||||
|
| "reset_bot_token"
|
||||||
>,
|
>,
|
||||||
) {
|
) {
|
||||||
const history = useHistory();
|
const history = useHistory();
|
||||||
|
|
@ -31,6 +32,7 @@ export default function Confirmation(
|
||||||
delete_bot: ["confirm_delete", "delete"],
|
delete_bot: ["confirm_delete", "delete"],
|
||||||
unfriend_user: ["unfriend_user", "remove"],
|
unfriend_user: ["unfriend_user", "remove"],
|
||||||
block_user: ["block_user", "block"],
|
block_user: ["block_user", "block"],
|
||||||
|
reset_bot_token: ["reset_bot_token", "reset"],
|
||||||
};
|
};
|
||||||
|
|
||||||
const event = EVENTS[props.type];
|
const event = EVENTS[props.type];
|
||||||
|
|
@ -88,6 +90,12 @@ export default function Confirmation(
|
||||||
.bots.delete(props.target);
|
.bots.delete(props.target);
|
||||||
props.cb?.();
|
props.cb?.();
|
||||||
break;
|
break;
|
||||||
|
case "reset_bot_token":
|
||||||
|
clientController
|
||||||
|
.getAvailableClient()
|
||||||
|
.bots
|
||||||
|
.edit(props.target.id, { remove: ["Token"] })
|
||||||
|
.then(props.callback)
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
submit={{
|
submit={{
|
||||||
|
|
|
||||||
|
|
@ -190,6 +190,11 @@ export type Modal = {
|
||||||
type: "report_success";
|
type: "report_success";
|
||||||
user?: User;
|
user?: User;
|
||||||
}
|
}
|
||||||
|
| {
|
||||||
|
type: "reset_bot_token";
|
||||||
|
target: { name: string, id: string },
|
||||||
|
callback: () => Promise<void>;
|
||||||
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
export type ModalProps<T extends Modal["type"]> = Modal & { type: T } & {
|
export type ModalProps<T extends Modal["type"]> = Modal & { type: T } & {
|
||||||
|
|
|
||||||
|
|
@ -35,6 +35,7 @@ import { modalController } from "../../../controllers/modals/ModalController";
|
||||||
|
|
||||||
interface Data {
|
interface Data {
|
||||||
_id: string;
|
_id: string;
|
||||||
|
token: string;
|
||||||
username: string;
|
username: string;
|
||||||
public: boolean;
|
public: boolean;
|
||||||
interactions_url?: string;
|
interactions_url?: string;
|
||||||
|
|
@ -74,6 +75,7 @@ function BotCard({ bot, onDelete, onUpdate }: Props) {
|
||||||
const [user, setUser] = useState<User>(client.users.get(bot._id)!);
|
const [user, setUser] = useState<User>(client.users.get(bot._id)!);
|
||||||
const [data, setData] = useState<Data>({
|
const [data, setData] = useState<Data>({
|
||||||
_id: bot._id,
|
_id: bot._id,
|
||||||
|
token: bot.token,
|
||||||
username: user.username,
|
username: user.username,
|
||||||
public: bot.public,
|
public: bot.public,
|
||||||
interactions_url: bot.interactions_url as any,
|
interactions_url: bot.interactions_url as any,
|
||||||
|
|
@ -94,7 +96,7 @@ function BotCard({ bot, onDelete, onUpdate }: Props) {
|
||||||
const refreshProfile = useCallback(() => {
|
const refreshProfile = useCallback(() => {
|
||||||
client.api
|
client.api
|
||||||
.get(`/users/${bot._id as ""}/profile`, undefined, {
|
.get(`/users/${bot._id as ""}/profile`, undefined, {
|
||||||
headers: { "x-bot-token": bot.token },
|
headers: { "x-bot-token": data.token },
|
||||||
})
|
})
|
||||||
.then((profile) => setProfile(profile ?? {}));
|
.then((profile) => setProfile(profile ?? {}));
|
||||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
|
|
@ -149,7 +151,7 @@ function BotCard({ bot, onDelete, onUpdate }: Props) {
|
||||||
"/users/@me",
|
"/users/@me",
|
||||||
avatar ? { avatar } : { remove: ["Avatar"] },
|
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 } }
|
? { profile: { background } }
|
||||||
: { remove: ["ProfileBackground"] },
|
: { 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",
|
"/users/@me",
|
||||||
content ? { profile: { content } } : { remove: ["ProfileContent"] },
|
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) {
|
if (editMode) {
|
||||||
setData({
|
setData({
|
||||||
_id: bot._id,
|
_id: bot._id,
|
||||||
|
token: data.token,
|
||||||
username: user!.username,
|
username: user!.username,
|
||||||
public: bot.public,
|
public: bot.public,
|
||||||
interactions_url: bot.interactions_url as any,
|
interactions_url: bot.interactions_url as any,
|
||||||
|
|
@ -334,7 +337,7 @@ function BotCard({ bot, onDelete, onUpdate }: Props) {
|
||||||
<CategoryButton
|
<CategoryButton
|
||||||
account
|
account
|
||||||
icon={<Key size={24} />}
|
icon={<Key size={24} />}
|
||||||
onClick={() => modalController.writeText(bot.token)}
|
onClick={() => modalController.writeText(data.token)}
|
||||||
description={
|
description={
|
||||||
<>
|
<>
|
||||||
{"••••• "}
|
{"••••• "}
|
||||||
|
|
@ -344,7 +347,7 @@ function BotCard({ bot, onDelete, onUpdate }: Props) {
|
||||||
ev,
|
ev,
|
||||||
modalController.push({
|
modalController.push({
|
||||||
type: "show_token",
|
type: "show_token",
|
||||||
token: bot.token,
|
token: data.token,
|
||||||
name: user!.username,
|
name: user!.username,
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
|
|
@ -490,6 +493,25 @@ function BotCard({ bot, onDelete, onUpdate }: Props) {
|
||||||
}>
|
}>
|
||||||
<Text id="app.settings.pages.bots.add" />
|
<Text id="app.settings.pages.bots.add" />
|
||||||
</Button>
|
</Button>
|
||||||
|
<Button
|
||||||
|
palette="error"
|
||||||
|
onClick={ async () => {
|
||||||
|
modalController.push({
|
||||||
|
type: "reset_bot_token",
|
||||||
|
target: { name: user.username, id: bot._id },
|
||||||
|
callback: async () => {
|
||||||
|
const updatedBot = await client.bots.fetch(bot._id);
|
||||||
|
setData({
|
||||||
|
...data,
|
||||||
|
token: updatedBot.bot.token
|
||||||
|
})
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
}
|
||||||
|
}>
|
||||||
|
<Text id="app.settings.pages.bots.reset_token" />
|
||||||
|
</Button>
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue