Temporary bot menu.

This commit is contained in:
Paul 2021-08-12 15:29:19 +01:00
parent c27f596d40
commit 237a0024df
6 changed files with 177 additions and 12 deletions

2
external/lang vendored

@ -1 +1 @@
Subproject commit 7be90cf44ba08d235ae52d7dc6073d8f9347232b Subproject commit cec5d62b11fa52bafea39ee905a8354fb840a078

View file

@ -115,8 +115,8 @@
"react-virtualized-auto-sizer": "^1.0.5", "react-virtualized-auto-sizer": "^1.0.5",
"react-virtuoso": "^1.10.4", "react-virtuoso": "^1.10.4",
"redux": "^4.1.0", "redux": "^4.1.0",
"revolt-api": "^0.5.2-alpha.0", "revolt-api": "0.5.2-alpha.1",
"revolt.js": "5.0.1-alpha.1", "revolt.js": "5.0.1-alpha.2",
"rimraf": "^3.0.2", "rimraf": "^3.0.2",
"sass": "^1.35.1", "sass": "^1.35.1",
"shade-blend-color": "^1.0.0", "shade-blend-color": "^1.0.0",

View file

@ -7,6 +7,7 @@ import Button from "../../../components/ui/Button";
import InputBox from "../../../components/ui/InputBox"; import InputBox from "../../../components/ui/InputBox";
import Modal from "../../../components/ui/Modal"; import Modal from "../../../components/ui/Modal";
import Overline from "../../../components/ui/Overline"; import Overline from "../../../components/ui/Overline";
import Tip from "../../../components/ui/Tip";
import { FileUploader } from "../../revoltjs/FileUploads"; import { FileUploader } from "../../revoltjs/FileUploads";
import { useClient } from "../../revoltjs/RevoltClient"; import { useClient } from "../../revoltjs/RevoltClient";
@ -30,6 +31,9 @@ export const ServerIdentityModal = observer(({ server, onClose }: Props) => {
return ( return (
<Modal visible={true} onClose={onClose}> <Modal visible={true} onClose={onClose}>
<Tip warning hideSeparator>
This section is under construction.
</Tip>
<Overline type="subtle">Nickname</Overline> <Overline type="subtle">Nickname</Overline>
<p> <p>
<InputBox <InputBox

View file

@ -4,6 +4,7 @@ import {
Globe, Globe,
LogOut, LogOut,
Desktop, Desktop,
Bot,
} from "@styled-icons/boxicons-regular"; } from "@styled-icons/boxicons-regular";
import { import {
Bell, Bell,
@ -39,6 +40,7 @@ import { Appearance } from "./panes/Appearance";
import { ExperimentsPage } from "./panes/Experiments"; import { ExperimentsPage } from "./panes/Experiments";
import { Feedback } from "./panes/Feedback"; import { Feedback } from "./panes/Feedback";
import { Languages } from "./panes/Languages"; import { Languages } from "./panes/Languages";
import { MyBots } from "./panes/MyBots";
import { Native } from "./panes/Native"; import { Native } from "./panes/Native";
import { Notifications } from "./panes/Notifications"; import { Notifications } from "./panes/Notifications";
import { Profile } from "./panes/Profile"; import { Profile } from "./panes/Profile";
@ -109,11 +111,17 @@ export default function Settings() {
title: <Text id="app.settings.pages.native.title" />, title: <Text id="app.settings.pages.native.title" />,
}, },
{ {
divider: true,
id: "experiments", id: "experiments",
icon: <Flask size={20} />, icon: <Flask size={20} />,
title: <Text id="app.settings.pages.experiments.title" />, title: <Text id="app.settings.pages.experiments.title" />,
}, },
{
divider: true,
category: "revolt",
id: "bots",
icon: <Bot size={20} />,
title: <Text id="app.settings.pages.bots.title" />,
},
{ {
id: "feedback", id: "feedback",
icon: <Megaphone size={20} />, icon: <Megaphone size={20} />,
@ -148,6 +156,9 @@ export default function Settings() {
<Route path="/settings/experiments"> <Route path="/settings/experiments">
<ExperimentsPage /> <ExperimentsPage />
</Route> </Route>
<Route path="/settings/bots">
<MyBots />
</Route>
<Route path="/settings/feedback"> <Route path="/settings/feedback">
<Feedback /> <Feedback />
</Route> </Route>

View file

@ -0,0 +1,150 @@
import { observer } from "mobx-react-lite";
import { Bot } from "revolt-api/types/Bots";
import { useEffect, useState } from "preact/hooks";
import { useClient } from "../../../context/revoltjs/RevoltClient";
import UserShort from "../../../components/common/user/UserShort";
import Button from "../../../components/ui/Button";
import Checkbox from "../../../components/ui/Checkbox";
import InputBox from "../../../components/ui/InputBox";
import Overline from "../../../components/ui/Overline";
import Tip from "../../../components/ui/Tip";
interface Data {
_id: string;
username: string;
public: boolean;
interactions_url?: string;
}
function BotEditor({ bot }: { bot: Data }) {
const client = useClient();
const [data, setData] = useState<Data>(bot);
function save() {
const changes: Record<string, string | boolean | undefined> = {};
if (data.username !== bot.username) changes.name = data.username;
if (data.public !== bot.public) changes.public = data.public;
if (data.interactions_url !== bot.interactions_url)
changes.interactions_url = data.interactions_url;
client.bots.edit(bot._id, changes);
}
return (
<div>
<p>
<InputBox
value={data.username}
onChange={(e) =>
setData({ ...data, username: e.currentTarget.value })
}
/>
</p>
<p>
<Checkbox
checked={data.public}
onChange={(v) => setData({ ...data, public: v })}>
is public
</Checkbox>
</p>
<p>interactions url: (reserved for the future)</p>
<p>
<InputBox
value={data.interactions_url}
onChange={(e) =>
setData({
...data,
interactions_url: e.currentTarget.value,
})
}
/>
</p>
<Button onClick={save}>save</Button>
</div>
);
}
export const MyBots = observer(() => {
const client = useClient();
const [bots, setBots] = useState<Bot[] | undefined>(undefined);
useEffect(() => {
client.bots.fetchOwned().then(({ bots }) => setBots(bots));
// eslint-disable-next-line
}, []);
const [name, setName] = useState("");
return (
<div>
<Tip warning hideSeparator>
This section is under construction.
</Tip>
<Overline>create a new bot</Overline>
<p>
<InputBox
value={name}
contrast
onChange={(e) => setName(e.currentTarget.value)}
/>
</p>
<p>
<Button
contrast
onClick={() =>
name.length > 0 &&
client.bots
.create({ name })
.then(({ bot }) => setBots([...(bots ?? []), bot]))
}>
create
</Button>
</p>
<Overline>my bots</Overline>
{bots?.map((bot) => {
const user = client.users.get(bot._id);
return (
<div
key={bot._id}
style={{
background: "var(--secondary-background)",
margin: "8px",
padding: "12px",
}}>
<UserShort user={user} />
<p>
token:{" "}
<code style={{ userSelect: "all" }}>
{bot.token}
</code>
</p>
<BotEditor
bot={{
...bot,
username: user!.username,
}}
/>
<Button
error
onClick={() =>
client.bots
.delete(bot._id)
.then(() =>
setBots(
bots.filter(
(x) => x._id !== bot._id,
),
),
)
}>
delete
</Button>
</div>
);
})}
</div>
);
});

View file

@ -3600,15 +3600,15 @@ reusify@^1.0.4:
resolved "https://registry.yarnpkg.com/reusify/-/reusify-1.0.4.tgz#90da382b1e126efc02146e90845a88db12925d76" resolved "https://registry.yarnpkg.com/reusify/-/reusify-1.0.4.tgz#90da382b1e126efc02146e90845a88db12925d76"
integrity sha512-U9nH88a3fc/ekCF1l0/UP1IosiuIjyTh7hBvXVMHYgVcfGvt897Xguj2UOLDeI5BG2m7/uwyaLVT6fbtCwTyzw== integrity sha512-U9nH88a3fc/ekCF1l0/UP1IosiuIjyTh7hBvXVMHYgVcfGvt897Xguj2UOLDeI5BG2m7/uwyaLVT6fbtCwTyzw==
revolt-api@^0.5.2-alpha.0: revolt-api@0.5.2-alpha.1:
version "0.5.2-alpha.0" version "0.5.2-alpha.1"
resolved "https://registry.yarnpkg.com/revolt-api/-/revolt-api-0.5.2-alpha.0.tgz#a41f44ee38622636c9b5b5843f9e2798a79f00d3" resolved "https://registry.yarnpkg.com/revolt-api/-/revolt-api-0.5.2-alpha.1.tgz#2164d04cd5581267ce59142557666bd386bc85c4"
integrity sha512-VI/o4nQTPXrDCVdFpZFfZfj7Q4nunj62gftdmYJtuSmXx+6eN2Nve7QQZjNt6UIH6Dc/IDgiFDcBdafBF9YXug== integrity sha512-3OrjYCDNPkJ+yO9d87NJvuUDAbungEbUfrfHlvFwV8hJze/RMkuYUTFWe1HyBMwBC7F/yWQK+2V7IoifC5STmw==
revolt.js@5.0.1-alpha.1: revolt.js@5.0.1-alpha.2:
version "5.0.1-alpha.1" version "5.0.1-alpha.2"
resolved "https://registry.yarnpkg.com/revolt.js/-/revolt.js-5.0.1-alpha.1.tgz#9af021d05d3cd098d0383c64e1fe10c70f2fb07a" resolved "https://registry.yarnpkg.com/revolt.js/-/revolt.js-5.0.1-alpha.2.tgz#ec4876da57367453ef38d6c9bf84828c5f068b74"
integrity sha512-QIbnR25ICey8iopMzu0FBueo7gd0ddZQVoyyC++jg4Rvt0zlcAHJfx/YTapZxzTFo0/u/YEgD68GuTh8ybmFdg== integrity sha512-QBulAUAqBGCY62jJjpKa/+y4QBjTEzPfHl/R9NY6wJ/nCfYX7/leOFWb1PWJ09KerPfbYEiQvQYk8YYFF9HptQ==
dependencies: dependencies:
axios "^0.19.2" axios "^0.19.2"
eventemitter3 "^4.0.7" eventemitter3 "^4.0.7"