Skip to content

Commit

Permalink
experimental
Browse files Browse the repository at this point in the history
  • Loading branch information
LarmuseauNiels committed Apr 6, 2023
1 parent cba77f8 commit fc266d4
Show file tree
Hide file tree
Showing 7 changed files with 166 additions and 16 deletions.
13 changes: 8 additions & 5 deletions interactions/commands/chat.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,17 @@ module.exports = {
],
max_tokens: 360,
});
console.log(response);
const { data } = response;
console.log(data);
console.log(
interaction.user.id + " used " + data.usage.total_tokens + " tokens"
);
if (data.choices[0].message.content.length > 2000) {
interaction.editReply("response too long");
await interaction.editReply("response too long");
return;
}
interaction.editReply(data.choices[0].message.content || "no response");
await interaction.editReply(
data.choices[0].message.content || "no response"
);
global.client.chats.set(interaction.user.id, {
convo: [
{
Expand All @@ -52,7 +55,7 @@ module.exports = {
} catch (e) {
global.bugsnag.notify(e);
console.log(e);
interaction.editReply({ content: "error" });
await interaction.editReply({ content: "error" });
}
},
isGuild: true,
Expand Down
13 changes: 8 additions & 5 deletions interactions/commands/respond.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,23 @@ module.exports = {
messages: convo,
max_tokens: 360,
});
console.log(response);
const { data } = response;
console.log(data);
console.log(
interaction.user.id + " used " + data.usage.total_tokens + " tokens"
);
if (data.choices[0].message.content.length > 2000) {
interaction.editReply("response too long");
await interaction.editReply("response too long");
return;
}
interaction.editReply(data.choices[0].message.content || "no response");
await interaction.editReply(
data.choices[0].message.content || "no response"
);
convo.push(data.choices[0].message);
global.client.chats.set(interaction.user.id, { convo: convo });
} catch (e) {
global.bugsnag.notify(e);
console.log(e);
interaction.editReply({ content: "error" });
await interaction.editReply({ content: "error" });
}
},
isGuild: true,
Expand Down
7 changes: 2 additions & 5 deletions islander/AchievementsModule.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import Canvas, { createCanvas, Image } from "@napi-rs/canvas";
import { AttachmentBuilder, User } from "discord.js";

const { request } = require("undici");

export class AchievementsModule {
Expand Down Expand Up @@ -73,9 +74,6 @@ export class AchievementsModule {
context.drawImage(backgroundImage, 0, 0, canvas.width, canvas.height);
context.strokeStyle = "#0099ff";
context.strokeRect(0, 0, canvas.width, canvas.height);
context.font = "28px sans-serif";
context.fillStyle = "#ffffff";
context.fillText("Profile", canvas.width / 2.5, canvas.height / 3.5);
context.font = applyText(canvas, `${guildMember.username}!`);
context.fillStyle = "#ffffff";
context.fillText(
Expand All @@ -93,10 +91,9 @@ export class AchievementsModule {
const avatar = new Image();
avatar.src = Buffer.from(await body.arrayBuffer());
context.drawImage(avatar, 25, 25, 200, 200);
const attachment = new AttachmentBuilder(canvas.toBuffer("image/png"), {
return new AttachmentBuilder(canvas.toBuffer("image/png"), {
name: "profile-image.png",
});
return attachment;
}
}

Expand Down
52 changes: 52 additions & 0 deletions modules/WebApi.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,57 @@
import express from "express";
import cors from "cors";
import passport from "passport";
const DiscordStrategy = require("passport-discord").Strategy;

const app = express();
const prompt = "consent";

export class WebApi {
constructor() {
passport.serializeUser(function (user, done) {
done(null, user);
});
passport.deserializeUser(function (obj, done) {
done(null, obj);
});
let jsonify = this.jsonify;
passport.use(
new DiscordStrategy(
{
clientID: "id",
clientSecret: "secret",
callbackURL: "callbackURL",
scope: ["identify", "guilds"],
},
function (accessToken, refreshToken, profile, done) {
console.log(profile);
return done(null, profile);
}
)
);
app.use(cors());

//auth test
app.get(
"/auth",
passport.authenticate("discord", {
scope: ["identify", "guilds"],
prompt: prompt,
}),
function (req, res) {}
);
app.get(
"/callback",
passport.authenticate("discord", { failureRedirect: "/" }),
function (req, res) {
res.redirect("/authtest");
} // auth success
);

app.get("/authtest", this.checkAuth, function (req, res) {
res.json(req);
});

app.get("/", function (req, res) {
res.send("KRAKEN API");
});
Expand Down Expand Up @@ -110,4 +157,9 @@ export class WebApi {
console.log("WebApi listening on port 3000");
});
}

checkAuth(req, res, next) {
if (req.isAuthenticated()) return next();
res.send("not logged in :(");
}
}
55 changes: 55 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
"node-cron": "^3.0.0",
"openai": "^3.2.1",
"passport": "^0.6.0",
"passport-discord": "^0.1.4",
"passport-oauth2-refresh": "^2.1.0",
"typescript": "^5.0.2"
},
"devDependencies": {
Expand Down
40 changes: 39 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,11 @@ axios@^0.26.0:
dependencies:
follow-redirects "^1.14.8"

base64url@3.x.x:
version "3.0.1"
resolved "https://registry.npmjs.org/base64url/-/base64url-3.0.1.tgz"
integrity sha512-ir1UPr3dkwexU7FdV8qBBbNDRUhMmIekYMFZfi+C/sLNnRESKPl23nB9b2pltqfOQNnGzsDdId90AEtG5tCx4A==

body-parser@1.20.1:
version "1.20.1"
resolved "https://registry.npmjs.org/body-parser/-/body-parser-1.20.1.tgz"
Expand Down Expand Up @@ -759,6 +764,11 @@ node-fetch@^2.6.1:
dependencies:
whatwg-url "^5.0.0"

oauth@0.9.x:
version "0.9.15"
resolved "https://registry.npmjs.org/oauth/-/oauth-0.9.15.tgz"
integrity sha512-a5ERWK1kh38ExDEfoO6qUHJb32rd7aYmPHuyCu3Fta/cnICvYmgd2uhuKXvPD+PXB+gCEYYEaQdIRAjCOwAKNA==

object-assign@^4:
version "4.1.1"
resolved "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz"
Expand Down Expand Up @@ -796,6 +806,29 @@ parseurl@~1.3.3:
resolved "https://registry.npmjs.org/parseurl/-/parseurl-1.3.3.tgz"
integrity sha512-CiyeOxFT/JZyN5m0z9PfXw4SCBJ6Sygz1Dpl0wqjlhDEGGBP1GnsUVEL0p63hoG1fcj3fHynXi9NYO4nWOL+qQ==

passport-discord@^0.1.4:
version "0.1.4"
resolved "https://registry.npmjs.org/passport-discord/-/passport-discord-0.1.4.tgz"
integrity sha512-VJWPYqSOmh7SaCLw/C+k1ZqCzJnn2frrmQRx1YrcPJ3MQ+Oa31XclbbmqFICSvl8xv3Fqd6YWQ4H4p1MpIN9rA==
dependencies:
passport-oauth2 "^1.5.0"

passport-oauth2-refresh@^2.1.0:
version "2.1.0"
resolved "https://registry.npmjs.org/passport-oauth2-refresh/-/passport-oauth2-refresh-2.1.0.tgz"
integrity sha512-4ML7ooCESCqiTgdDBzNUFTBcPR8zQq9iM6eppEUGMMvLdsjqRL93jKwWm4Az3OJcI+Q2eIVyI8sVRcPFvxcF/A==

passport-oauth2@^1.5.0:
version "1.7.0"
resolved "https://registry.npmjs.org/passport-oauth2/-/passport-oauth2-1.7.0.tgz"
integrity sha512-j2gf34szdTF2Onw3+76alNnaAExlUmHvkc7cL+cmaS5NzHzDP/BvFHJruueQ9XAeNOdpI+CH+PWid8RA7KCwAQ==
dependencies:
base64url "3.x.x"
oauth "0.9.x"
passport-strategy "1.x.x"
uid2 "0.0.x"
utils-merge "1.x.x"

passport-strategy@1.x.x:
version "1.0.0"
resolved "https://registry.npmjs.org/passport-strategy/-/passport-strategy-1.0.0.tgz"
Expand Down Expand Up @@ -1041,6 +1074,11 @@ typescript@^5.0.2, typescript@>=2.7:
resolved "https://registry.npmjs.org/typescript/-/typescript-5.0.2.tgz"
integrity sha512-wVORMBGO/FAs/++blGNeAVdbNKtIh1rbBL2EyQ1+J9lClJ93KiiKe8PmFIVdXhHcyv44SL9oglmfeSsndo0jRw==

uid2@0.0.x:
version "0.0.4"
resolved "https://registry.npmjs.org/uid2/-/uid2-0.0.4.tgz"
integrity sha512-IevTus0SbGwQzYh3+fRsAMTVVPOoIVufzacXcHPmdlle1jUpq7BRL+mw3dgeLanvGZdwwbWhRV6XrcFNdBmjWA==

undici@^5.20.0:
version "5.21.0"
resolved "https://registry.npmjs.org/undici/-/undici-5.21.0.tgz"
Expand All @@ -1058,7 +1096,7 @@ util-deprecate@^1.0.1:
resolved "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz"
integrity sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw==

utils-merge@^1.0.1, utils-merge@1.0.1:
utils-merge@^1.0.1, utils-merge@1.0.1, utils-merge@1.x.x:
version "1.0.1"
resolved "https://registry.npmjs.org/utils-merge/-/utils-merge-1.0.1.tgz"
integrity sha512-pMZTvIkT1d+TFGvDOqodOclx0QWkkgi6Tdoa8gC8ffGAAqz9pzPTZWAybbsHHoED/ztMtkv/VoYTYyShUn81hA==
Expand Down

0 comments on commit fc266d4

Please sign in to comment.