Skip to content

Commit

Permalink
🔨 change logic ?? -> ||, refactor codes
Browse files Browse the repository at this point in the history
  • Loading branch information
idinium96 committed Oct 27, 2023
1 parent 60dec30 commit 2e766cb
Show file tree
Hide file tree
Showing 14 changed files with 41 additions and 30 deletions.
2 changes: 1 addition & 1 deletion src/classes/MyHandler/MyHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2760,7 +2760,7 @@ interface OnNewTradeOffer {
meta?: Meta;
}

interface BotInfo {
export interface BotInfo {
name: string;
avatarURL: string;
steamID: SteamID;
Expand Down
11 changes: 9 additions & 2 deletions src/classes/Pricelist.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1143,7 +1143,13 @@ export default class Pricelist extends EventEmitter {
});

if (isDwEnabled && dw.showFailedToUpdate) {
sendFailedPriceUpdate(data, err as Error, this.isUseCustomPricer, this.options);
sendFailedPriceUpdate(
data,
err as Error,
this.isUseCustomPricer,
this.options,
this.bot.handler.getBotInfo
);
}

return;
Expand Down Expand Up @@ -1330,7 +1336,8 @@ export default class Pricelist extends EventEmitter {
match.sku === '5021;6' ? undefined : keyPrice,
buyChangesValue,
sellChangesValue,
this.isUseCustomPricer
this.isUseCustomPricer,
this.bot.handler.getBotInfo
);
}
}
Expand Down
8 changes: 5 additions & 3 deletions src/lib/DiscordWebhook/pricelistUpdate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import log from '../logger';
import { BuyAndSell } from '../../classes/Pricelist';
import Options from '../../classes/Options';
import { WebhookError } from './utils';
import { BotInfo } from '../../classes/MyHandler/MyHandler';

const australiumImageURL: { [defindex: number]: string } = {
// Australium Ambassador
Expand Down Expand Up @@ -1789,7 +1790,8 @@ export default function sendWebHookPriceUpdateV1(
conversion: number,
buyChangesValue: number | null,
sellChangesValue: number | null,
isCustomPricer: boolean
isCustomPricer: boolean,
botInfo: BotInfo
): void {
const baseItemData = schema.getItemBySKU(sku);
const item = SKU.fromString(sku);
Expand Down Expand Up @@ -1884,8 +1886,8 @@ export default function sendWebHookPriceUpdateV1(

const opt = options.discordWebhook;
const priceUpdate: Webhook = {
username: opt.displayName,
avatar_url: opt.avatarURL,
username: opt.displayName || botInfo.name,
avatar_url: opt.avatarURL || botInfo.avatarURL,
content: '',
embeds: [
{
Expand Down
8 changes: 5 additions & 3 deletions src/lib/DiscordWebhook/pricelistUpdateFailed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,19 @@ import { GetItemPriceResponse } from '../../classes/IPricer';
import * as timersPromises from 'timers/promises';
import { UnknownDictionary } from '../../types/common';
import Options from '../../classes/Options';
import { BotInfo } from '../../classes/MyHandler/MyHandler';

export default function sendFailedPriceUpdate(
data: GetItemPriceResponse,
err: Error,
isCustomPricer: boolean,
options: Options
options: Options,
botInfo: BotInfo
): void {
const opt = options.discordWebhook;
const priceUpdate: Webhook = {
username: opt.displayName,
avatar_url: opt.avatarURL,
username: opt.displayName || botInfo.name,
avatar_url: opt.avatarURL || botInfo.avatarURL,
content: '',
embeds: [
{
Expand Down
4 changes: 2 additions & 2 deletions src/lib/DiscordWebhook/sendAdminMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ export default function sendAdminMessage(
const botInfo = bot.handler.getBotInfo;

const discordAdminMsg: Webhook = {
username: opt.displayName ? opt.displayName : botInfo.name,
avatar_url: opt.avatarURL ? opt.avatarURL : botInfo.avatarURL,
username: opt.displayName || botInfo.name,
avatar_url: opt.avatarURL || botInfo.avatarURL,
content: `Message sent!`,
embeds: [
{
Expand Down
4 changes: 2 additions & 2 deletions src/lib/DiscordWebhook/sendAlert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -239,8 +239,8 @@ export default function sendAlert(
const optDW = bot.options.discordWebhook;

const sendAlertWebhook: Webhook = {
username: optDW.displayName ? optDW.displayName : botInfo.name,
avatar_url: optDW.avatarURL ? optDW.avatarURL : botInfo.avatarURL,
username: optDW.displayName || botInfo.name,
avatar_url: optDW.avatarURL || botInfo.avatarURL,
content:
([
'highValue',
Expand Down
4 changes: 2 additions & 2 deletions src/lib/DiscordWebhook/sendOfferReview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ export default function sendOfferReview(
const isShowInventory = opt.offerReview.misc.showInventory;

const webhookReview: Webhook = {
username: opt.displayName ? opt.displayName : botInfo.name,
avatar_url: opt.avatarURL ? opt.avatarURL : botInfo.avatarURL,
username: opt.displayName || botInfo.name,
avatar_url: opt.avatarURL || botInfo.avatarURL,
content: mentionOwner,
embeds: [
{
Expand Down
4 changes: 2 additions & 2 deletions src/lib/DiscordWebhook/sendPartnerMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ export default function sendPartnerMessage(
const botInfo = bot.handler.getBotInfo;

const discordPartnerMsg: Webhook = {
username: opt.displayName ? opt.displayName : botInfo.name,
avatar_url: opt.avatarURL ? opt.avatarURL : botInfo.avatarURL,
username: opt.displayName || botInfo.name,
avatar_url: opt.avatarURL || botInfo.avatarURL,
content: `${
opt.messages.isMention && opt.ownerID.length > 0 ? opt.ownerID.map(id => `<@!${id}>`).join(', ') + `, ` : ''
}new message! - ${steamID}`,
Expand Down
6 changes: 3 additions & 3 deletions src/lib/DiscordWebhook/sendStats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,14 @@ export default async function sendStats(bot: Bot, forceSend = false, steamID?: S
: '';

const discordStats: Webhook = {
username: optDW.displayName ? optDW.displayName : botInfo.name,
avatar_url: optDW.avatarURL ? optDW.avatarURL : botInfo.avatarURL,
username: optDW.displayName || botInfo.name,
avatar_url: optDW.avatarURL || botInfo.avatarURL,
content: '',
embeds: [
{
footer: {
text: `${timeNow(bot.options).time} • v${process.env.BOT_VERSION}`,
icon_url: optDW.avatarURL ? optDW.avatarURL : botInfo.avatarURL
icon_url: optDW.avatarURL || botInfo.avatarURL
},
title: '📊 Statistics 📊',
description:
Expand Down
4 changes: 2 additions & 2 deletions src/lib/DiscordWebhook/sendTf2DisplayNotification.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ export default function sendTf2DisplayNotification(bot: Bot, title: string, body
const botInfo = bot.handler.getBotInfo;

const webhook: Webhook = {
username: opt.displayName ? opt.displayName : botInfo.name,
avatar_url: opt.avatarURL ? opt.avatarURL : botInfo.avatarURL,
username: opt.displayName || botInfo.name,
avatar_url: opt.avatarURL || botInfo.avatarURL,
content: opt.sendTf2Events.displayNotification.custom.content || '',
embeds: [
{
Expand Down
4 changes: 2 additions & 2 deletions src/lib/DiscordWebhook/sendTf2ItemBroadcast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ export default function sendTf2ItemBroadcast(
const botInfo = bot.handler.getBotInfo;

const webhook: Webhook = {
username: opt.displayName ? opt.displayName : botInfo.name,
avatar_url: opt.avatarURL ? opt.avatarURL : botInfo.avatarURL,
username: opt.displayName || botInfo.name,
avatar_url: opt.avatarURL || botInfo.avatarURL,
content: opt.sendTf2Events.itemBroadcast.custom.content || '',
embeds: [
{
Expand Down
4 changes: 2 additions & 2 deletions src/lib/DiscordWebhook/sendTf2SystemMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ export default function sendTf2SystemMessage(bot: Bot, message: string): void {
const botInfo = bot.handler.getBotInfo;

const webhook: Webhook = {
username: opt.displayName ? opt.displayName : botInfo.name,
avatar_url: opt.avatarURL ? opt.avatarURL : botInfo.avatarURL,
username: opt.displayName || botInfo.name,
avatar_url: opt.avatarURL || botInfo.avatarURL,
content: opt.sendTf2Events.systemMessage.custom.content || '',
embeds: [
{
Expand Down
4 changes: 2 additions & 2 deletions src/lib/DiscordWebhook/sendTradeDeclined.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ export default async function sendTradeDeclined(

const declinedDescription = declined.reasonDescription;
const declinedTradeSummary: Webhook = {
username: optDW.displayName ?? botInfo.name,
avatar_url: optDW.avatarURL ?? optDW.avatarURL,
username: optDW.displayName || botInfo.name,
avatar_url: optDW.avatarURL || optDW.avatarURL,
content: '',
embeds: [
{
Expand Down
4 changes: 2 additions & 2 deletions src/lib/DiscordWebhook/sendTradeSummary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,8 @@ export default async function sendTradeSummary(
const isCustomPricer = bot.pricelist.isUseCustomPricer;

const acceptedTradeSummary: Webhook = {
username: optDW.displayName ? optDW.displayName : botInfo.name,
avatar_url: optDW.avatarURL ? optDW.avatarURL : botInfo.avatarURL,
username: optDW.displayName || botInfo.name,
avatar_url: optDW.avatarURL || botInfo.avatarURL,
content: mentionOwner,
embeds: [
{
Expand Down

0 comments on commit 2e766cb

Please sign in to comment.