mirror of
https://github.com/kirameki-cafe/Yumi.git
synced 2026-09-13 10:49:20 +00:00
No longer crash if unable to login to VRChat
This commit is contained in:
@@ -22,12 +22,6 @@ const EMBEDS = {
|
|||||||
user: data.getUser()
|
user: data.getUser()
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
NOT_INITIALIZED: (data: HybridInteractionMessage) => {
|
|
||||||
return makeErrorEmbed({
|
|
||||||
title: `VRChat feature is disabled`,
|
|
||||||
user: data.getUser()
|
|
||||||
});
|
|
||||||
},
|
|
||||||
ERROR: (data: HybridInteractionMessage) => {
|
ERROR: (data: HybridInteractionMessage) => {
|
||||||
return makeErrorEmbed({
|
return makeErrorEmbed({
|
||||||
title: `Something went wrong while connecting to VRChat`,
|
title: `Something went wrong while connecting to VRChat`,
|
||||||
|
|||||||
@@ -63,7 +63,7 @@ export default class VRChat extends DiscordModule {
|
|||||||
const Guild = await Prisma.client.guild.findFirst({ where: { id: data.getGuild()!.id } });
|
const Guild = await Prisma.client.guild.findFirst({ where: { id: data.getGuild()!.id } });
|
||||||
if (!Guild) return;
|
if (!Guild) return;
|
||||||
|
|
||||||
if (!VRChatAPI.client)
|
if (!VRChatAPI.isReady())
|
||||||
return await sendHybridInteractionMessageResponse(data, {
|
return await sendHybridInteractionMessageResponse(data, {
|
||||||
embeds: [EMBEDS.NOT_INITIALIZED(data)]
|
embeds: [EMBEDS.NOT_INITIALIZED(data)]
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ interface Cache {
|
|||||||
class VRChatAPI {
|
class VRChatAPI {
|
||||||
public client: VRChatAPIs | null;
|
public client: VRChatAPIs | null;
|
||||||
public configuration: VRChat.Configuration | null;
|
public configuration: VRChat.Configuration | null;
|
||||||
|
private ready = false;
|
||||||
private cache: Cache;
|
private cache: Cache;
|
||||||
private useragent: string | null = null;
|
private useragent: string | null = null;
|
||||||
|
|
||||||
@@ -66,8 +67,18 @@ class VRChatAPI {
|
|||||||
};
|
};
|
||||||
|
|
||||||
Logger.info('Logging in to VRChat');
|
Logger.info('Logging in to VRChat');
|
||||||
let res = await this.client.AuthenticationApi.getCurrentUser();
|
|
||||||
|
|
||||||
|
let res;
|
||||||
|
try {
|
||||||
|
res = await this.client.AuthenticationApi.getCurrentUser();
|
||||||
|
} catch (err: any) {
|
||||||
|
if (err.response?.status === 401) {
|
||||||
|
Logger.error('Unable to log in to VRChat, check your credentials');
|
||||||
|
return;
|
||||||
|
} else throw err;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.ready = true;
|
||||||
Logger.info('Logged in to VRChat as ' + res.data.displayName);
|
Logger.info('Logged in to VRChat as ' + res.data.displayName);
|
||||||
|
|
||||||
setInterval(() => {
|
setInterval(() => {
|
||||||
@@ -86,6 +97,10 @@ class VRChatAPI {
|
|||||||
}, VRC_CACHE_DURATION);
|
}, VRC_CACHE_DURATION);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public isReady(): boolean {
|
||||||
|
return this.ready;
|
||||||
|
}
|
||||||
|
|
||||||
public async getCachedUserById(id: string) {
|
public async getCachedUserById(id: string) {
|
||||||
if (typeof this.cache.Users[id] !== 'undefined') {
|
if (typeof this.cache.Users[id] !== 'undefined') {
|
||||||
Logger.debug('[VRChat] [Cache] Cache hit for user ' + id);
|
Logger.debug('[VRChat] [Cache] Cache hit for user ' + id);
|
||||||
|
|||||||
Reference in New Issue
Block a user