Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move and Use Discord Bot token from env.txt #774

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useContext, useEffect } from 'react';
import { useAgent, useAuthToken, useConversation } from 'react-agents';
import { useAgent, useAuthToken, useConversation, useEnv } from 'react-agents';
import type {
DiscordArgs,
DiscordProps,
Expand All @@ -10,7 +10,6 @@ import {

export const Discord: React.FC<DiscordProps> = (props: DiscordProps) => {
const {
token,
channels,
dms,
userWhitelist,
Expand All @@ -20,9 +19,16 @@ export const Discord: React.FC<DiscordProps> = (props: DiscordProps) => {
const appContextValue = useContext(AppContext);
const codecs = appContextValue.useCodecs();
const authToken = useAuthToken();
const env = useEnv();

useEffect(() => {
if (!conversation) {
const token = (env as { DISCORD_BOT_TOKEN: string }).DISCORD_BOT_TOKEN;

if (!token) {
throw new Error('DISCORD_BOT_TOKEN is not set in env.txt');
}

const args: DiscordArgs = {
token,
channels: channels ? (Array.isArray(channels) ? channels : [channels]) : [],
Expand All @@ -38,7 +44,7 @@ export const Discord: React.FC<DiscordProps> = (props: DiscordProps) => {
};
}
}, [
token,
(env as { DISCORD_BOT_TOKEN: string }).DISCORD_BOT_TOKEN,
JSON.stringify(channels),
JSON.stringify(dms),
JSON.stringify(userWhitelist),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@ export type TtsArgs = {
export type DiscordRoomSpec = RegExp | string;
export type DiscordRoomSpecs = DiscordRoomSpec | DiscordRoomSpec[];
export type DiscordProps = {
token: string;
channels?: DiscordRoomSpecs;
dms?: DiscordRoomSpecs;
userWhitelist?: string[];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -287,11 +287,11 @@ export const featureRenderers = {
<RateLimit maxUserMessages={maxUserMessages} maxUserMessagesTime={maxUserMessagesTime} message={message} />
);
},
discord: ({token, channels}) => {
if (token) {
discord: ({channels}) => {
if (channels) {
channels = channels && channels.map((c: string) => c.trim()).filter(Boolean);
return (
<Discord token={token} channels={channels} />
<Discord channels={channels} />
);
} else {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,12 +141,11 @@ export const featureSpecs = [
`,
schema: z.union([
z.object({
token: z.string(),
channels: z.array(z.string()),
}),
z.null(),
]),
examples: [{ token: 'YOUR_DISCORD_BOT_TOKEN', channels: ['general', 'voice'], }],
examples: [{ channels: ['general', 'voice'], }],
// imports: (discord) => {
// if (discord.token) {
// return ['Discord'];
Expand Down