mirror of
https://github.com/captbaritone/webamp.git
synced 2026-01-23 10:15:31 +00:00
Discord upgrade
This commit is contained in:
parent
c447cc75a4
commit
9156aec8c2
11 changed files with 100 additions and 41 deletions
|
|
@ -9,7 +9,7 @@ class DiscordWinstonTransport extends Transport {
|
|||
|
||||
static async addToLogger(client, logger) {
|
||||
await client.login(config.discordToken);
|
||||
const captbaritone = await client.fetchUser(config.CAPTBARITONE_USER_ID);
|
||||
const captbaritone = await client.users.fetch(config.CAPTBARITONE_USER_ID);
|
||||
const channel = await captbaritone.createDM();
|
||||
logger.add(new DiscordWinstonTransport(channel));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ export default class DiscordEventHandler {
|
|||
|
||||
private async getChannel(channelId: string): Promise<TextChannel> {
|
||||
const client = await this.getClient();
|
||||
const dest = client.channels.get(channelId) as TextChannel | null;
|
||||
const dest = (await client.channels.fetch(channelId)) as TextChannel | null;
|
||||
if (dest == null) {
|
||||
throw new Error(`Could not get channel with id: ${channelId}`);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -250,6 +250,11 @@ test("/skins/status", async () => {
|
|||
expect(body).toEqual({});
|
||||
});
|
||||
|
||||
test("/approved", async () => {
|
||||
const { body } = await request(app).get("/approved").expect(200);
|
||||
expect(body).toEqual(["an_approved_md5", "a_tweeted_md5"]);
|
||||
});
|
||||
|
||||
test("/skins/a_fake_md5", async () => {
|
||||
let response = await request(app).get("/skins/a_fake_md5");
|
||||
expect(response.body).toEqual({
|
||||
|
|
|
|||
|
|
@ -255,6 +255,14 @@ router.post(
|
|||
})
|
||||
);
|
||||
|
||||
router.get(
|
||||
"/approved",
|
||||
asyncHandler(async (req, res) => {
|
||||
const approved = await Skins.getAllApproved();
|
||||
res.json(approved);
|
||||
})
|
||||
);
|
||||
|
||||
router.get(
|
||||
"/stylegan.json",
|
||||
asyncHandler(async (req, res) => {
|
||||
|
|
|
|||
|
|
@ -569,6 +569,15 @@ GROUP BY skins.md5`,
|
|||
});
|
||||
}
|
||||
|
||||
export async function getAllApproved(): Promise<Array<string>> {
|
||||
const skins = await knex("skins")
|
||||
.leftJoin("skin_reviews", "skin_reviews.skin_md5", "=", "skins.md5")
|
||||
.where("review", "APPROVED")
|
||||
.select("md5");
|
||||
|
||||
return skins.map(({ md5 }) => md5);
|
||||
}
|
||||
|
||||
export async function getAllClassicScreenshotUrls(): Promise<
|
||||
Array<{ fileName: string; url: string }>
|
||||
> {
|
||||
|
|
|
|||
|
|
@ -61,7 +61,7 @@ async function handler(message) {
|
|||
tempScreenshotPath,
|
||||
"screenshot.png"
|
||||
);
|
||||
const embed = new Discord.RichEmbed()
|
||||
const embed = new Discord.MessageEmbed()
|
||||
.setTitle(`Here's a screenshot of ${file.filename}`)
|
||||
.attachFile(attachment)
|
||||
.setImage(`attachment://screenshot.png`);
|
||||
|
|
|
|||
|
|
@ -1,10 +1,9 @@
|
|||
import {
|
||||
RichEmbed,
|
||||
User,
|
||||
MessageReaction,
|
||||
TextChannel,
|
||||
DMChannel,
|
||||
GroupDMChannel,
|
||||
MessageEmbed,
|
||||
} from "discord.js";
|
||||
import SkinModel from "../data/SkinModel";
|
||||
import * as Skins from "../data/skins";
|
||||
|
|
@ -16,8 +15,9 @@ function isEligableToApprove(user: User): boolean {
|
|||
return !user.bot;
|
||||
}
|
||||
|
||||
const filter = (reaction: MessageReaction): boolean => {
|
||||
const hasNonBot = reaction.users.some(isEligableToApprove);
|
||||
const filter = async (reaction: MessageReaction): Promise<boolean> => {
|
||||
const users = await reaction.users.fetch();
|
||||
const hasNonBot = users.some(isEligableToApprove);
|
||||
|
||||
return (
|
||||
hasNonBot &&
|
||||
|
|
@ -32,7 +32,7 @@ export async function postSkin({
|
|||
}: {
|
||||
md5: string;
|
||||
title?: (filename: string | null) => string;
|
||||
dest: TextChannel | DMChannel | GroupDMChannel;
|
||||
dest: TextChannel | DMChannel;
|
||||
}) {
|
||||
const ctx = new UserContext();
|
||||
|
||||
|
|
@ -54,7 +54,7 @@ export async function postSkin({
|
|||
const nsfw = await skin.getIsNsfw();
|
||||
const title = _title ? _title(canonicalFilename) : canonicalFilename;
|
||||
|
||||
const embed = new RichEmbed()
|
||||
const embed = new MessageEmbed()
|
||||
.setTitle(title)
|
||||
.addField("Try Online", `[skins.webamp.org](${skin.getMuseumUrl()})`, true)
|
||||
.addField("Download", `[${canonicalFilename}](${skin.getSkinUrl()})`, true)
|
||||
|
|
@ -117,7 +117,14 @@ export async function postSkin({
|
|||
// TODO: Timeout at some point
|
||||
await msg.awaitReactions(filter, { max: 1 }).then(async (collected) => {
|
||||
const vote = collected.first();
|
||||
const user = vote.users.find(isEligableToApprove);
|
||||
if (vote == null) {
|
||||
throw new Error("Did not expect vote to be empty");
|
||||
}
|
||||
const users = await vote.users.fetch();
|
||||
const user = users.find(isEligableToApprove);
|
||||
if (user == null) {
|
||||
throw new Error("Expected to find approver.");
|
||||
}
|
||||
switch (vote.emoji.name) {
|
||||
case "👍":
|
||||
case "👏":
|
||||
|
|
@ -178,7 +185,7 @@ export async function sendAlreadyReviewed({
|
|||
dest,
|
||||
}: {
|
||||
md5: string;
|
||||
dest: TextChannel | DMChannel | GroupDMChannel;
|
||||
dest: TextChannel | DMChannel;
|
||||
}) {
|
||||
const ctx = new UserContext();
|
||||
const skin = await SkinModel.fromMd5(ctx, md5);
|
||||
|
|
@ -191,7 +198,7 @@ export async function sendAlreadyReviewed({
|
|||
const tweetStatus = await skin.getTweetStatus();
|
||||
const nsfw = await skin.getIsNsfw();
|
||||
|
||||
const embed = new RichEmbed()
|
||||
const embed = new MessageEmbed()
|
||||
.setTitle(
|
||||
`Someone flagged "${canonicalFilename}", but it's already been reviwed.`
|
||||
)
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@
|
|||
"cookie-session": "^1.4.0",
|
||||
"cors": "^2.8.5",
|
||||
"dataloader": "^2.0.0",
|
||||
"discord.js": "^11.4.2",
|
||||
"discord.js": "^12.5.3",
|
||||
"express": "^4.17.1",
|
||||
"express-async-handler": "^1.1.4",
|
||||
"express-fileupload": "^1.1.7-alpha.3",
|
||||
|
|
|
|||
|
|
@ -46,9 +46,7 @@ export async function refreshSkins(skins: SkinModel[]): Promise<void> {
|
|||
};
|
||||
await Shooter.withShooter(async (shooter: Shooter) => {
|
||||
for (const [i, skin] of skins.entries()) {
|
||||
console.log(`${i + 1}/${skins.length}: ${skin.getMd5()}`);
|
||||
await refresh(skin, shooter);
|
||||
console.log(`COMPLETE: ${i + 1}/${skins.length}: ${skin.getMd5()}`);
|
||||
// We end up caching a lot of stuff (the whole skin/zip) on the model, so we can't just leave these around for the whole process.
|
||||
delete skins[i];
|
||||
}
|
||||
|
|
@ -96,21 +94,17 @@ export async function refresh(
|
|||
shooter: Shooter
|
||||
): Promise<void> {
|
||||
if (skin.getSkinType() !== "CLASSIC") {
|
||||
console.log("Not classic");
|
||||
throw new Error("Can't refresh non-classic skins");
|
||||
}
|
||||
try {
|
||||
await _refresh(skin, shooter);
|
||||
console.log("Done!");
|
||||
} catch (e) {
|
||||
console.log("Caught error!!");
|
||||
await knex("refreshes").insert({
|
||||
skin_md5: skin.getMd5(),
|
||||
error: e.message,
|
||||
});
|
||||
return;
|
||||
}
|
||||
console.log("Insertting");
|
||||
await knex("refreshes").insert({
|
||||
skin_md5: skin.getMd5(),
|
||||
});
|
||||
|
|
|
|||
|
|
@ -13,7 +13,9 @@ const temp = _temp.track();
|
|||
|
||||
export async function tweet(discordClient: Client, anything: string | null) {
|
||||
const ctx = new UserContext();
|
||||
const tweetBotChannel = discordClient.channels.get(TWEET_BOT_CHANNEL_ID);
|
||||
const tweetBotChannel = await discordClient.channels.fetch(
|
||||
TWEET_BOT_CHANNEL_ID
|
||||
);
|
||||
if (tweetBotChannel == null) {
|
||||
throw new Error("Could not connect to the #tweet-bot channel");
|
||||
}
|
||||
|
|
|
|||
76
yarn.lock
76
yarn.lock
|
|
@ -1919,6 +1919,20 @@
|
|||
exec-sh "^0.3.2"
|
||||
minimist "^1.2.0"
|
||||
|
||||
"@discordjs/collection@^0.1.6":
|
||||
version "0.1.6"
|
||||
resolved "https://registry.yarnpkg.com/@discordjs/collection/-/collection-0.1.6.tgz#9e9a7637f4e4e0688fd8b2b5c63133c91607682c"
|
||||
integrity sha512-utRNxnd9kSS2qhyivo9lMlt5qgAUasH2gb7BEOn6p0efFh24gjGomHzWKMAPn2hEReOPQZCJaRKoURwRotKucQ==
|
||||
|
||||
"@discordjs/form-data@^3.0.1":
|
||||
version "3.0.1"
|
||||
resolved "https://registry.yarnpkg.com/@discordjs/form-data/-/form-data-3.0.1.tgz#5c9e6be992e2e57d0dfa0e39979a850225fb4697"
|
||||
integrity sha512-ZfFsbgEXW71Rw/6EtBdrP5VxBJy4dthyC0tpQKGKmYFImlmmrykO14Za+BiIVduwjte0jXEBlhSKf0MWbFp9Eg==
|
||||
dependencies:
|
||||
asynckit "^0.4.0"
|
||||
combined-stream "^1.0.8"
|
||||
mime-types "^2.1.12"
|
||||
|
||||
"@eslint/eslintrc@^0.2.1":
|
||||
version "0.2.1"
|
||||
resolved "https://registry.yarnpkg.com/@eslint/eslintrc/-/eslintrc-0.2.1.tgz#f72069c330461a06684d119384435e12a5d76e3c"
|
||||
|
|
@ -3237,6 +3251,13 @@ abbrev@1:
|
|||
version "1.1.1"
|
||||
resolved "https://registry.yarnpkg.com/abbrev/-/abbrev-1.1.1.tgz#f8f2c887ad10bf67f634f005b6987fed3179aac8"
|
||||
|
||||
abort-controller@^3.0.0:
|
||||
version "3.0.0"
|
||||
resolved "https://registry.yarnpkg.com/abort-controller/-/abort-controller-3.0.0.tgz#eaf54d53b62bae4138e809ca225c8439a6efb392"
|
||||
integrity sha512-h8lQ8tacZYnR3vNQTgibj+tODHI5/+l06Au2Pcriv/Gmet0eaj4TwWH41sO9wnHDiQsEj19q0drzdWdeAHtweg==
|
||||
dependencies:
|
||||
event-target-shim "^5.0.0"
|
||||
|
||||
accepts@~1.3.4, accepts@~1.3.5, accepts@~1.3.7:
|
||||
version "1.3.7"
|
||||
resolved "https://registry.yarnpkg.com/accepts/-/accepts-1.3.7.tgz#531bc726517a3b2b41f850021c6cc15eaab507cd"
|
||||
|
|
@ -5595,15 +5616,19 @@ dir-glob@^3.0.1:
|
|||
dependencies:
|
||||
path-type "^4.0.0"
|
||||
|
||||
discord.js@^11.4.2:
|
||||
version "11.6.4"
|
||||
resolved "https://registry.yarnpkg.com/discord.js/-/discord.js-11.6.4.tgz#76bab98de08d7586ecde44c063ef310e6b9a2700"
|
||||
discord.js@^12.5.3:
|
||||
version "12.5.3"
|
||||
resolved "https://registry.yarnpkg.com/discord.js/-/discord.js-12.5.3.tgz#56820d473c24320871df9ea0bbc6b462f21cf85c"
|
||||
integrity sha512-D3nkOa/pCkNyn6jLZnAiJApw2N9XrIsXUAdThf01i7yrEuqUmDGc7/CexVWwEcgbQR97XQ+mcnqJpmJ/92B4Aw==
|
||||
dependencies:
|
||||
long "^4.0.0"
|
||||
prism-media "^0.0.4"
|
||||
snekfetch "^3.6.4"
|
||||
tweetnacl "^1.0.0"
|
||||
ws "^6.0.0"
|
||||
"@discordjs/collection" "^0.1.6"
|
||||
"@discordjs/form-data" "^3.0.1"
|
||||
abort-controller "^3.0.0"
|
||||
node-fetch "^2.6.1"
|
||||
prism-media "^1.2.9"
|
||||
setimmediate "^1.0.5"
|
||||
tweetnacl "^1.0.3"
|
||||
ws "^7.4.4"
|
||||
|
||||
dns-equal@^1.0.0:
|
||||
version "1.0.0"
|
||||
|
|
@ -6261,6 +6286,11 @@ etag@~1.8.1:
|
|||
version "1.8.1"
|
||||
resolved "https://registry.yarnpkg.com/etag/-/etag-1.8.1.tgz#41ae2eeb65efa62268aebfea83ac7d79299b0887"
|
||||
|
||||
event-target-shim@^5.0.0:
|
||||
version "5.0.1"
|
||||
resolved "https://registry.yarnpkg.com/event-target-shim/-/event-target-shim-5.0.1.tgz#5d4d3ebdf9583d63a5333ce2deb7480ab2b05789"
|
||||
integrity sha512-i/2XbnSz/uxRCU6+NdVJgKWDTM427+MqYbkQzD321DuCQJUqOuJKIA0IM2+W2xtYHdKOmZ4dR6fExsd4SXL+WQ==
|
||||
|
||||
eventemitter3@^4.0.0:
|
||||
version "4.0.4"
|
||||
resolved "https://registry.yarnpkg.com/eventemitter3/-/eventemitter3-4.0.4.tgz#b5463ace635a083d018bdc7c917b4c5f10a85384"
|
||||
|
|
@ -9946,10 +9976,6 @@ loglevel@^1.6.8:
|
|||
version "1.6.8"
|
||||
resolved "https://registry.yarnpkg.com/loglevel/-/loglevel-1.6.8.tgz#8a25fb75d092230ecd4457270d80b54e28011171"
|
||||
|
||||
long@^4.0.0:
|
||||
version "4.0.0"
|
||||
resolved "https://registry.yarnpkg.com/long/-/long-4.0.0.tgz#9a7b71cfb7d361a194ea555241c92f7468d5bf28"
|
||||
|
||||
longest@^1.0.0:
|
||||
version "1.0.1"
|
||||
resolved "https://registry.yarnpkg.com/longest/-/longest-1.0.1.tgz#30a0b2da38f73770e8294a0d22e6625ed77d0097"
|
||||
|
|
@ -10524,6 +10550,11 @@ node-fetch@^2.6.0:
|
|||
version "2.6.0"
|
||||
resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.6.0.tgz#e633456386d4aa55863f676a7ab0daa8fdecb0fd"
|
||||
|
||||
node-fetch@^2.6.1:
|
||||
version "2.6.1"
|
||||
resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.6.1.tgz#045bd323631f76ed2e2b55573394416b639a0052"
|
||||
integrity sha512-V4aYg89jEoVRxRb2fJdAg8FHvI7cEyYdVAh94HH0UIK8oJxUfkjlDQN9RbMx+bEjP7+ggMiFRprSti032Oipxw==
|
||||
|
||||
node-forge@0.9.0:
|
||||
version "0.9.0"
|
||||
resolved "https://registry.yarnpkg.com/node-forge/-/node-forge-0.9.0.tgz#d624050edbb44874adca12bb9a52ec63cb782579"
|
||||
|
|
@ -11793,9 +11824,10 @@ pretty-format@^26.1.0:
|
|||
ansi-styles "^4.0.0"
|
||||
react-is "^16.12.0"
|
||||
|
||||
prism-media@^0.0.4:
|
||||
version "0.0.4"
|
||||
resolved "https://registry.yarnpkg.com/prism-media/-/prism-media-0.0.4.tgz#df5ddc6463670c97ff0e9cbac3c3e0db18df326f"
|
||||
prism-media@^1.2.9:
|
||||
version "1.2.9"
|
||||
resolved "https://registry.yarnpkg.com/prism-media/-/prism-media-1.2.9.tgz#8d4f97b36efdfc82483eb8d3db64020767866f36"
|
||||
integrity sha512-UHCYuqHipbTR1ZsXr5eg4JUmHER8Ss4YEb9Azn+9zzJ7/jlTtD1h0lc4g6tNx3eMlB8Mp6bfll0LPMAV4R6r3Q==
|
||||
|
||||
private@^0.1.8:
|
||||
version "0.1.8"
|
||||
|
|
@ -12841,7 +12873,7 @@ set-value@^2.0.0, set-value@^2.0.1:
|
|||
is-plain-object "^2.0.3"
|
||||
split-string "^3.0.1"
|
||||
|
||||
setimmediate@^1.0.4:
|
||||
setimmediate@^1.0.4, setimmediate@^1.0.5:
|
||||
version "1.0.5"
|
||||
resolved "https://registry.yarnpkg.com/setimmediate/-/setimmediate-1.0.5.tgz#290cbb232e306942d7d7ea9b83732ab7856f8285"
|
||||
|
||||
|
|
@ -13008,10 +13040,6 @@ snapdragon@^0.8.1:
|
|||
source-map-resolve "^0.5.0"
|
||||
use "^3.1.0"
|
||||
|
||||
snekfetch@^3.6.4:
|
||||
version "3.6.4"
|
||||
resolved "https://registry.yarnpkg.com/snekfetch/-/snekfetch-3.6.4.tgz#d13e80a616d892f3d38daae4289f4d258a645120"
|
||||
|
||||
sockjs-client@1.4.0:
|
||||
version "1.4.0"
|
||||
resolved "https://registry.yarnpkg.com/sockjs-client/-/sockjs-client-1.4.0.tgz#c9f2568e19c8fd8173b4997ea3420e0bb306c7d5"
|
||||
|
|
@ -13907,9 +13935,10 @@ tweetnacl@^0.14.3, tweetnacl@~0.14.0:
|
|||
version "0.14.5"
|
||||
resolved "https://registry.yarnpkg.com/tweetnacl/-/tweetnacl-0.14.5.tgz#5ae68177f192d4456269d108afa93ff8743f4f64"
|
||||
|
||||
tweetnacl@^1.0.0:
|
||||
tweetnacl@^1.0.3:
|
||||
version "1.0.3"
|
||||
resolved "https://registry.yarnpkg.com/tweetnacl/-/tweetnacl-1.0.3.tgz#ac0af71680458d8a6378d0d0d050ab1407d35596"
|
||||
integrity sha512-6rt+RN7aOi1nGMyC4Xa5DdYiukl2UWCbcJft7YhxReBGQD7OAM8Pbxw6YMo4r2diNEA8FEmu32YOn9rhaiE5yw==
|
||||
|
||||
twit@^2.2.11:
|
||||
version "2.2.11"
|
||||
|
|
@ -14688,6 +14717,11 @@ ws@^7.3.1:
|
|||
resolved "https://registry.yarnpkg.com/ws/-/ws-7.4.1.tgz#a333be02696bd0e54cea0434e21dcc8a9ac294bb"
|
||||
integrity sha512-pTsP8UAfhy3sk1lSk/O/s4tjD0CRwvMnzvwr4OKGX7ZvqZtUyx4KIJB5JWbkykPoc55tixMGgTNoh3k4FkNGFQ==
|
||||
|
||||
ws@^7.4.4:
|
||||
version "7.4.4"
|
||||
resolved "https://registry.yarnpkg.com/ws/-/ws-7.4.4.tgz#383bc9742cb202292c9077ceab6f6047b17f2d59"
|
||||
integrity sha512-Qm8k8ojNQIMx7S+Zp8u/uHOx7Qazv3Yv4q68MiWWWOJhiwG5W3x7iqmRtJo8xxrciZUY4vRxUTJCKuRnF28ZZw==
|
||||
|
||||
xml-js@^1.6.11:
|
||||
version "1.6.11"
|
||||
resolved "https://registry.yarnpkg.com/xml-js/-/xml-js-1.6.11.tgz#927d2f6947f7f1c19a316dd8eea3614e8b18f8e9"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue