npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, πŸ‘‹, I’m Ryan HefnerΒ  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you πŸ™

Β© 2024 – Pkg Stats / Ryan Hefner

@automatedtf/reactor

v0.0.9

Published

### πŸ“– Table of Contents - [πŸ‘‹ Introduction](#-introduction) - [πŸ”Œ Getting Started](#-getting-started) - [✨ Events](#-events) - [πŸ’Ž What can it be used for?](#-what-can-it-be-used-for) - [Single Instance Bots](#single-instance-bots) - [Distributed

Downloads

22

Readme

@automatedtf/reactor

πŸ“– Table of Contents

πŸ‘‹ Introduction

Reactor offers a standardised Steam API event sourcer implementation and interface for events and changes on a Steam user account. Updates are polled on a regular basis via Dr. McKay's node-steam-user and node-steam-tradeoffermanager and are emitted as events for applications to process and act upon via callback.

This abstraction simplifies worrying about the code to get a 'Steam bot' running, decoupling it away from the logic of other applications within a Steam-related automated system using Steam accounts.

πŸ”Œ Getting Started

You can install the npm package using the following command:

$ npm install @automatedtf/reactor

Most applications that will use @automatedtf/reactor will follow the below structure to subscribe to different events and some sort of callback function.

require("dotenv").config();
import { serialiseData, SteamEvents, SteamReactor } from '@automatedtf/reactor';

// Set up bot
const bot = new SteamReactor({
    steamid: process.env.STEAMID,
    accountName: process.env.ACCOUNT_NAME,
    password: process.env.ACCOUNT_PASSWORD,
    sharedSecret: process.env.SHARED_SECRET,
    identitySecret: process.env.IDENTITY_SECRET,
    logonID: process.env.LOGON_ID ? parseInt(process.env.LOGON_ID) : undefined
});

// Hook onto "OnLogin" event
bot.on(SteamEvents.OnLogin, () => {
    console.log("Bot has logged in!");
});

We will require the following environment variables within the application's .env file:

ACCOUNT_NAME=???
ACCOUNT_PASSWORD=???
SHARED_SECRET=???
IDENTITY_SECRET=???
STEAMID=???

The following can be optionally added:

PLAYING_GAME_NAME=???
LOGON_ID=??? # e.g 336162

✨ Events

All events are defined under the enum SteamEvents. Using the bot.on(event, callback) pattern to subscribe to a SteamEvents event will immediately provide the following type data within your IDE for your callback function.

OnError

Emitted when an error has occurred.

  • error: Error - Error object of the error

OnLogin

Emitted when the bot instance has logged into Steam's web client. No new information is learnt so none returned.

OnWebSessionJoin

Emitted when the bot has connected to a Steam web session.

  • sessionid: string
  • cookies: string[]

OnLogout

Emitted when the bot instance has logged out of Steam's web client

  • eresult: number
  • msg?: string

OnNewTrade

Emitted when the bot instance receives a new trade offer

  • offer: TradeOffer

OnTradeSent

Emitted when a trade offer from the bot has been sent out

  • offer: TradeOffer

OnSentTradeCompleted

Emitted when a trade offer sent out from the bot has been accepted and confirmed.

  • offer: AcceptedTradeOffer

OnIncomingTradeCompleted

Emitted when an incoming trade offer to the bot has been accepted and confirmed.

  • offer: AcceptedTradeOffer

OnTradeFailed

Emitted when any trade offer (incoming or sent) has not been accepted and can't be reacted upon further.

  • offer: TradeOffer

OnChatMessage

Emitted when a chat message was received from another user.

  • steamid: string
  • message: string

OnFriendRequest

Emitted when a user has chosen to send a friend request to the bot.

  • steamid: string

πŸ’Ž What can it be used for?

The SteamReactor class extends from an EventEmitter and can be used to subscribe to events and perform callback functions when those events are triggered. The callback functions can hook into a SteamUser instance via the user property, or into a SteamTradeOfferManager instance via the tradeManager property.

The intricate setup and maintenance for a bot is handled by this library, meaning that one can have a bot instance that starts publishing new events immediately from startup. This can be utilised in a number of ways.

Single Instance Bots

By applying on handlers within index.ts, one can easily use @automatedtf/reactor as a foundation for their own bot with more features.

// index.ts

require("dotenv").config();
import { serialiseData, SteamEvents, SteamReactor } from '@automatedtf/reactor';

// Set up bot
const bot = new SteamReactor({
    steamid: process.env.STEAMID,
    accountName: process.env.ACCOUNT_NAME,
    password: process.env.ACCOUNT_PASSWORD,
    sharedSecret: process.env.SHARED_SECRET,
    logonID: process.env.LOGON_ID ? parseInt(process.env.LOGON_ID) : undefined
});

// Hook onto "OnLogin" event
bot.on(SteamEvents.OnLogin, () => {
    console.log("Bot has logged in!");

    // interact with steam via bot.user or bot.tradeManager!
});
Applications
  • Donation bot
  • Backpack.tf classifieds bot
  • Chat message bot

Distributed Systems

The feature of pushing events to an upstream means that events can be propogated towards an inter-application event handler living somewhere else - think Kubernetes. This provides scalability, especially when event processing is much more memory-consuming in contrast to event sourcing.

See Sentinel for an example of how this can be done.

Applications
  • Bot array for a Steam items trading website
  • Steam bot event monitoring and logging to record statistics on incoming trades, chat messages etc.
  • Pub/Sub MQ to run a Discord notification, notify bot owner, perform the trade processing all as separate microservice applications