Add logger to project (#183)
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
# Description Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. List any dependencies that are required for this change. - Add the winston package to handle logging - Add logging to the project's logic #146 ## Type of change Please delete options that are not relevant. - [x] New feature (non-breaking change which adds functionality) # How Has This Been Tested? Please describe the tests that you ran to verify the changes. Provide instructions so we can reproduce. Please also list any relevant details to your test configuration. # Checklist - [ ] My code follows the style guidelines of this project - [ ] I have performed a self-review of my own code - [ ] I have commented my code, particularly in hard-to-understand areas - [ ] I have made corresponding changes to the documentation - [ ] My changes generate no new warnings - [ ] I have added tests that provde my fix is effective or that my feature works - [ ] New and existing unit tests pass locally with my changes - [ ] Any dependent changes have been merged and published in downstream modules Reviewed-on: https://gitea.vylpes.xyz/External/card-drop/pulls/183 Reviewed-by: VylpesTester <tester@vylpes.com> Co-authored-by: Ethan Lane <ethan@vylpes.com> Co-committed-by: Ethan Lane <ethan@vylpes.com>
This commit is contained in:
parent
42dfe2d047
commit
5dd50a3f3b
27 changed files with 465 additions and 26 deletions
|
@ -3,6 +3,7 @@ import { ButtonEvent } from "../type/buttonEvent";
|
|||
import Inventory from "../database/entities/app/Inventory";
|
||||
import { CoreClient } from "../client/client";
|
||||
import { default as eClaim } from "../database/entities/app/Claim";
|
||||
import AppLogger from "../client/appLogger";
|
||||
|
||||
export default class Claim extends ButtonEvent {
|
||||
public override async execute(interaction: ButtonInteraction) {
|
||||
|
@ -13,6 +14,8 @@ export default class Claim extends ButtonEvent {
|
|||
const droppedBy = interaction.customId.split(" ")[3];
|
||||
const userId = interaction.user.id;
|
||||
|
||||
AppLogger.LogSilly("Button/Claim", `Parameters: cardNumber=${cardNumber}, claimId=${claimId}, droppedBy=${droppedBy}, userId=${userId}`);
|
||||
|
||||
await interaction.deferReply();
|
||||
|
||||
const claimed = await eClaim.FetchOneByClaimId(claimId);
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import { ButtonInteraction } from "discord.js";
|
||||
import { ButtonEvent } from "../type/buttonEvent";
|
||||
import InventoryHelper from "../helpers/InventoryHelper";
|
||||
import AppLogger from "../client/appLogger";
|
||||
|
||||
export default class Inventory extends ButtonEvent {
|
||||
public override async execute(interaction: ButtonInteraction) {
|
||||
|
@ -9,6 +10,8 @@ export default class Inventory extends ButtonEvent {
|
|||
const userid = interaction.customId.split(" ")[1];
|
||||
const page = interaction.customId.split(" ")[2];
|
||||
|
||||
AppLogger.LogSilly("Button/Inventory", `Parameters: userid=${userid}, page=${page}`);
|
||||
|
||||
const member = interaction.guild.members.cache.find(x => x.id == userid) || await interaction.guild.members.fetch(userid);
|
||||
|
||||
if (!member) {
|
||||
|
@ -17,6 +20,8 @@ export default class Inventory extends ButtonEvent {
|
|||
}
|
||||
|
||||
try {
|
||||
AppLogger.LogVerbose("Button/Inventory", `Generating inventory page ${page} for ${member.user.username} with id ${member.user.id}`);
|
||||
|
||||
const embed = await InventoryHelper.GenerateInventoryPage(member.user.username, member.user.id, Number(page));
|
||||
|
||||
await interaction.update({
|
||||
|
@ -24,7 +29,8 @@ export default class Inventory extends ButtonEvent {
|
|||
components: [ embed.row ],
|
||||
});
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
AppLogger.LogError("Button/Inventory", `Error generating inventory page for ${member.user.username} with id ${member.user.id}: ${e}`);
|
||||
|
||||
await interaction.reply("No page for user found.");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@ import Inventory from "../database/entities/app/Inventory";
|
|||
import Config from "../database/entities/app/Config";
|
||||
import CardDropHelperMetadata from "../helpers/CardDropHelperMetadata";
|
||||
import path from "path";
|
||||
import AppLogger from "../client/appLogger";
|
||||
|
||||
export default class Reroll extends ButtonEvent {
|
||||
public override async execute(interaction: ButtonInteraction) {
|
||||
|
@ -16,6 +17,8 @@ export default class Reroll extends ButtonEvent {
|
|||
}
|
||||
|
||||
if (await Config.GetValue("safemode") == "true") {
|
||||
AppLogger.LogWarn("Button/Reroll", "Safe Mode is active, refusing to send next drop.");
|
||||
|
||||
await interaction.reply("Safe Mode has been activated, please resync to continue.");
|
||||
return;
|
||||
}
|
||||
|
@ -30,6 +33,8 @@ export default class Reroll extends ButtonEvent {
|
|||
await interaction.deferReply();
|
||||
|
||||
try {
|
||||
AppLogger.LogVerbose("Button/Reroll", `Sending next drop: ${randomCard.card.id} (${randomCard.card.name})`);
|
||||
|
||||
const image = readFileSync(path.join(process.env.DATA_DIR!, "cards", randomCard.card.path));
|
||||
const imageFileName = randomCard.card.path.split("/").pop()!;
|
||||
|
||||
|
@ -51,9 +56,8 @@ export default class Reroll extends ButtonEvent {
|
|||
});
|
||||
|
||||
CoreClient.ClaimId = claimId;
|
||||
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
AppLogger.LogError("Button/Reroll", `Error sending next drop for card ${randomCard.card.id}: ${e}`);
|
||||
|
||||
await interaction.editReply(`Unable to send next drop. Please try again, and report this if it keeps happening. (${randomCard.card.id})`);
|
||||
}
|
||||
|
|
|
@ -3,11 +3,14 @@ import { ButtonEvent } from "../type/buttonEvent";
|
|||
import { CoreClient } from "../client/client";
|
||||
import Inventory from "../database/entities/app/Inventory";
|
||||
import EmbedColours from "../constants/EmbedColours";
|
||||
import AppLogger from "../client/appLogger";
|
||||
|
||||
export default class Trade extends ButtonEvent {
|
||||
public override async execute(interaction: ButtonInteraction) {
|
||||
const action = interaction.customId.split(" ")[1];
|
||||
|
||||
AppLogger.LogSilly("Button/Trade", `Parameters: action=${action}`);
|
||||
|
||||
switch (action) {
|
||||
case "accept":
|
||||
await this.AcceptTrade(interaction);
|
||||
|
@ -26,6 +29,8 @@ export default class Trade extends ButtonEvent {
|
|||
const expiry = interaction.customId.split(" ")[6];
|
||||
const timeoutId = interaction.customId.split(" ")[7];
|
||||
|
||||
AppLogger.LogSilly("Button/Trade/AcceptTrade", `Parameters: giveUserId=${giveUserId}, receiveUserId=${receiveUserId}, giveCardNumber=${giveCardNumber}, receiveCardNumber=${receiveCardNumber}, expiry=${expiry}, timeoutId=${timeoutId}`);
|
||||
|
||||
const expiryDate = new Date(expiry);
|
||||
|
||||
if (expiryDate < new Date()) {
|
||||
|
@ -140,6 +145,8 @@ export default class Trade extends ButtonEvent {
|
|||
// No need to get expiry date
|
||||
const timeoutId = interaction.customId.split(" ")[7];
|
||||
|
||||
AppLogger.LogSilly("Button/Trade/DeclineTrade", `Parameters: giveUserId=${giveUserId}, receiveUserId=${receiveUserId}, giveCardNumber=${giveCardNumber}, receiveCardNumber=${receiveCardNumber}, timeoutId=${timeoutId}`);
|
||||
|
||||
if (interaction.user.id != receiveUserId && interaction.user.id !==giveUserId) {
|
||||
await interaction.reply("You are not the user who the trade is intended for");
|
||||
return;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue