Skip to content

Commit

Permalink
v10.12 (#1057)
Browse files Browse the repository at this point in the history
  • Loading branch information
iamtraction authored Aug 29, 2023
2 parents da3ace7 + 928e461 commit 6a7673f
Show file tree
Hide file tree
Showing 27 changed files with 353 additions and 132 deletions.
2 changes: 1 addition & 1 deletion .github/SECURITY.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
## Reporting a Vulnerability

If you find a vulnerability in Bastion, join [Bastion HQ] and send a direct
message to **iamtraction#8383** with the details about the vulnerability and
message to **@iamtraction** with the details about the vulnerability and
we will fix it as soon as practical.

Once fixed, you will be credited with finding the vulnerability in the release
Expand Down
2 changes: 1 addition & 1 deletion commands.json

Large diffs are not rendered by default.

28 changes: 14 additions & 14 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "bastion",
"version": "10.11.2",
"version": "10.12.0",
"description": "Get an enhanced Discord experience!",
"type": "module",
"homepage": "https://bastion.traction.one",
Expand All @@ -18,32 +18,32 @@
"test": "eslint src --ext .ts"
},
"devDependencies": {
"@types/discord-rpc": "^4.0.4",
"@types/discord-rpc": "^4.0.5",
"@types/express": "^4.17.17",
"@types/http-errors": "^2.0.1",
"@types/jsdom": "^21.1.1",
"@types/node": "^20.1.2",
"@typescript-eslint/eslint-plugin": "^5.57.0",
"@typescript-eslint/parser": "^5.57.0",
"eslint": "^8.37.0",
"typescript": "^5.0.3"
"@types/node": "^20.5.1",
"@typescript-eslint/eslint-plugin": "^6.4.0",
"@typescript-eslint/parser": "^6.4.0",
"eslint": "^8.47.0",
"typescript": "^5.1.6"
},
"dependencies": {
"@bastion/tesseract": "^5.0.1",
"@bastion/tesseract": "^5.0.4",
"@discordjs/opus": "^0.9.0",
"@iamtraction/google-translate": "^2.0.1",
"@types/gamedig": "^4.0.1",
"discord-rpc": "^4.0.1",
"dotenv": "^16.0.3",
"dotenv": "^16.3.1",
"emoji-regex": "^10.2.1",
"gamedig": "^4.0.6",
"jsdom": "^22.0.0",
"gamedig": "^4.0.7",
"jsdom": "^22.1.0",
"libsodium-wrappers": "^0.7.11",
"mathjs": "^11.7.0",
"mathjs": "^11.9.1",
"play-dl": "^1.9.6",
"r6api.js": "^4.4.1",
"undici": "^5.21.0",
"ytdl-core": "^4.11.3",
"undici": "^5.23.0",
"ytdl-core": "^4.11.5",
"ytpl": "^2.3.0"
},
"optionalDependencies": {
Expand Down
4 changes: 2 additions & 2 deletions settings.example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ mongoURI: "mongodb://127.0.0.1:27017/bastion"
# Presences
# Bastion will cycle through these activities randomly.
# status — online / idle / dnd / invisible
# activity — 0 (Playing) / 1 (Streaming) / 2 (Listening) / 3 (Watching) / 5 (Competing)
# activity — 0 (Playing) / 1 (Streaming) / 2 (Listening) / 3 (Watching) / 4 (Custom) / 5 (Competing)
# name — string
# url — Twitch URL when `activity` is set to
# url — Twitch URL when `activity` is set to `1` (Streaming)
presences:
- status: "online"
activity: 3
Expand Down
14 changes: 7 additions & 7 deletions src/commands/comic/xkcd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ import { Command } from "@bastion/tesseract";
import * as requests from "../../utils/requests.js";

interface XKCD {
title: string;
title?: string;
safe_title?: string;
alt: string;
num: string;
day: number;
month: number;
year: number;
img: string;
alt?: string;
num?: string;
day?: number;
month?: number;
year?: number;
img?: string;
}

class XKCDCommand extends Command {
Expand Down
87 changes: 87 additions & 0 deletions src/commands/config/filter/emails.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/*!
* @author TRACTION (iamtraction)
* @copyright 2023
*/
import { AutoModerationActionOptions, AutoModerationActionType, AutoModerationRuleEventType, AutoModerationRuleTriggerType, ChatInputCommandInteraction, PermissionFlagsBits } from "discord.js";
import { Command, Logger } from "@bastion/tesseract";

import GuildModel from "../../../models/Guild.js";

class FilterEmailsCommand extends Command {
constructor() {
super({
name: "emails",
description: "Configure Email Filter AutoMod rule in the server.",
userPermissions: [ PermissionFlagsBits.ManageGuild ],
clientPermissions: [ PermissionFlagsBits.ManageGuild ],
});
}

public async exec(interaction: ChatInputCommandInteraction<"cached">): Promise<unknown> {
await interaction.deferReply();

// get guild document
const guildDocument = await GuildModel.findById(interaction.guildId);

// get the email filter rule if it exists
const emailFilterRule = guildDocument.emailFilterRule && await interaction.guild.autoModerationRules.fetch({
autoModerationRule: guildDocument.emailFilterRule,
cache: false,
}).catch(Logger.ignore);

// toggle email filter rule if it exists
if (emailFilterRule) {
const newEmailFilterRule = await emailFilterRule.setEnabled(!emailFilterRule.enabled, `${ emailFilterRule.enabled ? "Disable" : "Enable" } Email Filter`);
return await interaction.editReply(`I've ${ newEmailFilterRule.enabled ? "enabled" : "disabled" } the **${ newEmailFilterRule.name }** AutoMod rule.`);
}

const actions: AutoModerationActionOptions[] = [
{
type: AutoModerationActionType.BlockMessage,
metadata: {
customMessage: "You are not allowed to send emails in this channel.",
},
},
{
type: AutoModerationActionType.Timeout,
metadata: {
durationSeconds: 60,
},
},
];

if (interaction.guild.channels.cache.has(guildDocument.moderationLogChannel)) {
actions.push({
type: AutoModerationActionType.SendAlertMessage,
metadata: {
channel: guildDocument.moderationLogChannel,
},
});
}

// create email filter rule
const newEmailFilterRule = await interaction.guild.autoModerationRules.create({
enabled: true,
name: "Block Emails",
eventType: AutoModerationRuleEventType.MessageSend,
triggerType: AutoModerationRuleTriggerType.Keyword,
triggerMetadata: {
regexPatterns: [
"[A-Za-z0-9.+~_-]+\\@[A-Za-z0-9.-]+\\.[A-Za-z0-9.-]+",
],
},
actions,
reason: "Configure Email Filter",
});

// update email filter rule id
guildDocument.emailFilterRule = newEmailFilterRule.id;

// save document
await guildDocument.save();

return await interaction.editReply("I've configured the email filter AutoMod rule.");
}
}

export { FilterEmailsCommand as Command };
29 changes: 25 additions & 4 deletions src/commands/gamestats/aimlab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,27 @@ import { Command } from "@bastion/tesseract";
import * as requests from "../../utils/requests.js";
import { COLORS } from "../../utils/constants.js";

interface AimLabResponse {
data?: {
aimlabProfile: {
username: string;
ranking: {
rank: {
displayName: string;
level: number;
minSkill: number;
maxSkill: number;
};
skill: number;
};
skillScores: {
name: string;
score: number;
}[];
};
};
}

class AimLabCommand extends Command {
constructor() {
super({
Expand Down Expand Up @@ -54,15 +75,15 @@ class AimLabCommand extends Command {
},
});

const body = await response.body.json();
const body: AimLabResponse = await response.body.json();

if (!body?.data?.aimlabProfile) {
return await interaction.editReply(`The profile for **${ username }** was not found.`);
}

const skillScores = body.data.aimlabProfile?.skillScores?.length ? body.data.aimlabProfile.skillScores.map((skill: { name: string; score: string }) => ({
const skillScores = body.data.aimlabProfile?.skillScores?.length ? body.data.aimlabProfile.skillScores.map(skill => ({
name: skill.name[0].toUpperCase() + skill.name.slice(1),
value: (skill.score as unknown as number).toFixed(),
value: skill.score.toFixed(),
inline: true,
})) : [];

Expand All @@ -83,7 +104,7 @@ class AimLabCommand extends Command {
},
{
name: "Skill Rating",
value: (body.data.aimlabProfile?.ranking?.skill as unknown as number)?.toFixed(),
value: body.data.aimlabProfile?.ranking?.skill?.toFixed(),
inline: true,
},
{
Expand Down
28 changes: 26 additions & 2 deletions src/commands/gamestats/apex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,30 @@ import * as requests from "../../utils/requests.js";
import { COLORS } from "../../utils/constants.js";
import Settings from "../../utils/settings.js";

interface ApexProfileResponse {
data?: {
platformInfo: {
platformUserHandle: string;
avatarUrl: string;
};
segments: {
type: string;
stats: {
rankScore: {
displayValue: string;
metadata: {
rankName: string;
iconUrl: string;
};
};
};
}[];
metadata: {
activeLegendName: string;
};
};
}

class ApexLegendsCommand extends Command {
constructor() {
super({
Expand Down Expand Up @@ -46,8 +70,8 @@ class ApexLegendsCommand extends Command {
"TRN-Api-Key": ((interaction.client as Client).settings as Settings).get("trackerNetworkApiKey"),
});

const body = await response.body.json();
const overview = body?.data?.segments?.find((s: { type: string }) => s.type === "overview");
const body: ApexProfileResponse = await response.body.json();
const overview = body?.data?.segments?.find(s => s.type === "overview");

if (!Object.keys(overview?.stats || {})?.length) return await interaction.editReply(`The profile for **${ username }** was not found in the specified platform.`);

Expand Down
26 changes: 24 additions & 2 deletions src/commands/gamestats/csgo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,28 @@ import * as requests from "../../utils/requests.js";
import { COLORS } from "../../utils/constants.js";
import Settings from "../../utils/settings.js";

interface CSGOProfileResponse {
data?: {
platformInfo: {
platformUserHandle: string;
avatarUrl: string;
};
segments: {
type: string;
stats: {
timePlayed: {
value: number;
};
rankScore: {
metadata: {
iconUrl: string;
};
};
};
}[];
};
}

class CSGOCommand extends Command {
constructor() {
super({
Expand All @@ -34,8 +56,8 @@ class CSGOCommand extends Command {
"TRN-Api-Key": ((interaction.client as Client).settings as Settings).get("trackerNetworkApiKey"),
});

const body = await response.body.json();
const overview = body?.data?.segments?.find((s: { type: string }) => s.type === "overview");
const body: CSGOProfileResponse = await response.body.json();
const overview = body?.data?.segments?.find(s => s.type === "overview");

if (!Object.keys(overview?.stats || {})?.length) return await interaction.editReply(`The profile for **${ username }** was not found.`);

Expand Down
13 changes: 11 additions & 2 deletions src/commands/gamestats/fortnite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@ import * as requests from "../../utils/requests.js";
import { COLORS } from "../../utils/constants.js";
import Settings from "../../utils/settings.js";

interface FortniteResponse {
lifeTimeStats?: {
key: string;
value: string;
}[];
epicUserHandle?: string;
platformNameLong?: string;
}

class FortniteCommand extends Command {
constructor() {
super({
Expand Down Expand Up @@ -46,7 +55,7 @@ class FortniteCommand extends Command {
"TRN-Api-Key": ((interaction.client as Client).settings as Settings).get("trackerNetworkApiKey"),
});

const body = await response.body.json();
const body: FortniteResponse = await response.body.json();

if (!body?.lifeTimeStats?.length) return await interaction.editReply(`The profile for **${ username }** was not found in the specified platform.`);

Expand All @@ -58,7 +67,7 @@ class FortniteCommand extends Command {
name: "Fortnite — Player Stats",
},
title: body.epicUserHandle,
fields: body.lifeTimeStats.map((stat: { key: string; value: string }) => ({
fields: body.lifeTimeStats.map(stat => ({
name: stat.key,
value: stat.value,
inline: true,
Expand Down
17 changes: 16 additions & 1 deletion src/commands/gamestats/overwatch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,21 @@ import { Command } from "@bastion/tesseract";
import * as requests from "../../utils/requests.js";
import { COLORS } from "../../utils/constants.js";

interface OverwatchResponse {
private?: boolean;
gamesPlayed?: string;
gamesWon?: string;
gamesLost?: string;
ratings?: {
role: string;
group: string;
tier: string;
}[];
icon?: string;
endorsementIcon?: string;
endorsement?: number;
}

class OverwatchCommand extends Command {
constructor() {
super({
Expand Down Expand Up @@ -53,7 +68,7 @@ class OverwatchCommand extends Command {

// get stats
const { body } = await requests.get("https://ow-api.com/v1/stats/" + platform + "/" + region + "/" + (username.replace("#", "-")) + "/profile");
const response = await body.json();
const response: OverwatchResponse = await body.json();

await interaction.editReply({
embeds: [
Expand Down
Loading

0 comments on commit 6a7673f

Please sign in to comment.