0
0
Fork 0

Add code to make the stuff work

This commit is contained in:
Oliver-Akins 2021-07-18 01:18:18 -06:00
parent a18b73fe52
commit 3d9feabe88
15 changed files with 517 additions and 0 deletions

View file

@ -0,0 +1,40 @@
import { db } from "@/main";
export async function selectQuote(data: any): Promise<object> {
let vote = parseInt(data.data.values[0]);
let userID = data.member.user.id;
let oldVote = db.bracket.users[userID];
// Set quote to 0 if it hasn't been voted for yet
if (!db.bracket.votes[vote]) {
db.bracket.votes[vote] = 0;
};
++db.bracket.votes[vote];
db.bracket.users[userID] = vote;
// User changed their vote
if (oldVote != null) {
--db.bracket.votes[oldVote];
return {
type: 4,
data: {
content: `Your vote has been changed from:\n> ${db.bracket.quotes[oldVote]}\nto:\n> ${db.bracket.quotes[vote]}`,
flags: 1 << 6,
}
};
}
// User voted for the first time
else {
return {
type: 4,
data: {
content: `Your vote has been recorded for:\n> ${db.bracket.quotes[vote]}`,
flags: 1 << 6,
}
};
};
};