]> git.localhorst.tv Git - alttp.git/commitdiff
centralize discord bot invitation links
authorDaniel Karbach <daniel.karbach@localhorst.tv>
Wed, 30 Jul 2025 20:36:44 +0000 (22:36 +0200)
committerDaniel Karbach <daniel.karbach@localhorst.tv>
Wed, 30 Jul 2025 20:36:44 +0000 (22:36 +0200)
resources/js/components/tournament/SettingsDialog.jsx
resources/js/helpers/discord.js [new file with mode: 0644]
resources/js/pages/DiscordBot.jsx

index a40a0a1d76c639af30dc8a5fa6dd037db612e12a..ad2de5702042bb214a39ea3a7ab37f58776f43f3 100644 (file)
@@ -9,6 +9,7 @@ import DiscordForm from './DiscordForm';
 import DiscordSelect from '../common/DiscordSelect';
 import Icon from '../common/Icon';
 import ToggleSwitch from '../common/ToggleSwitch';
+import { INVITE_URL } from '../../helpers/discord';
 import Tournament from '../../helpers/Tournament';
 import i18n from '../../i18n';
 
@@ -17,7 +18,7 @@ const open = async tournament => {
                await axios.post(`/api/tournaments/${tournament.id}/open`);
                toastr.success(i18n.t('tournaments.openSuccess'));
        } catch (e) {
-               toastr.error(i18n.t('tournaments.openError'));
+               toastr.error(i18n.t('tournaments.openError', { error: e.message }));
        }
 };
 
@@ -26,7 +27,7 @@ const close = async tournament => {
                await axios.post(`/api/tournaments/${tournament.id}/close`);
                toastr.success(i18n.t('tournaments.closeSuccess'));
        } catch (e) {
-               toastr.error(i18n.t('tournaments.closeError'));
+               toastr.error(i18n.t('tournaments.closeError', { error: e.message }));
        }
 };
 
@@ -35,7 +36,7 @@ const lock = async tournament => {
                await axios.post(`/api/tournaments/${tournament.id}/lock`);
                toastr.success(i18n.t('tournaments.lockSuccess'));
        } catch (e) {
-               toastr.error(i18n.t('tournaments.lockError'));
+               toastr.error(i18n.t('tournaments.lockError', { error: e.message }));
        }
 };
 
@@ -44,7 +45,7 @@ const unlock = async tournament => {
                await axios.post(`/api/tournaments/${tournament.id}/unlock`);
                toastr.success(i18n.t('tournaments.unlockSuccess'));
        } catch (e) {
-               toastr.error(i18n.t('tournaments.unlockError'));
+               toastr.error(i18n.t('tournaments.unlockError', { error: e.message }));
        }
 };
 
@@ -53,7 +54,7 @@ const setDiscord = async (tournament, guild_id) => {
                await axios.post(`/api/tournaments/${tournament.id}/discord`, { guild_id });
                toastr.success(i18n.t('tournaments.discordSuccess'));
        } catch (e) {
-               toastr.error(i18n.t('tournaments.discordError'));
+               toastr.error(i18n.t('tournaments.discordError', { error: e.message }));
        }
 };
 
@@ -62,12 +63,10 @@ const settings = async (tournament, params) => {
                await axios.post(`/api/tournaments/${tournament.id}/settings`, params);
                toastr.success(i18n.t('tournaments.settingsSuccess'));
        } catch (e) {
-               toastr.error(i18n.t('tournaments.settingsError'));
+               toastr.error(i18n.t('tournaments.settingsError', { error: e.message }));
        }
 };
 
-const inviteUrl = 'https://discordapp.com/oauth2/authorize?client_id=951113702839549982&scope=bot';
-
 const SettingsDialog = ({
        onHide,
        show,
@@ -140,7 +139,7 @@ const SettingsDialog = ({
                                                {!tournament.discord ?
                                                        <div>
                                                                <Button
-                                                                       href={inviteUrl}
+                                                                       href={INVITE_URL}
                                                                        target="_blank"
                                                                        variant="discord"
                                                                >
diff --git a/resources/js/helpers/discord.js b/resources/js/helpers/discord.js
new file mode 100644 (file)
index 0000000..bf0e349
--- /dev/null
@@ -0,0 +1,6 @@
+const authEndpoint = 'https://discord.com/oauth2/authorize';
+const clientId = import.meta.env.VITE_DISCORD_CLIENT_ID;
+const scope = 'bot+applications.commands';
+// Manage Roles, Manage Channels, View Channels, Manage Events, Create Events
+const permissions = '17601044415504';
+export const INVITE_URL = `${authEndpoint}?client_id=${clientId}&scope=${scope}&permissions=${permissions}`;
index 215a407b6cf19a74cde795180ca5829005066ea8..e53a6c19aa4a08cc924f77f1fa9aef44283ee7aa 100644 (file)
@@ -6,9 +6,7 @@ import { useTranslation } from 'react-i18next';
 import ErrorBoundary from '../components/common/ErrorBoundary';
 import Icon from '../components/common/Icon';
 import Controls from '../components/discord-bot/Controls';
-
-const authEndpoint = 'https://discord.com/oauth2/authorize';
-const clientId = import.meta.env.VITE_DISCORD_CLIENT_ID;
+import { INVITE_URL } from '../helpers/discord';
 
 export const Component = () => {
        const { t } = useTranslation();
@@ -23,7 +21,7 @@ export const Component = () => {
                <p>
                        <span className="button-bar">
                                <Button
-                                       href={`${authEndpoint}?client_id=${clientId}&scope=bot%20applications.commands`}
+                                       href={INVITE_URL}
                                        target="_blank"
                                        variant="discord"
                                >