Skip to content

Commit

Permalink
Merge pull request #973 from TheBastionBot/dev
Browse files Browse the repository at this point in the history
v10.2
  • Loading branch information
iamtraction authored Nov 25, 2022
2 parents b979ff4 + 7b8a3e6 commit d17d2e2
Show file tree
Hide file tree
Showing 18 changed files with 391 additions and 31 deletions.
6 changes: 4 additions & 2 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
# EXPERIMENTAL. DO NOT USE THIS!
# This will change in upcoming versions.

TESSERACT_OWNER_ID=
TESSERACT_BOT_ID=
TESSERACT_BOT_TOKEN=
TESSERACT_OWNER_ID=
TESSERACT_MONGO_URI=
TESSERACT_UNSAFE_MODE=FALSE

BASTION_MUSIC_ACTIVITY=TRUE
BASTION_SAFE_MODE=TRUE
BASTION_RELAY_DMS=FALSE
BASTION_API_PORT=8377
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "bastion",
"version": "10.1.0",
"version": "10.2.0",
"description": "Get an enhanced Discord experience!",
"homepage": "https://bastion.traction.one",
"main": "./dist/index.js",
Expand All @@ -25,7 +25,7 @@
"typescript": "^4.9.3"
},
"dependencies": {
"@bastion/tesseract": "^3.0.1",
"@bastion/tesseract": "^3.1.0",
"@discordjs/rest": "^1.3.0",
"@iamtraction/google-translate": "^2.0.1",
"@types/gamedig": "^4.0.0",
Expand Down
10 changes: 9 additions & 1 deletion scripts/bash/methods.sh
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ function method::update () {

echo "Updating dependencies..."

rm -fr node_modules package-lock.json screenlog.0
rm -fr dist node_modules package-lock.json screenlog.0
npm install --no-package-lock
if ! [[ "$?" -eq 0 ]]
then
Expand All @@ -140,6 +140,14 @@ function method::update () {
exit 1
fi

npm run commands
if ! [[ "$?" -eq 0 ]]
then
print::error "Found some errors while publishing Bastion commands."
print::message "Contact Bastion Support for help."
exit 1
fi

print::message "Ready to boot up and start running."
fi
}
10 changes: 9 additions & 1 deletion scripts/powershell/Update.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ Pass-Step
Write-Host "[Bastion]: Updating dependencies..."
Write-Host

Remove-Item -Path ".\node_modules", ".\package-lock.json" -Force -Recurse -ErrorAction SilentlyContinue
Remove-Item -Path ".\dist", ".\node_modules", ".\package-lock.json" -Force -Recurse -ErrorAction SilentlyContinue
npm install --no-package-lock
If (-Not ($?)) {
Write-Host "[Bastion]: Unable to update Bastion, error while updating dependencies."
Expand All @@ -73,6 +73,14 @@ If (-Not ($?)) {
Exit-Bastion-Updater
}

npm run commands
If (-Not ($?)) {
Write-Host "[Bastion]: Found some errors while publishing Bastion commands."
Write-Host "[Bastion]: Contact Bastion Support for further help."

Exit-Bastion-Updater
}

Pass-Step


Expand Down
17 changes: 12 additions & 5 deletions settings.example.yaml
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
# Bot ID
# Add the Client ID of bot which should be running Bastion.
# https://discord.com/developers/applications
# `TESSERACT_BOT_ID` environment variable overwrites this value.
id: ""

# Bot Token
# Add the token of the bot which should be running Bastion.
# https://discord.com/developers/applications
# `TESSERACT_BOT_TOKEN` environment variable overwrites this value.
token: ""

# Bot Owners
# User IDs of users who should be considered as the bot owners.
# `TESSERACT_OWNER_ID` environment variable adds an additional owner to the list.
owners:
- "YOUR_USER_ID"
- "ANOTHER_USER_ID"

# Add the token of the bot which should be running Bastion.
# https://discord.com/developers/applications
# `TESSERACT_BOT_TOKEN` environment variable overwrites this value.
token: ""

# MongoDB connection URI
# `TESSERACT_MONGO_URI` environment variable overwrites this value.
mongoURI: "mongodb://localhost:27017/bastion"
Expand Down
36 changes: 33 additions & 3 deletions src/commands/config/verification.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
* @author TRACTION (iamtraction)
* @copyright 2022
*/
import { ApplicationCommandOptionType, ChatInputCommandInteraction, PermissionFlagsBits } from "discord.js";
import { ApplicationCommandOptionType, ButtonStyle, ChatInputCommandInteraction, ComponentType, PermissionFlagsBits } from "discord.js";
import { Command } from "@bastion/tesseract";

import GuildModel from "../../models/Guild";
import MessageComponents from "../../utils/components";

class VerificationCommand extends Command {
constructor() {
Expand All @@ -18,6 +19,11 @@ class VerificationCommand extends Command {
name: "role",
description: "The role that should be assigned to verified users.",
},
{
type: ApplicationCommandOptionType.String,
name: "text",
description: "Type a text message that will be shown to the users trying to verify.",
},
],
userPermissions: [ PermissionFlagsBits.ManageGuild ],
});
Expand All @@ -26,13 +32,37 @@ class VerificationCommand extends Command {
public async exec(interaction: ChatInputCommandInteraction<"cached">): Promise<unknown> {
await interaction.deferReply();
const role = interaction.options.getRole("role");
const text = interaction.options.getString("text");

const guildDocument = await GuildModel.findById(interaction.guildId);

if (text) {
if (guildDocument.verifiedRole) {
return await interaction.editReply({
content: text,
components: [
{
type: ComponentType.ActionRow,
components: [
{
type: ComponentType.Button,
label: "I am human",
style: ButtonStyle.Primary,
customId: MessageComponents.VerificationButton,
},
],
},
],
});
}

return await interaction.editReply("A role for verified users hasn't been set.");
}

if (role?.id === interaction.guildId) {
return await interaction.editReply("**@everyone** isn't a valid role for this.");
}

const guildDocument = await GuildModel.findById(interaction.guildId);

// update verified role
guildDocument.verifiedRole = role?.id || undefined;

Expand Down
2 changes: 1 addition & 1 deletion src/commands/iam.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class IamCommand extends Command {
type: ComponentType.ActionRow,
components: [
{
type: ComponentType.SelectMenu,
type: ComponentType.StringSelect,
customId: MessageComponents.SelfRolesSelect,
placeholder: "Select Roles",
minValues: 0,
Expand Down
7 changes: 6 additions & 1 deletion src/commands/profile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class ProfileCommand extends Command {
if (!member) return interaction.editReply(`${ user } is not a member of the server anymore.`);

// get user's profile data
const memberProfile = await MemberModel.findOne({ user: member.id, guild: interaction.guild.id });
const memberProfile = await MemberModel.findOne({ user: member.id, guild: interaction.guildId });

// check whether user profile exists
if (!memberProfile) return interaction.editReply({
Expand Down Expand Up @@ -125,6 +125,11 @@ class ProfileCommand extends Command {
value: (memberProfile.balance || 0).toLocaleString(),
inline: true,
},
{
name: "Infractions",
value: `${ (memberProfile.infractions?.length || 0).toLocaleString() } warnings`,
inline: true,
},
{
name: `Progress — ${ totalRequiredXP.currentLevel } / ${ totalRequiredXP.nextLevel }${ Math.round(currentProgress) }%`,
value: `\`${ progress(currentProgress, 35) }\``,
Expand Down
13 changes: 11 additions & 2 deletions src/commands/say.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import { ApplicationCommandOptionType, ChatInputCommandInteraction } from "discord.js";
import { Command } from "@bastion/tesseract";

import { generate as generateEmbed } from "../utils/embeds";

class SayCommand extends Command {
constructor() {
super({
Expand All @@ -21,8 +23,15 @@ class SayCommand extends Command {
});
}

public async exec(interaction: ChatInputCommandInteraction<"cached">): Promise<void> {
await interaction.reply(interaction.options.getString("message"));
public async exec(interaction: ChatInputCommandInteraction<"cached">): Promise<unknown> {
const message = generateEmbed(interaction.options.getString("message"));

if (typeof message === "string") {
return await interaction.reply(message);
}
return await interaction.reply({
embeds: [ message ],
});
}
}

Expand Down
104 changes: 104 additions & 0 deletions src/commands/user/infractions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
/*!
* @author TRACTION (iamtraction)
* @copyright 2022
*/
import { ApplicationCommandOptionType, ChatInputCommandInteraction, PermissionFlagsBits } from "discord.js";
import { Command, Logger } from "@bastion/tesseract";

import GuildModel from "../../models/Guild";
import MemberModel from "../../models/Member";
import { COLORS } from "../../utils/constants";

class UserInfractionsCommand extends Command {
constructor() {
super({
name: "infractions",
description: "Configure infraction actions and displays infractions of the specified user.",
options: [
{
type: ApplicationCommandOptionType.Integer,
name: "timeout",
description: "Number of violations after which the user is timed out.",
min_value: 1,
},
{
type: ApplicationCommandOptionType.Integer,
name: "kick",
description: "Number of violations after which the user is kicked.",
min_value: 1,
},
{
type: ApplicationCommandOptionType.Integer,
name: "ban",
description: "Number of violations after which the user is banned.",
min_value: 1,
},
{
type: ApplicationCommandOptionType.User,
name: "user",
description: "The user whose infractions you want to display.",
},
],
userPermissions: [ PermissionFlagsBits.ModerateMembers ],
});
}

public async exec(interaction: ChatInputCommandInteraction<"cached">): Promise<unknown> {
await interaction.deferReply();
const timeoutThreshold = interaction.options.getInteger("timeout");
const kickThreshold = interaction.options.getInteger("kick");
const banThreshold = interaction.options.getInteger("ban");
const user = interaction.options.getUser("user");

if (user) {
// get member
const member = user ? await interaction.guild.members.fetch(user).catch(Logger.ignore) : undefined;
const memberDocument = await MemberModel.findOne({ user: user.id, guild: interaction.guildId });

if (memberDocument?.infractions?.length) {
return await interaction.editReply({
embeds: [
{
color: COLORS.PRIMARY,
author: {
name: user.tag + (member && member.nickname ? " / " + member.nickname : ""),
},
title: "Infractions",
fields: memberDocument.infractions.map((infraction, i) => ({
name: `#${ i + 1 }`,
value: infraction,
})),
footer: {
text: user.id,
},
},
],
});
}

return await interaction.editReply({
content: `${ user } has no active infractions.`,
allowedMentions: {
users: [],
},
});
}

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

if (interaction.channel.permissionsFor(interaction.member)?.has(PermissionFlagsBits.ManageGuild)) {
guildDocument.infractionsTimeoutThreshold = timeoutThreshold;
guildDocument.infractionsKickThreshold = kickThreshold;
guildDocument.infractionsBanThreshold = banThreshold;

await guildDocument.save();

return await interaction.editReply(`**Timeout**, **Kick** and **Ban** thresholds have been set to **${ timeoutThreshold || 0 }**, **${ kickThreshold || 0 }** and **${ banThreshold || 0 }** warnings, respectively.`);
}

return await interaction.editReply(`**Timeout**, **Kick** and **Ban** thresholds are set to **${ guildDocument.infractionsTimeoutThreshold || 0 }**, **${ guildDocument.infractionsKickThreshold || 0 }** and **${ guildDocument.infractionsBanThreshold || 0 }** warnings, respectively.`);
}
}

export = UserInfractionsCommand;
41 changes: 41 additions & 0 deletions src/components/VerificationButton.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*!
* @author TRACTION (iamtraction)
* @copyright 2022
*/
import { ButtonInteraction, ComponentType, TextInputStyle } from "discord.js";
import { MessageComponent } from "@bastion/tesseract";

import MessageComponents from "../utils/components";

class VerificationButton extends MessageComponent {
constructor() {
super({
id: MessageComponents.VerificationButton,
scope: "guild",
});
}

public async exec(interaction: ButtonInteraction<"cached">): Promise<unknown> {
return interaction.showModal({
custom_id: MessageComponents.VerificationModal,
title: "Are you a human?",
components: [
{
type: ComponentType.ActionRow,
components: [
{
custom_id: MessageComponents.VerificationTextInput,
type: ComponentType.TextInput,
label: "Type \"i am human\" to verify yourself.",
placeholder: "i am human",
required: true,
style: TextInputStyle.Short,
},
],
},
],
});
}
}

export = VerificationButton;
Loading

0 comments on commit d17d2e2

Please sign in to comment.