steamutils 1.2.77 → 1.2.79

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. package/SteamClient.js +52 -46
  2. package/index.js +15 -5
  3. package/package.json +1 -1
package/SteamClient.js CHANGED
@@ -168,7 +168,7 @@ function SteamClient({
168
168
  delete e.callback
169
169
  }
170
170
  })
171
- _.remove(_events, e => e.once)
171
+ _.remove(_events, e => !e || e?.once)
172
172
  }
173
173
 
174
174
  function onEvent(name, callback, once, timeout) {
@@ -1079,51 +1079,6 @@ function SteamClient({
1079
1079
  "avatar_pending_review": null
1080
1080
  }
1081
1081
  },
1082
- async friendMessage(data) {
1083
- if (!data) return
1084
- data.message_no_bbcode = data.message_no_bbcode?.replaceAll(`ː`, `:`)
1085
- data.message = data.message?.replaceAll(`ː`, `:`)
1086
- const example = {
1087
- "steamid_friend": {
1088
- "universe": 1,
1089
- "type": 1,
1090
- "instance": 1,
1091
- "accountid": 1080136620
1092
- },
1093
- "chat_entry_type": 1,
1094
- "from_limited_account": false,
1095
- "message": "xxx",
1096
- "ordinal": 0,
1097
- "local_echo": false,
1098
- "message_no_bbcode": "xxx",
1099
- "low_priority": false,
1100
- "server_timestamp": "2023-05-14T09:26:25.000Z",
1101
- "message_bbcode_parsed": [
1102
- "xxx"
1103
- ]
1104
- }
1105
- const timestamp = new Date(data.server_timestamp).getTime()
1106
- const steamId = data.steamid_friend.getSteamID64()
1107
- const personas = await getPersonas([steamId])
1108
- const player_name = personas.find(p => p.id == steamId)?.player_name || ''
1109
- const invite = [`Invited you to play a game!`, `Đã mời bạn chơi một trò chơi!`].includes(data.message_no_bbcode || data.message)
1110
- const emotion = (data.message_no_bbcode || '').split(' ').find(m => m.startsWith(':') && m.endsWith(':'))
1111
-
1112
- callEvent(events.friendMessage, {
1113
- player_name,
1114
- message: data.message_no_bbcode,
1115
- invite,
1116
- steamId,
1117
- timestamp,
1118
- from_limited_account: data.from_limited_account,
1119
- emotion,
1120
- })
1121
- },
1122
- async friendTyping(steamId, message) {
1123
- callEvent(events.friendTyping, {
1124
- steamId, message
1125
- })
1126
- },
1127
1082
  async playingState(playing_blocked, playing_app) {
1128
1083
  playingBlocked = playing_blocked
1129
1084
  if (playing_app === 0) {
@@ -1184,6 +1139,53 @@ function SteamClient({
1184
1139
  }
1185
1140
  }
1186
1141
 
1142
+ const chatEvents = {
1143
+ async friendMessage(data) {
1144
+ if (!data) return
1145
+ data.message_no_bbcode = data.message_no_bbcode?.replaceAll(`ː`, `:`)
1146
+ data.message = data.message?.replaceAll(`ː`, `:`)
1147
+ const example = {
1148
+ "steamid_friend": {
1149
+ "universe": 1,
1150
+ "type": 1,
1151
+ "instance": 1,
1152
+ "accountid": 1080136620
1153
+ },
1154
+ "chat_entry_type": 1,
1155
+ "from_limited_account": false,
1156
+ "message": "xxx",
1157
+ "ordinal": 0,
1158
+ "local_echo": false,
1159
+ "message_no_bbcode": "xxx",
1160
+ "low_priority": false,
1161
+ "server_timestamp": "2023-05-14T09:26:25.000Z",
1162
+ "message_bbcode_parsed": [
1163
+ "xxx"
1164
+ ]
1165
+ }
1166
+ const timestamp = new Date(data.server_timestamp).getTime()
1167
+ const steamId = data.steamid_friend.getSteamID64()
1168
+ const personas = await getPersonas([steamId])
1169
+ const player_name = personas.find(p => p.id == steamId)?.player_name || ''
1170
+ const invite = [`Invited you to play a game!`, `Đã mời bạn chơi một trò chơi!`].includes(data.message_no_bbcode || data.message)
1171
+ const emotion = (data.message_no_bbcode || '').split(' ').find(m => m.startsWith(':') && m.endsWith(':'))
1172
+
1173
+ callEvent(events.friendMessage, {
1174
+ player_name,
1175
+ message: data.message_no_bbcode,
1176
+ invite,
1177
+ steamId,
1178
+ timestamp,
1179
+ from_limited_account: data.from_limited_account,
1180
+ emotion,
1181
+ })
1182
+ },
1183
+ async friendTyping(steamId, message) {
1184
+ callEvent(events.friendTyping, {
1185
+ steamId, message
1186
+ })
1187
+ },
1188
+ }
1187
1189
 
1188
1190
  // steamClient.on('lobbyInvite', (inviterID, lobbyID ) => {
1189
1191
  // joinLobby(lobbyID)
@@ -1226,6 +1228,10 @@ function SteamClient({
1226
1228
  for (const name in events) {
1227
1229
  steamClient.on(name, events[name])
1228
1230
  }
1231
+
1232
+ for (const name in chatEvents) {
1233
+ steamClient.chat.on(name, chatEvents[name])
1234
+ }
1229
1235
  }
1230
1236
 
1231
1237
  function getFriendList() {
package/index.js CHANGED
@@ -15,7 +15,7 @@ import {getTableHasHeaders, table2json} from './cheerio.js'
15
15
  import {getJSObjectFronXML} from './xml2json.js'
16
16
  import axios from 'axios'
17
17
  import url from 'url'
18
- import * as cherrio from "cheerio";
18
+ import * as cheerio from "cheerio";
19
19
  import fs from "fs";
20
20
  import FormData from "form-data";
21
21
 
@@ -2427,7 +2427,7 @@ class SteamUser {
2427
2427
  }
2428
2428
 
2429
2429
  _parsePendingFriendList(html, selector) {
2430
- const $ = cherrio.load(html || '')
2430
+ const $ = cheerio.load(html || '')
2431
2431
  const data = []
2432
2432
  $(selector).each(function () {
2433
2433
  const el = $(this)
@@ -5691,7 +5691,7 @@ class SteamUser {
5691
5691
 
5692
5692
  async getTradeURL() {
5693
5693
  const result = await this._httpRequest(`${this.getMyProfileURL()}/tradeoffers/privacy`)
5694
- const $ = cherrio.load(result?.data || '')
5694
+ const $ = cheerio.load(result?.data || '')
5695
5695
  const trade_offer_access_url = $('#trade_offer_access_url').attr('value')
5696
5696
  return trade_offer_access_url
5697
5697
  }
@@ -5825,9 +5825,19 @@ class SteamUser {
5825
5825
  }
5826
5826
  const partnerSteamId = partner.split(`',`)[0].trim()
5827
5827
  let partnerName = partner.split(`', "`)[1].trim();
5828
+ const playerAvatar = $1.find('.playerAvatar')
5829
+ const avatar = playerAvatar.find('img')?.attr('src')
5830
+ const link = playerAvatar.find('a')?.attr('href')
5831
+ const header = $1.find('.tradeoffer_header').text().replaceAll(/\t/g, ' ').replaceAll(/\s+/g, ' ').trim()
5832
+ const active = $1.find('.tradeoffer_items_ctn').hasClass("active")
5833
+
5828
5834
  tradeOffers.push({
5829
5835
  tradeofferid, partner: {
5830
- steamId: partnerSteamId, name: partnerName
5836
+ steamId: partnerSteamId,
5837
+ name: partnerName,
5838
+ avatar,
5839
+ link,
5840
+ header,
5831
5841
  },
5832
5842
  })
5833
5843
  }
@@ -6061,7 +6071,7 @@ class SteamUser {
6061
6071
  url: `market/mylistings/render/?count=100`,
6062
6072
  }))?.data
6063
6073
  if (result?.success === true) {
6064
- const $ = cherrio.load(result.results_html)
6074
+ const $ = cheerio.load(result.results_html)
6065
6075
  const list = []
6066
6076
  $('.market_listing_row').each(function () {
6067
6077
  try {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "steamutils",
3
- "version": "1.2.77",
3
+ "version": "1.2.79",
4
4
  "main": "index.js",
5
5
  "dependencies": {
6
6
  "axios": "^1.5.1",