Skip to content

Commit

Permalink
feat: Just update all the data
Browse files Browse the repository at this point in the history
  • Loading branch information
zhiyan114 committed Aug 1, 2023
1 parent 5b60d7c commit a52da68
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 33 deletions.
2 changes: 1 addition & 1 deletion extra/whisper/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
LOGGER = logging.getLogger(__name__)

# Keep it disable when not debugging
#logging.basicConfig(level=logging.DEBUG, format=LOG_FORMAT, filename="whisper.log")
# logging.basicConfig(level=logging.DEBUG, format=LOG_FORMAT, filename="whisper.log")
41 changes: 9 additions & 32 deletions src/commands/Eval.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ import {client} from "../index";
import { ICommand } from "../interface";
import { tmiClient } from "../services/TwitchHandler";
import { withScope as sentryScope } from "@sentry/node";
import { members, Prisma } from "@prisma/client";
import globalCmdRegister from "../globalCmdRegister";

/* Command Builder */
const EvalCmd = new SlashCommandBuilder()
.setName("eval")
Expand Down Expand Up @@ -53,42 +51,21 @@ const utils = {
// Manually update all the out-of-date users to the database
updateUserData: async() => {
if(!prisma) return;
const allwait: Promise<members | undefined>[] = [];
const guild = client.guilds.cache.find(g=>g.id == guildID);
if(!guild) return;

for(const [,member] of await guild.members.fetch()) {
if(member.user.bot) continue;
allwait.push((async()=>{
try {
const newUsername = member.user.discriminator === "0" ? member.user.username : member.user.tag;
return await prisma.members.update({
data: {
username: newUsername,
displayname: member.user.displayName
},
where: {
id: member.id,
OR: [
{
NOT: {
username: newUsername
},
},
{
NOT: {
displayname: member.user.displayName
}
}
]
}
});
} catch(ex){
if(ex instanceof Prisma.PrismaClientKnownRequestError && ex.code == "P2025") return;
throw ex;
await prisma.members.update({
data: {
username: member.user.username,
displayname: member.user.displayName,
},
where: {
id: member.user.id,
}
})());
});
}
await Promise.all(allwait);
},

// Manually reset the bot's status in-case it was removed from discord's backend
Expand Down

0 comments on commit a52da68

Please sign in to comment.