Skip to content

Commit

Permalink
style: prettified code
Browse files Browse the repository at this point in the history
  • Loading branch information
arthurfiorette committed Sep 24, 2021
1 parent 4550707 commit 0e38623
Show file tree
Hide file tree
Showing 18 changed files with 128 additions and 57 deletions.
3 changes: 2 additions & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
node_modules
dist
build
build
/CHANGELOG.md
62 changes: 33 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,41 +31,42 @@
## 📖 About

This project is an open source initiative to host multiple steam bot accounts to trade inventory
items, automatically calculating the prices and items in each exchange sent and responding to them
at the same time, like some Trading Card Exchange bots, but with any item. We still have a lot to
improve, and that is what i'll do in the next days, Feel free to send a PR or open a new issue.
This project is an open source initiative to host multiple steam bot accounts to trade
inventory items, automatically calculating the prices and items in each exchange sent and
responding to them at the same time, like some Trading Card Exchange bots, but with any
item. We still have a lot to improve, and that is what i'll do in the next days, Feel free
to send a PR or open a new issue.

## 📁 Downloading

> _The main branch is used for development, to download the code, prefer to download a specific
> tag._
> _The main branch is used for development, to download the code, prefer to download a
> specific tag._
Open this repository
<a href="https://github.com/ArthurFiorette/steam-trader/releases" target="_blank">releases</a> tab
and download the latest source code **.zip** file.
<a href="https://github.com/ArthurFiorette/steam-trader/releases" target="_blank">releases</a>
tab and download the latest source code **.zip** file.

## ⚙️ Configuration

A `config.json` file already existed in previous versions, however, now everything is officially
configured by our panel. To access it, start the application correctly and go to localhost at the
specified port.
A `config.json` file already existed in previous versions, however, now everything is
officially configured by our panel. To access it, start the application correctly and go
to localhost at the specified port.

#### 🔐 SDA, Shared Secret and Identity Secret

To register a steam account with **steam-trader**, you need to know the `Shared Secret` and
`Identity Secret` of your account. These two secrets are responsible for the automatic generation of
the steam guard mobile code and auto reconnection.
To register a steam account with **steam-trader**, you need to know the `Shared Secret`
and `Identity Secret` of your account. These two secrets are responsible for the automatic
generation of the steam guard mobile code and auto reconnection.

To get them easily, you will need to enable
<a href="https://github.com/Jessecar96/SteamDesktopAuthenticator" target="_blank">SDA</a> on the
account and after that, you will find it
<a href="https://github.com/Jessecar96/SteamDesktopAuthenticator" target="_blank">SDA</a>
on the account and after that, you will find it
<a href="https://www.youtube.com/watch?v=JjdOJVSZ9Mo" target="_blank">here</a>.

## 🏃 Executing

You can host it docker on any hosting service that supports containerized applications or use docker
locally, simply by typing:
You can host it docker on any hosting service that supports containerized applications or
use docker locally, simply by typing:

> _For any help with docker, here are the
> <a href="https://docs.docker.com/compose/" target="_blank">docs</a>._
Expand All @@ -78,10 +79,12 @@ $ docker-compose up
$ docker-compose up -d
```

If you have no access or knowledge to use Docker, you can run it having **Node.JS** installed. As we
have a `package.json` in our root containing some scripts, all you need to do is follow these steps.
If you have no access or knowledge to use Docker, you can run it having **Node.JS**
installed. As we have a `package.json` in our root containing some scripts, all you need
to do is follow these steps.

> _Always prefer to use Docker, as this application was built based on it and is totally faster._
> _Always prefer to use Docker, as this application was built based on it and is totally
> faster._
```sh
# Install yarn and concurrently to run the next scripts.
Expand All @@ -94,15 +97,15 @@ $ npm run build
$ npm run start
```

After building and installing it for the first time, you are ready to go and you can start it every
time only running the last command.
After building and installing it for the first time, you are ready to go and you can start
it every time only running the last command.

### Security

We assume that all connections are secure and trustworthy, so we don't require any passwords. If
you're hosting it on third-party services like AWS or Azure, make sure you only allow its IP address
to connect to the web interface and server. You can also use a proxy between authenticated
connections to prevent unauthorized requests.
We assume that all connections are secure and trustworthy, so we don't require any
passwords. If you're hosting it on third-party services like AWS or Azure, make sure you
only allow its IP address to connect to the web interface and server. You can also use a
proxy between authenticated connections to prevent unauthorized requests.

## 📃 License

Expand All @@ -111,5 +114,6 @@ Licensed under the **GNU General Public License v3.0**. See

## 📧 Contact

See my contact information on my <a href="https://github.com/ArthurFiorette" target="_blank">GitHub
Profile Page</a> or open a new issue.
See my contact information on my
<a href="https://github.com/ArthurFiorette" target="_blank">GitHub Profile Page</a> or
open a new issue.
3 changes: 2 additions & 1 deletion SECURITY.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@

## Reporting a Vulnerability

**DO NOT CREATE AN ISSUE** to report a security problem. Instead, please send an email to [email protected]
**DO NOT CREATE AN ISSUE** to report a security problem. Instead, please send an email to
[email protected]
8 changes: 6 additions & 2 deletions app/src/accounts/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,13 @@ export default class Account {
this.client.on('webSession', (_sessionId: number, cookies: string[]) =>
this.onWebSession(cookies)
);
this.client.on('wallet', (_hasWallet: boolean, currency: number) => this.setCurrency(currency));
this.client.on('wallet', (_hasWallet: boolean, currency: number) =>
this.setCurrency(currency)
);
this.client.on('loggedOn', () => this.onLogin());
this.client.on('disconnected', (_eResult: number, msg: string) => this.onDisconnect(msg));
this.client.on('disconnected', (_eResult: number, msg: string) =>
this.onDisconnect(msg)
);
this.client.on('steamGuard', (_domain: any, callback: (code: string) => void) =>
callback(this.getAuthCode())
);
Expand Down
5 changes: 4 additions & 1 deletion app/src/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ function _createLogger(account: string, ..._transports: Transport[]) {
return winston.createLogger({
...levelFormat,
defaultMeta: { account },
transports: [new transports.Console({ format: combine(colorize(), cli()) }), ..._transports]
transports: [
new transports.Console({ format: combine(colorize(), cli()) }),
..._transports
]
});
}

Expand Down
10 changes: 9 additions & 1 deletion app/src/server/routes/users.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
import { json, Router } from 'express';
import { create, edit, getAll, getByName, login, logout, remove } from '../../accounts/controller';
import {
create,
edit,
getAll,
getByName,
login,
logout,
remove
} from '../../accounts/controller';

const router = Router();

Expand Down
10 changes: 8 additions & 2 deletions app/src/steam/market.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,20 @@ export function getItemName({ market_name, market_hash_name, name }: Item) {
return name;
}

function parseData({ success, lowest_price, median_price }: any, { parse }: ICurrency): ItemPrice {
function parseData(
{ success, lowest_price, median_price }: any,
{ parse }: ICurrency
): ItemPrice {
return {
success,
lowest_price: parse(lowest_price),
median_price: median_price ? parse(median_price) : undefined
};
}

export async function getAllItemsPrice(items: Item[], currency?: ICurrency): Promise<ItemPrice[]> {
export async function getAllItemsPrice(
items: Item[],
currency?: ICurrency
): Promise<ItemPrice[]> {
return Promise.all(items.map((item) => getItemPrice(item, currency)));
}
8 changes: 6 additions & 2 deletions app/src/storage/accounts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ async function checkAccountOptions(options: AccountOptions[]) {

async function handleInvalidAccountFile() {
const newName = `accounts-invalid-${new Date().getTime()}.json`;
logger.error(`Invalid accounts.json, Renaming it to ${newName} and creating a new empty one...`);
logger.error(
`Invalid accounts.json, Renaming it to ${newName} and creating a new empty one...`
);
await fs.rename(accountsPath, join(configPath, newName));
await createAccountFileIfNeeded();
}
Expand All @@ -47,7 +49,9 @@ async function createAccountFileIfNeeded() {
fs
.writeFile(accountsPath, '[]')
.catch((err) =>
logger.error(`Occurred an error while creating the config/accounts.json: ${err}`)
logger.error(
`Occurred an error while creating the config/accounts.json: ${err}`
)
)
);
}
4 changes: 3 additions & 1 deletion app/src/storage/logs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ function getPath(...paths: string[]) {
fs.mkdir(getPath()).catch(() => {});

function getDate(fileName: string) {
return fileName !== 'system' ? '' : `-${new Date().toLocaleDateString().replace(/\//gi, '')}`;
return fileName !== 'system'
? ''
: `-${new Date().toLocaleDateString().replace(/\//gi, '')}`;
}

export function getFileTransport(fileName: string) {
Expand Down
23 changes: 19 additions & 4 deletions app/src/storage/trades.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ import { simplifyOffer } from './util';
const filePath = path.resolve(__dirname, `../../output/trades/`);
fs.mkdir(filePath).catch(() => {});

export async function writeOffer(context: OfferContext, reason: string, accepted: boolean) {
export async function writeOffer(
context: OfferContext,
reason: string,
accepted: boolean
) {
const account = context.processor.account.options.login.username;

context.processor.account.logger.debug(`Saving transaction ${context.id}`);
Expand All @@ -18,11 +22,22 @@ export async function writeOffer(context: OfferContext, reason: string, accepted
);
}

export async function emitOffer(context: OfferContext, reason: string, accepted: boolean) {
export async function emitOffer(
context: OfferContext,
reason: string,
accepted: boolean
) {
const account = context.processor.account.options.login.username;
io.emit('trade', simplifyOffer({ account, context, reason, accepted, mapItems: true }));
}

export async function saveOffer(context: OfferContext, reason: string, accepted: boolean) {
return Promise.all([writeOffer(context, reason, accepted), emitOffer(context, reason, accepted)]);
export async function saveOffer(
context: OfferContext,
reason: string,
accepted: boolean
) {
return Promise.all([
writeOffer(context, reason, accepted),
emitOffer(context, reason, accepted)
]);
}
8 changes: 7 additions & 1 deletion app/src/storage/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,13 @@ type simplifyOptions = {
mapItems: boolean;
};

export function simplifyOffer({ account, context, reason, accepted, mapItems }: simplifyOptions) {
export function simplifyOffer({
account,
context,
reason,
accepted,
mapItems
}: simplifyOptions) {
const { partner, id: offerId, itemsToGive, itemsToReceive, profit } = context;
return {
account,
Expand Down
7 changes: 2 additions & 5 deletions app/src/transactions/logic/calculatePrices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,9 @@ import { ItemPrice, OfferContext } from '../types';
export default async function middleware(context: OfferContext, next: NextFunction) {
const { processor, itemsToReceive, itemsToGive } = context;
const { options } = processor.account;
const currency = Currency[options.status.currency || 'USD']
const currency = Currency[options.status.currency || 'USD'];

context.receiveItemsPrices = await getAllItemsPrice(
itemsToReceive,
currency
);
context.receiveItemsPrices = await getAllItemsPrice(itemsToReceive, currency);

if (context.receiveItemsPrices.some((item) => isTrash(item, options))) {
processor.decline(context, Reason.TRASH);
Expand Down
6 changes: 5 additions & 1 deletion web/src/components/accounts/account.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import React, { useEffect, useState } from 'react';
import { Person, Power } from 'react-bootstrap-icons';
import { getAccount, login as loginAcc, logout as logoutAcc } from '../../services/accounts';
import {
getAccount,
login as loginAcc,
logout as logoutAcc
} from '../../services/accounts';
import socket from '../../services/socket';
import { AccountOptions } from '../../types';
import { ColoredButton, ColoredIconButton } from '../button';
Expand Down
4 changes: 3 additions & 1 deletion web/src/components/accounts/forms/edit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ export const EditForm = (({ data = emptyAccount() }) => {
};

const onChangeFactory = (cb: (val: any) => any) => {
return ({ target: { type, checked, value } }: React.ChangeEvent<HTMLInputElement>) => {
return ({
target: { type, checked, value }
}: React.ChangeEvent<HTMLInputElement>) => {
cb(type === 'checkbox' ? checked : value);
setData({ login, status, trading });
};
Expand Down
4 changes: 3 additions & 1 deletion web/src/components/accounts/forms/login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ export const LoginForm = (({}) => {
};

const onChangeFactory = (cb: (val: any) => any) => {
return ({ target: { type, checked, value } }: React.ChangeEvent<HTMLInputElement>) => {
return ({
target: { type, checked, value }
}: React.ChangeEvent<HTMLInputElement>) => {
cb(type === 'checkbox' ? checked : value);
setData({ login, status, trading });
};
Expand Down
6 changes: 5 additions & 1 deletion web/src/components/button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@ const ButtonTemplate = (({ children, classes, ...props }) => {

export const CloseButton = (({ classes, ariaLabel = 'Close', children, ...props }) => {
return (
<ButtonTemplate classes={`btn-close text-reset ${classes}`} {...props} aria-label={ariaLabel}>
<ButtonTemplate
classes={`btn-close text-reset ${classes}`}
{...props}
aria-label={ariaLabel}
>
{children}
</ButtonTemplate>
);
Expand Down
6 changes: 5 additions & 1 deletion web/src/components/offcanvas.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ import { CloseButton } from './button';

export const Offcanvas = (({ id, title, children }) => {
return (
<div className="offcanvas offcanvas-start" id={id} aria-labelledby={`${id}-offcanvasLabel`}>
<div
className="offcanvas offcanvas-start"
id={id}
aria-labelledby={`${id}-offcanvasLabel`}
>
<div className="offcanvas-header pb-2">
<h5 className="offcanvas-title" id={`${id}-offcanvasLabel`}>
{title}
Expand Down
8 changes: 6 additions & 2 deletions web/src/components/trades/items.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ const ItemPicture = (({ item, received }) => {
return (
<li className="list-inline-item m-0">
<img
className={`alert shadow-sm border-2 alert-${received ? 'success' : 'danger'} p-1 m-1`}
className={`alert shadow-sm border-2 alert-${
received ? 'success' : 'danger'
} p-1 m-1`}
src={getImageUrl(item)}
alt={name}
height="50px"
Expand All @@ -40,7 +42,9 @@ const EmptyItemPicture = (({ received }) => {
return (
<li className="list-inline-item m-0">
<img
className={`alert shadow-sm border-2 alert-${received ? 'success' : 'danger'} p-1 m-1`}
className={`alert shadow-sm border-2 alert-${
received ? 'success' : 'danger'
} p-1 m-1`}
alt=""
src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" // Empty 1px image
height="50px"
Expand Down

0 comments on commit 0e38623

Please sign in to comment.