mirror of
https://github.com/TheNetsky/Microsoft-Rewards-Script.git
synced 2026-01-17 21:43:59 +00:00
Compare commits
32 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
cb3c249d8b | ||
|
|
d76106d3cc | ||
|
|
f5c7ff4907 | ||
|
|
d6d3b05836 | ||
|
|
ba4155bf3f | ||
|
|
03aa7f167f | ||
|
|
a37d60a9df | ||
|
|
2738c85030 | ||
|
|
bd96aeb20c | ||
|
|
996d9485cd | ||
|
|
6b6028bb52 | ||
|
|
368417c5d8 | ||
|
|
49b607d78c | ||
|
|
8c8bdaf3e5 | ||
|
|
7f0da3098d | ||
|
|
398c6db4ad | ||
|
|
169faf2b70 | ||
|
|
8e9c6308d5 | ||
|
|
b2ed289bba | ||
|
|
2c413dad99 | ||
|
|
5aa05804be | ||
|
|
3c1778a7e5 | ||
|
|
b78cea16ae | ||
|
|
a9e5693b71 | ||
|
|
2a8ab7242f | ||
|
|
f2d00225c9 | ||
|
|
abd6117db3 | ||
|
|
4d928d7dd9 | ||
|
|
dc7e122bce | ||
|
|
3e499be8a9 | ||
|
|
554227e200 | ||
|
|
15f62963f8 |
3
.eslintignore
Normal file
3
.eslintignore
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
dist/
|
||||||
|
node_modules/
|
||||||
|
setup/
|
||||||
@@ -16,10 +16,7 @@ module.exports = {
|
|||||||
'@typescript-eslint'
|
'@typescript-eslint'
|
||||||
],
|
],
|
||||||
'rules': {
|
'rules': {
|
||||||
'linebreak-style': [
|
'linebreak-style': 'off',
|
||||||
'error',
|
|
||||||
'unix'
|
|
||||||
],
|
|
||||||
'quotes': [
|
'quotes': [
|
||||||
'error',
|
'error',
|
||||||
'single'
|
'single'
|
||||||
|
|||||||
28
.eslintrc.json
Normal file
28
.eslintrc.json
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
{
|
||||||
|
"root": true,
|
||||||
|
"env": {
|
||||||
|
"es2021": true,
|
||||||
|
"node": true
|
||||||
|
},
|
||||||
|
"parser": "@typescript-eslint/parser",
|
||||||
|
"parserOptions": {
|
||||||
|
"project": ["./tsconfig.json"],
|
||||||
|
"sourceType": "module",
|
||||||
|
"ecmaVersion": 2021
|
||||||
|
},
|
||||||
|
"plugins": ["@typescript-eslint", "modules-newline"],
|
||||||
|
"extends": [
|
||||||
|
"eslint:recommended",
|
||||||
|
"plugin:@typescript-eslint/recommended"
|
||||||
|
],
|
||||||
|
"rules": {
|
||||||
|
"modules-newline/import-declaration-newline": ["warn", { "count": 3 }],
|
||||||
|
"@typescript-eslint/consistent-type-imports": ["warn", { "prefer": "type-imports" }],
|
||||||
|
"@typescript-eslint/no-unused-vars": ["warn", { "argsIgnorePattern": "^_", "varsIgnorePattern": "^_" }],
|
||||||
|
"@typescript-eslint/no-explicit-any": "off",
|
||||||
|
"no-console": ["warn", { "allow": ["error", "warn"] }],
|
||||||
|
"quotes": ["error", "double", { "avoidEscape": true }],
|
||||||
|
"linebreak-style": "off"
|
||||||
|
},
|
||||||
|
"ignorePatterns": ["dist/**", "node_modules/**", "setup/**"]
|
||||||
|
}
|
||||||
7
.gitignore
vendored
7
.gitignore
vendored
@@ -1,9 +1,12 @@
|
|||||||
sessions/
|
sessions/
|
||||||
dist/
|
dist/
|
||||||
node_modules/
|
node_modules/
|
||||||
package-lock.json
|
.vscode/
|
||||||
|
.github/
|
||||||
|
diagnostic/
|
||||||
|
report/
|
||||||
accounts.json
|
accounts.json
|
||||||
notes
|
notes
|
||||||
accounts.dev.json
|
accounts.dev.json
|
||||||
accounts.main.json
|
|
||||||
.DS_Store
|
.DS_Store
|
||||||
|
.playwright-chromium-installed
|
||||||
105
Dockerfile
105
Dockerfile
@@ -1,67 +1,90 @@
|
|||||||
###############################################################################
|
###############################################################################
|
||||||
# Stage 1: Builder (compile TypeScript)
|
# Stage 1: Builder
|
||||||
###############################################################################
|
###############################################################################
|
||||||
FROM node:18-slim AS builder
|
FROM node:22-slim AS builder
|
||||||
|
|
||||||
WORKDIR /usr/src/microsoft-rewards-script
|
WORKDIR /usr/src/microsoft-rewards-script
|
||||||
|
|
||||||
# Install minimal tooling if needed
|
ENV PLAYWRIGHT_BROWSERS_PATH=0
|
||||||
RUN apt-get update \
|
|
||||||
&& apt-get install -y --no-install-recommends ca-certificates \
|
|
||||||
&& rm -rf /var/lib/apt/lists/*
|
|
||||||
|
|
||||||
# Copy package manifests
|
# Copy package files
|
||||||
COPY package*.json ./
|
COPY package.json package-lock.json tsconfig.json ./
|
||||||
|
|
||||||
# Conditional install: npm ci if lockfile exists, else npm install
|
# Install all dependencies required to build the script
|
||||||
RUN if [ -f package-lock.json ]; then \
|
RUN npm ci --ignore-scripts
|
||||||
npm ci; \
|
|
||||||
else \
|
|
||||||
npm install; \
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Copy source code
|
# Copy source and build
|
||||||
COPY . .
|
COPY . .
|
||||||
|
|
||||||
# Build TypeScript
|
|
||||||
RUN npm run build
|
RUN npm run build
|
||||||
|
|
||||||
|
# Remove build dependencies, and reinstall only runtime dependencies
|
||||||
|
RUN rm -rf node_modules \
|
||||||
|
&& npm ci --omit=dev --ignore-scripts \
|
||||||
|
&& npm cache clean --force
|
||||||
|
|
||||||
|
# Install Chromium Headless Shell, and cleanup
|
||||||
|
RUN npx playwright install --with-deps --only-shell chromium \
|
||||||
|
&& rm -rf /root/.cache /tmp/* /var/tmp/*
|
||||||
|
|
||||||
###############################################################################
|
###############################################################################
|
||||||
# Stage 2: Runtime (Playwright image)
|
# Stage 2: Runtime
|
||||||
###############################################################################
|
###############################################################################
|
||||||
FROM mcr.microsoft.com/playwright:v1.52.0-jammy
|
FROM node:22-slim AS runtime
|
||||||
|
|
||||||
WORKDIR /usr/src/microsoft-rewards-script
|
WORKDIR /usr/src/microsoft-rewards-script
|
||||||
|
|
||||||
# Install cron, gettext-base (for envsubst), tzdata noninteractively
|
# Set production environment variables
|
||||||
RUN apt-get update \
|
ENV NODE_ENV=production \
|
||||||
&& DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
|
TZ=UTC \
|
||||||
cron gettext-base tzdata \
|
PLAYWRIGHT_BROWSERS_PATH=0 \
|
||||||
&& rm -rf /var/lib/apt/lists/*
|
FORCE_HEADLESS=1
|
||||||
|
|
||||||
# Ensure Playwright uses preinstalled browsers
|
# Install minimal system libraries required for Chromium headless to run
|
||||||
ENV PLAYWRIGHT_BROWSERS_PATH=/ms-playwright
|
RUN apt-get update && apt-get install -y --no-install-recommends \
|
||||||
|
cron \
|
||||||
|
gettext-base \
|
||||||
|
tzdata \
|
||||||
|
ca-certificates \
|
||||||
|
libglib2.0-0 \
|
||||||
|
libdbus-1-3 \
|
||||||
|
libexpat1 \
|
||||||
|
libfontconfig1 \
|
||||||
|
libgtk-3-0 \
|
||||||
|
libnspr4 \
|
||||||
|
libnss3 \
|
||||||
|
libasound2 \
|
||||||
|
libflac12 \
|
||||||
|
libatk1.0-0 \
|
||||||
|
libatspi2.0-0 \
|
||||||
|
libdrm2 \
|
||||||
|
libgbm1 \
|
||||||
|
libdav1d6 \
|
||||||
|
libx11-6 \
|
||||||
|
libx11-xcb1 \
|
||||||
|
libxcomposite1 \
|
||||||
|
libxcursor1 \
|
||||||
|
libxdamage1 \
|
||||||
|
libxext6 \
|
||||||
|
libxfixes3 \
|
||||||
|
libxi6 \
|
||||||
|
libxrandr2 \
|
||||||
|
libxrender1 \
|
||||||
|
libxss1 \
|
||||||
|
libxtst6 \
|
||||||
|
libdouble-conversion3 \
|
||||||
|
&& rm -rf /var/lib/apt/lists/* /var/cache/apt/archives/*
|
||||||
|
|
||||||
# Copy package files first for better caching
|
# Copy compiled application and dependencies from builder stage
|
||||||
COPY --from=builder /usr/src/microsoft-rewards-script/package*.json ./
|
|
||||||
|
|
||||||
# Install only production dependencies, with fallback
|
|
||||||
RUN if [ -f package-lock.json ]; then \
|
|
||||||
npm ci --omit=dev --ignore-scripts; \
|
|
||||||
else \
|
|
||||||
npm install --production --ignore-scripts; \
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Copy built application
|
|
||||||
COPY --from=builder /usr/src/microsoft-rewards-script/dist ./dist
|
COPY --from=builder /usr/src/microsoft-rewards-script/dist ./dist
|
||||||
|
COPY --from=builder /usr/src/microsoft-rewards-script/package*.json ./
|
||||||
|
COPY --from=builder /usr/src/microsoft-rewards-script/node_modules ./node_modules
|
||||||
|
|
||||||
# Copy runtime scripts with proper permissions from the start
|
# Copy runtime scripts with proper permissions and normalize line endings for non-Unix users
|
||||||
COPY --chmod=755 src/run_daily.sh ./src/run_daily.sh
|
COPY --chmod=755 src/run_daily.sh ./src/run_daily.sh
|
||||||
COPY --chmod=644 src/crontab.template /etc/cron.d/microsoft-rewards-cron.template
|
COPY --chmod=644 src/crontab.template /etc/cron.d/microsoft-rewards-cron.template
|
||||||
COPY --chmod=755 entrypoint.sh /usr/local/bin/entrypoint.sh
|
COPY --chmod=755 entrypoint.sh /usr/local/bin/entrypoint.sh
|
||||||
|
RUN sed -i 's/\r$//' /usr/local/bin/entrypoint.sh \
|
||||||
# Default TZ (overridden by user via environment)
|
&& sed -i 's/\r$//' ./src/run_daily.sh
|
||||||
ENV TZ=UTC
|
|
||||||
|
|
||||||
# Entrypoint handles TZ, initial run toggle, cron templating & launch
|
# Entrypoint handles TZ, initial run toggle, cron templating & launch
|
||||||
ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]
|
ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]
|
||||||
|
|||||||
674
LICENSE
Normal file
674
LICENSE
Normal file
@@ -0,0 +1,674 @@
|
|||||||
|
GNU GENERAL PUBLIC LICENSE
|
||||||
|
Version 3, 29 June 2007
|
||||||
|
|
||||||
|
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
||||||
|
Everyone is permitted to copy and distribute verbatim copies
|
||||||
|
of this license document, but changing it is not allowed.
|
||||||
|
|
||||||
|
Preamble
|
||||||
|
|
||||||
|
The GNU General Public License is a free, copyleft license for
|
||||||
|
software and other kinds of works.
|
||||||
|
|
||||||
|
The licenses for most software and other practical works are designed
|
||||||
|
to take away your freedom to share and change the works. By contrast,
|
||||||
|
the GNU General Public License is intended to guarantee your freedom to
|
||||||
|
share and change all versions of a program--to make sure it remains free
|
||||||
|
software for all its users. We, the Free Software Foundation, use the
|
||||||
|
GNU General Public License for most of our software; it applies also to
|
||||||
|
any other work released this way by its authors. You can apply it to
|
||||||
|
your programs, too.
|
||||||
|
|
||||||
|
When we speak of free software, we are referring to freedom, not
|
||||||
|
price. Our General Public Licenses are designed to make sure that you
|
||||||
|
have the freedom to distribute copies of free software (and charge for
|
||||||
|
them if you wish), that you receive source code or can get it if you
|
||||||
|
want it, that you can change the software or use pieces of it in new
|
||||||
|
free programs, and that you know you can do these things.
|
||||||
|
|
||||||
|
To protect your rights, we need to prevent others from denying you
|
||||||
|
these rights or asking you to surrender the rights. Therefore, you have
|
||||||
|
certain responsibilities if you distribute copies of the software, or if
|
||||||
|
you modify it: responsibilities to respect the freedom of others.
|
||||||
|
|
||||||
|
For example, if you distribute copies of such a program, whether
|
||||||
|
gratis or for a fee, you must pass on to the recipients the same
|
||||||
|
freedoms that you received. You must make sure that they, too, receive
|
||||||
|
or can get the source code. And you must show them these terms so they
|
||||||
|
know their rights.
|
||||||
|
|
||||||
|
Developers that use the GNU GPL protect your rights with two steps:
|
||||||
|
(1) assert copyright on the software, and (2) offer you this License
|
||||||
|
giving you legal permission to copy, distribute and/or modify it.
|
||||||
|
|
||||||
|
For the developers' and authors' protection, the GPL clearly explains
|
||||||
|
that there is no warranty for this free software. For both users' and
|
||||||
|
authors' sake, the GPL requires that modified versions be marked as
|
||||||
|
changed, so that their problems will not be attributed erroneously to
|
||||||
|
authors of previous versions.
|
||||||
|
|
||||||
|
Some devices are designed to deny users access to install or run
|
||||||
|
modified versions of the software inside them, although the manufacturer
|
||||||
|
can do so. This is fundamentally incompatible with the aim of
|
||||||
|
protecting users' freedom to change the software. The systematic
|
||||||
|
pattern of such abuse occurs in the area of products for individuals to
|
||||||
|
use, which is precisely where it is most unacceptable. Therefore, we
|
||||||
|
have designed this version of the GPL to prohibit the practice for those
|
||||||
|
products. If such problems arise substantially in other domains, we
|
||||||
|
stand ready to extend this provision to those domains in future versions
|
||||||
|
of the GPL, as needed to protect the freedom of users.
|
||||||
|
|
||||||
|
Finally, every program is threatened constantly by software patents.
|
||||||
|
States should not allow patents to restrict development and use of
|
||||||
|
software on general-purpose computers, but in those that do, we wish to
|
||||||
|
avoid the special danger that patents applied to a free program could
|
||||||
|
make it effectively proprietary. To prevent this, the GPL assures that
|
||||||
|
patents cannot be used to render the program non-free.
|
||||||
|
|
||||||
|
The precise terms and conditions for copying, distribution and
|
||||||
|
modification follow.
|
||||||
|
|
||||||
|
TERMS AND CONDITIONS
|
||||||
|
|
||||||
|
0. Definitions.
|
||||||
|
|
||||||
|
"This License" refers to version 3 of the GNU General Public License.
|
||||||
|
|
||||||
|
"Copyright" also means copyright-like laws that apply to other kinds of
|
||||||
|
works, such as semiconductor masks.
|
||||||
|
|
||||||
|
"The Program" refers to any copyrightable work licensed under this
|
||||||
|
License. Each licensee is addressed as "you". "Licensees" and
|
||||||
|
"recipients" may be individuals or organizations.
|
||||||
|
|
||||||
|
To "modify" a work means to copy from or adapt all or part of the work
|
||||||
|
in a fashion requiring copyright permission, other than the making of an
|
||||||
|
exact copy. The resulting work is called a "modified version" of the
|
||||||
|
earlier work or a work "based on" the earlier work.
|
||||||
|
|
||||||
|
A "covered work" means either the unmodified Program or a work based
|
||||||
|
on the Program.
|
||||||
|
|
||||||
|
To "propagate" a work means to do anything with it that, without
|
||||||
|
permission, would make you directly or secondarily liable for
|
||||||
|
infringement under applicable copyright law, except executing it on a
|
||||||
|
computer or modifying a private copy. Propagation includes copying,
|
||||||
|
distribution (with or without modification), making available to the
|
||||||
|
public, and in some countries other activities as well.
|
||||||
|
|
||||||
|
To "convey" a work means any kind of propagation that enables other
|
||||||
|
parties to make or receive copies. Mere interaction with a user through
|
||||||
|
a computer network, with no transfer of a copy, is not conveying.
|
||||||
|
|
||||||
|
An interactive user interface displays "Appropriate Legal Notices"
|
||||||
|
to the extent that it includes a convenient and prominently visible
|
||||||
|
feature that (1) displays an appropriate copyright notice, and (2)
|
||||||
|
tells the user that there is no warranty for the work (except to the
|
||||||
|
extent that warranties are provided), that licensees may convey the
|
||||||
|
work under this License, and how to view a copy of this License. If
|
||||||
|
the interface presents a list of user commands or options, such as a
|
||||||
|
menu, a prominent item in the list meets this criterion.
|
||||||
|
|
||||||
|
1. Source Code.
|
||||||
|
|
||||||
|
The "source code" for a work means the preferred form of the work
|
||||||
|
for making modifications to it. "Object code" means any non-source
|
||||||
|
form of a work.
|
||||||
|
|
||||||
|
A "Standard Interface" means an interface that either is an official
|
||||||
|
standard defined by a recognized standards body, or, in the case of
|
||||||
|
interfaces specified for a particular programming language, one that
|
||||||
|
is widely used among developers working in that language.
|
||||||
|
|
||||||
|
The "System Libraries" of an executable work include anything, other
|
||||||
|
than the work as a whole, that (a) is included in the normal form of
|
||||||
|
packaging a Major Component, but which is not part of that Major
|
||||||
|
Component, and (b) serves only to enable use of the work with that
|
||||||
|
Major Component, or to implement a Standard Interface for which an
|
||||||
|
implementation is available to the public in source code form. A
|
||||||
|
"Major Component", in this context, means a major essential component
|
||||||
|
(kernel, window system, and so on) of the specific operating system
|
||||||
|
(if any) on which the executable work runs, or a compiler used to
|
||||||
|
produce the work, or an object code interpreter used to run it.
|
||||||
|
|
||||||
|
The "Corresponding Source" for a work in object code form means all
|
||||||
|
the source code needed to generate, install, and (for an executable
|
||||||
|
work) run the object code and to modify the work, including scripts to
|
||||||
|
control those activities. However, it does not include the work's
|
||||||
|
System Libraries, or general-purpose tools or generally available free
|
||||||
|
programs which are used unmodified in performing those activities but
|
||||||
|
which are not part of the work. For example, Corresponding Source
|
||||||
|
includes interface definition files associated with source files for
|
||||||
|
the work, and the source code for shared libraries and dynamically
|
||||||
|
linked subprograms that the work is specifically designed to require,
|
||||||
|
such as by intimate data communication or control flow between those
|
||||||
|
subprograms and other parts of the work.
|
||||||
|
|
||||||
|
The Corresponding Source need not include anything that users
|
||||||
|
can regenerate automatically from other parts of the Corresponding
|
||||||
|
Source.
|
||||||
|
|
||||||
|
The Corresponding Source for a work in source code form is that
|
||||||
|
same work.
|
||||||
|
|
||||||
|
2. Basic Permissions.
|
||||||
|
|
||||||
|
All rights granted under this License are granted for the term of
|
||||||
|
copyright on the Program, and are irrevocable provided the stated
|
||||||
|
conditions are met. This License explicitly affirms your unlimited
|
||||||
|
permission to run the unmodified Program. The output from running a
|
||||||
|
covered work is covered by this License only if the output, given its
|
||||||
|
content, constitutes a covered work. This License acknowledges your
|
||||||
|
rights of fair use or other equivalent, as provided by copyright law.
|
||||||
|
|
||||||
|
You may make, run and propagate covered works that you do not
|
||||||
|
convey, without conditions so long as your license otherwise remains
|
||||||
|
in force. You may convey covered works to others for the sole purpose
|
||||||
|
of having them make modifications exclusively for you, or provide you
|
||||||
|
with facilities for running those works, provided that you comply with
|
||||||
|
the terms of this License in conveying all material for which you do
|
||||||
|
not control copyright. Those thus making or running the covered works
|
||||||
|
for you must do so exclusively on your behalf, under your direction
|
||||||
|
and control, on terms that prohibit them from making any copies of
|
||||||
|
your copyrighted material outside their relationship with you.
|
||||||
|
|
||||||
|
Conveying under any other circumstances is permitted solely under
|
||||||
|
the conditions stated below. Sublicensing is not allowed; section 10
|
||||||
|
makes it unnecessary.
|
||||||
|
|
||||||
|
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
||||||
|
|
||||||
|
No covered work shall be deemed part of an effective technological
|
||||||
|
measure under any applicable law fulfilling obligations under article
|
||||||
|
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
||||||
|
similar laws prohibiting or restricting circumvention of such
|
||||||
|
measures.
|
||||||
|
|
||||||
|
When you convey a covered work, you waive any legal power to forbid
|
||||||
|
circumvention of technological measures to the extent such circumvention
|
||||||
|
is effected by exercising rights under this License with respect to
|
||||||
|
the covered work, and you disclaim any intention to limit operation or
|
||||||
|
modification of the work as a means of enforcing, against the work's
|
||||||
|
users, your or third parties' legal rights to forbid circumvention of
|
||||||
|
technological measures.
|
||||||
|
|
||||||
|
4. Conveying Verbatim Copies.
|
||||||
|
|
||||||
|
You may convey verbatim copies of the Program's source code as you
|
||||||
|
receive it, in any medium, provided that you conspicuously and
|
||||||
|
appropriately publish on each copy an appropriate copyright notice;
|
||||||
|
keep intact all notices stating that this License and any
|
||||||
|
non-permissive terms added in accord with section 7 apply to the code;
|
||||||
|
keep intact all notices of the absence of any warranty; and give all
|
||||||
|
recipients a copy of this License along with the Program.
|
||||||
|
|
||||||
|
You may charge any price or no price for each copy that you convey,
|
||||||
|
and you may offer support or warranty protection for a fee.
|
||||||
|
|
||||||
|
5. Conveying Modified Source Versions.
|
||||||
|
|
||||||
|
You may convey a work based on the Program, or the modifications to
|
||||||
|
produce it from the Program, in the form of source code under the
|
||||||
|
terms of section 4, provided that you also meet all of these conditions:
|
||||||
|
|
||||||
|
a) The work must carry prominent notices stating that you modified
|
||||||
|
it, and giving a relevant date.
|
||||||
|
|
||||||
|
b) The work must carry prominent notices stating that it is
|
||||||
|
released under this License and any conditions added under section
|
||||||
|
7. This requirement modifies the requirement in section 4 to
|
||||||
|
"keep intact all notices".
|
||||||
|
|
||||||
|
c) You must license the entire work, as a whole, under this
|
||||||
|
License to anyone who comes into possession of a copy. This
|
||||||
|
License will therefore apply, along with any applicable section 7
|
||||||
|
additional terms, to the whole of the work, and all its parts,
|
||||||
|
regardless of how they are packaged. This License gives no
|
||||||
|
permission to license the work in any other way, but it does not
|
||||||
|
invalidate such permission if you have separately received it.
|
||||||
|
|
||||||
|
d) If the work has interactive user interfaces, each must display
|
||||||
|
Appropriate Legal Notices; however, if the Program has interactive
|
||||||
|
interfaces that do not display Appropriate Legal Notices, your
|
||||||
|
work need not make them do so.
|
||||||
|
|
||||||
|
A compilation of a covered work with other separate and independent
|
||||||
|
works, which are not by their nature extensions of the covered work,
|
||||||
|
and which are not combined with it such as to form a larger program,
|
||||||
|
in or on a volume of a storage or distribution medium, is called an
|
||||||
|
"aggregate" if the compilation and its resulting copyright are not
|
||||||
|
used to limit the access or legal rights of the compilation's users
|
||||||
|
beyond what the individual works permit. Inclusion of a covered work
|
||||||
|
in an aggregate does not cause this License to apply to the other
|
||||||
|
parts of the aggregate.
|
||||||
|
|
||||||
|
6. Conveying Non-Source Forms.
|
||||||
|
|
||||||
|
You may convey a covered work in object code form under the terms
|
||||||
|
of sections 4 and 5, provided that you also convey the
|
||||||
|
machine-readable Corresponding Source under the terms of this License,
|
||||||
|
in one of these ways:
|
||||||
|
|
||||||
|
a) Convey the object code in, or embodied in, a physical product
|
||||||
|
(including a physical distribution medium), accompanied by the
|
||||||
|
Corresponding Source fixed on a durable physical medium
|
||||||
|
customarily used for software interchange.
|
||||||
|
|
||||||
|
b) Convey the object code in, or embodied in, a physical product
|
||||||
|
(including a physical distribution medium), accompanied by a
|
||||||
|
written offer, valid for at least three years and valid for as
|
||||||
|
long as you offer spare parts or customer support for that product
|
||||||
|
model, to give anyone who possesses the object code either (1) a
|
||||||
|
copy of the Corresponding Source for all the software in the
|
||||||
|
product that is covered by this License, on a durable physical
|
||||||
|
medium customarily used for software interchange, for a price no
|
||||||
|
more than your reasonable cost of physically performing this
|
||||||
|
conveying of source, or (2) access to copy the
|
||||||
|
Corresponding Source from a network server at no charge.
|
||||||
|
|
||||||
|
c) Convey individual copies of the object code with a copy of the
|
||||||
|
written offer to provide the Corresponding Source. This
|
||||||
|
alternative is allowed only occasionally and noncommercially, and
|
||||||
|
only if you received the object code with such an offer, in accord
|
||||||
|
with subsection 6b.
|
||||||
|
|
||||||
|
d) Convey the object code by offering access from a designated
|
||||||
|
place (gratis or for a charge), and offer equivalent access to the
|
||||||
|
Corresponding Source in the same way through the same place at no
|
||||||
|
further charge. You need not require recipients to copy the
|
||||||
|
Corresponding Source along with the object code. If the place to
|
||||||
|
copy the object code is a network server, the Corresponding Source
|
||||||
|
may be on a different server (operated by you or a third party)
|
||||||
|
that supports equivalent copying facilities, provided you maintain
|
||||||
|
clear directions next to the object code saying where to find the
|
||||||
|
Corresponding Source. Regardless of what server hosts the
|
||||||
|
Corresponding Source, you remain obligated to ensure that it is
|
||||||
|
available for as long as needed to satisfy these requirements.
|
||||||
|
|
||||||
|
e) Convey the object code using peer-to-peer transmission, provided
|
||||||
|
you inform other peers where the object code and Corresponding
|
||||||
|
Source of the work are being offered to the general public at no
|
||||||
|
charge under subsection 6d.
|
||||||
|
|
||||||
|
A separable portion of the object code, whose source code is excluded
|
||||||
|
from the Corresponding Source as a System Library, need not be
|
||||||
|
included in conveying the object code work.
|
||||||
|
|
||||||
|
A "User Product" is either (1) a "consumer product", which means any
|
||||||
|
tangible personal property which is normally used for personal, family,
|
||||||
|
or household purposes, or (2) anything designed or sold for incorporation
|
||||||
|
into a dwelling. In determining whether a product is a consumer product,
|
||||||
|
doubtful cases shall be resolved in favor of coverage. For a particular
|
||||||
|
product received by a particular user, "normally used" refers to a
|
||||||
|
typical or common use of that class of product, regardless of the status
|
||||||
|
of the particular user or of the way in which the particular user
|
||||||
|
actually uses, or expects or is expected to use, the product. A product
|
||||||
|
is a consumer product regardless of whether the product has substantial
|
||||||
|
commercial, industrial or non-consumer uses, unless such uses represent
|
||||||
|
the only significant mode of use of the product.
|
||||||
|
|
||||||
|
"Installation Information" for a User Product means any methods,
|
||||||
|
procedures, authorization keys, or other information required to install
|
||||||
|
and execute modified versions of a covered work in that User Product from
|
||||||
|
a modified version of its Corresponding Source. The information must
|
||||||
|
suffice to ensure that the continued functioning of the modified object
|
||||||
|
code is in no case prevented or interfered with solely because
|
||||||
|
modification has been made.
|
||||||
|
|
||||||
|
If you convey an object code work under this section in, or with, or
|
||||||
|
specifically for use in, a User Product, and the conveying occurs as
|
||||||
|
part of a transaction in which the right of possession and use of the
|
||||||
|
User Product is transferred to the recipient in perpetuity or for a
|
||||||
|
fixed term (regardless of how the transaction is characterized), the
|
||||||
|
Corresponding Source conveyed under this section must be accompanied
|
||||||
|
by the Installation Information. But this requirement does not apply
|
||||||
|
if neither you nor any third party retains the ability to install
|
||||||
|
modified object code on the User Product (for example, the work has
|
||||||
|
been installed in ROM).
|
||||||
|
|
||||||
|
The requirement to provide Installation Information does not include a
|
||||||
|
requirement to continue to provide support service, warranty, or updates
|
||||||
|
for a work that has been modified or installed by the recipient, or for
|
||||||
|
the User Product in which it has been modified or installed. Access to a
|
||||||
|
network may be denied when the modification itself materially and
|
||||||
|
adversely affects the operation of the network or violates the rules and
|
||||||
|
protocols for communication across the network.
|
||||||
|
|
||||||
|
Corresponding Source conveyed, and Installation Information provided,
|
||||||
|
in accord with this section must be in a format that is publicly
|
||||||
|
documented (and with an implementation available to the public in
|
||||||
|
source code form), and must require no special password or key for
|
||||||
|
unpacking, reading or copying.
|
||||||
|
|
||||||
|
7. Additional Terms.
|
||||||
|
|
||||||
|
"Additional permissions" are terms that supplement the terms of this
|
||||||
|
License by making exceptions from one or more of its conditions.
|
||||||
|
Additional permissions that are applicable to the entire Program shall
|
||||||
|
be treated as though they were included in this License, to the extent
|
||||||
|
that they are valid under applicable law. If additional permissions
|
||||||
|
apply only to part of the Program, that part may be used separately
|
||||||
|
under those permissions, but the entire Program remains governed by
|
||||||
|
this License without regard to the additional permissions.
|
||||||
|
|
||||||
|
When you convey a copy of a covered work, you may at your option
|
||||||
|
remove any additional permissions from that copy, or from any part of
|
||||||
|
it. (Additional permissions may be written to require their own
|
||||||
|
removal in certain cases when you modify the work.) You may place
|
||||||
|
additional permissions on material, added by you to a covered work,
|
||||||
|
for which you have or can give appropriate copyright permission.
|
||||||
|
|
||||||
|
Notwithstanding any other provision of this License, for material you
|
||||||
|
add to a covered work, you may (if authorized by the copyright holders of
|
||||||
|
that material) supplement the terms of this License with terms:
|
||||||
|
|
||||||
|
a) Disclaiming warranty or limiting liability differently from the
|
||||||
|
terms of sections 15 and 16 of this License; or
|
||||||
|
|
||||||
|
b) Requiring preservation of specified reasonable legal notices or
|
||||||
|
author attributions in that material or in the Appropriate Legal
|
||||||
|
Notices displayed by works containing it; or
|
||||||
|
|
||||||
|
c) Prohibiting misrepresentation of the origin of that material, or
|
||||||
|
requiring that modified versions of such material be marked in
|
||||||
|
reasonable ways as different from the original version; or
|
||||||
|
|
||||||
|
d) Limiting the use for publicity purposes of names of licensors or
|
||||||
|
authors of the material; or
|
||||||
|
|
||||||
|
e) Declining to grant rights under trademark law for use of some
|
||||||
|
trade names, trademarks, or service marks; or
|
||||||
|
|
||||||
|
f) Requiring indemnification of licensors and authors of that
|
||||||
|
material by anyone who conveys the material (or modified versions of
|
||||||
|
it) with contractual assumptions of liability to the recipient, for
|
||||||
|
any liability that these contractual assumptions directly impose on
|
||||||
|
those licensors and authors.
|
||||||
|
|
||||||
|
All other non-permissive additional terms are considered "further
|
||||||
|
restrictions" within the meaning of section 10. If the Program as you
|
||||||
|
received it, or any part of it, contains a notice stating that it is
|
||||||
|
governed by this License along with a term that is a further
|
||||||
|
restriction, you may remove that term. If a license document contains
|
||||||
|
a further restriction but permits relicensing or conveying under this
|
||||||
|
License, you may add to a covered work material governed by the terms
|
||||||
|
of that license document, provided that the further restriction does
|
||||||
|
not survive such relicensing or conveying.
|
||||||
|
|
||||||
|
If you add terms to a covered work in accord with this section, you
|
||||||
|
must place, in the relevant source files, a statement of the
|
||||||
|
additional terms that apply to those files, or a notice indicating
|
||||||
|
where to find the applicable terms.
|
||||||
|
|
||||||
|
Additional terms, permissive or non-permissive, may be stated in the
|
||||||
|
form of a separately written license, or stated as exceptions;
|
||||||
|
the above requirements apply either way.
|
||||||
|
|
||||||
|
8. Termination.
|
||||||
|
|
||||||
|
You may not propagate or modify a covered work except as expressly
|
||||||
|
provided under this License. Any attempt otherwise to propagate or
|
||||||
|
modify it is void, and will automatically terminate your rights under
|
||||||
|
this License (including any patent licenses granted under the third
|
||||||
|
paragraph of section 11).
|
||||||
|
|
||||||
|
However, if you cease all violation of this License, then your
|
||||||
|
license from a particular copyright holder is reinstated (a)
|
||||||
|
provisionally, unless and until the copyright holder explicitly and
|
||||||
|
finally terminates your license, and (b) permanently, if the copyright
|
||||||
|
holder fails to notify you of the violation by some reasonable means
|
||||||
|
prior to 60 days after the cessation.
|
||||||
|
|
||||||
|
Moreover, your license from a particular copyright holder is
|
||||||
|
reinstated permanently if the copyright holder notifies you of the
|
||||||
|
violation by some reasonable means, this is the first time you have
|
||||||
|
received notice of violation of this License (for any work) from that
|
||||||
|
copyright holder, and you cure the violation prior to 30 days after
|
||||||
|
your receipt of the notice.
|
||||||
|
|
||||||
|
Termination of your rights under this section does not terminate the
|
||||||
|
licenses of parties who have received copies or rights from you under
|
||||||
|
this License. If your rights have been terminated and not permanently
|
||||||
|
reinstated, you do not qualify to receive new licenses for the same
|
||||||
|
material under section 10.
|
||||||
|
|
||||||
|
9. Acceptance Not Required for Having Copies.
|
||||||
|
|
||||||
|
You are not required to accept this License in order to receive or
|
||||||
|
run a copy of the Program. Ancillary propagation of a covered work
|
||||||
|
occurring solely as a consequence of using peer-to-peer transmission
|
||||||
|
to receive a copy likewise does not require acceptance. However,
|
||||||
|
nothing other than this License grants you permission to propagate or
|
||||||
|
modify any covered work. These actions infringe copyright if you do
|
||||||
|
not accept this License. Therefore, by modifying or propagating a
|
||||||
|
covered work, you indicate your acceptance of this License to do so.
|
||||||
|
|
||||||
|
10. Automatic Licensing of Downstream Recipients.
|
||||||
|
|
||||||
|
Each time you convey a covered work, the recipient automatically
|
||||||
|
receives a license from the original licensors, to run, modify and
|
||||||
|
propagate that work, subject to this License. You are not responsible
|
||||||
|
for enforcing compliance by third parties with this License.
|
||||||
|
|
||||||
|
An "entity transaction" is a transaction transferring control of an
|
||||||
|
organization, or substantially all assets of one, or subdividing an
|
||||||
|
organization, or merging organizations. If propagation of a covered
|
||||||
|
work results from an entity transaction, each party to that
|
||||||
|
transaction who receives a copy of the work also receives whatever
|
||||||
|
licenses to the work the party's predecessor in interest had or could
|
||||||
|
give under the previous paragraph, plus a right to possession of the
|
||||||
|
Corresponding Source of the work from the predecessor in interest, if
|
||||||
|
the predecessor has it or can get it with reasonable efforts.
|
||||||
|
|
||||||
|
You may not impose any further restrictions on the exercise of the
|
||||||
|
rights granted or affirmed under this License. For example, you may
|
||||||
|
not impose a license fee, royalty, or other charge for exercise of
|
||||||
|
rights granted under this License, and you may not initiate litigation
|
||||||
|
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
||||||
|
any patent claim is infringed by making, using, selling, offering for
|
||||||
|
sale, or importing the Program or any portion of it.
|
||||||
|
|
||||||
|
11. Patents.
|
||||||
|
|
||||||
|
A "contributor" is a copyright holder who authorizes use under this
|
||||||
|
License of the Program or a work on which the Program is based. The
|
||||||
|
work thus licensed is called the contributor's "contributor version".
|
||||||
|
|
||||||
|
A contributor's "essential patent claims" are all patent claims
|
||||||
|
owned or controlled by the contributor, whether already acquired or
|
||||||
|
hereafter acquired, that would be infringed by some manner, permitted
|
||||||
|
by this License, of making, using, or selling its contributor version,
|
||||||
|
but do not include claims that would be infringed only as a
|
||||||
|
consequence of further modification of the contributor version. For
|
||||||
|
purposes of this definition, "control" includes the right to grant
|
||||||
|
patent sublicenses in a manner consistent with the requirements of
|
||||||
|
this License.
|
||||||
|
|
||||||
|
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
||||||
|
patent license under the contributor's essential patent claims, to
|
||||||
|
make, use, sell, offer for sale, import and otherwise run, modify and
|
||||||
|
propagate the contents of its contributor version.
|
||||||
|
|
||||||
|
In the following three paragraphs, a "patent license" is any express
|
||||||
|
agreement or commitment, however denominated, not to enforce a patent
|
||||||
|
(such as an express permission to practice a patent or covenant not to
|
||||||
|
sue for patent infringement). To "grant" such a patent license to a
|
||||||
|
party means to make such an agreement or commitment not to enforce a
|
||||||
|
patent against the party.
|
||||||
|
|
||||||
|
If you convey a covered work, knowingly relying on a patent license,
|
||||||
|
and the Corresponding Source of the work is not available for anyone
|
||||||
|
to copy, free of charge and under the terms of this License, through a
|
||||||
|
publicly available network server or other readily accessible means,
|
||||||
|
then you must either (1) cause the Corresponding Source to be so
|
||||||
|
available, or (2) arrange to deprive yourself of the benefit of the
|
||||||
|
patent license for this particular work, or (3) arrange, in a manner
|
||||||
|
consistent with the requirements of this License, to extend the patent
|
||||||
|
license to downstream recipients. "Knowingly relying" means you have
|
||||||
|
actual knowledge that, but for the patent license, your conveying the
|
||||||
|
covered work in a country, or your recipient's use of the covered work
|
||||||
|
in a country, would infringe one or more identifiable patents in that
|
||||||
|
country that you have reason to believe are valid.
|
||||||
|
|
||||||
|
If, pursuant to or in connection with a single transaction or
|
||||||
|
arrangement, you convey, or propagate by procuring conveyance of, a
|
||||||
|
covered work, and grant a patent license to some of the parties
|
||||||
|
receiving the covered work authorizing them to use, propagate, modify
|
||||||
|
or convey a specific copy of the covered work, then the patent license
|
||||||
|
you grant is automatically extended to all recipients of the covered
|
||||||
|
work and works based on it.
|
||||||
|
|
||||||
|
A patent license is "discriminatory" if it does not include within
|
||||||
|
the scope of its coverage, prohibits the exercise of, or is
|
||||||
|
conditioned on the non-exercise of one or more of the rights that are
|
||||||
|
specifically granted under this License. You may not convey a covered
|
||||||
|
work if you are a party to an arrangement with a third party that is
|
||||||
|
in the business of distributing software, under which you make payment
|
||||||
|
to the third party based on the extent of your activity of conveying
|
||||||
|
the work, and under which the third party grants, to any of the
|
||||||
|
parties who would receive the covered work from you, a discriminatory
|
||||||
|
patent license (a) in connection with copies of the covered work
|
||||||
|
conveyed by you (or copies made from those copies), or (b) primarily
|
||||||
|
for and in connection with specific products or compilations that
|
||||||
|
contain the covered work, unless you entered into that arrangement,
|
||||||
|
or that patent license was granted, prior to 28 March 2007.
|
||||||
|
|
||||||
|
Nothing in this License shall be construed as excluding or limiting
|
||||||
|
any implied license or other defenses to infringement that may
|
||||||
|
otherwise be available to you under applicable patent law.
|
||||||
|
|
||||||
|
12. No Surrender of Others' Freedom.
|
||||||
|
|
||||||
|
If conditions are imposed on you (whether by court order, agreement or
|
||||||
|
otherwise) that contradict the conditions of this License, they do not
|
||||||
|
excuse you from the conditions of this License. If you cannot convey a
|
||||||
|
covered work so as to satisfy simultaneously your obligations under this
|
||||||
|
License and any other pertinent obligations, then as a consequence you may
|
||||||
|
not convey it at all. For example, if you agree to terms that obligate you
|
||||||
|
to collect a royalty for further conveying from those to whom you convey
|
||||||
|
the Program, the only way you could satisfy both those terms and this
|
||||||
|
License would be to refrain entirely from conveying the Program.
|
||||||
|
|
||||||
|
13. Use with the GNU Affero General Public License.
|
||||||
|
|
||||||
|
Notwithstanding any other provision of this License, you have
|
||||||
|
permission to link or combine any covered work with a work licensed
|
||||||
|
under version 3 of the GNU Affero General Public License into a single
|
||||||
|
combined work, and to convey the resulting work. The terms of this
|
||||||
|
License will continue to apply to the part which is the covered work,
|
||||||
|
but the special requirements of the GNU Affero General Public License,
|
||||||
|
section 13, concerning interaction through a network will apply to the
|
||||||
|
combination as such.
|
||||||
|
|
||||||
|
14. Revised Versions of this License.
|
||||||
|
|
||||||
|
The Free Software Foundation may publish revised and/or new versions of
|
||||||
|
the GNU General Public License from time to time. Such new versions will
|
||||||
|
be similar in spirit to the present version, but may differ in detail to
|
||||||
|
address new problems or concerns.
|
||||||
|
|
||||||
|
Each version is given a distinguishing version number. If the
|
||||||
|
Program specifies that a certain numbered version of the GNU General
|
||||||
|
Public License "or any later version" applies to it, you have the
|
||||||
|
option of following the terms and conditions either of that numbered
|
||||||
|
version or of any later version published by the Free Software
|
||||||
|
Foundation. If the Program does not specify a version number of the
|
||||||
|
GNU General Public License, you may choose any version ever published
|
||||||
|
by the Free Software Foundation.
|
||||||
|
|
||||||
|
If the Program specifies that a proxy can decide which future
|
||||||
|
versions of the GNU General Public License can be used, that proxy's
|
||||||
|
public statement of acceptance of a version permanently authorizes you
|
||||||
|
to choose that version for the Program.
|
||||||
|
|
||||||
|
Later license versions may give you additional or different
|
||||||
|
permissions. However, no additional obligations are imposed on any
|
||||||
|
author or copyright holder as a result of your choosing to follow a
|
||||||
|
later version.
|
||||||
|
|
||||||
|
15. Disclaimer of Warranty.
|
||||||
|
|
||||||
|
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
||||||
|
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
||||||
|
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
||||||
|
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
||||||
|
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||||
|
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
||||||
|
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
||||||
|
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||||
|
|
||||||
|
16. Limitation of Liability.
|
||||||
|
|
||||||
|
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||||
|
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
||||||
|
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
||||||
|
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
||||||
|
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
||||||
|
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
||||||
|
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
||||||
|
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
||||||
|
SUCH DAMAGES.
|
||||||
|
|
||||||
|
17. Interpretation of Sections 15 and 16.
|
||||||
|
|
||||||
|
If the disclaimer of warranty and limitation of liability provided
|
||||||
|
above cannot be given local legal effect according to their terms,
|
||||||
|
reviewing courts shall apply local law that most closely approximates
|
||||||
|
an absolute waiver of all civil liability in connection with the
|
||||||
|
Program, unless a warranty or assumption of liability accompanies a
|
||||||
|
copy of the Program in return for a fee.
|
||||||
|
|
||||||
|
END OF TERMS AND CONDITIONS
|
||||||
|
|
||||||
|
How to Apply These Terms to Your New Programs
|
||||||
|
|
||||||
|
If you develop a new program, and you want it to be of the greatest
|
||||||
|
possible use to the public, the best way to achieve this is to make it
|
||||||
|
free software which everyone can redistribute and change under these terms.
|
||||||
|
|
||||||
|
To do so, attach the following notices to the program. It is safest
|
||||||
|
to attach them to the start of each source file to most effectively
|
||||||
|
state the exclusion of warranty; and each file should have at least
|
||||||
|
the "copyright" line and a pointer to where the full notice is found.
|
||||||
|
|
||||||
|
<one line to give the program's name and a brief idea of what it does.>
|
||||||
|
Copyright (C) <year> <name of author>
|
||||||
|
|
||||||
|
This program is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
Also add information on how to contact you by electronic and paper mail.
|
||||||
|
|
||||||
|
If the program does terminal interaction, make it output a short
|
||||||
|
notice like this when it starts in an interactive mode:
|
||||||
|
|
||||||
|
<program> Copyright (C) <year> <name of author>
|
||||||
|
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||||
|
This is free software, and you are welcome to redistribute it
|
||||||
|
under certain conditions; type `show c' for details.
|
||||||
|
|
||||||
|
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||||
|
parts of the General Public License. Of course, your program's commands
|
||||||
|
might be different; for a GUI interface, you would use an "about box".
|
||||||
|
|
||||||
|
You should also get your employer (if you work as a programmer) or school,
|
||||||
|
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
||||||
|
For more information on this, and how to apply and follow the GNU GPL, see
|
||||||
|
<https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
The GNU General Public License does not permit incorporating your program
|
||||||
|
into proprietary programs. If your program is a subroutine library, you
|
||||||
|
may consider it more useful to permit linking proprietary applications with
|
||||||
|
the library. If this is what you want to do, use the GNU Lesser General
|
||||||
|
Public License instead of this License. But first, please read
|
||||||
|
<https://www.gnu.org/licenses/why-not-lgpl.html>.
|
||||||
452
README.md
452
README.md
@@ -1,191 +1,353 @@
|
|||||||
# Microsoft-Rewards-Script
|
[](https://discord.gg/8BxYbV4pkj)
|
||||||
Automated Microsoft Rewards script built with TypeScript, Cheerio and Playwright.
|
|
||||||
|
|
||||||
Under development, however mainly for personal use!
|
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## 🚀 Quick Setup (Recommended)
|
## Table of Contents
|
||||||
|
- [Setup](#setup)
|
||||||
**The easiest way to get started - just download and run!**
|
- [1. Clone the Repository](#1-clone-the-repository)
|
||||||
|
- [2. Copy Configuration Files](#2-copy-configuration-files)
|
||||||
1. **Download or clone** the source code
|
- [3. Install Dependencies and Prepare the Browser](#3-install-dependencies-and-prepare-the-browser)
|
||||||
2. **Run the setup script:**
|
- [4. Build and Run](#4-build-and-run)
|
||||||
|
- [Nix Users](#nix-setup)
|
||||||
**Windows:** Double-click `setup/setup.bat` or run it from command line
|
- [Docker Setup](#docker-setup)
|
||||||
|
- [Before Starting](#before-starting)
|
||||||
**Linux/macOS/WSL:** `bash setup/setup.sh`
|
- [Quick Start](#quick-start)
|
||||||
|
- [Example compose.yaml](#example-composeyaml)
|
||||||
**Alternative (any platform):** `npm run setup`
|
- [Configuration Reference](#configuration-reference)
|
||||||
|
- [Account Configuration](#account-configuration)
|
||||||
3. **Follow the prompts:** The setup script will automatically:
|
- [Features Overview](#features-overview)
|
||||||
- Rename `accounts.example.json` to `accounts.json`
|
- [Disclaimer](#disclaimer)
|
||||||
- Ask you to enter your Microsoft account credentials
|
|
||||||
- Remind you to review configuration options in `config.json`
|
|
||||||
- Install all dependencies (`npm install`)
|
|
||||||
- Build the project (`npm run build`)
|
|
||||||
- Optionally start the script immediately
|
|
||||||
|
|
||||||
**That's it!** The setup script handles everything for you.
|
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## ⚙️ Advanced Setup Options
|
## Setup
|
||||||
|
|
||||||
### Nix Users
|
**Requirements:** Node.js ≥ 20 and Git
|
||||||
1. Get [Nix](https://nixos.org/)
|
Works on Windows, Linux, macOS, and WSL.
|
||||||
2. Run `./run.sh`
|
|
||||||
3. Done!
|
|
||||||
|
|
||||||
### Manual Setup (Troubleshooting)
|
---
|
||||||
If the automatic setup script doesn't work for your environment:
|
|
||||||
|
|
||||||
1. Manually rename `src/accounts.example.json` to `src/accounts.json`
|
### 1. Clone the Repository
|
||||||
2. Add your Microsoft account details to `accounts.json`
|
**All systems:**
|
||||||
3. Customize `src/config.json` to your preferences
|
```bash
|
||||||
4. Install dependencies: `npm install`
|
git clone https://github.com/TheNetsky/Microsoft-Rewards-Script.git
|
||||||
5. Build the project: `npm run build`
|
cd Microsoft-Rewards-Script
|
||||||
6. Start the script: `npm run start`---
|
```
|
||||||
|
Or download the latest release ZIP and extract it.
|
||||||
|
|
||||||
## 🐳 Docker Setup (Experimental)
|
---
|
||||||
|
|
||||||
For automated scheduling and containerized deployment.
|
### 2. Copy Configuration Files
|
||||||
|
|
||||||
|
**Windows:**
|
||||||
|
Rename manually:
|
||||||
|
```
|
||||||
|
src/accounts.example.json → src/accounts.json
|
||||||
|
```
|
||||||
|
|
||||||
|
**Linux / macOS / WSL:**
|
||||||
|
```bash
|
||||||
|
cp src/accounts.example.json src/accounts.json
|
||||||
|
```
|
||||||
|
|
||||||
|
Then edit:
|
||||||
|
- `src/accounts.json` — fill in your Microsoft account credentials.
|
||||||
|
- `src/config.json` — review or customize options.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### 3. Install Dependencies and Prepare the Browser
|
||||||
|
|
||||||
|
**All systems:**
|
||||||
|
```bash
|
||||||
|
npm run pre-build
|
||||||
|
```
|
||||||
|
|
||||||
|
This command:
|
||||||
|
- Installs all dependencies
|
||||||
|
- Clears old builds (`dist/`)
|
||||||
|
- Installs Playwright Chromium (required browser)
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### 4. Build and Run
|
||||||
|
|
||||||
|
**All systems:**
|
||||||
|
```bash
|
||||||
|
npm run build
|
||||||
|
npm run start
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Nix Setup
|
||||||
|
|
||||||
|
If using Nix:
|
||||||
|
|
||||||
|
1. Run the pre-build step first:
|
||||||
|
```bash
|
||||||
|
npm run pre-build
|
||||||
|
```
|
||||||
|
|
||||||
|
2. Then start the script:
|
||||||
|
```bash
|
||||||
|
./run.sh
|
||||||
|
```
|
||||||
|
|
||||||
|
This will launch the script headlessly using `xvfb-run`.
|
||||||
|
|
||||||
|
## Docker Setup
|
||||||
|
|
||||||
### Before Starting
|
### Before Starting
|
||||||
- Remove `/node_modules` and `/dist` folders if you previously built locally
|
- Remove local `/node_modules` and `/dist` if previously built.
|
||||||
- Remove old Docker volumes if upgrading from version 1.4 or earlier
|
- Remove old Docker volumes if upgrading from older versions.
|
||||||
- Old `accounts.json` files can be reused
|
- You can reuse your existing `accounts.json`.
|
||||||
|
|
||||||
### Quick Docker Setup
|
|
||||||
1. **Download source code** and configure `accounts.json`
|
|
||||||
2. **Edit `config.json`** - ensure `"headless": true`
|
|
||||||
3. **Customize `compose.yaml`:**
|
|
||||||
- Set your timezone (`TZ` variable)
|
|
||||||
- Configure schedule (`CRON_SCHEDULE`) - use [crontab.guru](https://crontab.guru) for help
|
|
||||||
- Optional: Set `RUN_ON_START=true` for immediate execution
|
|
||||||
4. **Start container:** `docker compose up -d`
|
|
||||||
5. **Monitor logs:** `docker logs microsoft-rewards-script`
|
|
||||||
|
|
||||||
**Note:** The container adds 5–50 minutes random delay to scheduled runs for more natural behavior.
|
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## 📋 Usage Notes
|
### Quick Start
|
||||||
|
1. Clone the repository and configure your `accounts.json`.
|
||||||
|
2. Ensure `config.json` has `"headless": true`.
|
||||||
|
3. Edit `compose.yaml`:
|
||||||
|
- Set your timezone (`TZ`)
|
||||||
|
- Set the cron schedule (`CRON_SCHEDULE`)
|
||||||
|
- Optionally enable `RUN_ON_START=true`
|
||||||
|
4. Start the container:
|
||||||
|
```bash
|
||||||
|
docker compose up -d
|
||||||
|
```
|
||||||
|
5. Monitor logs:
|
||||||
|
```bash
|
||||||
|
docker logs microsoft-rewards-script
|
||||||
|
```
|
||||||
|
|
||||||
- **Browser Instances:** If you stop the script without closing browser windows (headless=false), use Task Manager or `npm run kill-chrome-win` to clean up
|
The container includes a randomized delay (about 5–50 minutes by default)
|
||||||
- **Automation Scheduling:** Run at least twice daily, set `"runOnZeroPoints": false` to skip when no points available
|
before each scheduled run to appear more natural. This can be configured or disabled via environment variables.
|
||||||
- **Multiple Accounts:** The script supports clustering - configure `clusters` in `config.json`
|
|
||||||
|
|
||||||
---
|
---
|
||||||
## ⚙️ Configuration Reference
|
|
||||||
|
|
||||||
Customize behavior by editing `src/config.json`:
|
### Example compose.yaml
|
||||||
|
|
||||||
### Core Settings
|
```yaml
|
||||||
|
services:
|
||||||
|
microsoft-rewards-script:
|
||||||
|
image: ghcr.io/your-org/microsoft-rewards-script:latest
|
||||||
|
container_name: microsoft-rewards-script
|
||||||
|
restart: unless-stopped
|
||||||
|
|
||||||
|
volumes:
|
||||||
|
- ./src/accounts.json:/usr/src/microsoft-rewards-script/dist/accounts.json:ro
|
||||||
|
- ./src/config.json:/usr/src/microsoft-rewards-script/dist/config.json:ro
|
||||||
|
- ./sessions:/usr/src/microsoft-rewards-script/dist/sessions
|
||||||
|
# - ./jobstate:/usr/src/microsoft-rewards-script/dist/jobstate
|
||||||
|
|
||||||
|
environment:
|
||||||
|
TZ: "Europe/Amsterdam"
|
||||||
|
NODE_ENV: "production"
|
||||||
|
CRON_SCHEDULE: "0 7,16,20 * * *"
|
||||||
|
RUN_ON_START: "true"
|
||||||
|
# MIN_SLEEP_MINUTES: "5"
|
||||||
|
# MAX_SLEEP_MINUTES: "50"
|
||||||
|
# SKIP_RANDOM: "true"
|
||||||
|
|
||||||
|
deploy:
|
||||||
|
resources:
|
||||||
|
limits:
|
||||||
|
cpus: "1.0"
|
||||||
|
memory: "1g"
|
||||||
|
```
|
||||||
|
|
||||||
|
#### compose.yaml Notes
|
||||||
|
- **volumes**
|
||||||
|
- `accounts.json` and `config.json` are mounted read-only to prevent accidental edits.
|
||||||
|
- `sessions` persists login sessions and fingerprints across runs.
|
||||||
|
- If `jobState.enabled` is used, mount its directory as a volume.
|
||||||
|
- **CRON_SCHEDULE**
|
||||||
|
- Uses standard crontab syntax (e.g., via [crontab.guru](https://crontab.guru/)).
|
||||||
|
- Schedule is evaluated inside the container using the configured `TZ`.
|
||||||
|
- **RUN_ON_START**
|
||||||
|
- Runs the script once immediately on startup, then continues on schedule.
|
||||||
|
- **Randomization**
|
||||||
|
- Default delay: 5–50 minutes.
|
||||||
|
- Adjustable via `MIN_SLEEP_MINUTES` and `MAX_SLEEP_MINUTES`, or disable with `SKIP_RANDOM`.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Configuration Reference
|
||||||
|
|
||||||
|
Edit `src/config.json` to customize behavior.
|
||||||
|
Below is a summary of key configuration sections.
|
||||||
|
|
||||||
|
### Core
|
||||||
| Setting | Description | Default |
|
| Setting | Description | Default |
|
||||||
|---------|-------------|---------|
|
|----------|-------------|----------|
|
||||||
| `baseURL` | Microsoft Rewards page URL | `https://rewards.bing.com` |
|
| `baseURL` | Microsoft Rewards base URL | `https://rewards.bing.com` |
|
||||||
| `sessionPath` | Session/fingerprint storage location | `sessions` |
|
| `sessionPath` | Folder to store browser sessions | `sessions` |
|
||||||
| `headless` | Run browser in background | `false` (visible) |
|
| `dryRun` | Simulate execution without running tasks | `false` |
|
||||||
| `parallel` | Run mobile/desktop tasks simultaneously | `true` |
|
|
||||||
| `runOnZeroPoints` | Continue when no points available | `false` |
|
|
||||||
| `clusters` | Number of concurrent account instances | `1` |
|
|
||||||
|
|
||||||
### Fingerprint Settings
|
### Browser
|
||||||
| Setting | Description | Default |
|
| Setting | Description | Default |
|
||||||
|---------|-------------|---------|
|
|----------|-------------|----------|
|
||||||
| `saveFingerprint.mobile` | Reuse mobile browser fingerprint | `false` |
|
| `browser.headless` | Run browser invisibly | `false` |
|
||||||
| `saveFingerprint.desktop` | Reuse desktop browser fingerprint | `false` |
|
| `browser.globalTimeout` | Timeout for actions | `"30s"` |
|
||||||
|
|
||||||
### Task Settings
|
### Fingerprinting
|
||||||
| Setting | Description | Default |
|
| Setting | Description | Default |
|
||||||
|---------|-------------|---------|
|
|----------|-------------|----------|
|
||||||
| `workers.doDailySet` | Complete daily set activities | `true` |
|
| `fingerprinting.saveFingerprint.mobile` | Reuse mobile fingerprint | `true` |
|
||||||
| `workers.doMorePromotions` | Complete promotional offers | `true` |
|
| `fingerprinting.saveFingerprint.desktop` | Reuse desktop fingerprint | `true` |
|
||||||
| `workers.doPunchCards` | Complete punchcard activities | `true` |
|
|
||||||
| `workers.doDesktopSearch` | Perform desktop searches | `true` |
|
|
||||||
| `workers.doMobileSearch` | Perform mobile searches | `true` |
|
|
||||||
| `workers.doDailyCheckIn` | Complete daily check-in | `true` |
|
|
||||||
| `workers.doReadToEarn` | Complete read-to-earn activities | `true` |
|
|
||||||
|
|
||||||
### Search Settings
|
### Execution
|
||||||
| Setting | Description | Default |
|
| Setting | Description | Default |
|
||||||
|---------|-------------|---------|
|
|----------|-------------|----------|
|
||||||
| `searchOnBingLocalQueries` | Use local queries vs. fetched | `false` |
|
| `execution.parallel` | Run desktop and mobile simultaneously | `false` |
|
||||||
| `searchSettings.useGeoLocaleQueries` | Generate location-based queries | `false` |
|
| `execution.runOnZeroPoints` | Run even with zero points | `false` |
|
||||||
| `searchSettings.scrollRandomResults` | Randomly scroll search results | `true` |
|
| `execution.clusters` | Number of concurrent account clusters | `1` |
|
||||||
| `searchSettings.clickRandomResults` | Click random result links | `true` |
|
|
||||||
| `searchSettings.searchDelay` | Delay between searches (min/max) | `3-5 minutes` |
|
|
||||||
| `searchSettings.retryMobileSearchAmount` | Mobile search retry attempts | `2` |
|
|
||||||
|
|
||||||
### Advanced Settings
|
### Job State
|
||||||
| Setting | Description | Default |
|
| Setting | Description | Default |
|
||||||
|---------|-------------|---------|
|
|----------|-------------|----------|
|
||||||
| `globalTimeout` | Action timeout duration | `30s` |
|
| `jobState.enabled` | Save last job state | `true` |
|
||||||
| `logExcludeFunc` | Functions to exclude from logs | `SEARCH-CLOSE-TABS` |
|
| `jobState.dir` | Directory for job data | `""` |
|
||||||
| `webhookLogExcludeFunc` | Functions to exclude from webhooks | `SEARCH-CLOSE-TABS` |
|
|
||||||
|
### Workers (Tasks)
|
||||||
|
| Setting | Description | Default |
|
||||||
|
|----------|-------------|----------|
|
||||||
|
| `doDailySet` | Complete daily set | `true` |
|
||||||
|
| `doMorePromotions` | Complete more promotions | `true` |
|
||||||
|
| `doPunchCards` | Complete punchcards | `true` |
|
||||||
|
| `doDesktopSearch` | Perform desktop searches | `true` |
|
||||||
|
| `doMobileSearch` | Perform mobile searches | `true` |
|
||||||
|
| `doDailyCheckIn` | Complete daily check-in | `true` |
|
||||||
|
| `doReadToEarn` | Complete Read-to-Earn | `true` |
|
||||||
|
| `bundleDailySetWithSearch` | Combine daily set and searches | `true` |
|
||||||
|
|
||||||
|
### Search
|
||||||
|
| Setting | Description | Default |
|
||||||
|
|----------|-------------|----------|
|
||||||
|
| `search.useLocalQueries` | Use local query list | `true` |
|
||||||
|
| `search.settings.useGeoLocaleQueries` | Use region-based queries | `true` |
|
||||||
|
| `search.settings.scrollRandomResults` | Random scrolling | `true` |
|
||||||
|
| `search.settings.clickRandomResults` | Random link clicking | `true` |
|
||||||
|
| `search.settings.retryMobileSearchAmount` | Retry mobile searches | `2` |
|
||||||
|
| `search.settings.delay.min` | Minimum delay between searches | `1min` |
|
||||||
|
| `search.settings.delay.max` | Maximum delay between searches | `5min` |
|
||||||
|
|
||||||
|
### Query Diversity
|
||||||
|
| Setting | Description | Default |
|
||||||
|
|----------|-------------|----------|
|
||||||
|
| `queryDiversity.enabled` | Enable multiple query sources | `true` |
|
||||||
|
| `queryDiversity.sources` | Query providers | `["google-trends", "reddit", "local-fallback"]` |
|
||||||
|
| `queryDiversity.maxQueriesPerSource` | Limit per source | `10` |
|
||||||
|
| `queryDiversity.cacheMinutes` | Cache lifetime | `30` |
|
||||||
|
|
||||||
|
### Humanization
|
||||||
|
| Setting | Description | Default |
|
||||||
|
|----------|-------------|----------|
|
||||||
|
| `humanization.enabled` | Enable human behavior | `true` |
|
||||||
|
| `stopOnBan` | Stop immediately on ban | `true` |
|
||||||
|
| `immediateBanAlert` | Alert instantly if banned | `true` |
|
||||||
|
| `actionDelay.min` | Minimum delay per action (ms) | `500` |
|
||||||
|
| `actionDelay.max` | Maximum delay per action (ms) | `2200` |
|
||||||
|
| `gestureMoveProb` | Chance of random mouse movement | `0.65` |
|
||||||
|
| `gestureScrollProb` | Chance of random scrolls | `0.4` |
|
||||||
|
|
||||||
|
### Vacation Mode
|
||||||
|
| Setting | Description | Default |
|
||||||
|
|----------|-------------|----------|
|
||||||
|
| `vacation.enabled` | Enable random pauses | `true` |
|
||||||
|
| `minDays` | Minimum days off | `2` |
|
||||||
|
| `maxDays` | Maximum days off | `4` |
|
||||||
|
|
||||||
|
### Risk Management
|
||||||
|
| Setting | Description | Default |
|
||||||
|
|----------|-------------|----------|
|
||||||
|
| `enabled` | Enable risk-based adjustments | `true` |
|
||||||
|
| `autoAdjustDelays` | Adapt delays dynamically | `true` |
|
||||||
|
| `stopOnCritical` | Stop on critical warning | `false` |
|
||||||
|
| `banPrediction` | Predict bans based on signals | `true` |
|
||||||
|
| `riskThreshold` | Risk tolerance level | `75` |
|
||||||
|
|
||||||
|
### Retry Policy
|
||||||
|
| Setting | Description | Default |
|
||||||
|
|----------|-------------|----------|
|
||||||
|
| `maxAttempts` | Maximum retry attempts | `3` |
|
||||||
|
| `baseDelay` | Initial retry delay | `1000` |
|
||||||
|
| `maxDelay` | Maximum retry delay | `30s` |
|
||||||
|
| `multiplier` | Backoff multiplier | `2` |
|
||||||
|
| `jitter` | Random jitter factor | `0.2` |
|
||||||
|
|
||||||
|
### Proxy
|
||||||
|
| Setting | Description | Default |
|
||||||
|
|----------|-------------|----------|
|
||||||
| `proxy.proxyGoogleTrends` | Proxy Google Trends requests | `true` |
|
| `proxy.proxyGoogleTrends` | Proxy Google Trends requests | `true` |
|
||||||
| `proxy.proxyBingTerms` | Proxy Bing Terms requests | `true` |
|
| `proxy.proxyBingTerms` | Proxy Bing terms requests | `true` |
|
||||||
|
|
||||||
### Webhook Settings
|
### Notifications
|
||||||
| Setting | Description | Default |
|
| Setting | Description | Default |
|
||||||
|---------|-------------|---------|
|
|----------|-------------|----------|
|
||||||
| `webhook.enabled` | Enable Discord notifications | `false` |
|
| `notifications.webhook.enabled` | Enable Discord webhook | `false` |
|
||||||
| `webhook.url` | Discord webhook URL | `null` |
|
| `notifications.webhook.url` | Discord webhook URL | `""` |
|
||||||
| `conclusionWebhook.enabled` | Enable summary-only webhook | `false` |
|
| `notifications.conclusionWebhook.enabled` | Enable summary webhook | `false` |
|
||||||
| `conclusionWebhook.url` | Summary webhook URL | `null` |
|
| `notifications.conclusionWebhook.url` | Summary webhook URL | `""` |
|
||||||
|
| `notifications.ntfy.enabled` | Enable Ntfy push alerts | `false` |
|
||||||
|
| `notifications.ntfy.url` | Ntfy server URL | `""` |
|
||||||
|
| `notifications.ntfy.topic` | Ntfy topic name | `"rewards"` |
|
||||||
|
|
||||||
|
### Logging
|
||||||
|
| Setting | Description | Default |
|
||||||
|
|----------|-------------|----------|
|
||||||
|
| `excludeFunc` | Exclude from console logs | `["SEARCH-CLOSE-TABS", "LOGIN-NO-PROMPT", "FLOW"]` |
|
||||||
|
| `webhookExcludeFunc` | Exclude from webhook logs | `["SEARCH-CLOSE-TABS", "LOGIN-NO-PROMPT", "FLOW"]` |
|
||||||
|
| `redactEmails` | Hide emails in logs | `true` |
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## ✨ Features
|
## Account Configuration
|
||||||
|
|
||||||
**Account Management:**
|
Edit `src/accounts.json`:
|
||||||
- ✅ Multi-Account Support
|
|
||||||
- ✅ Session Storage & Persistence
|
|
||||||
- ✅ 2FA Support
|
|
||||||
- ✅ Passwordless Login Support
|
|
||||||
|
|
||||||
**Automation & Control:**
|
```json
|
||||||
- ✅ Headless Browser Operation
|
{
|
||||||
- ✅ Clustering Support (Multiple accounts simultaneously)
|
"accounts": [
|
||||||
- ✅ Configurable Task Selection
|
{
|
||||||
- ✅ Proxy Support
|
"enabled": true,
|
||||||
- ✅ Automatic Scheduling (Docker)
|
"email": "email_1@outlook.com",
|
||||||
|
"password": "password_1",
|
||||||
**Search & Activities:**
|
"totp": "",
|
||||||
- ✅ Desktop & Mobile Searches
|
"recoveryEmail": "your_email@domain.com",
|
||||||
- ✅ Microsoft Edge Search Simulation
|
"proxy": {
|
||||||
- ✅ Geo-Located Search Queries
|
"proxyAxios": true,
|
||||||
- ✅ Emulated Scrolling & Link Clicking
|
"url": "",
|
||||||
- ✅ Daily Set Completion
|
"port": 0,
|
||||||
- ✅ Promotional Activities
|
"username": "",
|
||||||
- ✅ Punchcard Completion
|
"password": ""
|
||||||
- ✅ Daily Check-in
|
}
|
||||||
- ✅ Read to Earn Activities
|
}
|
||||||
|
]
|
||||||
**Quiz & Interactive Content:**
|
}
|
||||||
- ✅ Quiz Solving (10 & 30-40 point variants)
|
```
|
||||||
- ✅ This Or That Quiz (Random answers)
|
|
||||||
- ✅ ABC Quiz Solving
|
|
||||||
- ✅ Poll Completion
|
|
||||||
- ✅ Click Rewards
|
|
||||||
|
|
||||||
**Notifications & Monitoring:**
|
|
||||||
- ✅ Discord Webhook Integration
|
|
||||||
- ✅ Dedicated Summary Webhook
|
|
||||||
- ✅ Comprehensive Logging
|
|
||||||
- ✅ Docker Support with Monitoring
|
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## ⚠️ Disclaimer
|
## Features Overview
|
||||||
|
|
||||||
**Use at your own risk!** Your Microsoft Rewards account may be suspended or banned when using automation scripts.
|
- Multi-account and session handling
|
||||||
|
- Persistent browser fingerprints
|
||||||
This script is provided for educational purposes. The authors are not responsible for any account actions taken by Microsoft.
|
- Parallel task execution
|
||||||
|
- Proxy and retry support
|
||||||
|
- Human-like behavior simulation
|
||||||
|
- Full daily set automation
|
||||||
|
- Mobile and desktop search support
|
||||||
|
- Vacation and risk protection
|
||||||
|
- Webhook and Ntfy notifications
|
||||||
|
- Docker scheduling support
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## 🤝 Contributing
|
## Disclaimer
|
||||||
|
|
||||||
This project is primarily for personal use but contributions are welcome. Please ensure any changes maintain compatibility with the existing configuration system.
|
Use at your own risk.
|
||||||
|
Automation of Microsoft Rewards may lead to account suspension or bans.
|
||||||
|
This software is provided for educational purposes only.
|
||||||
|
The authors are not responsible for any actions taken by Microsoft.
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
|
||||||
# Ensure Playwright uses preinstalled browsers
|
# Ensure Playwright uses preinstalled browsers
|
||||||
export PLAYWRIGHT_BROWSERS_PATH=/ms-playwright
|
export PLAYWRIGHT_BROWSERS_PATH=0
|
||||||
|
|
||||||
# 1. Timezone: default to UTC if not provided
|
# 1. Timezone: default to UTC if not provided
|
||||||
: "${TZ:=UTC}"
|
: "${TZ:=UTC}"
|
||||||
|
|||||||
3174
package-lock.json
generated
Normal file
3174
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
34
package.json
34
package.json
@@ -1,18 +1,30 @@
|
|||||||
{
|
{
|
||||||
"name": "microsoft-rewards-script",
|
"name": "microsoft-rewards-script",
|
||||||
"version": "1.5.3",
|
"version": "2.4.1",
|
||||||
"description": "Automatically do tasks for Microsoft Rewards but in TS!",
|
"description": "Automatically do tasks for Microsoft Rewards but in TS!",
|
||||||
|
"private": true,
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=18.0.0"
|
"node": ">=20.0.0"
|
||||||
},
|
},
|
||||||
|
"repository": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://github.com/TheNetsky/Microsoft-Rewards-Script.git"
|
||||||
|
},
|
||||||
|
"bugs": {
|
||||||
|
"url": "https://github.com/TheNetsky/Microsoft-Rewards-Script/issues"
|
||||||
|
},
|
||||||
|
"homepage": "https://github.com/TheNetsky/Microsoft-Rewards-Script#readme",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"pre-build": "npm i && rimraf dist && npx playwright install chromium",
|
"clean": "rimraf dist",
|
||||||
|
"pre-build": "npm i && npm run clean && node -e \"process.exit(process.env.SKIP_PLAYWRIGHT_INSTALL?0:1)\" || npx playwright install chromium",
|
||||||
|
"typecheck": "tsc --noEmit",
|
||||||
"build": "tsc",
|
"build": "tsc",
|
||||||
"start": "node ./dist/index.js",
|
"start": "node --enable-source-maps ./dist/index.js",
|
||||||
"ts-start": "ts-node ./src/index.ts",
|
"ts-start": "node --loader ts-node/esm ./src/index.ts",
|
||||||
"dev": "ts-node ./src/index.ts -dev",
|
"dev": "ts-node ./src/index.ts -dev",
|
||||||
"setup": "node ./setup/setup.mjs",
|
"lint": "eslint \"src/**/*.{ts,tsx}\"",
|
||||||
|
"prepare": "npm run build",
|
||||||
"kill-chrome-win": "powershell -Command \"Get-Process | Where-Object { $_.MainModule.FileVersionInfo.FileDescription -eq 'Google Chrome for Testing' } | ForEach-Object { Stop-Process -Id $_.Id -Force }\"",
|
"kill-chrome-win": "powershell -Command \"Get-Process | Where-Object { $_.MainModule.FileVersionInfo.FileDescription -eq 'Google Chrome for Testing' } | ForEach-Object { Stop-Process -Id $_.Id -Force }\"",
|
||||||
"create-docker": "docker build -t microsoft-rewards-script-docker ."
|
"create-docker": "docker build -t microsoft-rewards-script-docker ."
|
||||||
},
|
},
|
||||||
@@ -28,8 +40,8 @@
|
|||||||
"author": "Netsky",
|
"author": "Netsky",
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/node": "^20.14.11",
|
|
||||||
"@types/ms": "^0.7.34",
|
"@types/ms": "^0.7.34",
|
||||||
|
"@types/node": "^20.14.11",
|
||||||
"@typescript-eslint/eslint-plugin": "^7.17.0",
|
"@typescript-eslint/eslint-plugin": "^7.17.0",
|
||||||
"eslint": "^8.57.0",
|
"eslint": "^8.57.0",
|
||||||
"eslint-plugin-modules-newline": "^0.0.6",
|
"eslint-plugin-modules-newline": "^0.0.6",
|
||||||
@@ -37,13 +49,15 @@
|
|||||||
"typescript": "^5.5.4"
|
"typescript": "^5.5.4"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"axios": "^1.8.4",
|
"axios": "^1.13.2",
|
||||||
"chalk": "^4.1.2",
|
"chalk": "^4.1.2",
|
||||||
"cheerio": "^1.0.0",
|
"cheerio": "^1.0.0",
|
||||||
"fingerprint-generator": "^2.1.66",
|
"cron-parser": "^5.4.0",
|
||||||
"fingerprint-injector": "^2.1.66",
|
"fingerprint-generator": "^2.1.76",
|
||||||
|
"fingerprint-injector": "^2.1.76",
|
||||||
"http-proxy-agent": "^7.0.2",
|
"http-proxy-agent": "^7.0.2",
|
||||||
"https-proxy-agent": "^7.0.6",
|
"https-proxy-agent": "^7.0.6",
|
||||||
|
"luxon": "^3.5.0",
|
||||||
"ms": "^2.1.3",
|
"ms": "^2.1.3",
|
||||||
"playwright": "1.52.0",
|
"playwright": "1.52.0",
|
||||||
"rebrowser-playwright": "1.52.0",
|
"rebrowser-playwright": "1.52.0",
|
||||||
|
|||||||
@@ -1,22 +0,0 @@
|
|||||||
@echo off
|
|
||||||
setlocal
|
|
||||||
REM Lightweight wrapper to run setup.mjs without prereq detection (Windows)
|
|
||||||
REM Assumes Node is already installed and available in PATH.
|
|
||||||
|
|
||||||
set SCRIPT_DIR=%~dp0
|
|
||||||
set SETUP_FILE=%SCRIPT_DIR%setup.mjs
|
|
||||||
|
|
||||||
if not exist "%SETUP_FILE%" (
|
|
||||||
echo [ERROR] setup.mjs not found next to this batch file.
|
|
||||||
pause
|
|
||||||
exit /b 1
|
|
||||||
)
|
|
||||||
|
|
||||||
echo Running setup script...
|
|
||||||
node "%SETUP_FILE%"
|
|
||||||
set EXITCODE=%ERRORLEVEL%
|
|
||||||
echo.
|
|
||||||
echo Setup finished with exit code %EXITCODE%.
|
|
||||||
echo Press Enter to close.
|
|
||||||
pause >NUL
|
|
||||||
exit /b %EXITCODE%
|
|
||||||
171
setup/setup.mjs
171
setup/setup.mjs
@@ -1,171 +0,0 @@
|
|||||||
#!/usr/bin/env node
|
|
||||||
/**
|
|
||||||
* Unified cross-platform setup script for Microsoft Rewards Script.
|
|
||||||
* Handles:
|
|
||||||
* - Renaming accounts.example.json -> accounts.json (idempotent)
|
|
||||||
* - Prompt loop to confirm passwords added
|
|
||||||
* - Inform about config.json and conclusionWebhook
|
|
||||||
* - Run npm install + npm run build
|
|
||||||
* - Optional start
|
|
||||||
*/
|
|
||||||
|
|
||||||
import fs from 'fs';
|
|
||||||
import path from 'path';
|
|
||||||
import { fileURLToPath } from 'url';
|
|
||||||
import { spawn } from 'child_process';
|
|
||||||
|
|
||||||
const __filename = fileURLToPath(import.meta.url);
|
|
||||||
const __dirname = path.dirname(__filename);
|
|
||||||
// Project root = parent of this setup directory
|
|
||||||
const PROJECT_ROOT = path.resolve(__dirname, '..');
|
|
||||||
const SRC_DIR = path.join(PROJECT_ROOT, 'src');
|
|
||||||
|
|
||||||
function log(msg) { console.log(msg); }
|
|
||||||
function warn(msg) { console.warn(msg); }
|
|
||||||
function error(msg) { console.error(msg); }
|
|
||||||
|
|
||||||
function renameAccountsIfNeeded() {
|
|
||||||
const accounts = path.join(SRC_DIR, 'accounts.json');
|
|
||||||
const example = path.join(SRC_DIR, 'accounts.example.json');
|
|
||||||
if (fs.existsSync(accounts)) {
|
|
||||||
log('accounts.json already exists - skipping rename.');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (fs.existsSync(example)) {
|
|
||||||
log('Renaming accounts.example.json to accounts.json...');
|
|
||||||
fs.renameSync(example, accounts);
|
|
||||||
} else {
|
|
||||||
warn('Neither accounts.json nor accounts.example.json found.');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async function prompt(question) {
|
|
||||||
return await new Promise(resolve => {
|
|
||||||
process.stdout.write(question);
|
|
||||||
const onData = (data) => {
|
|
||||||
const ans = data.toString().trim();
|
|
||||||
process.stdin.off('data', onData);
|
|
||||||
resolve(ans);
|
|
||||||
};
|
|
||||||
process.stdin.on('data', onData);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
async function loopForAccountsConfirmation() {
|
|
||||||
// Keep asking until user says yes
|
|
||||||
for (;;) {
|
|
||||||
const ans = (await prompt('Have you entered your passwords in accounts.json? (yes/no) : ')).toLowerCase();
|
|
||||||
if (['yes', 'y'].includes(ans)) break;
|
|
||||||
if (['no', 'n'].includes(ans)) {
|
|
||||||
log('Please enter your passwords in accounts.json and save the file (Ctrl+S), then answer yes.');
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
log('Please answer yes or no.');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function runCommand(cmd, args, opts = {}) {
|
|
||||||
return new Promise((resolve, reject) => {
|
|
||||||
log(`Running: ${cmd} ${args.join(' ')}`);
|
|
||||||
const child = spawn(cmd, args, { stdio: 'inherit', shell: process.platform === 'win32', ...opts });
|
|
||||||
child.on('exit', (code) => {
|
|
||||||
if (code === 0) return resolve();
|
|
||||||
reject(new Error(`${cmd} exited with code ${code}`));
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
async function ensureNpmAvailable() {
|
|
||||||
try {
|
|
||||||
await runCommand(process.platform === 'win32' ? 'npm.cmd' : 'npm', ['-v']);
|
|
||||||
} catch (e) {
|
|
||||||
throw new Error('npm not found in PATH. Install Node.js first.');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async function startOnly() {
|
|
||||||
log('Starting program (npm run start)...');
|
|
||||||
await ensureNpmAvailable();
|
|
||||||
// Assume user already installed & built; if dist missing inform user.
|
|
||||||
const distIndex = path.join(PROJECT_ROOT, 'dist', 'index.js');
|
|
||||||
if (!fs.existsSync(distIndex)) {
|
|
||||||
warn('Build output not found. Running build first.');
|
|
||||||
await runCommand(process.platform === 'win32' ? 'npm.cmd' : 'npm', ['run', 'build']);
|
|
||||||
await installPlaywrightBrowsers();
|
|
||||||
} else {
|
|
||||||
// Even if build exists, ensure browsers are installed once.
|
|
||||||
await installPlaywrightBrowsers();
|
|
||||||
}
|
|
||||||
await runCommand(process.platform === 'win32' ? 'npm.cmd' : 'npm', ['run', 'start']);
|
|
||||||
}
|
|
||||||
|
|
||||||
async function fullSetup() {
|
|
||||||
renameAccountsIfNeeded();
|
|
||||||
await loopForAccountsConfirmation();
|
|
||||||
log('\nYou can now review config.json (same folder) to adjust settings such as conclusionWebhook.');
|
|
||||||
log('(How to enable it is documented in the repository README.)\n');
|
|
||||||
await ensureNpmAvailable();
|
|
||||||
await runCommand(process.platform === 'win32' ? 'npm.cmd' : 'npm', ['install']);
|
|
||||||
await runCommand(process.platform === 'win32' ? 'npm.cmd' : 'npm', ['run', 'build']);
|
|
||||||
await installPlaywrightBrowsers();
|
|
||||||
const start = (await prompt('Do you want to start the program now? (yes/no) : ')).toLowerCase();
|
|
||||||
if (['yes', 'y'].includes(start)) {
|
|
||||||
await runCommand(process.platform === 'win32' ? 'npm.cmd' : 'npm', ['run', 'start']);
|
|
||||||
} else {
|
|
||||||
log('Finished setup without starting.');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async function installPlaywrightBrowsers() {
|
|
||||||
const PLAYWRIGHT_MARKER = path.join(PROJECT_ROOT, '.playwright-chromium-installed');
|
|
||||||
// Idempotent: skip if marker exists
|
|
||||||
if (fs.existsSync(PLAYWRIGHT_MARKER)) {
|
|
||||||
log('Playwright chromium already installed (marker found).');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
log('Ensuring Playwright chromium browser is installed...');
|
|
||||||
try {
|
|
||||||
await runCommand(process.platform === 'win32' ? 'npx.cmd' : 'npx', ['playwright', 'install', 'chromium']);
|
|
||||||
fs.writeFileSync(PLAYWRIGHT_MARKER, new Date().toISOString());
|
|
||||||
log('Playwright chromium install complete.');
|
|
||||||
} catch (e) {
|
|
||||||
warn('Failed to install Playwright chromium automatically. You can manually run: npx playwright install chromium');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async function main() {
|
|
||||||
if (!fs.existsSync(SRC_DIR)) {
|
|
||||||
error('[ERROR] Cannot find src directory at ' + SRC_DIR);
|
|
||||||
process.exit(1);
|
|
||||||
}
|
|
||||||
process.chdir(PROJECT_ROOT);
|
|
||||||
|
|
||||||
for (;;) {
|
|
||||||
log('============================');
|
|
||||||
log(' Microsoft Rewards Setup ');
|
|
||||||
log('============================');
|
|
||||||
log('Select an option:');
|
|
||||||
log(' 1) Start program now (skip setup)');
|
|
||||||
log(' 2) Full first-time setup');
|
|
||||||
log(' 3) Exit');
|
|
||||||
const choice = (await prompt('Enter choice (1/2/3): ')).trim();
|
|
||||||
if (choice === '1') { await startOnly(); break; }
|
|
||||||
if (choice === '2') { await fullSetup(); break; }
|
|
||||||
if (choice === '3') { log('Exiting.'); process.exit(0); }
|
|
||||||
log('\nInvalid choice. Please select 1, 2 or 3.\n');
|
|
||||||
}
|
|
||||||
// After completing action, optionally pause if launched by double click on Windows (no TTY detection simple heuristic)
|
|
||||||
if (process.platform === 'win32' && process.stdin.isTTY) {
|
|
||||||
log('\nDone. Press Enter to close.');
|
|
||||||
await prompt('');
|
|
||||||
}
|
|
||||||
process.exit(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Allow clean Ctrl+C
|
|
||||||
process.on('SIGINT', () => { console.log('\nInterrupted.'); process.exit(1); });
|
|
||||||
|
|
||||||
main().catch(err => {
|
|
||||||
error('\nSetup failed: ' + err.message);
|
|
||||||
process.exit(1);
|
|
||||||
});
|
|
||||||
@@ -1,41 +0,0 @@
|
|||||||
#!/usr/bin/env bash
|
|
||||||
set -euo pipefail
|
|
||||||
|
|
||||||
# Wrapper to run unified Node setup script (setup/setup.mjs) regardless of CWD.
|
|
||||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
||||||
SETUP_FILE="${SCRIPT_DIR}/setup.mjs"
|
|
||||||
|
|
||||||
echo "=== Prerequisite Check ==="
|
|
||||||
|
|
||||||
if command -v node >/dev/null 2>&1; then
|
|
||||||
NODE_VERSION="$(node -v 2>/dev/null || true)"
|
|
||||||
echo "Node detected: ${NODE_VERSION}"
|
|
||||||
else
|
|
||||||
echo "[WARN] Node.js not detected."
|
|
||||||
echo " Install (Linux): use your package manager (e.g. 'sudo apt install nodejs npm' or install from nodejs.org for latest)."
|
|
||||||
fi
|
|
||||||
|
|
||||||
if command -v git >/dev/null 2>&1; then
|
|
||||||
GIT_VERSION="$(git --version 2>/dev/null || true)"
|
|
||||||
echo "Git detected: ${GIT_VERSION}"
|
|
||||||
else
|
|
||||||
echo "[WARN] Git not detected."
|
|
||||||
echo " Install (Linux): e.g. 'sudo apt install git' (or your distro equivalent)."
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ -z "${NODE_VERSION:-}" ]; then
|
|
||||||
read -r -p "Continue anyway? (yes/no) : " CONTINUE
|
|
||||||
case "${CONTINUE,,}" in
|
|
||||||
yes|y) ;;
|
|
||||||
*) echo "Aborting. Install prerequisites then re-run."; exit 1;;
|
|
||||||
esac
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ ! -f "${SETUP_FILE}" ]; then
|
|
||||||
echo "[ERROR] setup.mjs not found at ${SETUP_FILE}" >&2
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo
|
|
||||||
echo "=== Running setup script ==="
|
|
||||||
exec node "${SETUP_FILE}"
|
|
||||||
@@ -1,24 +1,32 @@
|
|||||||
[
|
{
|
||||||
|
"accounts": [
|
||||||
{
|
{
|
||||||
"email": "email_1",
|
"enabled": true,
|
||||||
"password": "password_1",
|
"email": "email_1@outlook.com",
|
||||||
"proxy": {
|
"password": "password_1",
|
||||||
"proxyAxios": true,
|
"totp": "",
|
||||||
"url": "",
|
"recoveryEmail": "your_email@domain.com",
|
||||||
"port": 0,
|
"proxy": {
|
||||||
"username": "",
|
"proxyAxios": true,
|
||||||
"password": ""
|
"url": "",
|
||||||
}
|
"port": 0,
|
||||||
|
"username": "",
|
||||||
|
"password": ""
|
||||||
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"email": "email_2",
|
"enabled": false,
|
||||||
"password": "password_2",
|
"email": "email_2@outlook.com",
|
||||||
"proxy": {
|
"password": "password_2",
|
||||||
"proxyAxios": true,
|
"totp": "",
|
||||||
"url": "",
|
"recoveryEmail": "your_email@domain.com",
|
||||||
"port": 0,
|
"proxy": {
|
||||||
"username": "",
|
"proxyAxios": true,
|
||||||
"password": ""
|
"url": "",
|
||||||
}
|
"port": 0,
|
||||||
|
"username": "",
|
||||||
|
"password": ""
|
||||||
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
}
|
||||||
@@ -25,20 +25,22 @@ class Browser {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async createBrowser(proxy: AccountProxy, email: string): Promise<BrowserContext> {
|
async createBrowser(proxy: AccountProxy, email: string): Promise<BrowserContext> {
|
||||||
// Optional automatic browser installation (set AUTO_INSTALL_BROWSERS=1)
|
let browser: playwright.Browser
|
||||||
if (process.env.AUTO_INSTALL_BROWSERS === '1') {
|
|
||||||
try {
|
|
||||||
// Dynamically import child_process to avoid overhead otherwise
|
|
||||||
const { execSync } = await import('child_process') as any
|
|
||||||
execSync('npx playwright install chromium', { stdio: 'ignore' })
|
|
||||||
} catch { /* silent */ }
|
|
||||||
}
|
|
||||||
|
|
||||||
let browser: any
|
|
||||||
try {
|
try {
|
||||||
|
// FORCE_HEADLESS env takes precedence (used in Docker with headless shell only)
|
||||||
|
const envForceHeadless = process.env.FORCE_HEADLESS === '1'
|
||||||
|
// Support legacy config.headless OR nested config.browser.headless
|
||||||
|
const legacyHeadless = (this.bot.config as { headless?: boolean }).headless
|
||||||
|
const nestedHeadless = (this.bot.config.browser as { headless?: boolean } | undefined)?.headless
|
||||||
|
const headlessValue = envForceHeadless ? true : (legacyHeadless ?? nestedHeadless ?? false)
|
||||||
|
const headless: boolean = Boolean(headlessValue)
|
||||||
|
|
||||||
|
const engineName = 'chromium' // current hard-coded engine
|
||||||
|
this.bot.log(this.bot.isMobile, 'BROWSER', `Launching ${engineName} (headless=${headless})`) // explicit engine log
|
||||||
browser = await playwright.chromium.launch({
|
browser = await playwright.chromium.launch({
|
||||||
//channel: 'msedge', // Uses Edge instead of chrome
|
// Optional: uncomment to use Edge instead of Chromium
|
||||||
headless: this.bot.config.headless,
|
// channel: 'msedge',
|
||||||
|
headless,
|
||||||
...(proxy.url && { proxy: { username: proxy.username, password: proxy.password, server: `${proxy.url}:${proxy.port}` } }),
|
...(proxy.url && { proxy: { username: proxy.username, password: proxy.password, server: `${proxy.url}:${proxy.port}` } }),
|
||||||
args: [
|
args: [
|
||||||
'--no-sandbox',
|
'--no-sandbox',
|
||||||
@@ -49,29 +51,71 @@ class Browser {
|
|||||||
'--ignore-ssl-errors'
|
'--ignore-ssl-errors'
|
||||||
]
|
]
|
||||||
})
|
})
|
||||||
} catch (e: any) {
|
} catch (e: unknown) {
|
||||||
const msg = (e instanceof Error ? e.message : String(e))
|
const msg = (e instanceof Error ? e.message : String(e))
|
||||||
// Common missing browser executable guidance
|
// Common missing browser executable guidance
|
||||||
if (/Executable doesn't exist/i.test(msg)) {
|
if (/Executable doesn't exist/i.test(msg)) {
|
||||||
this.bot.log(this.bot.isMobile, 'BROWSER', 'Chromium not installed for Playwright. Run: "npx playwright install chromium" (or set AUTO_INSTALL_BROWSERS=1 to auto attempt).', 'error')
|
this.bot.log(this.bot.isMobile, 'BROWSER', 'Chromium not installed for Playwright. Run "npm run pre-build" to install all dependencies', 'error')
|
||||||
} else {
|
} else {
|
||||||
this.bot.log(this.bot.isMobile, 'BROWSER', 'Failed to launch browser: ' + msg, 'error')
|
this.bot.log(this.bot.isMobile, 'BROWSER', 'Failed to launch browser: ' + msg, 'error')
|
||||||
}
|
}
|
||||||
throw e
|
throw e
|
||||||
}
|
}
|
||||||
|
|
||||||
const sessionData = await loadSessionData(this.bot.config.sessionPath, email, this.bot.isMobile, this.bot.config.saveFingerprint)
|
// Resolve saveFingerprint from legacy root or new fingerprinting.saveFingerprint
|
||||||
|
const legacyFp = (this.bot.config as { saveFingerprint?: { mobile: boolean; desktop: boolean } }).saveFingerprint
|
||||||
|
const nestedFp = (this.bot.config.fingerprinting as { saveFingerprint?: { mobile: boolean; desktop: boolean } } | undefined)?.saveFingerprint
|
||||||
|
const saveFingerprint = legacyFp || nestedFp || { mobile: false, desktop: false }
|
||||||
|
|
||||||
|
const sessionData = await loadSessionData(this.bot.config.sessionPath, email, this.bot.isMobile, saveFingerprint)
|
||||||
|
|
||||||
const fingerprint = sessionData.fingerprint ? sessionData.fingerprint : await this.generateFingerprint()
|
const fingerprint = sessionData.fingerprint ? sessionData.fingerprint : await this.generateFingerprint()
|
||||||
|
|
||||||
const context = await newInjectedContext(browser as any, { fingerprint: fingerprint })
|
const context = await newInjectedContext(browser as unknown as import('playwright').Browser, { fingerprint: fingerprint })
|
||||||
|
|
||||||
// Set timeout to preferred amount
|
// Set timeout to preferred amount (supports legacy globalTimeout or browser.globalTimeout)
|
||||||
context.setDefaultTimeout(this.bot.utils.stringToMs(this.bot.config?.globalTimeout ?? 30000))
|
const legacyTimeout = (this.bot.config as { globalTimeout?: number | string }).globalTimeout
|
||||||
|
const nestedTimeout = (this.bot.config.browser as { globalTimeout?: number | string } | undefined)?.globalTimeout
|
||||||
|
const globalTimeout = legacyTimeout ?? nestedTimeout ?? 30000
|
||||||
|
context.setDefaultTimeout(this.bot.utils.stringToMs(globalTimeout))
|
||||||
|
|
||||||
|
// Normalize viewport and page rendering so content fits typical screens
|
||||||
|
try {
|
||||||
|
const desktopViewport = { width: 1280, height: 800 }
|
||||||
|
const mobileViewport = { width: 390, height: 844 }
|
||||||
|
|
||||||
|
context.on('page', async (page) => {
|
||||||
|
try {
|
||||||
|
// Set a reasonable viewport size depending on device type
|
||||||
|
if (this.bot.isMobile) {
|
||||||
|
await page.setViewportSize(mobileViewport)
|
||||||
|
} else {
|
||||||
|
await page.setViewportSize(desktopViewport)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Inject a tiny CSS to avoid gigantic scaling on some environments
|
||||||
|
await page.addInitScript(() => {
|
||||||
|
try {
|
||||||
|
const style = document.createElement('style')
|
||||||
|
style.id = '__mrs_fit_style'
|
||||||
|
style.textContent = `
|
||||||
|
html, body { overscroll-behavior: contain; }
|
||||||
|
/* Mild downscale to keep content within window on very large DPI */
|
||||||
|
@media (min-width: 1000px) {
|
||||||
|
html { zoom: 0.9 !important; }
|
||||||
|
}
|
||||||
|
`
|
||||||
|
document.documentElement.appendChild(style)
|
||||||
|
} catch { /* ignore */ }
|
||||||
|
})
|
||||||
|
} catch { /* ignore */ }
|
||||||
|
})
|
||||||
|
} catch { /* ignore */ }
|
||||||
|
|
||||||
await context.addCookies(sessionData.cookies)
|
await context.addCookies(sessionData.cookies)
|
||||||
|
|
||||||
if (this.bot.config.saveFingerprint) {
|
// Persist fingerprint when feature is configured
|
||||||
|
if (saveFingerprint.mobile || saveFingerprint.desktop) {
|
||||||
await saveFingerprintData(this.bot.config.sessionPath, email, this.bot.isMobile, fingerprint)
|
await saveFingerprintData(this.bot.config.sessionPath, email, this.bot.isMobile, fingerprint)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,9 +4,10 @@ import { AxiosRequestConfig } from 'axios'
|
|||||||
|
|
||||||
import { MicrosoftRewardsBot } from '../index'
|
import { MicrosoftRewardsBot } from '../index'
|
||||||
import { saveSessionData } from '../util/Load'
|
import { saveSessionData } from '../util/Load'
|
||||||
|
import { TIMEOUTS, RETRY_LIMITS, SELECTORS, URLS } from '../constants'
|
||||||
|
|
||||||
import { Counters, DashboardData, MorePromotion, PromotionalItem } from './../interface/DashboardData'
|
import { Counters, DashboardData, MorePromotion, PromotionalItem } from '../interface/DashboardData'
|
||||||
import { QuizData } from './../interface/QuizData'
|
import { QuizData } from '../interface/QuizData'
|
||||||
import { AppUserData } from '../interface/AppUserData'
|
import { AppUserData } from '../interface/AppUserData'
|
||||||
import { EarnablePoints } from '../interface/Points'
|
import { EarnablePoints } from '../interface/Points'
|
||||||
|
|
||||||
@@ -24,79 +25,154 @@ export default class BrowserFunc {
|
|||||||
* @param {Page} page Playwright page
|
* @param {Page} page Playwright page
|
||||||
*/
|
*/
|
||||||
async goHome(page: Page) {
|
async goHome(page: Page) {
|
||||||
|
const navigateHome = async () => {
|
||||||
|
try {
|
||||||
|
await page.goto(this.bot.config.baseURL, {
|
||||||
|
waitUntil: 'domcontentloaded',
|
||||||
|
timeout: 30000
|
||||||
|
})
|
||||||
|
} catch (e: any) {
|
||||||
|
if (typeof e?.message === 'string' && e.message.includes('ERR_ABORTED')) {
|
||||||
|
this.bot.log(this.bot.isMobile, 'GO-HOME', 'Navigation aborted, retrying...', 'warn')
|
||||||
|
await this.bot.utils.wait(1500)
|
||||||
|
await page.goto(this.bot.config.baseURL, {
|
||||||
|
waitUntil: 'domcontentloaded',
|
||||||
|
timeout: 30000
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
throw e
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const dashboardURL = new URL(this.bot.config.baseURL)
|
const dashboardURL = new URL(this.bot.config.baseURL)
|
||||||
|
|
||||||
if (page.url() === dashboardURL.href) {
|
if (new URL(page.url()).hostname !== dashboardURL.hostname) {
|
||||||
return
|
await navigateHome()
|
||||||
}
|
}
|
||||||
|
|
||||||
await page.goto(this.bot.config.baseURL)
|
let success = false
|
||||||
|
|
||||||
const maxIterations = 5 // Maximum iterations set to 5
|
for (let iteration = 1; iteration <= RETRY_LIMITS.GO_HOME_MAX; iteration++) {
|
||||||
|
await this.bot.utils.wait(TIMEOUTS.LONG)
|
||||||
for (let iteration = 1; iteration <= maxIterations; iteration++) {
|
|
||||||
await this.bot.utils.wait(3000)
|
|
||||||
await this.bot.browser.utils.tryDismissAllMessages(page)
|
await this.bot.browser.utils.tryDismissAllMessages(page)
|
||||||
|
|
||||||
// Check if account is suspended
|
|
||||||
const isSuspended = await page.waitForSelector('#suspendedAccountHeader', { state: 'visible', timeout: 2000 }).then(() => true).catch(() => false)
|
|
||||||
if (isSuspended) {
|
|
||||||
this.bot.log(this.bot.isMobile, 'GO-HOME', 'This account is suspended!', 'error')
|
|
||||||
throw new Error('Account has been suspended!')
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// If activities are found, exit the loop
|
await page.waitForSelector(SELECTORS.MORE_ACTIVITIES, { timeout: 1000 })
|
||||||
await page.waitForSelector('#more-activities', { timeout: 1000 })
|
|
||||||
this.bot.log(this.bot.isMobile, 'GO-HOME', 'Visited homepage successfully')
|
this.bot.log(this.bot.isMobile, 'GO-HOME', 'Visited homepage successfully')
|
||||||
|
success = true
|
||||||
break
|
break
|
||||||
|
} catch {
|
||||||
|
const suspendedByHeader = await page
|
||||||
|
.waitForSelector(SELECTORS.SUSPENDED_ACCOUNT, { state: 'visible', timeout: 500 })
|
||||||
|
.then(() => true)
|
||||||
|
.catch(() => false)
|
||||||
|
|
||||||
} catch (error) {
|
if (suspendedByHeader) {
|
||||||
// Continue if element is not found
|
this.bot.log(
|
||||||
|
this.bot.isMobile,
|
||||||
|
'GO-HOME',
|
||||||
|
`Account suspension detected by header selector (iteration ${iteration})`,
|
||||||
|
'error'
|
||||||
|
)
|
||||||
|
throw new Error('Account has been suspended!')
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const mainContent =
|
||||||
|
(await page
|
||||||
|
.locator('#contentContainer, #main, .main-content')
|
||||||
|
.first()
|
||||||
|
.textContent({ timeout: 500 })
|
||||||
|
.catch(() => '')) || ''
|
||||||
|
|
||||||
|
const suspensionPatterns = [
|
||||||
|
/account\s+has\s+been\s+suspended/i,
|
||||||
|
/suspended\s+due\s+to\s+unusual\s+activity/i,
|
||||||
|
/your\s+account\s+is\s+temporarily\s+suspended/i
|
||||||
|
]
|
||||||
|
|
||||||
|
const isSuspended = suspensionPatterns.some((p) => p.test(mainContent))
|
||||||
|
if (isSuspended) {
|
||||||
|
this.bot.log(
|
||||||
|
this.bot.isMobile,
|
||||||
|
'GO-HOME',
|
||||||
|
`Account suspension detected by content text (iteration ${iteration})`,
|
||||||
|
'error'
|
||||||
|
)
|
||||||
|
throw new Error('Account has been suspended!')
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
this.bot.log(
|
||||||
|
this.bot.isMobile,
|
||||||
|
'GO-HOME',
|
||||||
|
`Suspension text check skipped: ${e instanceof Error ? e.message : String(e)}`,
|
||||||
|
'warn'
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
const currentURL = new URL(page.url())
|
||||||
|
if (currentURL.hostname !== dashboardURL.hostname) {
|
||||||
|
await this.bot.browser.utils.tryDismissAllMessages(page)
|
||||||
|
await this.bot.utils.wait(TIMEOUTS.MEDIUM_LONG)
|
||||||
|
try {
|
||||||
|
await navigateHome()
|
||||||
|
} catch (e: any) {
|
||||||
|
if (typeof e?.message === 'string' && e.message.includes('ERR_ABORTED')) {
|
||||||
|
this.bot.log(this.bot.isMobile, 'GO-HOME', 'Navigation aborted again; continuing...', 'warn')
|
||||||
|
} else {
|
||||||
|
throw e
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
this.bot.log(
|
||||||
|
this.bot.isMobile,
|
||||||
|
'GO-HOME',
|
||||||
|
`Activities not found yet (iteration ${iteration}/${RETRY_LIMITS.GO_HOME_MAX}), retrying...`,
|
||||||
|
'warn'
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Below runs if the homepage was unable to be visited
|
const backoff = Math.min(TIMEOUTS.VERY_LONG, 1000 + iteration * 500)
|
||||||
const currentURL = new URL(page.url())
|
await this.bot.utils.wait(backoff)
|
||||||
|
|
||||||
if (currentURL.hostname !== dashboardURL.hostname) {
|
|
||||||
await this.bot.browser.utils.tryDismissAllMessages(page)
|
|
||||||
|
|
||||||
await this.bot.utils.wait(2000)
|
|
||||||
await page.goto(this.bot.config.baseURL)
|
|
||||||
} else {
|
|
||||||
this.bot.log(this.bot.isMobile, 'GO-HOME', 'Visited homepage successfully')
|
|
||||||
break
|
|
||||||
}
|
|
||||||
|
|
||||||
await this.bot.utils.wait(5000)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!success) {
|
||||||
|
throw new Error('Failed to reach homepage or find activities within retry limit')
|
||||||
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw this.bot.log(this.bot.isMobile, 'GO-HOME', 'An error occurred:' + error, 'error')
|
throw this.bot.log(
|
||||||
|
this.bot.isMobile,
|
||||||
|
'GO-HOME',
|
||||||
|
'An error occurred:' + (error instanceof Error ? ` ${error.message}` : ` ${String(error)}`),
|
||||||
|
'error'
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fetch user dashboard data
|
* Fetch user dashboard data
|
||||||
* @returns {DashboardData} Object of user bing rewards dashboard data
|
* @returns {DashboardData} Object of user bing rewards dashboard data
|
||||||
*/
|
*/
|
||||||
async getDashboardData(): Promise<DashboardData> {
|
async getDashboardData(page?: Page): Promise<DashboardData> {
|
||||||
|
const target = page ?? this.bot.homePage
|
||||||
const dashboardURL = new URL(this.bot.config.baseURL)
|
const dashboardURL = new URL(this.bot.config.baseURL)
|
||||||
const currentURL = new URL(this.bot.homePage.url())
|
const currentURL = new URL(target.url())
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Should never happen since tasks are opened in a new tab!
|
// Should never happen since tasks are opened in a new tab!
|
||||||
if (currentURL.hostname !== dashboardURL.hostname) {
|
if (currentURL.hostname !== dashboardURL.hostname) {
|
||||||
this.bot.log(this.bot.isMobile, 'DASHBOARD-DATA', 'Provided page did not equal dashboard page, redirecting to dashboard page')
|
this.bot.log(this.bot.isMobile, 'DASHBOARD-DATA', 'Provided page did not equal dashboard page, redirecting to dashboard page')
|
||||||
await this.goHome(this.bot.homePage)
|
await this.goHome(target)
|
||||||
}
|
}
|
||||||
let lastError: any = null
|
let lastError: unknown = null
|
||||||
for (let attempt = 1; attempt <= 2; attempt++) {
|
for (let attempt = 1; attempt <= 2; attempt++) {
|
||||||
try {
|
try {
|
||||||
// Reload the page to get new data
|
// Reload the page to get new data
|
||||||
await this.bot.homePage.reload({ waitUntil: 'domcontentloaded' })
|
await target.reload({ waitUntil: 'domcontentloaded' })
|
||||||
lastError = null
|
lastError = null
|
||||||
break
|
break
|
||||||
} catch (re) {
|
} catch (re) {
|
||||||
@@ -108,8 +184,8 @@ export default class BrowserFunc {
|
|||||||
if (attempt === 1) {
|
if (attempt === 1) {
|
||||||
this.bot.log(this.bot.isMobile, 'GET-DASHBOARD-DATA', 'Page appears closed; trying one navigation fallback', 'warn')
|
this.bot.log(this.bot.isMobile, 'GET-DASHBOARD-DATA', 'Page appears closed; trying one navigation fallback', 'warn')
|
||||||
try {
|
try {
|
||||||
await this.goHome(this.bot.homePage)
|
await this.goHome(target)
|
||||||
} catch {/* ignore */}
|
} catch {/* ignore */ }
|
||||||
} else {
|
} else {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
@@ -119,7 +195,15 @@ export default class BrowserFunc {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const scriptContent = await this.bot.homePage.evaluate(() => {
|
// Wait a bit longer for scripts to load, especially on mobile
|
||||||
|
await this.bot.utils.wait(this.bot.isMobile ? TIMEOUTS.LONG : TIMEOUTS.MEDIUM)
|
||||||
|
|
||||||
|
// Wait for the more-activities element to ensure page is fully loaded
|
||||||
|
await target.waitForSelector(SELECTORS.MORE_ACTIVITIES, { timeout: TIMEOUTS.DASHBOARD_WAIT }).catch(() => {
|
||||||
|
this.bot.log(this.bot.isMobile, 'GET-DASHBOARD-DATA', 'Activities element not found, continuing anyway', 'warn')
|
||||||
|
})
|
||||||
|
|
||||||
|
let scriptContent = await target.evaluate(() => {
|
||||||
const scripts = Array.from(document.querySelectorAll('script'))
|
const scripts = Array.from(document.querySelectorAll('script'))
|
||||||
const targetScript = scripts.find(script => script.innerText.includes('var dashboard'))
|
const targetScript = scripts.find(script => script.innerText.includes('var dashboard'))
|
||||||
|
|
||||||
@@ -127,22 +211,68 @@ export default class BrowserFunc {
|
|||||||
})
|
})
|
||||||
|
|
||||||
if (!scriptContent) {
|
if (!scriptContent) {
|
||||||
throw this.bot.log(this.bot.isMobile, 'GET-DASHBOARD-DATA', 'Dashboard data not found within script', 'error')
|
this.bot.log(this.bot.isMobile, 'GET-DASHBOARD-DATA', 'Dashboard script not found on first try, attempting recovery', 'warn')
|
||||||
|
|
||||||
|
// Force a navigation retry once before failing hard
|
||||||
|
try {
|
||||||
|
await this.goHome(target)
|
||||||
|
await target.waitForLoadState('domcontentloaded', { timeout: TIMEOUTS.VERY_LONG }).catch((e) => {
|
||||||
|
this.bot.log(this.bot.isMobile, 'GET-DASHBOARD-DATA', `Wait for load state failed: ${e}`, 'warn')
|
||||||
|
})
|
||||||
|
await this.bot.utils.wait(this.bot.isMobile ? TIMEOUTS.LONG : TIMEOUTS.MEDIUM)
|
||||||
|
} catch (e) {
|
||||||
|
this.bot.log(this.bot.isMobile, 'GET-DASHBOARD-DATA', `Recovery navigation failed: ${e}`, 'warn')
|
||||||
|
}
|
||||||
|
|
||||||
|
const retryContent = await target.evaluate(() => {
|
||||||
|
const scripts = Array.from(document.querySelectorAll('script'))
|
||||||
|
const targetScript = scripts.find(script => script.innerText.includes('var dashboard'))
|
||||||
|
return targetScript?.innerText ? targetScript.innerText : null
|
||||||
|
}).catch(() => null)
|
||||||
|
|
||||||
|
if (!retryContent) {
|
||||||
|
// Log additional debug info
|
||||||
|
const scriptsDebug = await target.evaluate(() => {
|
||||||
|
const scripts = Array.from(document.querySelectorAll('script'))
|
||||||
|
return scripts.map(s => s.innerText.substring(0, 100)).join(' | ')
|
||||||
|
}).catch(() => 'Unable to get script debug info')
|
||||||
|
|
||||||
|
this.bot.log(this.bot.isMobile, 'GET-DASHBOARD-DATA', `Available scripts preview: ${scriptsDebug}`, 'warn')
|
||||||
|
throw this.bot.log(this.bot.isMobile, 'GET-DASHBOARD-DATA', 'Dashboard data not found within script', 'error')
|
||||||
|
}
|
||||||
|
scriptContent = retryContent
|
||||||
}
|
}
|
||||||
|
|
||||||
// Extract the dashboard object from the script content
|
// Extract the dashboard object from the script content
|
||||||
const dashboardData = await this.bot.homePage.evaluate((scriptContent: string) => {
|
const dashboardData = await target.evaluate((scriptContent: string) => {
|
||||||
// Extract the dashboard object using regex
|
// Try multiple regex patterns for better compatibility
|
||||||
const regex = /var dashboard = (\{.*?\});/s
|
const patterns = [
|
||||||
const match = regex.exec(scriptContent)
|
/var dashboard = (\{.*?\});/s, // Original pattern
|
||||||
|
/var dashboard=(\{.*?\});/s, // No spaces
|
||||||
|
/var\s+dashboard\s*=\s*(\{.*?\});/s, // Flexible whitespace
|
||||||
|
/dashboard\s*=\s*(\{[\s\S]*?\});/ // More permissive
|
||||||
|
]
|
||||||
|
|
||||||
if (match && match[1]) {
|
for (const regex of patterns) {
|
||||||
return JSON.parse(match[1])
|
const match = regex.exec(scriptContent)
|
||||||
|
if (match && match[1]) {
|
||||||
|
try {
|
||||||
|
return JSON.parse(match[1])
|
||||||
|
} catch (e) {
|
||||||
|
// Try next pattern if JSON parsing fails
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return null
|
||||||
|
|
||||||
}, scriptContent)
|
}, scriptContent)
|
||||||
|
|
||||||
if (!dashboardData) {
|
if (!dashboardData) {
|
||||||
|
// Log a snippet of the script content for debugging
|
||||||
|
const scriptPreview = scriptContent.substring(0, 200)
|
||||||
|
this.bot.log(this.bot.isMobile, 'GET-DASHBOARD-DATA', `Script preview: ${scriptPreview}`, 'warn')
|
||||||
throw this.bot.log(this.bot.isMobile, 'GET-DASHBOARD-DATA', 'Unable to parse dashboard script', 'error')
|
throw this.bot.log(this.bot.isMobile, 'GET-DASHBOARD-DATA', 'Unable to parse dashboard script', 'error')
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -232,11 +362,15 @@ export default class BrowserFunc {
|
|||||||
]
|
]
|
||||||
|
|
||||||
const data = await this.getDashboardData()
|
const data = await this.getDashboardData()
|
||||||
let geoLocale = data.userProfile.attributes.country
|
// Guard against missing profile/attributes and undefined settings
|
||||||
geoLocale = (this.bot.config.searchSettings.useGeoLocaleQueries && geoLocale.length === 2) ? geoLocale.toLowerCase() : 'us'
|
let geoLocale = data?.userProfile?.attributes?.country || 'US'
|
||||||
|
const useGeo = !!(this.bot?.config?.searchSettings?.useGeoLocaleQueries)
|
||||||
|
geoLocale = (useGeo && typeof geoLocale === 'string' && geoLocale.length === 2)
|
||||||
|
? geoLocale.toLowerCase()
|
||||||
|
: 'us'
|
||||||
|
|
||||||
const userDataRequest: AxiosRequestConfig = {
|
const userDataRequest: AxiosRequestConfig = {
|
||||||
url: 'https://prod.rewardsplatform.microsoft.com/dapi/me?channel=SAAndroid&options=613',
|
url: URLS.APP_USER_DATA,
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
headers: {
|
headers: {
|
||||||
'Authorization': `Bearer ${accessToken}`,
|
'Authorization': `Bearer ${accessToken}`,
|
||||||
@@ -292,37 +426,73 @@ export default class BrowserFunc {
|
|||||||
*/
|
*/
|
||||||
async getQuizData(page: Page): Promise<QuizData> {
|
async getQuizData(page: Page): Promise<QuizData> {
|
||||||
try {
|
try {
|
||||||
|
// Wait for page to be fully loaded
|
||||||
|
await page.waitForLoadState('domcontentloaded')
|
||||||
|
await this.bot.utils.wait(TIMEOUTS.MEDIUM)
|
||||||
|
|
||||||
const html = await page.content()
|
const html = await page.content()
|
||||||
const $ = load(html)
|
const $ = load(html)
|
||||||
|
|
||||||
const scriptContent = $('script').filter((index: number, element: any) => {
|
// Try multiple possible variable names
|
||||||
return $(element).text().includes('_w.rewardsQuizRenderInfo')
|
const possibleVariables = [
|
||||||
}).text()
|
'_w.rewardsQuizRenderInfo',
|
||||||
|
'rewardsQuizRenderInfo',
|
||||||
|
'_w.quizRenderInfo',
|
||||||
|
'quizRenderInfo'
|
||||||
|
]
|
||||||
|
|
||||||
if (scriptContent) {
|
let scriptContent = ''
|
||||||
const regex = /_w\.rewardsQuizRenderInfo\s*=\s*({.*?});/s
|
let foundVariable = ''
|
||||||
|
|
||||||
|
for (const varName of possibleVariables) {
|
||||||
|
scriptContent = $('script')
|
||||||
|
.toArray()
|
||||||
|
.map(el => $(el).text())
|
||||||
|
.find(t => t.includes(varName)) || ''
|
||||||
|
|
||||||
|
if (scriptContent) {
|
||||||
|
foundVariable = varName
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (scriptContent && foundVariable) {
|
||||||
|
// Escape dots in variable name for regex
|
||||||
|
const escapedVar = foundVariable.replace(/\./g, '\\.')
|
||||||
|
const regex = new RegExp(`${escapedVar}\\s*=\\s*({.*?});`, 's')
|
||||||
const match = regex.exec(scriptContent)
|
const match = regex.exec(scriptContent)
|
||||||
|
|
||||||
if (match && match[1]) {
|
if (match && match[1]) {
|
||||||
const quizData = JSON.parse(match[1])
|
const quizData = JSON.parse(match[1])
|
||||||
|
this.bot.log(this.bot.isMobile, 'GET-QUIZ-DATA', `Found quiz data using variable: ${foundVariable}`, 'log')
|
||||||
return quizData
|
return quizData
|
||||||
} else {
|
} else {
|
||||||
throw this.bot.log(this.bot.isMobile, 'GET-QUIZ-DATA', 'Quiz data not found within script', 'error')
|
throw this.bot.log(this.bot.isMobile, 'GET-QUIZ-DATA', `Variable ${foundVariable} found but could not extract JSON data`, 'error')
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
// Log available scripts for debugging
|
||||||
|
const allScripts = $('script')
|
||||||
|
.toArray()
|
||||||
|
.map(el => $(el).text())
|
||||||
|
.filter(t => t.length > 0)
|
||||||
|
.map(t => t.substring(0, 100))
|
||||||
|
|
||||||
|
this.bot.log(this.bot.isMobile, 'GET-QUIZ-DATA', `Script not found. Tried variables: ${possibleVariables.join(', ')}`, 'error')
|
||||||
|
this.bot.log(this.bot.isMobile, 'GET-QUIZ-DATA', `Found ${allScripts.length} scripts on page`, 'warn')
|
||||||
|
|
||||||
throw this.bot.log(this.bot.isMobile, 'GET-QUIZ-DATA', 'Script containing quiz data not found', 'error')
|
throw this.bot.log(this.bot.isMobile, 'GET-QUIZ-DATA', 'Script containing quiz data not found', 'error')
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw this.bot.log(this.bot.isMobile, 'GET-QUIZ-DATA', 'An error occurred:' + error, 'error')
|
throw this.bot.log(this.bot.isMobile, 'GET-QUIZ-DATA', 'An error occurred: ' + error, 'error')
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async waitForQuizRefresh(page: Page): Promise<boolean> {
|
async waitForQuizRefresh(page: Page): Promise<boolean> {
|
||||||
try {
|
try {
|
||||||
await page.waitForSelector('span.rqMCredits', { state: 'visible', timeout: 10000 })
|
await page.waitForSelector(SELECTORS.QUIZ_CREDITS, { state: 'visible', timeout: TIMEOUTS.DASHBOARD_WAIT })
|
||||||
await this.bot.utils.wait(2000)
|
await this.bot.utils.wait(TIMEOUTS.MEDIUM_LONG)
|
||||||
|
|
||||||
return true
|
return true
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -333,8 +503,8 @@ export default class BrowserFunc {
|
|||||||
|
|
||||||
async checkQuizCompleted(page: Page): Promise<boolean> {
|
async checkQuizCompleted(page: Page): Promise<boolean> {
|
||||||
try {
|
try {
|
||||||
await page.waitForSelector('#quizCompleteContainer', { state: 'visible', timeout: 2000 })
|
await page.waitForSelector(SELECTORS.QUIZ_COMPLETE, { state: 'visible', timeout: TIMEOUTS.MEDIUM_LONG })
|
||||||
await this.bot.utils.wait(2000)
|
await this.bot.utils.wait(TIMEOUTS.MEDIUM_LONG)
|
||||||
|
|
||||||
return true
|
return true
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -355,7 +525,10 @@ export default class BrowserFunc {
|
|||||||
const html = await page.content()
|
const html = await page.content()
|
||||||
const $ = load(html)
|
const $ = load(html)
|
||||||
|
|
||||||
const element = $('.offer-cta').toArray().find((x: any) => x.attribs.href?.includes(activity.offerId))
|
const element = $('.offer-cta').toArray().find((x: unknown) => {
|
||||||
|
const el = x as { attribs?: { href?: string } }
|
||||||
|
return !!el.attribs?.href?.includes(activity.offerId)
|
||||||
|
})
|
||||||
if (element) {
|
if (element) {
|
||||||
selector = `a[href*="${element.attribs.href}"]`
|
selector = `a[href*="${element.attribs.href}"]`
|
||||||
}
|
}
|
||||||
@@ -371,7 +544,7 @@ export default class BrowserFunc {
|
|||||||
// Save cookies
|
// Save cookies
|
||||||
await saveSessionData(this.bot.config.sessionPath, browser, email, this.bot.isMobile)
|
await saveSessionData(this.bot.config.sessionPath, browser, email, this.bot.isMobile)
|
||||||
|
|
||||||
await this.bot.utils.wait(2000)
|
await this.bot.utils.wait(TIMEOUTS.MEDIUM_LONG)
|
||||||
|
|
||||||
// Close browser
|
// Close browser
|
||||||
await browser.close()
|
await browser.close()
|
||||||
|
|||||||
@@ -3,61 +3,171 @@ import { load } from 'cheerio'
|
|||||||
|
|
||||||
import { MicrosoftRewardsBot } from '../index'
|
import { MicrosoftRewardsBot } from '../index'
|
||||||
|
|
||||||
|
type DismissButton = { selector: string; label: string; isXPath?: boolean }
|
||||||
|
|
||||||
export default class BrowserUtil {
|
export default class BrowserUtil {
|
||||||
private bot: MicrosoftRewardsBot
|
private bot: MicrosoftRewardsBot
|
||||||
|
|
||||||
|
private static readonly DISMISS_BUTTONS: readonly DismissButton[] = [
|
||||||
|
{ selector: '#acceptButton', label: 'AcceptButton' },
|
||||||
|
{ selector: '.optanon-allow-all, .optanon-alert-box-button', label: 'OneTrust Accept' },
|
||||||
|
{ selector: '.ext-secondary.ext-button', label: 'Skip For Now' },
|
||||||
|
{ selector: '#iLandingViewAction', label: 'Landing Continue' },
|
||||||
|
{ selector: '#iShowSkip', label: 'Show Skip' },
|
||||||
|
{ selector: '#iNext', label: 'Next' },
|
||||||
|
{ selector: '#iLooksGood', label: 'LooksGood' },
|
||||||
|
{ selector: '#idSIButton9', label: 'PrimaryLoginButton' },
|
||||||
|
{ selector: '.ms-Button.ms-Button--primary', label: 'Primary Generic' },
|
||||||
|
{ selector: '.c-glyph.glyph-cancel', label: 'Mobile Welcome Cancel' },
|
||||||
|
{ selector: '.maybe-later, button[data-automation-id*="maybeLater" i]', label: 'Maybe Later' },
|
||||||
|
{ selector: '#bnp_btn_reject', label: 'Bing Cookie Reject' },
|
||||||
|
{ selector: '#bnp_btn_accept', label: 'Bing Cookie Accept' },
|
||||||
|
{ selector: '#bnp_close_link', label: 'Bing Cookie Close' },
|
||||||
|
{ selector: '#reward_pivot_earn', label: 'Rewards Pivot Earn' },
|
||||||
|
{ selector: '//div[@id="cookieConsentContainer"]//button[contains(text(), "Accept")]', label: 'Legacy Cookie Accept', isXPath: true }
|
||||||
|
]
|
||||||
|
|
||||||
|
private static readonly OVERLAY_SELECTORS = {
|
||||||
|
container: '#bnp_overlay_wrapper',
|
||||||
|
reject: '#bnp_btn_reject, button[aria-label*="Reject" i]',
|
||||||
|
accept: '#bnp_btn_accept'
|
||||||
|
} as const
|
||||||
|
|
||||||
|
private static readonly STREAK_DIALOG_SELECTORS = {
|
||||||
|
container: '[role="dialog"], div[role="alert"], div.ms-Dialog',
|
||||||
|
textFilter: /streak protection has run out/i,
|
||||||
|
closeButtons: 'button[aria-label*="close" i], button:has-text("Close"), button:has-text("Dismiss"), button:has-text("Got it"), button:has-text("OK"), button:has-text("Ok")'
|
||||||
|
} as const
|
||||||
|
|
||||||
|
private static readonly TERMS_UPDATE_SELECTORS = {
|
||||||
|
titleId: '#iTOUTitle',
|
||||||
|
titleText: /we're updating our terms/i,
|
||||||
|
nextButton: 'button[data-testid="primaryButton"]:has-text("Next"), button[type="submit"]:has-text("Next")'
|
||||||
|
} as const
|
||||||
|
|
||||||
constructor(bot: MicrosoftRewardsBot) {
|
constructor(bot: MicrosoftRewardsBot) {
|
||||||
this.bot = bot
|
this.bot = bot
|
||||||
}
|
}
|
||||||
|
|
||||||
async tryDismissAllMessages(page: Page): Promise<void> {
|
async tryDismissAllMessages(page: Page): Promise<void> {
|
||||||
const buttons = [
|
const maxRounds = 3
|
||||||
{ selector: '#acceptButton', label: 'AcceptButton' },
|
for (let round = 0; round < maxRounds; round++) {
|
||||||
{ selector: '.ext-secondary.ext-button', label: '"Skip for now" Button' },
|
const dismissCount = await this.dismissRound(page)
|
||||||
{ selector: '#iLandingViewAction', label: 'iLandingViewAction' },
|
if (dismissCount === 0) break
|
||||||
{ selector: '#iShowSkip', label: 'iShowSkip' },
|
}
|
||||||
{ selector: '#iNext', label: 'iNext' },
|
}
|
||||||
{ selector: '#iLooksGood', label: 'iLooksGood' },
|
|
||||||
{ selector: '#idSIButton9', label: 'idSIButton9' },
|
|
||||||
{ selector: '.ms-Button.ms-Button--primary', label: 'Primary Button' },
|
|
||||||
{ selector: '.c-glyph.glyph-cancel', label: 'Mobile Welcome Button' },
|
|
||||||
{ selector: '.maybe-later', label: 'Mobile Rewards App Banner' },
|
|
||||||
{ selector: '//div[@id="cookieConsentContainer"]//button[contains(text(), "Accept")]', label: 'Accept Cookie Consent Container', isXPath: true },
|
|
||||||
{ selector: '#bnp_btn_accept', label: 'Bing Cookie Banner' },
|
|
||||||
{ selector: '#reward_pivot_earn', label: 'Reward Coupon Accept' }
|
|
||||||
]
|
|
||||||
|
|
||||||
for (const button of buttons) {
|
private async dismissRound(page: Page): Promise<number> {
|
||||||
try {
|
let count = 0
|
||||||
const element = button.isXPath ? page.locator(`xpath=${button.selector}`) : page.locator(button.selector)
|
count += await this.dismissStandardButtons(page)
|
||||||
await element.first().click({ timeout: 500 })
|
count += await this.dismissOverlayButtons(page)
|
||||||
await page.waitForTimeout(500)
|
count += await this.dismissStreakDialog(page)
|
||||||
|
count += await this.dismissTermsUpdateDialog(page)
|
||||||
|
return count
|
||||||
|
}
|
||||||
|
|
||||||
this.bot.log(this.bot.isMobile, 'DISMISS-ALL-MESSAGES', `Dismissed: ${button.label}`)
|
private async dismissStandardButtons(page: Page): Promise<number> {
|
||||||
|
let count = 0
|
||||||
} catch (error) {
|
for (const btn of BrowserUtil.DISMISS_BUTTONS) {
|
||||||
// Silent fail
|
const dismissed = await this.tryClickButton(page, btn)
|
||||||
|
if (dismissed) {
|
||||||
|
count++
|
||||||
|
await page.waitForTimeout(150)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return count
|
||||||
|
}
|
||||||
|
|
||||||
// Handle blocking Bing privacy overlay intercepting clicks (#bnp_overlay_wrapper)
|
private async tryClickButton(page: Page, btn: DismissButton): Promise<boolean> {
|
||||||
try {
|
try {
|
||||||
const overlay = await page.locator('#bnp_overlay_wrapper').first()
|
const loc = btn.isXPath ? page.locator(`xpath=${btn.selector}`) : page.locator(btn.selector)
|
||||||
if (await overlay.isVisible({ timeout: 500 }).catch(()=>false)) {
|
const visible = await loc.first().isVisible({ timeout: 200 }).catch(() => false)
|
||||||
// Try common dismiss buttons inside overlay
|
if (!visible) return false
|
||||||
const rejectBtn = await page.locator('#bnp_btn_reject, button[aria-label*="Reject" i]').first()
|
|
||||||
const acceptBtn = await page.locator('#bnp_btn_accept').first()
|
await loc.first().click({ timeout: 500 }).catch(() => {})
|
||||||
if (await rejectBtn.isVisible().catch(()=>false)) {
|
this.bot.log(this.bot.isMobile, 'DISMISS-ALL-MESSAGES', `Dismissed: ${btn.label}`)
|
||||||
await rejectBtn.click({ timeout: 500 }).catch(()=>{})
|
return true
|
||||||
this.bot.log(this.bot.isMobile, 'DISMISS-ALL-MESSAGES', 'Dismissed: Bing Overlay Reject')
|
} catch {
|
||||||
} else if (await acceptBtn.isVisible().catch(()=>false)) {
|
return false
|
||||||
await acceptBtn.click({ timeout: 500 }).catch(()=>{})
|
}
|
||||||
this.bot.log(this.bot.isMobile, 'DISMISS-ALL-MESSAGES', 'Dismissed: Bing Overlay Accept (fallback)')
|
}
|
||||||
}
|
|
||||||
await page.waitForTimeout(300)
|
private async dismissOverlayButtons(page: Page): Promise<number> {
|
||||||
|
try {
|
||||||
|
const { container, reject, accept } = BrowserUtil.OVERLAY_SELECTORS
|
||||||
|
const overlay = page.locator(container)
|
||||||
|
const visible = await overlay.isVisible({ timeout: 200 }).catch(() => false)
|
||||||
|
if (!visible) return 0
|
||||||
|
|
||||||
|
const rejectBtn = overlay.locator(reject)
|
||||||
|
if (await rejectBtn.first().isVisible().catch(() => false)) {
|
||||||
|
await rejectBtn.first().click({ timeout: 500 }).catch(() => {})
|
||||||
|
this.bot.log(this.bot.isMobile, 'DISMISS-ALL-MESSAGES', 'Dismissed: Overlay Reject')
|
||||||
|
return 1
|
||||||
}
|
}
|
||||||
} catch { /* ignore */ }
|
|
||||||
|
const acceptBtn = overlay.locator(accept)
|
||||||
|
if (await acceptBtn.first().isVisible().catch(() => false)) {
|
||||||
|
await acceptBtn.first().click({ timeout: 500 }).catch(() => {})
|
||||||
|
this.bot.log(this.bot.isMobile, 'DISMISS-ALL-MESSAGES', 'Dismissed: Overlay Accept')
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0
|
||||||
|
} catch {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private async dismissStreakDialog(page: Page): Promise<number> {
|
||||||
|
try {
|
||||||
|
const { container, textFilter, closeButtons } = BrowserUtil.STREAK_DIALOG_SELECTORS
|
||||||
|
const dialog = page.locator(container).filter({ hasText: textFilter })
|
||||||
|
const visible = await dialog.first().isVisible({ timeout: 200 }).catch(() => false)
|
||||||
|
if (!visible) return 0
|
||||||
|
|
||||||
|
const closeBtn = dialog.locator(closeButtons).first()
|
||||||
|
if (await closeBtn.isVisible({ timeout: 200 }).catch(() => false)) {
|
||||||
|
await closeBtn.click({ timeout: 500 }).catch(() => {})
|
||||||
|
this.bot.log(this.bot.isMobile, 'DISMISS-ALL-MESSAGES', 'Dismissed: Streak Protection Dialog Button')
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
|
await page.keyboard.press('Escape').catch(() => {})
|
||||||
|
this.bot.log(this.bot.isMobile, 'DISMISS-ALL-MESSAGES', 'Dismissed: Streak Protection Dialog Escape')
|
||||||
|
return 1
|
||||||
|
} catch {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private async dismissTermsUpdateDialog(page: Page): Promise<number> {
|
||||||
|
try {
|
||||||
|
const { titleId, titleText, nextButton } = BrowserUtil.TERMS_UPDATE_SELECTORS
|
||||||
|
|
||||||
|
// Check if terms update page is present
|
||||||
|
const titleById = page.locator(titleId)
|
||||||
|
const titleByText = page.locator('h1').filter({ hasText: titleText })
|
||||||
|
|
||||||
|
const hasTitle = await titleById.isVisible({ timeout: 200 }).catch(() => false) ||
|
||||||
|
await titleByText.first().isVisible({ timeout: 200 }).catch(() => false)
|
||||||
|
|
||||||
|
if (!hasTitle) return 0
|
||||||
|
|
||||||
|
// Click the Next button
|
||||||
|
const nextBtn = page.locator(nextButton).first()
|
||||||
|
if (await nextBtn.isVisible({ timeout: 500 }).catch(() => false)) {
|
||||||
|
await nextBtn.click({ timeout: 1000 }).catch(() => {})
|
||||||
|
this.bot.log(this.bot.isMobile, 'DISMISS-ALL-MESSAGES', 'Dismissed: Terms Update Dialog (Next)')
|
||||||
|
// Wait a bit for navigation
|
||||||
|
await page.waitForTimeout(1000)
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0
|
||||||
|
} catch {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async getLatestTab(page: Page): Promise<Page> {
|
async getLatestTab(page: Page): Promise<Page> {
|
||||||
@@ -78,40 +188,6 @@ export default class BrowserUtil {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async getTabs(page: Page) {
|
|
||||||
try {
|
|
||||||
const browser = page.context()
|
|
||||||
const pages = browser.pages()
|
|
||||||
|
|
||||||
const homeTab = pages[1]
|
|
||||||
let homeTabURL: URL
|
|
||||||
|
|
||||||
if (!homeTab) {
|
|
||||||
throw this.bot.log(this.bot.isMobile, 'GET-TABS', 'Home tab could not be found!', 'error')
|
|
||||||
|
|
||||||
} else {
|
|
||||||
homeTabURL = new URL(homeTab.url())
|
|
||||||
|
|
||||||
if (homeTabURL.hostname !== 'rewards.bing.com') {
|
|
||||||
throw this.bot.log(this.bot.isMobile, 'GET-TABS', 'Reward page hostname is invalid: ' + homeTabURL.host, 'error')
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const workerTab = pages[2]
|
|
||||||
if (!workerTab) {
|
|
||||||
throw this.bot.log(this.bot.isMobile, 'GET-TABS', 'Worker tab could not be found!', 'error')
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
homeTab: homeTab,
|
|
||||||
workerTab: workerTab
|
|
||||||
}
|
|
||||||
|
|
||||||
} catch (error) {
|
|
||||||
throw this.bot.log(this.bot.isMobile, 'GET-TABS', 'An error occurred:' + error, 'error')
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async reloadBadPage(page: Page): Promise<void> {
|
async reloadBadPage(page: Page): Promise<void> {
|
||||||
try {
|
try {
|
||||||
const html = await page.content().catch(() => '')
|
const html = await page.content().catch(() => '')
|
||||||
@@ -129,4 +205,15 @@ export default class BrowserUtil {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Perform small human-like gestures: short waits, minor mouse moves and occasional scrolls.
|
||||||
|
* This should be called sparingly between actions to avoid a fixed cadence.
|
||||||
|
*/
|
||||||
|
async humanizePage(page: Page): Promise<void> {
|
||||||
|
try {
|
||||||
|
await this.bot.humanizer.microGestures(page)
|
||||||
|
await this.bot.humanizer.actionPause()
|
||||||
|
} catch { /* swallow */ }
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
130
src/config.json
130
src/config.json
@@ -1,13 +1,25 @@
|
|||||||
{
|
{
|
||||||
"baseURL": "https://rewards.bing.com",
|
"baseURL": "https://rewards.bing.com",
|
||||||
"sessionPath": "sessions",
|
"sessionPath": "sessions",
|
||||||
"headless": false,
|
"dryRun": false,
|
||||||
"parallel": false,
|
"browser": {
|
||||||
"runOnZeroPoints": false,
|
"headless": false,
|
||||||
"clusters": 1,
|
"globalTimeout": "30s"
|
||||||
"saveFingerprint": {
|
},
|
||||||
"mobile": false,
|
"fingerprinting": {
|
||||||
"desktop": false
|
"saveFingerprint": {
|
||||||
|
"mobile": true,
|
||||||
|
"desktop": true
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"execution": {
|
||||||
|
"parallel": false,
|
||||||
|
"runOnZeroPoints": false,
|
||||||
|
"clusters": 1
|
||||||
|
},
|
||||||
|
"jobState": {
|
||||||
|
"enabled": true,
|
||||||
|
"dir": ""
|
||||||
},
|
},
|
||||||
"workers": {
|
"workers": {
|
||||||
"doDailySet": true,
|
"doDailySet": true,
|
||||||
@@ -16,36 +28,94 @@
|
|||||||
"doDesktopSearch": true,
|
"doDesktopSearch": true,
|
||||||
"doMobileSearch": true,
|
"doMobileSearch": true,
|
||||||
"doDailyCheckIn": true,
|
"doDailyCheckIn": true,
|
||||||
"doReadToEarn": true
|
"doReadToEarn": true,
|
||||||
|
"bundleDailySetWithSearch": true
|
||||||
},
|
},
|
||||||
"searchOnBingLocalQueries": false,
|
"search": {
|
||||||
"globalTimeout": "30s",
|
"useLocalQueries": true,
|
||||||
"searchSettings": {
|
"settings": {
|
||||||
"useGeoLocaleQueries": false,
|
"useGeoLocaleQueries": true,
|
||||||
"scrollRandomResults": true,
|
"scrollRandomResults": true,
|
||||||
"clickRandomResults": true,
|
"clickRandomResults": true,
|
||||||
"searchDelay": {
|
"retryMobileSearchAmount": 2,
|
||||||
"min": "3min",
|
"delay": {
|
||||||
"max": "5min"
|
"min": "2min",
|
||||||
|
"max": "5min"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"queryDiversity": {
|
||||||
|
"enabled": true,
|
||||||
|
"sources": [
|
||||||
|
"google-trends",
|
||||||
|
"reddit",
|
||||||
|
"local-fallback"
|
||||||
|
],
|
||||||
|
"maxQueriesPerSource": 10,
|
||||||
|
"cacheMinutes": 30
|
||||||
|
},
|
||||||
|
"humanization": {
|
||||||
|
"enabled": true,
|
||||||
|
"stopOnBan": true,
|
||||||
|
"immediateBanAlert": true,
|
||||||
|
"actionDelay": {
|
||||||
|
"min": 500,
|
||||||
|
"max": 2200
|
||||||
},
|
},
|
||||||
"retryMobileSearchAmount": 2
|
"gestureMoveProb": 0.65,
|
||||||
|
"gestureScrollProb": 0.4,
|
||||||
|
"allowedWindows": []
|
||||||
|
},
|
||||||
|
"vacation": {
|
||||||
|
"enabled": true,
|
||||||
|
"minDays": 2,
|
||||||
|
"maxDays": 4
|
||||||
|
},
|
||||||
|
"riskManagement": {
|
||||||
|
"enabled": true,
|
||||||
|
"autoAdjustDelays": true,
|
||||||
|
"stopOnCritical": false,
|
||||||
|
"banPrediction": true,
|
||||||
|
"riskThreshold": 75
|
||||||
|
},
|
||||||
|
"retryPolicy": {
|
||||||
|
"maxAttempts": 3,
|
||||||
|
"baseDelay": 1000,
|
||||||
|
"maxDelay": "30s",
|
||||||
|
"multiplier": 2,
|
||||||
|
"jitter": 0.2
|
||||||
},
|
},
|
||||||
"logExcludeFunc": [
|
|
||||||
"SEARCH-CLOSE-TABS"
|
|
||||||
],
|
|
||||||
"webhookLogExcludeFunc": [
|
|
||||||
"SEARCH-CLOSE-TABS"
|
|
||||||
],
|
|
||||||
"proxy": {
|
"proxy": {
|
||||||
"proxyGoogleTrends": true,
|
"proxyGoogleTrends": true,
|
||||||
"proxyBingTerms": true
|
"proxyBingTerms": true
|
||||||
},
|
},
|
||||||
"webhook": {
|
"notifications": {
|
||||||
"enabled": false,
|
"webhook": {
|
||||||
"url": ""
|
"enabled": false,
|
||||||
|
"url": ""
|
||||||
|
},
|
||||||
|
"conclusionWebhook": {
|
||||||
|
"enabled": false,
|
||||||
|
"url": ""
|
||||||
|
},
|
||||||
|
"ntfy": {
|
||||||
|
"enabled": false,
|
||||||
|
"url": "",
|
||||||
|
"topic": "rewards",
|
||||||
|
"authToken": ""
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"conclusionWebhook": {
|
"logging": {
|
||||||
"enabled": false,
|
"excludeFunc": [
|
||||||
"url": ""
|
"SEARCH-CLOSE-TABS",
|
||||||
|
"LOGIN-NO-PROMPT",
|
||||||
|
"FLOW"
|
||||||
|
],
|
||||||
|
"webhookExcludeFunc": [
|
||||||
|
"SEARCH-CLOSE-TABS",
|
||||||
|
"LOGIN-NO-PROMPT",
|
||||||
|
"FLOW"
|
||||||
|
],
|
||||||
|
"redactEmails": true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
74
src/constants.ts
Normal file
74
src/constants.ts
Normal file
@@ -0,0 +1,74 @@
|
|||||||
|
/**
|
||||||
|
* Central constants file for the Microsoft Rewards Script
|
||||||
|
* Defines timeouts, retry limits, and other magic numbers used throughout the application
|
||||||
|
*/
|
||||||
|
|
||||||
|
export const TIMEOUTS = {
|
||||||
|
SHORT: 500,
|
||||||
|
MEDIUM: 1500,
|
||||||
|
MEDIUM_LONG: 2000,
|
||||||
|
LONG: 3000,
|
||||||
|
VERY_LONG: 5000,
|
||||||
|
EXTRA_LONG: 10000,
|
||||||
|
DASHBOARD_WAIT: 10000,
|
||||||
|
LOGIN_MAX: 180000, // 3 minutes
|
||||||
|
NETWORK_IDLE: 5000
|
||||||
|
} as const
|
||||||
|
|
||||||
|
export const RETRY_LIMITS = {
|
||||||
|
MAX_ITERATIONS: 5,
|
||||||
|
DASHBOARD_RELOAD: 2,
|
||||||
|
MOBILE_SEARCH: 3,
|
||||||
|
ABC_MAX: 15,
|
||||||
|
POLL_MAX: 15,
|
||||||
|
QUIZ_MAX: 15,
|
||||||
|
QUIZ_ANSWER_TIMEOUT: 10000,
|
||||||
|
GO_HOME_MAX: 5
|
||||||
|
} as const
|
||||||
|
|
||||||
|
export const DELAYS = {
|
||||||
|
ACTION_MIN: 1000,
|
||||||
|
ACTION_MAX: 3000,
|
||||||
|
SEARCH_DEFAULT_MIN: 2000,
|
||||||
|
SEARCH_DEFAULT_MAX: 5000,
|
||||||
|
BROWSER_CLOSE: 2000,
|
||||||
|
TYPING_DELAY: 20,
|
||||||
|
SEARCH_ON_BING_WAIT: 5000,
|
||||||
|
SEARCH_ON_BING_COMPLETE: 3000,
|
||||||
|
SEARCH_ON_BING_FOCUS: 200,
|
||||||
|
SEARCH_BAR_TIMEOUT: 15000,
|
||||||
|
QUIZ_ANSWER_WAIT: 2000,
|
||||||
|
THIS_OR_THAT_START: 2000
|
||||||
|
} as const
|
||||||
|
|
||||||
|
export const SELECTORS = {
|
||||||
|
MORE_ACTIVITIES: '#more-activities',
|
||||||
|
SUSPENDED_ACCOUNT: '#suspendedAccountHeader',
|
||||||
|
QUIZ_COMPLETE: '#quizCompleteContainer',
|
||||||
|
QUIZ_CREDITS: 'span.rqMCredits'
|
||||||
|
} as const
|
||||||
|
|
||||||
|
export const URLS = {
|
||||||
|
REWARDS_BASE: 'https://rewards.bing.com',
|
||||||
|
REWARDS_SIGNIN: 'https://rewards.bing.com/signin',
|
||||||
|
APP_USER_DATA: 'https://prod.rewardsplatform.microsoft.com/dapi/me?channel=SAAndroid&options=613'
|
||||||
|
} as const
|
||||||
|
|
||||||
|
export const DISCORD = {
|
||||||
|
MAX_EMBED_LENGTH: 1900,
|
||||||
|
RATE_LIMIT_DELAY: 500,
|
||||||
|
WEBHOOK_TIMEOUT: 10000,
|
||||||
|
DEBOUNCE_DELAY: 750,
|
||||||
|
COLOR_RED: 0xFF0000,
|
||||||
|
COLOR_CRIMSON: 0xDC143C,
|
||||||
|
COLOR_ORANGE: 0xFFA500,
|
||||||
|
COLOR_BLUE: 0x3498DB,
|
||||||
|
COLOR_GREEN: 0x00D26A,
|
||||||
|
AVATAR_URL: 'https://media.discordapp.net/attachments/1421163952972369931/1421929950377939125/Gc.png'
|
||||||
|
} as const
|
||||||
|
|
||||||
|
export const META = {
|
||||||
|
|
||||||
|
C: 'aHR0cHM6Ly9kaXNjb3JkLmdnL2tuMzY5NUt4MzI=',
|
||||||
|
R: 'aHR0cHM6Ly9naXRodWIuY29tL0xpZ2h0NjAtMS9NaWNyb3NvZnQtUmV3YXJkcy1SZXdp'
|
||||||
|
} as const
|
||||||
@@ -13,15 +13,109 @@ import { ReadToEarn } from './activities/ReadToEarn'
|
|||||||
import { DailyCheckIn } from './activities/DailyCheckIn'
|
import { DailyCheckIn } from './activities/DailyCheckIn'
|
||||||
|
|
||||||
import { DashboardData, MorePromotion, PromotionalItem } from '../interface/DashboardData'
|
import { DashboardData, MorePromotion, PromotionalItem } from '../interface/DashboardData'
|
||||||
|
import type { ActivityHandler } from '../interface/ActivityHandler'
|
||||||
|
|
||||||
|
type ActivityKind =
|
||||||
|
| { type: 'poll' }
|
||||||
|
| { type: 'abc' }
|
||||||
|
| { type: 'thisOrThat' }
|
||||||
|
| { type: 'quiz' }
|
||||||
|
| { type: 'urlReward' }
|
||||||
|
| { type: 'searchOnBing' }
|
||||||
|
| { type: 'unsupported' }
|
||||||
|
|
||||||
|
|
||||||
export default class Activities {
|
export default class Activities {
|
||||||
private bot: MicrosoftRewardsBot
|
private bot: MicrosoftRewardsBot
|
||||||
|
private handlers: ActivityHandler[] = []
|
||||||
|
|
||||||
constructor(bot: MicrosoftRewardsBot) {
|
constructor(bot: MicrosoftRewardsBot) {
|
||||||
this.bot = bot
|
this.bot = bot
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Register external/custom handlers (optional extension point)
|
||||||
|
registerHandler(handler: ActivityHandler) {
|
||||||
|
this.handlers.push(handler)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Centralized dispatcher for activities from dashboard/punchcards
|
||||||
|
async run(page: Page, activity: MorePromotion | PromotionalItem): Promise<void> {
|
||||||
|
// First, try custom handlers (if any)
|
||||||
|
for (const h of this.handlers) {
|
||||||
|
try {
|
||||||
|
if (h.canHandle(activity)) {
|
||||||
|
await h.run(page, activity)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
this.bot.log(this.bot.isMobile, 'ACTIVITY', `Custom handler ${(h.id || 'unknown')} failed: ${e instanceof Error ? e.message : e}`, 'error')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const kind = this.classifyActivity(activity)
|
||||||
|
try {
|
||||||
|
switch (kind.type) {
|
||||||
|
case 'poll':
|
||||||
|
await this.doPoll(page)
|
||||||
|
break
|
||||||
|
case 'abc':
|
||||||
|
await this.doABC(page)
|
||||||
|
break
|
||||||
|
case 'thisOrThat':
|
||||||
|
await this.doThisOrThat(page)
|
||||||
|
break
|
||||||
|
case 'quiz':
|
||||||
|
await this.doQuiz(page)
|
||||||
|
break
|
||||||
|
case 'searchOnBing':
|
||||||
|
await this.doSearchOnBing(page, activity)
|
||||||
|
break
|
||||||
|
case 'urlReward':
|
||||||
|
await this.doUrlReward(page)
|
||||||
|
break
|
||||||
|
default:
|
||||||
|
this.bot.log(this.bot.isMobile, 'ACTIVITY', `Skipped activity "${activity.title}" | Reason: Unsupported type: "${String((activity as { promotionType?: string }).promotionType)}"!`, 'warn')
|
||||||
|
break
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
this.bot.log(this.bot.isMobile, 'ACTIVITY', `Dispatcher error for "${activity.title}": ${e instanceof Error ? e.message : e}`, 'error')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public getTypeLabel(activity: MorePromotion | PromotionalItem): string {
|
||||||
|
const k = this.classifyActivity(activity)
|
||||||
|
switch (k.type) {
|
||||||
|
case 'poll': return 'Poll'
|
||||||
|
case 'abc': return 'ABC'
|
||||||
|
case 'thisOrThat': return 'ThisOrThat'
|
||||||
|
case 'quiz': return 'Quiz'
|
||||||
|
case 'searchOnBing': return 'SearchOnBing'
|
||||||
|
case 'urlReward': return 'UrlReward'
|
||||||
|
default: return 'Unsupported'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private classifyActivity(activity: MorePromotion | PromotionalItem): ActivityKind {
|
||||||
|
const type = (activity.promotionType || '').toLowerCase()
|
||||||
|
if (type === 'quiz') {
|
||||||
|
// Distinguish Poll/ABC/ThisOrThat vs general quiz using current heuristics
|
||||||
|
const max = activity.pointProgressMax
|
||||||
|
const url = (activity.destinationUrl || '').toLowerCase()
|
||||||
|
if (max === 10) {
|
||||||
|
if (url.includes('pollscenarioid')) return { type: 'poll' }
|
||||||
|
return { type: 'abc' }
|
||||||
|
}
|
||||||
|
if (max === 50) return { type: 'thisOrThat' }
|
||||||
|
return { type: 'quiz' }
|
||||||
|
}
|
||||||
|
if (type === 'urlreward') {
|
||||||
|
const name = (activity.name || '').toLowerCase()
|
||||||
|
if (name.includes('exploreonbing')) return { type: 'searchOnBing' }
|
||||||
|
return { type: 'urlReward' }
|
||||||
|
}
|
||||||
|
return { type: 'unsupported' }
|
||||||
|
}
|
||||||
|
|
||||||
doSearch = async (page: Page, data: DashboardData): Promise<void> => {
|
doSearch = async (page: Page, data: DashboardData): Promise<void> => {
|
||||||
const search = new Search(this.bot)
|
const search = new Search(this.bot)
|
||||||
await search.doSearch(page, data)
|
await search.doSearch(page, data)
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -3,19 +3,30 @@ import { Page } from 'rebrowser-playwright'
|
|||||||
import { DashboardData, MorePromotion, PromotionalItem, PunchCard } from '../interface/DashboardData'
|
import { DashboardData, MorePromotion, PromotionalItem, PunchCard } from '../interface/DashboardData'
|
||||||
|
|
||||||
import { MicrosoftRewardsBot } from '../index'
|
import { MicrosoftRewardsBot } from '../index'
|
||||||
|
import JobState from '../util/JobState'
|
||||||
|
import Retry from '../util/Retry'
|
||||||
|
import { AdaptiveThrottler } from '../util/AdaptiveThrottler'
|
||||||
|
|
||||||
export class Workers {
|
export class Workers {
|
||||||
public bot: MicrosoftRewardsBot
|
public bot: MicrosoftRewardsBot
|
||||||
|
private jobState: JobState
|
||||||
|
|
||||||
constructor(bot: MicrosoftRewardsBot) {
|
constructor(bot: MicrosoftRewardsBot) {
|
||||||
this.bot = bot
|
this.bot = bot
|
||||||
|
this.jobState = new JobState(this.bot.config)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Daily Set
|
// Daily Set
|
||||||
async doDailySet(page: Page, data: DashboardData) {
|
async doDailySet(page: Page, data: DashboardData) {
|
||||||
const todayData = data.dailySetPromotions[this.bot.utils.getFormattedDate()]
|
const todayData = data.dailySetPromotions[this.bot.utils.getFormattedDate()]
|
||||||
|
|
||||||
const activitiesUncompleted = todayData?.filter(x => !x.complete && x.pointProgressMax > 0) ?? []
|
const today = this.bot.utils.getFormattedDate()
|
||||||
|
const activitiesUncompleted = (todayData?.filter(x => !x.complete && x.pointProgressMax > 0) ?? [])
|
||||||
|
.filter(x => {
|
||||||
|
if (this.bot.config.jobState?.enabled === false) return true
|
||||||
|
const email = this.bot.currentAccountEmail || 'unknown'
|
||||||
|
return !this.jobState.isDone(email, today, x.offerId)
|
||||||
|
})
|
||||||
|
|
||||||
if (!activitiesUncompleted.length) {
|
if (!activitiesUncompleted.length) {
|
||||||
this.bot.log(this.bot.isMobile, 'DAILY-SET', 'All Daily Set" items have already been completed')
|
this.bot.log(this.bot.isMobile, 'DAILY-SET', 'All Daily Set" items have already been completed')
|
||||||
@@ -27,12 +38,30 @@ export class Workers {
|
|||||||
|
|
||||||
await this.solveActivities(page, activitiesUncompleted)
|
await this.solveActivities(page, activitiesUncompleted)
|
||||||
|
|
||||||
|
// Mark as done to prevent duplicate work if checkpoints enabled
|
||||||
|
if (this.bot.config.jobState?.enabled !== false) {
|
||||||
|
const email = this.bot.currentAccountEmail || 'unknown'
|
||||||
|
for (const a of activitiesUncompleted) {
|
||||||
|
this.jobState.markDone(email, today, a.offerId)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
page = await this.bot.browser.utils.getLatestTab(page)
|
page = await this.bot.browser.utils.getLatestTab(page)
|
||||||
|
|
||||||
// Always return to the homepage if not already
|
// Always return to the homepage if not already
|
||||||
await this.bot.browser.func.goHome(page)
|
await this.bot.browser.func.goHome(page)
|
||||||
|
|
||||||
this.bot.log(this.bot.isMobile, 'DAILY-SET', 'All "Daily Set" items have been completed')
|
this.bot.log(this.bot.isMobile, 'DAILY-SET', 'All "Daily Set" items have been completed')
|
||||||
|
|
||||||
|
// Optional: immediately run desktop search bundle
|
||||||
|
if (!this.bot.isMobile && this.bot.config.workers.bundleDailySetWithSearch && this.bot.config.workers.doDesktopSearch) {
|
||||||
|
try {
|
||||||
|
await this.bot.utils.waitRandom(1200, 2600)
|
||||||
|
await this.bot.activities.doSearch(page, data)
|
||||||
|
} catch (e) {
|
||||||
|
this.bot.log(this.bot.isMobile, 'DAILY-SET', `Post-DailySet search failed: ${e instanceof Error ? e.message : e}`, 'warn')
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Punch Card
|
// Punch Card
|
||||||
@@ -118,113 +147,96 @@ export class Workers {
|
|||||||
|
|
||||||
// Solve all the different types of activities
|
// Solve all the different types of activities
|
||||||
private async solveActivities(activityPage: Page, activities: PromotionalItem[] | MorePromotion[], punchCard?: PunchCard) {
|
private async solveActivities(activityPage: Page, activities: PromotionalItem[] | MorePromotion[], punchCard?: PunchCard) {
|
||||||
const activityInitial = activityPage.url() // Homepage for Daily/More and Index for promotions
|
const activityInitial = activityPage.url()
|
||||||
|
const retry = new Retry(this.bot.config.retryPolicy)
|
||||||
|
const throttle = new AdaptiveThrottler()
|
||||||
|
|
||||||
for (const activity of activities) {
|
for (const activity of activities) {
|
||||||
try {
|
try {
|
||||||
// Reselect the worker page
|
activityPage = await this.manageTabLifecycle(activityPage, activityInitial)
|
||||||
activityPage = await this.bot.browser.utils.getLatestTab(activityPage)
|
await this.applyThrottle(throttle, 800, 1400)
|
||||||
|
|
||||||
const pages = activityPage.context().pages()
|
const selector = await this.buildActivitySelector(activityPage, activity, punchCard)
|
||||||
if (pages.length > 3) {
|
await this.prepareActivityPage(activityPage, selector, throttle)
|
||||||
await activityPage.close()
|
|
||||||
|
|
||||||
activityPage = await this.bot.browser.utils.getLatestTab(activityPage)
|
const typeLabel = this.bot.activities.getTypeLabel(activity)
|
||||||
|
if (typeLabel !== 'Unsupported') {
|
||||||
|
await this.executeActivity(activityPage, activity, selector, throttle, retry)
|
||||||
|
} else {
|
||||||
|
this.bot.log(this.bot.isMobile, 'ACTIVITY', `Skipped activity "${activity.title}" | Reason: Unsupported type: "${activity.promotionType}"!`, 'warn')
|
||||||
}
|
}
|
||||||
|
|
||||||
await this.bot.utils.wait(1000)
|
await this.applyThrottle(throttle, 1200, 2600)
|
||||||
|
|
||||||
if (activityPage.url() !== activityInitial) {
|
|
||||||
await activityPage.goto(activityInitial)
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
let selector = `[data-bi-id^="${activity.offerId}"] .pointLink:not(.contentContainer .pointLink)`
|
|
||||||
|
|
||||||
if (punchCard) {
|
|
||||||
selector = await this.bot.browser.func.getPunchCardActivity(activityPage, activity)
|
|
||||||
|
|
||||||
} else if (activity.name.toLowerCase().includes('membercenter') || activity.name.toLowerCase().includes('exploreonbing')) {
|
|
||||||
selector = `[data-bi-id^="${activity.name}"] .pointLink:not(.contentContainer .pointLink)`
|
|
||||||
}
|
|
||||||
|
|
||||||
// Wait for the new tab to fully load, ignore error.
|
|
||||||
/*
|
|
||||||
Due to common false timeout on this function, we're ignoring the error regardless, if it worked then it's faster,
|
|
||||||
if it didn't then it gave enough time for the page to load.
|
|
||||||
*/
|
|
||||||
await activityPage.waitForLoadState('networkidle', { timeout: 10000 }).catch(() => { })
|
|
||||||
await this.bot.utils.wait(2000)
|
|
||||||
|
|
||||||
switch (activity.promotionType) {
|
|
||||||
// Quiz (Poll, Quiz or ABC)
|
|
||||||
case 'quiz':
|
|
||||||
switch (activity.pointProgressMax) {
|
|
||||||
// Poll or ABC (Usually 10 points)
|
|
||||||
case 10:
|
|
||||||
// Normal poll
|
|
||||||
if (activity.destinationUrl.toLowerCase().includes('pollscenarioid')) {
|
|
||||||
this.bot.log(this.bot.isMobile, 'ACTIVITY', `Found activity type: "Poll" title: "${activity.title}"`)
|
|
||||||
await activityPage.click(selector)
|
|
||||||
activityPage = await this.bot.browser.utils.getLatestTab(activityPage)
|
|
||||||
await this.bot.activities.doPoll(activityPage)
|
|
||||||
} else { // ABC
|
|
||||||
this.bot.log(this.bot.isMobile, 'ACTIVITY', `Found activity type: "ABC" title: "${activity.title}"`)
|
|
||||||
await activityPage.click(selector)
|
|
||||||
activityPage = await this.bot.browser.utils.getLatestTab(activityPage)
|
|
||||||
await this.bot.activities.doABC(activityPage)
|
|
||||||
}
|
|
||||||
break
|
|
||||||
|
|
||||||
// This Or That Quiz (Usually 50 points)
|
|
||||||
case 50:
|
|
||||||
this.bot.log(this.bot.isMobile, 'ACTIVITY', `Found activity type: "ThisOrThat" title: "${activity.title}"`)
|
|
||||||
await activityPage.click(selector)
|
|
||||||
activityPage = await this.bot.browser.utils.getLatestTab(activityPage)
|
|
||||||
await this.bot.activities.doThisOrThat(activityPage)
|
|
||||||
break
|
|
||||||
|
|
||||||
// Quizzes are usually 30-40 points
|
|
||||||
default:
|
|
||||||
this.bot.log(this.bot.isMobile, 'ACTIVITY', `Found activity type: "Quiz" title: "${activity.title}"`)
|
|
||||||
await activityPage.click(selector)
|
|
||||||
activityPage = await this.bot.browser.utils.getLatestTab(activityPage)
|
|
||||||
await this.bot.activities.doQuiz(activityPage)
|
|
||||||
break
|
|
||||||
}
|
|
||||||
break
|
|
||||||
|
|
||||||
// UrlReward (Visit)
|
|
||||||
case 'urlreward':
|
|
||||||
// Search on Bing are subtypes of "urlreward"
|
|
||||||
if (activity.name.toLowerCase().includes('exploreonbing')) {
|
|
||||||
this.bot.log(this.bot.isMobile, 'ACTIVITY', `Found activity type: "SearchOnBing" title: "${activity.title}"`)
|
|
||||||
await activityPage.click(selector)
|
|
||||||
activityPage = await this.bot.browser.utils.getLatestTab(activityPage)
|
|
||||||
await this.bot.activities.doSearchOnBing(activityPage, activity)
|
|
||||||
|
|
||||||
} else {
|
|
||||||
this.bot.log(this.bot.isMobile, 'ACTIVITY', `Found activity type: "UrlReward" title: "${activity.title}"`)
|
|
||||||
await activityPage.click(selector)
|
|
||||||
activityPage = await this.bot.browser.utils.getLatestTab(activityPage)
|
|
||||||
await this.bot.activities.doUrlReward(activityPage)
|
|
||||||
}
|
|
||||||
break
|
|
||||||
|
|
||||||
// Unsupported types
|
|
||||||
default:
|
|
||||||
this.bot.log(this.bot.isMobile, 'ACTIVITY', `Skipped activity "${activity.title}" | Reason: Unsupported type: "${activity.promotionType}"!`, 'warn')
|
|
||||||
break
|
|
||||||
}
|
|
||||||
|
|
||||||
// Cooldown
|
|
||||||
await this.bot.utils.wait(2000)
|
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
this.bot.log(this.bot.isMobile, 'ACTIVITY', 'An error occurred:' + error, 'error')
|
this.bot.log(this.bot.isMobile, 'ACTIVITY', 'An error occurred:' + error, 'error')
|
||||||
|
throttle.record(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async manageTabLifecycle(page: Page, initialUrl: string): Promise<Page> {
|
||||||
|
page = await this.bot.browser.utils.getLatestTab(page)
|
||||||
|
|
||||||
|
const pages = page.context().pages()
|
||||||
|
if (pages.length > 3) {
|
||||||
|
await page.close()
|
||||||
|
page = await this.bot.browser.utils.getLatestTab(page)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (page.url() !== initialUrl) {
|
||||||
|
await page.goto(initialUrl)
|
||||||
|
}
|
||||||
|
|
||||||
|
return page
|
||||||
|
}
|
||||||
|
|
||||||
|
private async buildActivitySelector(page: Page, activity: PromotionalItem | MorePromotion, punchCard?: PunchCard): Promise<string> {
|
||||||
|
if (punchCard) {
|
||||||
|
return await this.bot.browser.func.getPunchCardActivity(page, activity)
|
||||||
|
}
|
||||||
|
|
||||||
|
const name = activity.name.toLowerCase()
|
||||||
|
if (name.includes('membercenter') || name.includes('exploreonbing')) {
|
||||||
|
return `[data-bi-id^="${activity.name}"] .pointLink:not(.contentContainer .pointLink)`
|
||||||
|
}
|
||||||
|
|
||||||
|
return `[data-bi-id^="${activity.offerId}"] .pointLink:not(.contentContainer .pointLink)`
|
||||||
|
}
|
||||||
|
|
||||||
|
private async prepareActivityPage(page: Page, selector: string, throttle: AdaptiveThrottler): Promise<void> {
|
||||||
|
await page.waitForLoadState('networkidle', { timeout: 10000 }).catch(() => {})
|
||||||
|
await this.bot.browser.utils.humanizePage(page)
|
||||||
|
await this.applyThrottle(throttle, 1200, 2600)
|
||||||
|
}
|
||||||
|
|
||||||
|
private async executeActivity(page: Page, activity: PromotionalItem | MorePromotion, selector: string, throttle: AdaptiveThrottler, retry: Retry): Promise<void> {
|
||||||
|
this.bot.log(this.bot.isMobile, 'ACTIVITY', `Found activity type: "${this.bot.activities.getTypeLabel(activity)}" title: "${activity.title}"`)
|
||||||
|
|
||||||
|
await page.click(selector)
|
||||||
|
page = await this.bot.browser.utils.getLatestTab(page)
|
||||||
|
|
||||||
|
const timeoutMs = this.bot.utils.stringToMs(this.bot.config?.globalTimeout ?? '30s') * 2
|
||||||
|
const runWithTimeout = (p: Promise<void>) => Promise.race([
|
||||||
|
p,
|
||||||
|
new Promise<void>((_, rej) => setTimeout(() => rej(new Error('activity-timeout')), timeoutMs))
|
||||||
|
])
|
||||||
|
|
||||||
|
await retry.run(async () => {
|
||||||
|
try {
|
||||||
|
await runWithTimeout(this.bot.activities.run(page, activity))
|
||||||
|
throttle.record(true)
|
||||||
|
} catch (e) {
|
||||||
|
throttle.record(false)
|
||||||
|
throw e
|
||||||
|
}
|
||||||
|
}, () => true)
|
||||||
|
|
||||||
|
await this.bot.browser.utils.humanizePage(page)
|
||||||
|
}
|
||||||
|
|
||||||
|
private async applyThrottle(throttle: AdaptiveThrottler, min: number, max: number): Promise<void> {
|
||||||
|
const multiplier = throttle.getDelayMultiplier()
|
||||||
|
await this.bot.utils.waitRandom(Math.floor(min * multiplier), Math.floor(max * multiplier))
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
import { Page } from 'rebrowser-playwright'
|
import { Page } from 'rebrowser-playwright'
|
||||||
|
|
||||||
import { Workers } from '../Workers'
|
import { Workers } from '../Workers'
|
||||||
|
import { RETRY_LIMITS, TIMEOUTS } from '../../constants'
|
||||||
|
|
||||||
|
|
||||||
export class ABC extends Workers {
|
export class ABC extends Workers {
|
||||||
@@ -11,34 +12,32 @@ export class ABC extends Workers {
|
|||||||
try {
|
try {
|
||||||
let $ = await this.bot.browser.func.loadInCheerio(page)
|
let $ = await this.bot.browser.func.loadInCheerio(page)
|
||||||
|
|
||||||
// Don't loop more than 15 in case unable to solve, would lock otherwise
|
|
||||||
const maxIterations = 15
|
|
||||||
let i
|
let i
|
||||||
for (i = 0; i < maxIterations && !$('span.rw_icon').length; i++) {
|
for (i = 0; i < RETRY_LIMITS.ABC_MAX && !$('span.rw_icon').length; i++) {
|
||||||
await page.waitForSelector('.wk_OptionClickClass', { state: 'visible', timeout: 10000 })
|
await page.waitForSelector('.wk_OptionClickClass', { state: 'visible', timeout: TIMEOUTS.DASHBOARD_WAIT })
|
||||||
|
|
||||||
const answers = $('.wk_OptionClickClass')
|
const answers = $('.wk_OptionClickClass')
|
||||||
const answer = answers[this.bot.utils.randomNumber(0, 2)]?.attribs['id']
|
const answer = answers[this.bot.utils.randomNumber(0, 2)]?.attribs['id']
|
||||||
|
|
||||||
await page.waitForSelector(`#${answer}`, { state: 'visible', timeout: 10000 })
|
await page.waitForSelector(`#${answer}`, { state: 'visible', timeout: TIMEOUTS.DASHBOARD_WAIT })
|
||||||
|
|
||||||
await this.bot.utils.wait(2000)
|
await this.bot.utils.wait(TIMEOUTS.MEDIUM_LONG)
|
||||||
await page.click(`#${answer}`) // Click answer
|
await page.click(`#${answer}`) // Click answer
|
||||||
|
|
||||||
await this.bot.utils.wait(4000)
|
await this.bot.utils.wait(TIMEOUTS.LONG + 1000)
|
||||||
await page.waitForSelector('div.wk_button', { state: 'visible', timeout: 10000 })
|
await page.waitForSelector('div.wk_button', { state: 'visible', timeout: TIMEOUTS.DASHBOARD_WAIT })
|
||||||
await page.click('div.wk_button') // Click next question button
|
await page.click('div.wk_button') // Click next question button
|
||||||
|
|
||||||
page = await this.bot.browser.utils.getLatestTab(page)
|
page = await this.bot.browser.utils.getLatestTab(page)
|
||||||
$ = await this.bot.browser.func.loadInCheerio(page)
|
$ = await this.bot.browser.func.loadInCheerio(page)
|
||||||
await this.bot.utils.wait(1000)
|
await this.bot.utils.wait(TIMEOUTS.MEDIUM)
|
||||||
}
|
}
|
||||||
|
|
||||||
await this.bot.utils.wait(4000)
|
await this.bot.utils.wait(TIMEOUTS.LONG + 1000)
|
||||||
await page.close()
|
await page.close()
|
||||||
|
|
||||||
if (i === maxIterations) {
|
if (i === RETRY_LIMITS.ABC_MAX) {
|
||||||
this.bot.log(this.bot.isMobile, 'ABC', 'Failed to solve quiz, exceeded max iterations of 15', 'warn')
|
this.bot.log(this.bot.isMobile, 'ABC', `Failed to solve quiz, exceeded max iterations of ${RETRY_LIMITS.ABC_MAX}`, 'warn')
|
||||||
} else {
|
} else {
|
||||||
this.bot.log(this.bot.isMobile, 'ABC', 'Completed the ABC successfully')
|
this.bot.log(this.bot.isMobile, 'ABC', 'Completed the ABC successfully')
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,7 +31,8 @@ export class DailyCheckIn extends Workers {
|
|||||||
'Authorization': `Bearer ${accessToken}`,
|
'Authorization': `Bearer ${accessToken}`,
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
'X-Rewards-Country': geoLocale,
|
'X-Rewards-Country': geoLocale,
|
||||||
'X-Rewards-Language': 'en'
|
'X-Rewards-Language': 'en',
|
||||||
|
'X-Rewards-ismobile': 'true'
|
||||||
},
|
},
|
||||||
data: JSON.stringify(jsonData)
|
data: JSON.stringify(jsonData)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import { Page } from 'rebrowser-playwright'
|
import { Page } from 'rebrowser-playwright'
|
||||||
|
|
||||||
import { Workers } from '../Workers'
|
import { Workers } from '../Workers'
|
||||||
|
import { TIMEOUTS } from '../../constants'
|
||||||
|
|
||||||
|
|
||||||
export class Poll extends Workers {
|
export class Poll extends Workers {
|
||||||
@@ -11,12 +12,14 @@ export class Poll extends Workers {
|
|||||||
try {
|
try {
|
||||||
const buttonId = `#btoption${Math.floor(this.bot.utils.randomNumber(0, 1))}`
|
const buttonId = `#btoption${Math.floor(this.bot.utils.randomNumber(0, 1))}`
|
||||||
|
|
||||||
await page.waitForSelector(buttonId, { state: 'visible', timeout: 10000 }).catch(() => { }) // We're gonna click regardless or not
|
await page.waitForSelector(buttonId, { state: 'visible', timeout: TIMEOUTS.DASHBOARD_WAIT }).catch((e) => {
|
||||||
await this.bot.utils.wait(2000)
|
this.bot.log(this.bot.isMobile, 'POLL', `Could not find poll button: ${e}`, 'warn')
|
||||||
|
})
|
||||||
|
await this.bot.utils.wait(TIMEOUTS.MEDIUM_LONG)
|
||||||
|
|
||||||
await page.click(buttonId)
|
await page.click(buttonId)
|
||||||
|
|
||||||
await this.bot.utils.wait(4000)
|
await this.bot.utils.wait(TIMEOUTS.LONG + 1000)
|
||||||
await page.close()
|
await page.close()
|
||||||
|
|
||||||
this.bot.log(this.bot.isMobile, 'POLL', 'Completed the poll successfully')
|
this.bot.log(this.bot.isMobile, 'POLL', 'Completed the poll successfully')
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import { Page } from 'rebrowser-playwright'
|
import { Page } from 'rebrowser-playwright'
|
||||||
|
|
||||||
import { Workers } from '../Workers'
|
import { Workers } from '../Workers'
|
||||||
|
import { RETRY_LIMITS, TIMEOUTS, DELAYS } from '../../constants'
|
||||||
|
|
||||||
|
|
||||||
export class Quiz extends Workers {
|
export class Quiz extends Workers {
|
||||||
@@ -10,16 +11,24 @@ export class Quiz extends Workers {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
// Check if the quiz has been started or not
|
// Check if the quiz has been started or not
|
||||||
const quizNotStarted = await page.waitForSelector('#rqStartQuiz', { state: 'visible', timeout: 2000 }).then(() => true).catch(() => false)
|
const quizNotStarted = await page.waitForSelector('#rqStartQuiz', { state: 'visible', timeout: TIMEOUTS.MEDIUM_LONG }).then(() => true).catch(() => false)
|
||||||
if (quizNotStarted) {
|
if (quizNotStarted) {
|
||||||
await page.click('#rqStartQuiz')
|
await page.click('#rqStartQuiz')
|
||||||
} else {
|
} else {
|
||||||
this.bot.log(this.bot.isMobile, 'QUIZ', 'Quiz has already been started, trying to finish it')
|
this.bot.log(this.bot.isMobile, 'QUIZ', 'Quiz has already been started, trying to finish it')
|
||||||
}
|
}
|
||||||
|
|
||||||
await this.bot.utils.wait(2000)
|
await this.bot.utils.wait(TIMEOUTS.MEDIUM_LONG)
|
||||||
|
|
||||||
let quizData = await this.bot.browser.func.getQuizData(page)
|
let quizData = await this.bot.browser.func.getQuizData(page)
|
||||||
|
|
||||||
|
// Verify quiz is actually loaded before proceeding
|
||||||
|
const firstOptionExists = await page.waitForSelector('#rqAnswerOption0', { state: 'attached', timeout: TIMEOUTS.VERY_LONG }).then(() => true).catch(() => false)
|
||||||
|
if (!firstOptionExists) {
|
||||||
|
this.bot.log(this.bot.isMobile, 'QUIZ', 'Quiz options not found - page may not have loaded correctly. Skipping.', 'warn')
|
||||||
|
await page.close()
|
||||||
|
return
|
||||||
|
}
|
||||||
const questionsRemaining = quizData.maxQuestions - quizData.CorrectlyAnsweredQuestionCount // Amount of questions remaining
|
const questionsRemaining = quizData.maxQuestions - quizData.CorrectlyAnsweredQuestionCount // Amount of questions remaining
|
||||||
|
|
||||||
// All questions
|
// All questions
|
||||||
@@ -29,17 +38,30 @@ export class Quiz extends Workers {
|
|||||||
const answers: string[] = []
|
const answers: string[] = []
|
||||||
|
|
||||||
for (let i = 0; i < quizData.numberOfOptions; i++) {
|
for (let i = 0; i < quizData.numberOfOptions; i++) {
|
||||||
const answerSelector = await page.waitForSelector(`#rqAnswerOption${i}`, { state: 'visible', timeout: 10000 })
|
const answerSelector = await page.waitForSelector(`#rqAnswerOption${i}`, { state: 'visible', timeout: TIMEOUTS.DASHBOARD_WAIT }).catch(() => null)
|
||||||
const answerAttribute = await answerSelector?.evaluate((el: any) => el.getAttribute('iscorrectoption'))
|
|
||||||
|
if (!answerSelector) {
|
||||||
|
this.bot.log(this.bot.isMobile, 'QUIZ', `Option ${i} not found - quiz structure may have changed. Skipping remaining options.`, 'warn')
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
const answerAttribute = await answerSelector?.evaluate((el: Element) => el.getAttribute('iscorrectoption'))
|
||||||
|
|
||||||
if (answerAttribute && answerAttribute.toLowerCase() === 'true') {
|
if (answerAttribute && answerAttribute.toLowerCase() === 'true') {
|
||||||
answers.push(`#rqAnswerOption${i}`)
|
answers.push(`#rqAnswerOption${i}`)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If no correct answers found, skip this question
|
||||||
|
if (answers.length === 0) {
|
||||||
|
this.bot.log(this.bot.isMobile, 'QUIZ', 'No correct answers found for 8-option quiz. Skipping.', 'warn')
|
||||||
|
await page.close()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// Click the answers
|
// Click the answers
|
||||||
for (const answer of answers) {
|
for (const answer of answers) {
|
||||||
await page.waitForSelector(answer, { state: 'visible', timeout: 2000 })
|
await page.waitForSelector(answer, { state: 'visible', timeout: DELAYS.QUIZ_ANSWER_WAIT })
|
||||||
|
|
||||||
// Click the answer on page
|
// Click the answer on page
|
||||||
await page.click(answer)
|
await page.click(answer)
|
||||||
@@ -57,14 +79,23 @@ export class Quiz extends Workers {
|
|||||||
quizData = await this.bot.browser.func.getQuizData(page) // Refresh Quiz Data
|
quizData = await this.bot.browser.func.getQuizData(page) // Refresh Quiz Data
|
||||||
const correctOption = quizData.correctAnswer
|
const correctOption = quizData.correctAnswer
|
||||||
|
|
||||||
|
let answerClicked = false
|
||||||
|
|
||||||
for (let i = 0; i < quizData.numberOfOptions; i++) {
|
for (let i = 0; i < quizData.numberOfOptions; i++) {
|
||||||
|
|
||||||
const answerSelector = await page.waitForSelector(`#rqAnswerOption${i}`, { state: 'visible', timeout: 10000 })
|
const answerSelector = await page.waitForSelector(`#rqAnswerOption${i}`, { state: 'visible', timeout: RETRY_LIMITS.QUIZ_ANSWER_TIMEOUT }).catch(() => null)
|
||||||
const dataOption = await answerSelector?.evaluate((el: any) => el.getAttribute('data-option'))
|
|
||||||
|
if (!answerSelector) {
|
||||||
|
this.bot.log(this.bot.isMobile, 'QUIZ', `Option ${i} not found for ${quizData.numberOfOptions}-option quiz. Skipping.`, 'warn')
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
const dataOption = await answerSelector?.evaluate((el: Element) => el.getAttribute('data-option'))
|
||||||
|
|
||||||
if (dataOption === correctOption) {
|
if (dataOption === correctOption) {
|
||||||
// Click the answer on page
|
// Click the answer on page
|
||||||
await page.click(`#rqAnswerOption${i}`)
|
await page.click(`#rqAnswerOption${i}`)
|
||||||
|
answerClicked = true
|
||||||
|
|
||||||
const refreshSuccess = await this.bot.browser.func.waitForQuizRefresh(page)
|
const refreshSuccess = await this.bot.browser.func.waitForQuizRefresh(page)
|
||||||
if (!refreshSuccess) {
|
if (!refreshSuccess) {
|
||||||
@@ -72,14 +103,22 @@ export class Quiz extends Workers {
|
|||||||
this.bot.log(this.bot.isMobile, 'QUIZ', 'An error occurred, refresh was unsuccessful', 'error')
|
this.bot.log(this.bot.isMobile, 'QUIZ', 'An error occurred, refresh was unsuccessful', 'error')
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
await this.bot.utils.wait(2000)
|
|
||||||
|
if (!answerClicked) {
|
||||||
|
this.bot.log(this.bot.isMobile, 'QUIZ', `Could not find correct answer for ${quizData.numberOfOptions}-option quiz. Skipping.`, 'warn')
|
||||||
|
await page.close()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
await this.bot.utils.wait(DELAYS.QUIZ_ANSWER_WAIT)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Done with
|
// Done with
|
||||||
await this.bot.utils.wait(2000)
|
await this.bot.utils.wait(DELAYS.QUIZ_ANSWER_WAIT)
|
||||||
await page.close()
|
await page.close()
|
||||||
|
|
||||||
this.bot.log(this.bot.isMobile, 'QUIZ', 'Completed the quiz successfully')
|
this.bot.log(this.bot.isMobile, 'QUIZ', 'Completed the quiz successfully')
|
||||||
|
|||||||
@@ -47,7 +47,8 @@ export class ReadToEarn extends Workers {
|
|||||||
'Authorization': `Bearer ${accessToken}`,
|
'Authorization': `Bearer ${accessToken}`,
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
'X-Rewards-Country': geoLocale,
|
'X-Rewards-Country': geoLocale,
|
||||||
'X-Rewards-Language': 'en'
|
'X-Rewards-Language': 'en',
|
||||||
|
'X-Rewards-ismobile': 'true'
|
||||||
},
|
},
|
||||||
data: JSON.stringify(jsonData)
|
data: JSON.stringify(jsonData)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,12 +33,32 @@ export class Search extends Workers {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Generate search queries
|
// Generate search queries (primary: Google Trends)
|
||||||
let googleSearchQueries = await this.getGoogleTrends(this.bot.config.searchSettings.useGeoLocaleQueries ? data.userProfile.attributes.country : 'US')
|
const geo = this.bot.config.searchSettings.useGeoLocaleQueries ? data.userProfile.attributes.country : 'US'
|
||||||
googleSearchQueries = this.bot.utils.shuffleArray(googleSearchQueries)
|
let googleSearchQueries = await this.getGoogleTrends(geo)
|
||||||
|
|
||||||
// Deduplicate the search terms
|
// Fallback: if trends failed or insufficient, sample from local queries file
|
||||||
googleSearchQueries = [...new Set(googleSearchQueries)]
|
if (!googleSearchQueries.length || googleSearchQueries.length < 10) {
|
||||||
|
this.bot.log(this.bot.isMobile, 'SEARCH-BING', 'Primary trends source insufficient, falling back to local queries.json', 'warn')
|
||||||
|
try {
|
||||||
|
const local = await import('../queries.json')
|
||||||
|
// Flatten & sample
|
||||||
|
const sampleSize = Math.max(5, Math.min(this.bot.config.searchSettings.localFallbackCount || 25, local.default.length))
|
||||||
|
const sampled = this.bot.utils.shuffleArray(local.default).slice(0, sampleSize)
|
||||||
|
googleSearchQueries = sampled.map((x: { title: string; queries: string[] }) => ({ topic: x.queries[0] || x.title, related: x.queries.slice(1) }))
|
||||||
|
} catch (e) {
|
||||||
|
this.bot.log(this.bot.isMobile, 'SEARCH-BING', 'Failed loading local queries fallback: ' + (e instanceof Error ? e.message : e), 'error')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
googleSearchQueries = this.bot.utils.shuffleArray(googleSearchQueries)
|
||||||
|
// Deduplicate topics
|
||||||
|
const seen = new Set<string>()
|
||||||
|
googleSearchQueries = googleSearchQueries.filter(q => {
|
||||||
|
if (seen.has(q.topic.toLowerCase())) return false
|
||||||
|
seen.add(q.topic.toLowerCase())
|
||||||
|
return true
|
||||||
|
})
|
||||||
|
|
||||||
// Go to bing
|
// Go to bing
|
||||||
await page.goto(this.searchPageURL ? this.searchPageURL : this.bingHome)
|
await page.goto(this.searchPageURL ? this.searchPageURL : this.bingHome)
|
||||||
@@ -47,7 +67,7 @@ export class Search extends Workers {
|
|||||||
|
|
||||||
await this.bot.browser.utils.tryDismissAllMessages(page)
|
await this.bot.browser.utils.tryDismissAllMessages(page)
|
||||||
|
|
||||||
let maxLoop = 0 // If the loop hits 10 this when not gaining any points, we're assuming it's stuck. If it doesn't continue after 5 more searches with alternative queries, abort search
|
let stagnation = 0 // consecutive searches without point progress
|
||||||
|
|
||||||
const queries: string[] = []
|
const queries: string[] = []
|
||||||
// Mobile search doesn't seem to like related queries?
|
// Mobile search doesn't seem to like related queries?
|
||||||
@@ -63,28 +83,26 @@ export class Search extends Workers {
|
|||||||
const newMissingPoints = this.calculatePoints(searchCounters)
|
const newMissingPoints = this.calculatePoints(searchCounters)
|
||||||
|
|
||||||
// If the new point amount is the same as before
|
// If the new point amount is the same as before
|
||||||
if (newMissingPoints == missingPoints) {
|
if (newMissingPoints === missingPoints) {
|
||||||
maxLoop++ // Add to max loop
|
stagnation++
|
||||||
} else { // There has been a change in points
|
} else {
|
||||||
maxLoop = 0 // Reset the loop
|
stagnation = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
missingPoints = newMissingPoints
|
missingPoints = newMissingPoints
|
||||||
|
|
||||||
if (missingPoints === 0) {
|
if (missingPoints === 0) break
|
||||||
break
|
|
||||||
}
|
|
||||||
|
|
||||||
// Only for mobile searches
|
// Only for mobile searches
|
||||||
if (maxLoop > 5 && this.bot.isMobile) {
|
if (stagnation > 5 && this.bot.isMobile) {
|
||||||
this.bot.log(this.bot.isMobile, 'SEARCH-BING', 'Search didn\'t gain point for 5 iterations, likely bad User-Agent', 'warn')
|
this.bot.log(this.bot.isMobile, 'SEARCH-BING', 'Search didn\'t gain point for 5 iterations, likely bad User-Agent', 'warn')
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
// If we didn't gain points for 10 iterations, assume it's stuck
|
// If we didn't gain points for 10 iterations, assume it's stuck
|
||||||
if (maxLoop > 10) {
|
if (stagnation > 10) {
|
||||||
this.bot.log(this.bot.isMobile, 'SEARCH-BING', 'Search didn\'t gain point for 10 iterations aborting searches', 'warn')
|
this.bot.log(this.bot.isMobile, 'SEARCH-BING', 'Search didn\'t gain point for 10 iterations aborting searches', 'warn')
|
||||||
maxLoop = 0 // Reset to 0 so we can retry with related searches below
|
stagnation = 0 // allow fallback loop below
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -99,8 +117,11 @@ export class Search extends Workers {
|
|||||||
this.bot.log(this.bot.isMobile, 'SEARCH-BING', `Search completed but we're missing ${missingPoints} points, generating extra searches`)
|
this.bot.log(this.bot.isMobile, 'SEARCH-BING', `Search completed but we're missing ${missingPoints} points, generating extra searches`)
|
||||||
|
|
||||||
let i = 0
|
let i = 0
|
||||||
while (missingPoints > 0) {
|
let fallbackRounds = 0
|
||||||
|
const extraRetries = this.bot.config.searchSettings.extraFallbackRetries || 1
|
||||||
|
while (missingPoints > 0 && fallbackRounds <= extraRetries) {
|
||||||
const query = googleSearchQueries[i++] as GoogleSearch
|
const query = googleSearchQueries[i++] as GoogleSearch
|
||||||
|
if (!query) break
|
||||||
|
|
||||||
// Get related search terms to the Google search queries
|
// Get related search terms to the Google search queries
|
||||||
const relatedTerms = await this.getRelatedTerms(query?.topic)
|
const relatedTerms = await this.getRelatedTerms(query?.topic)
|
||||||
@@ -113,10 +134,10 @@ export class Search extends Workers {
|
|||||||
const newMissingPoints = this.calculatePoints(searchCounters)
|
const newMissingPoints = this.calculatePoints(searchCounters)
|
||||||
|
|
||||||
// If the new point amount is the same as before
|
// If the new point amount is the same as before
|
||||||
if (newMissingPoints == missingPoints) {
|
if (newMissingPoints === missingPoints) {
|
||||||
maxLoop++ // Add to max loop
|
stagnation++
|
||||||
} else { // There has been a change in points
|
} else {
|
||||||
maxLoop = 0 // Reset the loop
|
stagnation = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
missingPoints = newMissingPoints
|
missingPoints = newMissingPoints
|
||||||
@@ -127,11 +148,12 @@ export class Search extends Workers {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Try 5 more times, then we tried a total of 15 times, fair to say it's stuck
|
// Try 5 more times, then we tried a total of 15 times, fair to say it's stuck
|
||||||
if (maxLoop > 5) {
|
if (stagnation > 5) {
|
||||||
this.bot.log(this.bot.isMobile, 'SEARCH-BING-EXTRA', 'Search didn\'t gain point for 5 iterations aborting searches', 'warn')
|
this.bot.log(this.bot.isMobile, 'SEARCH-BING-EXTRA', 'Search didn\'t gain point for 5 iterations aborting searches', 'warn')
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
fallbackRounds++
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -156,20 +178,38 @@ export class Search extends Workers {
|
|||||||
await this.bot.utils.wait(500)
|
await this.bot.utils.wait(500)
|
||||||
|
|
||||||
const searchBar = '#sb_form_q'
|
const searchBar = '#sb_form_q'
|
||||||
await searchPage.waitForSelector(searchBar, { state: 'visible', timeout: 10000 })
|
// Prefer attached over visible to avoid strict visibility waits when overlays exist
|
||||||
await searchPage.click(searchBar) // Focus on the textarea
|
const box = searchPage.locator(searchBar)
|
||||||
await this.bot.utils.wait(500)
|
await box.waitFor({ state: 'attached', timeout: 15000 })
|
||||||
await searchPage.keyboard.down(platformControlKey)
|
|
||||||
await searchPage.keyboard.press('A')
|
// Try dismissing overlays before interacting
|
||||||
await searchPage.keyboard.press('Backspace')
|
await this.bot.browser.utils.tryDismissAllMessages(searchPage)
|
||||||
await searchPage.keyboard.up(platformControlKey)
|
await this.bot.utils.wait(200)
|
||||||
await searchPage.keyboard.type(query)
|
|
||||||
await searchPage.keyboard.press('Enter')
|
let navigatedDirectly = false
|
||||||
|
try {
|
||||||
|
// Try focusing and filling instead of clicking (more reliable on mobile)
|
||||||
|
await box.focus({ timeout: 2000 }).catch(() => { /* ignore focus errors */ })
|
||||||
|
await box.fill('')
|
||||||
|
await this.bot.utils.wait(200)
|
||||||
|
await searchPage.keyboard.down(platformControlKey)
|
||||||
|
await searchPage.keyboard.press('A')
|
||||||
|
await searchPage.keyboard.press('Backspace')
|
||||||
|
await searchPage.keyboard.up(platformControlKey)
|
||||||
|
await box.type(query, { delay: 20 })
|
||||||
|
await searchPage.keyboard.press('Enter')
|
||||||
|
} catch (typeErr) {
|
||||||
|
// As a robust fallback, navigate directly to the search results URL
|
||||||
|
const q = encodeURIComponent(query)
|
||||||
|
const url = `https://www.bing.com/search?q=${q}`
|
||||||
|
await searchPage.goto(url)
|
||||||
|
navigatedDirectly = true
|
||||||
|
}
|
||||||
|
|
||||||
await this.bot.utils.wait(3000)
|
await this.bot.utils.wait(3000)
|
||||||
|
|
||||||
// Bing.com in Chrome opens a new tab when searching
|
// Bing.com in Chrome opens a new tab when searching via Enter; if we navigated directly, stay on current tab
|
||||||
const resultPage = await this.bot.browser.utils.getLatestTab(searchPage)
|
const resultPage = navigatedDirectly ? searchPage : await this.bot.browser.utils.getLatestTab(searchPage)
|
||||||
this.searchPageURL = new URL(resultPage.url()).href // Set the results page
|
this.searchPageURL = new URL(resultPage.url()).href // Set the results page
|
||||||
|
|
||||||
await this.bot.browser.utils.reloadBadPage(resultPage)
|
await this.bot.browser.utils.reloadBadPage(resultPage)
|
||||||
@@ -185,7 +225,10 @@ export class Search extends Workers {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Delay between searches
|
// Delay between searches
|
||||||
await this.bot.utils.wait(Math.floor(this.bot.utils.randomNumber(this.bot.utils.stringToMs(this.bot.config.searchSettings.searchDelay.min), this.bot.utils.stringToMs(this.bot.config.searchSettings.searchDelay.max))))
|
const minDelay = this.bot.utils.stringToMs(this.bot.config.searchSettings.searchDelay.min)
|
||||||
|
const maxDelay = this.bot.utils.stringToMs(this.bot.config.searchSettings.searchDelay.max)
|
||||||
|
const adaptivePad = Math.min(4000, Math.max(0, Math.floor(Math.random() * 800)))
|
||||||
|
await this.bot.utils.wait(Math.floor(this.bot.utils.randomNumber(minDelay, maxDelay)) + adaptivePad)
|
||||||
|
|
||||||
return await this.bot.browser.func.getSearchPoints()
|
return await this.bot.browser.func.getSearchPoints()
|
||||||
|
|
||||||
@@ -234,8 +277,10 @@ export class Search extends Workers {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const mappedTrendsData = trendsData.map(query => [query[0], query[9]!.slice(1)])
|
const mappedTrendsData = trendsData.map(query => [query[0], query[9]!.slice(1)])
|
||||||
if (mappedTrendsData.length < 90) {
|
this.bot.log(this.bot.isMobile, 'SEARCH-GOOGLE-TRENDS', `Found ${mappedTrendsData.length} search queries for ${geoLocale}`)
|
||||||
this.bot.log(this.bot.isMobile, 'SEARCH-GOOGLE-TRENDS', 'Insufficient search queries, falling back to US', 'warn')
|
|
||||||
|
if (mappedTrendsData.length < 30 && geoLocale.toUpperCase() !== 'US') {
|
||||||
|
this.bot.log(this.bot.isMobile, 'SEARCH-GOOGLE-TRENDS', `Insufficient search queries (${mappedTrendsData.length} < 30), falling back to US`, 'warn')
|
||||||
return this.getGoogleTrends()
|
return this.getGoogleTrends()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import * as fs from 'fs'
|
|||||||
import path from 'path'
|
import path from 'path'
|
||||||
|
|
||||||
import { Workers } from '../Workers'
|
import { Workers } from '../Workers'
|
||||||
|
import { DELAYS } from '../../constants'
|
||||||
|
|
||||||
import { MorePromotion, PromotionalItem } from '../../interface/DashboardData'
|
import { MorePromotion, PromotionalItem } from '../../interface/DashboardData'
|
||||||
|
|
||||||
@@ -13,19 +14,28 @@ export class SearchOnBing extends Workers {
|
|||||||
this.bot.log(this.bot.isMobile, 'SEARCH-ON-BING', 'Trying to complete SearchOnBing')
|
this.bot.log(this.bot.isMobile, 'SEARCH-ON-BING', 'Trying to complete SearchOnBing')
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await this.bot.utils.wait(5000)
|
await this.bot.utils.wait(DELAYS.SEARCH_ON_BING_WAIT)
|
||||||
|
|
||||||
await this.bot.browser.utils.tryDismissAllMessages(page)
|
await this.bot.browser.utils.tryDismissAllMessages(page)
|
||||||
|
|
||||||
const query = await this.getSearchQuery(activity.title)
|
const query = await this.getSearchQuery(activity.title)
|
||||||
|
|
||||||
const searchBar = '#sb_form_q'
|
const searchBar = '#sb_form_q'
|
||||||
await page.waitForSelector(searchBar, { state: 'visible', timeout: 10000 })
|
const box = page.locator(searchBar)
|
||||||
await this.safeClick(page, searchBar)
|
await box.waitFor({ state: 'attached', timeout: DELAYS.SEARCH_BAR_TIMEOUT })
|
||||||
await this.bot.utils.wait(500)
|
await this.bot.browser.utils.tryDismissAllMessages(page)
|
||||||
await page.keyboard.type(query)
|
await this.bot.utils.wait(DELAYS.SEARCH_ON_BING_FOCUS)
|
||||||
await page.keyboard.press('Enter')
|
try {
|
||||||
await this.bot.utils.wait(3000)
|
await box.focus({ timeout: DELAYS.THIS_OR_THAT_START }).catch(() => { /* ignore */ })
|
||||||
|
await box.fill('')
|
||||||
|
await this.bot.utils.wait(DELAYS.SEARCH_ON_BING_FOCUS)
|
||||||
|
await page.keyboard.type(query, { delay: DELAYS.TYPING_DELAY })
|
||||||
|
await page.keyboard.press('Enter')
|
||||||
|
} catch {
|
||||||
|
const url = `https://www.bing.com/search?q=${encodeURIComponent(query)}`
|
||||||
|
await page.goto(url)
|
||||||
|
}
|
||||||
|
await this.bot.utils.wait(DELAYS.SEARCH_ON_BING_COMPLETE)
|
||||||
|
|
||||||
await page.close()
|
await page.close()
|
||||||
|
|
||||||
@@ -36,22 +46,6 @@ export class SearchOnBing extends Workers {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async safeClick(page: Page, selector: string) {
|
|
||||||
try {
|
|
||||||
await page.click(selector, { timeout: 5000 })
|
|
||||||
} catch (e: any) {
|
|
||||||
const msg = (e?.message || '')
|
|
||||||
if (/Timeout.*click/i.test(msg) || /intercepts pointer events/i.test(msg)) {
|
|
||||||
// Try to dismiss overlays then retry once
|
|
||||||
await this.bot.browser.utils.tryDismissAllMessages(page)
|
|
||||||
await this.bot.utils.wait(500)
|
|
||||||
await page.click(selector, { timeout: 5000 })
|
|
||||||
} else {
|
|
||||||
throw e
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private async getSearchQuery(title: string): Promise<string> {
|
private async getSearchQuery(title: string): Promise<string> {
|
||||||
interface Queries {
|
interface Queries {
|
||||||
title: string;
|
title: string;
|
||||||
@@ -68,7 +62,7 @@ export class SearchOnBing extends Workers {
|
|||||||
// Fetch from the repo directly so the user doesn't need to redownload the script for the new activities
|
// Fetch from the repo directly so the user doesn't need to redownload the script for the new activities
|
||||||
const response = await this.bot.axios.request({
|
const response = await this.bot.axios.request({
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
url: 'https://raw.githubusercontent.com/TheNetsky/Microsoft-Rewards-Script/refs/heads/main/src/functions/queries.json'
|
url: 'https://raw.githubusercontent.com/TheNetsky/Microsoft-Rewards-Script/refs/heads/v2/src/functions/queries.json'
|
||||||
})
|
})
|
||||||
queries = response.data
|
queries = response.data
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import { Page } from 'rebrowser-playwright'
|
import { Page } from 'rebrowser-playwright'
|
||||||
|
|
||||||
import { Workers } from '../Workers'
|
import { Workers } from '../Workers'
|
||||||
|
import { DELAYS } from '../../constants'
|
||||||
|
|
||||||
|
|
||||||
export class ThisOrThat extends Workers {
|
export class ThisOrThat extends Workers {
|
||||||
@@ -11,14 +12,14 @@ export class ThisOrThat extends Workers {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
// Check if the quiz has been started or not
|
// Check if the quiz has been started or not
|
||||||
const quizNotStarted = await page.waitForSelector('#rqStartQuiz', { state: 'visible', timeout: 2000 }).then(() => true).catch(() => false)
|
const quizNotStarted = await page.waitForSelector('#rqStartQuiz', { state: 'visible', timeout: DELAYS.THIS_OR_THAT_START }).then(() => true).catch(() => false)
|
||||||
if (quizNotStarted) {
|
if (quizNotStarted) {
|
||||||
await page.click('#rqStartQuiz')
|
await page.click('#rqStartQuiz')
|
||||||
} else {
|
} else {
|
||||||
this.bot.log(this.bot.isMobile, 'THIS-OR-THAT', 'ThisOrThat has already been started, trying to finish it')
|
this.bot.log(this.bot.isMobile, 'THIS-OR-THAT', 'ThisOrThat has already been started, trying to finish it')
|
||||||
}
|
}
|
||||||
|
|
||||||
await this.bot.utils.wait(2000)
|
await this.bot.utils.wait(DELAYS.THIS_OR_THAT_START)
|
||||||
|
|
||||||
// Solving
|
// Solving
|
||||||
const quizData = await this.bot.browser.func.getQuizData(page)
|
const quizData = await this.bot.browser.func.getQuizData(page)
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ export class UrlReward extends Workers {
|
|||||||
this.bot.log(this.bot.isMobile, 'URL-REWARD', 'Trying to complete UrlReward')
|
this.bot.log(this.bot.isMobile, 'URL-REWARD', 'Trying to complete UrlReward')
|
||||||
|
|
||||||
try {
|
try {
|
||||||
this.bot.utils.wait(2000)
|
await this.bot.utils.wait(2000)
|
||||||
|
|
||||||
await page.close()
|
await page.close()
|
||||||
|
|
||||||
|
|||||||
627
src/index.ts
627
src/index.ts
@@ -1,4 +1,5 @@
|
|||||||
import cluster from 'cluster'
|
import cluster from 'cluster'
|
||||||
|
import type { Worker } from 'cluster'
|
||||||
// Use Page type from playwright for typings; at runtime rebrowser-playwright extends playwright
|
// Use Page type from playwright for typings; at runtime rebrowser-playwright extends playwright
|
||||||
import type { Page } from 'playwright'
|
import type { Page } from 'playwright'
|
||||||
|
|
||||||
@@ -9,6 +10,7 @@ import BrowserUtil from './browser/BrowserUtil'
|
|||||||
import { log } from './util/Logger'
|
import { log } from './util/Logger'
|
||||||
import Util from './util/Utils'
|
import Util from './util/Utils'
|
||||||
import { loadAccounts, loadConfig, saveSessionData } from './util/Load'
|
import { loadAccounts, loadConfig, saveSessionData } from './util/Load'
|
||||||
|
import { DISCORD } from './constants'
|
||||||
|
|
||||||
import { Login } from './functions/Login'
|
import { Login } from './functions/Login'
|
||||||
import { Workers } from './functions/Workers'
|
import { Workers } from './functions/Workers'
|
||||||
@@ -18,6 +20,8 @@ import { Account } from './interface/Account'
|
|||||||
import Axios from './util/Axios'
|
import Axios from './util/Axios'
|
||||||
import fs from 'fs'
|
import fs from 'fs'
|
||||||
import path from 'path'
|
import path from 'path'
|
||||||
|
import Humanizer from './util/Humanizer'
|
||||||
|
import { detectBanReason } from './util/BanDetector'
|
||||||
|
|
||||||
|
|
||||||
// Main bot class
|
// Main bot class
|
||||||
@@ -30,8 +34,17 @@ export class MicrosoftRewardsBot {
|
|||||||
func: BrowserFunc,
|
func: BrowserFunc,
|
||||||
utils: BrowserUtil
|
utils: BrowserUtil
|
||||||
}
|
}
|
||||||
|
public humanizer: Humanizer
|
||||||
public isMobile: boolean
|
public isMobile: boolean
|
||||||
public homePage!: Page
|
public homePage!: Page
|
||||||
|
public currentAccountEmail?: string
|
||||||
|
public currentAccountRecoveryEmail?: string
|
||||||
|
public compromisedModeActive: boolean = false
|
||||||
|
public compromisedReason?: string
|
||||||
|
public compromisedEmail?: string
|
||||||
|
// Mutex-like flag to prevent parallel execution when config.parallel is accidentally misconfigured
|
||||||
|
private isDesktopRunning: boolean = false
|
||||||
|
private isMobileRunning: boolean = false
|
||||||
|
|
||||||
private pointsCanCollect: number = 0
|
private pointsCanCollect: number = 0
|
||||||
private pointsInitial: number = 0
|
private pointsInitial: number = 0
|
||||||
@@ -46,9 +59,11 @@ export class MicrosoftRewardsBot {
|
|||||||
|
|
||||||
// Summary collection (per process)
|
// Summary collection (per process)
|
||||||
private accountSummaries: AccountSummary[] = []
|
private accountSummaries: AccountSummary[] = []
|
||||||
|
private runId: string = Math.random().toString(36).slice(2)
|
||||||
|
private bannedTriggered: { email: string; reason: string } | null = null
|
||||||
|
private globalStandby: { active: boolean; reason?: string } = { active: false }
|
||||||
|
|
||||||
//@ts-expect-error Will be initialized later
|
public axios!: Axios
|
||||||
public axios: Axios
|
|
||||||
|
|
||||||
constructor(isMobile: boolean) {
|
constructor(isMobile: boolean) {
|
||||||
this.isMobile = isMobile
|
this.isMobile = isMobile
|
||||||
@@ -56,24 +71,27 @@ export class MicrosoftRewardsBot {
|
|||||||
|
|
||||||
this.accounts = []
|
this.accounts = []
|
||||||
this.utils = new Util()
|
this.utils = new Util()
|
||||||
this.workers = new Workers(this)
|
this.config = loadConfig()
|
||||||
this.browser = {
|
this.browser = {
|
||||||
func: new BrowserFunc(this),
|
func: new BrowserFunc(this),
|
||||||
utils: new BrowserUtil(this)
|
utils: new BrowserUtil(this)
|
||||||
}
|
}
|
||||||
this.config = loadConfig()
|
this.workers = new Workers(this)
|
||||||
|
this.humanizer = new Humanizer(this.utils, this.config.humanization)
|
||||||
this.activeWorkers = this.config.clusters
|
this.activeWorkers = this.config.clusters
|
||||||
this.mobileRetryAttempts = 0
|
this.mobileRetryAttempts = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
async initialize() {
|
async initialize() {
|
||||||
this.accounts = loadAccounts()
|
this.accounts = loadAccounts()
|
||||||
}
|
}
|
||||||
|
|
||||||
async run() {
|
async run() {
|
||||||
this.printBanner()
|
|
||||||
log('main', 'MAIN', `Bot started with ${this.config.clusters} clusters`)
|
log('main', 'MAIN', `Bot started with ${this.config.clusters} clusters`)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Only cluster when there's more than 1 cluster demanded
|
// Only cluster when there's more than 1 cluster demanded
|
||||||
if (this.config.clusters > 1) {
|
if (this.config.clusters > 1) {
|
||||||
if (cluster.isPrimary) {
|
if (cluster.isPrimary) {
|
||||||
@@ -86,32 +104,6 @@ export class MicrosoftRewardsBot {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private printBanner() {
|
|
||||||
// Only print once (primary process or single cluster execution)
|
|
||||||
if (this.config.clusters > 1 && !cluster.isPrimary) return
|
|
||||||
try {
|
|
||||||
const pkgPath = path.join(__dirname, '../', 'package.json')
|
|
||||||
let version = 'unknown'
|
|
||||||
if (fs.existsSync(pkgPath)) {
|
|
||||||
const raw = fs.readFileSync(pkgPath, 'utf-8')
|
|
||||||
const pkg = JSON.parse(raw)
|
|
||||||
version = pkg.version || version
|
|
||||||
}
|
|
||||||
const banner = [
|
|
||||||
' __ __ _____ _____ _ ',
|
|
||||||
' | \/ |/ ____| | __ \\ | | ',
|
|
||||||
' | \ / | (___ ______| |__) |_____ ____ _ _ __ __| |___ ',
|
|
||||||
' | |\/| |\\___ \\______| _ // _ \\ \\ /\\ / / _` | \'__/ _` / __|',
|
|
||||||
' | | | |____) | | | \\ \\ __/ \\ V V / (_| | | | (_| \\__ \\',
|
|
||||||
' |_| |_|_____/ |_| \\_\\___| \\_/\\_/ \\__,_|_| \\__,_|___/',
|
|
||||||
'',
|
|
||||||
` Version: v${version}`,
|
|
||||||
''
|
|
||||||
].join('\n')
|
|
||||||
console.log(banner)
|
|
||||||
} catch { /* ignore banner errors */ }
|
|
||||||
}
|
|
||||||
|
|
||||||
// Return summaries (used when clusters==1)
|
// Return summaries (used when clusters==1)
|
||||||
public getSummaries() {
|
public getSummaries() {
|
||||||
return this.accountSummaries
|
return this.accountSummaries
|
||||||
@@ -120,32 +112,71 @@ export class MicrosoftRewardsBot {
|
|||||||
private runMaster() {
|
private runMaster() {
|
||||||
log('main', 'MAIN-PRIMARY', 'Primary process started')
|
log('main', 'MAIN-PRIMARY', 'Primary process started')
|
||||||
|
|
||||||
const accountChunks = this.utils.chunkArray(this.accounts, this.config.clusters)
|
const totalAccounts = this.accounts.length
|
||||||
|
|
||||||
for (let i = 0; i < accountChunks.length; i++) {
|
// Validate accounts exist
|
||||||
|
if (totalAccounts === 0) {
|
||||||
|
log('main', 'MAIN-PRIMARY', 'No accounts found to process. Exiting.', 'warn')
|
||||||
|
process.exit(0)
|
||||||
|
}
|
||||||
|
|
||||||
|
// If user over-specified clusters (e.g. 10 clusters but only 2 accounts), don't spawn useless idle workers.
|
||||||
|
const workerCount = Math.min(this.config.clusters, totalAccounts)
|
||||||
|
const accountChunks = this.utils.chunkArray(this.accounts, workerCount)
|
||||||
|
// Reset activeWorkers to actual spawn count (constructor used raw clusters)
|
||||||
|
this.activeWorkers = workerCount
|
||||||
|
|
||||||
|
for (let i = 0; i < workerCount; i++) {
|
||||||
const worker = cluster.fork()
|
const worker = cluster.fork()
|
||||||
const chunk = accountChunks[i]
|
const chunk = accountChunks[i] || []
|
||||||
;(worker as any).send?.({ chunk })
|
|
||||||
// Collect summaries from workers
|
// Validate chunk has accounts
|
||||||
worker.on('message', (msg: any) => {
|
if (chunk.length === 0) {
|
||||||
if (msg && msg.type === 'summary' && Array.isArray(msg.data)) {
|
log('main', 'MAIN-PRIMARY', `Warning: Worker ${i} received empty account chunk`, 'warn')
|
||||||
this.accountSummaries.push(...msg.data)
|
}
|
||||||
|
|
||||||
|
(worker as unknown as { send?: (m: { chunk: Account[] }) => void }).send?.({ chunk })
|
||||||
|
worker.on('message', (msg: unknown) => {
|
||||||
|
const m = msg as { type?: string; data?: AccountSummary[] }
|
||||||
|
if (m && m.type === 'summary' && Array.isArray(m.data)) {
|
||||||
|
this.accountSummaries.push(...m.data)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
cluster.on('exit', (worker: any, code: number) => {
|
cluster.on('exit', (worker: Worker, code: number) => {
|
||||||
this.activeWorkers -= 1
|
this.activeWorkers -= 1
|
||||||
|
|
||||||
log('main', 'MAIN-WORKER', `Worker ${worker.process.pid} destroyed | Code: ${code} | Active workers: ${this.activeWorkers}`, 'warn')
|
log('main', 'MAIN-WORKER', `Worker ${worker.process.pid} destroyed | Code: ${code} | Active workers: ${this.activeWorkers}`, 'warn')
|
||||||
|
|
||||||
|
// Optional: restart crashed worker (basic heuristic) if crashRecovery allows
|
||||||
|
try {
|
||||||
|
const cr = this.config.crashRecovery
|
||||||
|
if (cr?.restartFailedWorker && code !== 0) {
|
||||||
|
const attempts = (worker as unknown as { _restartAttempts?: number })._restartAttempts || 0
|
||||||
|
if (attempts < (cr.restartFailedWorkerAttempts ?? 1)) {
|
||||||
|
(worker as unknown as { _restartAttempts?: number })._restartAttempts = attempts + 1
|
||||||
|
log('main','CRASH-RECOVERY',`Respawning worker (attempt ${attempts + 1})`, 'warn','yellow')
|
||||||
|
const newW = cluster.fork()
|
||||||
|
// NOTE: account chunk re-assignment simplistic: unused; real mapping improvement todo
|
||||||
|
newW.on('message', (msg: unknown) => {
|
||||||
|
const m = msg as { type?: string; data?: AccountSummary[] }
|
||||||
|
if (m && m.type === 'summary' && Array.isArray(m.data)) this.accountSummaries.push(...m.data)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch { /* ignore */ }
|
||||||
|
|
||||||
// Check if all workers have exited
|
// Check if all workers have exited
|
||||||
if (this.activeWorkers === 0) {
|
if (this.activeWorkers === 0) {
|
||||||
// All workers done -> send conclusion (if enabled) then exit
|
// All workers done
|
||||||
this.sendConclusion(this.accountSummaries).finally(() => {
|
(async () => {
|
||||||
|
try {
|
||||||
|
await this.sendConclusion(this.accountSummaries)
|
||||||
|
} catch {/* ignore */}
|
||||||
log('main', 'MAIN-WORKER', 'All workers destroyed. Exiting main process!', 'warn')
|
log('main', 'MAIN-WORKER', 'All workers destroyed. Exiting main process!', 'warn')
|
||||||
process.exit(0)
|
process.exit(0)
|
||||||
})
|
})()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -153,13 +184,40 @@ export class MicrosoftRewardsBot {
|
|||||||
private runWorker() {
|
private runWorker() {
|
||||||
log('main', 'MAIN-WORKER', `Worker ${process.pid} spawned`)
|
log('main', 'MAIN-WORKER', `Worker ${process.pid} spawned`)
|
||||||
// Receive the chunk of accounts from the master
|
// Receive the chunk of accounts from the master
|
||||||
;(process as any).on('message', async ({ chunk }: { chunk: Account[] }) => {
|
;(process as unknown as { on: (ev: 'message', cb: (m: { chunk: Account[] }) => void) => void }).on('message', async ({ chunk }: { chunk: Account[] }) => {
|
||||||
await this.runTasks(chunk)
|
await this.runTasks(chunk)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
private async runTasks(accounts: Account[]) {
|
private async runTasks(accounts: Account[]) {
|
||||||
for (const account of accounts) {
|
for (const account of accounts) {
|
||||||
|
// If a global standby is active due to security/banned, stop processing further accounts
|
||||||
|
if (this.globalStandby.active) {
|
||||||
|
log('main','SECURITY',`Global standby active (${this.globalStandby.reason || 'security-issue'}). Not proceeding to next accounts until resolved.`, 'warn', 'yellow')
|
||||||
|
break
|
||||||
|
}
|
||||||
|
// Optional global stop after first ban
|
||||||
|
if (this.config?.humanization?.stopOnBan === true && this.bannedTriggered) {
|
||||||
|
log('main','TASK',`Stopping remaining accounts due to ban on ${this.bannedTriggered.email}: ${this.bannedTriggered.reason}`,'warn')
|
||||||
|
break
|
||||||
|
}
|
||||||
|
// Reset compromised state per account
|
||||||
|
this.compromisedModeActive = false
|
||||||
|
this.compromisedReason = undefined
|
||||||
|
this.compromisedEmail = undefined
|
||||||
|
// If humanization allowed windows are configured, wait until within a window
|
||||||
|
try {
|
||||||
|
const windows: string[] | undefined = this.config?.humanization?.allowedWindows
|
||||||
|
if (Array.isArray(windows) && windows.length > 0) {
|
||||||
|
const waitMs = this.computeWaitForAllowedWindow(windows)
|
||||||
|
if (waitMs > 0) {
|
||||||
|
log('main','HUMANIZATION',`Waiting ${Math.ceil(waitMs/1000)}s until next allowed window before starting ${account.email}`,'warn')
|
||||||
|
await new Promise<void>(r => setTimeout(r, waitMs))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch {/* ignore */}
|
||||||
|
this.currentAccountEmail = account.email
|
||||||
|
this.currentAccountRecoveryEmail = account.recoveryEmail
|
||||||
log('main', 'MAIN-WORKER', `Started tasks for account ${account.email}`)
|
log('main', 'MAIN-WORKER', `Started tasks for account ${account.email}`)
|
||||||
|
|
||||||
const accountStart = Date.now()
|
const accountStart = Date.now()
|
||||||
@@ -168,10 +226,11 @@ export class MicrosoftRewardsBot {
|
|||||||
let desktopCollected = 0
|
let desktopCollected = 0
|
||||||
let mobileCollected = 0
|
let mobileCollected = 0
|
||||||
const errors: string[] = []
|
const errors: string[] = []
|
||||||
|
const banned = { status: false, reason: '' }
|
||||||
|
|
||||||
this.axios = new Axios(account.proxy)
|
this.axios = new Axios(account.proxy)
|
||||||
const verbose = process.env.DEBUG_REWARDS_VERBOSE === '1'
|
const verbose = process.env.DEBUG_REWARDS_VERBOSE === '1'
|
||||||
const formatFullErr = (label: string, e: any) => {
|
const formatFullErr = (label: string, e: unknown) => {
|
||||||
const base = shortErr(e)
|
const base = shortErr(e)
|
||||||
if (verbose && e instanceof Error) {
|
if (verbose && e instanceof Error) {
|
||||||
return `${label}:${base} :: ${e.stack?.split('\n').slice(0,4).join(' | ')}`
|
return `${label}:${base} :: ${e.stack?.split('\n').slice(0,4).join(' | ')}`
|
||||||
@@ -184,48 +243,110 @@ export class MicrosoftRewardsBot {
|
|||||||
mobileInstance.axios = this.axios
|
mobileInstance.axios = this.axios
|
||||||
// Run both and capture results with detailed logging
|
// Run both and capture results with detailed logging
|
||||||
const desktopPromise = this.Desktop(account).catch(e => {
|
const desktopPromise = this.Desktop(account).catch(e => {
|
||||||
log(false, 'TASK', `Desktop flow failed early for ${account.email}: ${e instanceof Error ? e.message : e}`,'error')
|
const msg = e instanceof Error ? e.message : String(e)
|
||||||
|
log(false, 'TASK', `Desktop flow failed early for ${account.email}: ${msg}`,'error')
|
||||||
|
const bd = detectBanReason(e)
|
||||||
|
if (bd.status) {
|
||||||
|
banned.status = true; banned.reason = bd.reason.substring(0,200)
|
||||||
|
void this.handleImmediateBanAlert(account.email, banned.reason)
|
||||||
|
}
|
||||||
errors.push(formatFullErr('desktop', e)); return null
|
errors.push(formatFullErr('desktop', e)); return null
|
||||||
})
|
})
|
||||||
const mobilePromise = mobileInstance.Mobile(account).catch(e => {
|
const mobilePromise = mobileInstance.Mobile(account).catch(e => {
|
||||||
log(true, 'TASK', `Mobile flow failed early for ${account.email}: ${e instanceof Error ? e.message : e}`,'error')
|
const msg = e instanceof Error ? e.message : String(e)
|
||||||
|
log(true, 'TASK', `Mobile flow failed early for ${account.email}: ${msg}`,'error')
|
||||||
|
const bd = detectBanReason(e)
|
||||||
|
if (bd.status) {
|
||||||
|
banned.status = true; banned.reason = bd.reason.substring(0,200)
|
||||||
|
void this.handleImmediateBanAlert(account.email, banned.reason)
|
||||||
|
}
|
||||||
errors.push(formatFullErr('mobile', e)); return null
|
errors.push(formatFullErr('mobile', e)); return null
|
||||||
})
|
})
|
||||||
const [desktopResult, mobileResult] = await Promise.all([desktopPromise, mobilePromise])
|
const [desktopResult, mobileResult] = await Promise.allSettled([desktopPromise, mobilePromise])
|
||||||
if (desktopResult) {
|
|
||||||
desktopInitial = desktopResult.initialPoints
|
// Handle desktop result
|
||||||
desktopCollected = desktopResult.collectedPoints
|
if (desktopResult.status === 'fulfilled' && desktopResult.value) {
|
||||||
}
|
desktopInitial = desktopResult.value.initialPoints
|
||||||
if (mobileResult) {
|
desktopCollected = desktopResult.value.collectedPoints
|
||||||
mobileInitial = mobileResult.initialPoints
|
} else if (desktopResult.status === 'rejected') {
|
||||||
mobileCollected = mobileResult.collectedPoints
|
log(false, 'TASK', `Desktop promise rejected unexpectedly: ${shortErr(desktopResult.reason)}`,'error')
|
||||||
}
|
errors.push(formatFullErr('desktop-rejected', desktopResult.reason))
|
||||||
} else {
|
|
||||||
this.isMobile = false
|
|
||||||
const desktopResult = await this.Desktop(account).catch(e => {
|
|
||||||
log(false, 'TASK', `Desktop flow failed early for ${account.email}: ${e instanceof Error ? e.message : e}`,'error')
|
|
||||||
errors.push(formatFullErr('desktop', e)); return null
|
|
||||||
})
|
|
||||||
if (desktopResult) {
|
|
||||||
desktopInitial = desktopResult.initialPoints
|
|
||||||
desktopCollected = desktopResult.collectedPoints
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.isMobile = true
|
// Handle mobile result
|
||||||
const mobileResult = await this.Mobile(account).catch(e => {
|
if (mobileResult.status === 'fulfilled' && mobileResult.value) {
|
||||||
log(true, 'TASK', `Mobile flow failed early for ${account.email}: ${e instanceof Error ? e.message : e}`,'error')
|
mobileInitial = mobileResult.value.initialPoints
|
||||||
errors.push(formatFullErr('mobile', e)); return null
|
mobileCollected = mobileResult.value.collectedPoints
|
||||||
})
|
} else if (mobileResult.status === 'rejected') {
|
||||||
if (mobileResult) {
|
log(true, 'TASK', `Mobile promise rejected unexpectedly: ${shortErr(mobileResult.reason)}`,'error')
|
||||||
mobileInitial = mobileResult.initialPoints
|
errors.push(formatFullErr('mobile-rejected', mobileResult.reason))
|
||||||
mobileCollected = mobileResult.collectedPoints
|
}
|
||||||
|
} else {
|
||||||
|
// Sequential execution with safety checks
|
||||||
|
if (this.isDesktopRunning || this.isMobileRunning) {
|
||||||
|
log('main', 'TASK', `Race condition detected: Desktop=${this.isDesktopRunning}, Mobile=${this.isMobileRunning}. Skipping to prevent conflicts.`, 'error')
|
||||||
|
errors.push('race-condition-detected')
|
||||||
|
} else {
|
||||||
|
this.isMobile = false
|
||||||
|
this.isDesktopRunning = true
|
||||||
|
const desktopResult = await this.Desktop(account).catch(e => {
|
||||||
|
const msg = e instanceof Error ? e.message : String(e)
|
||||||
|
log(false, 'TASK', `Desktop flow failed early for ${account.email}: ${msg}`,'error')
|
||||||
|
const bd = detectBanReason(e)
|
||||||
|
if (bd.status) {
|
||||||
|
banned.status = true; banned.reason = bd.reason.substring(0,200)
|
||||||
|
void this.handleImmediateBanAlert(account.email, banned.reason)
|
||||||
|
}
|
||||||
|
errors.push(formatFullErr('desktop', e)); return null
|
||||||
|
})
|
||||||
|
if (desktopResult) {
|
||||||
|
desktopInitial = desktopResult.initialPoints
|
||||||
|
desktopCollected = desktopResult.collectedPoints
|
||||||
|
}
|
||||||
|
this.isDesktopRunning = false
|
||||||
|
|
||||||
|
// If banned or compromised detected, skip mobile to save time
|
||||||
|
if (!banned.status && !this.compromisedModeActive) {
|
||||||
|
this.isMobile = true
|
||||||
|
this.isMobileRunning = true
|
||||||
|
const mobileResult = await this.Mobile(account).catch(e => {
|
||||||
|
const msg = e instanceof Error ? e.message : String(e)
|
||||||
|
log(true, 'TASK', `Mobile flow failed early for ${account.email}: ${msg}`,'error')
|
||||||
|
const bd = detectBanReason(e)
|
||||||
|
if (bd.status) {
|
||||||
|
banned.status = true; banned.reason = bd.reason.substring(0,200)
|
||||||
|
void this.handleImmediateBanAlert(account.email, banned.reason)
|
||||||
|
}
|
||||||
|
errors.push(formatFullErr('mobile', e)); return null
|
||||||
|
})
|
||||||
|
if (mobileResult) {
|
||||||
|
mobileInitial = mobileResult.initialPoints
|
||||||
|
mobileCollected = mobileResult.collectedPoints
|
||||||
|
}
|
||||||
|
this.isMobileRunning = false
|
||||||
|
} else {
|
||||||
|
const why = banned.status ? 'banned status' : 'compromised status'
|
||||||
|
log(true, 'TASK', `Skipping mobile flow for ${account.email} due to ${why}`, 'warn')
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const accountEnd = Date.now()
|
const accountEnd = Date.now()
|
||||||
const durationMs = accountEnd - accountStart
|
const durationMs = accountEnd - accountStart
|
||||||
const totalCollected = desktopCollected + mobileCollected
|
const totalCollected = desktopCollected + mobileCollected
|
||||||
const initialTotal = (desktopInitial || 0) + (mobileInitial || 0)
|
// Correct initial points (previous version double counted desktop+mobile baselines)
|
||||||
|
// Strategy: pick the lowest non-zero baseline (desktopInitial or mobileInitial) as true start.
|
||||||
|
// Sequential flow: desktopInitial < mobileInitial after gain -> min = original baseline.
|
||||||
|
// Parallel flow: both baselines equal -> min is fine.
|
||||||
|
const baselines: number[] = []
|
||||||
|
if (desktopInitial) baselines.push(desktopInitial)
|
||||||
|
if (mobileInitial) baselines.push(mobileInitial)
|
||||||
|
let initialTotal = 0
|
||||||
|
if (baselines.length === 1) initialTotal = baselines[0]!
|
||||||
|
else if (baselines.length === 2) initialTotal = Math.min(baselines[0]!, baselines[1]!)
|
||||||
|
// Fallback if both missing
|
||||||
|
if (initialTotal === 0 && (desktopInitial || mobileInitial)) initialTotal = desktopInitial || mobileInitial || 0
|
||||||
|
const endTotal = initialTotal + totalCollected
|
||||||
this.accountSummaries.push({
|
this.accountSummaries.push({
|
||||||
email: account.email,
|
email: account.email,
|
||||||
durationMs,
|
durationMs,
|
||||||
@@ -233,32 +354,105 @@ export class MicrosoftRewardsBot {
|
|||||||
mobileCollected,
|
mobileCollected,
|
||||||
totalCollected,
|
totalCollected,
|
||||||
initialTotal,
|
initialTotal,
|
||||||
endTotal: initialTotal + totalCollected,
|
endTotal,
|
||||||
errors
|
errors,
|
||||||
|
banned
|
||||||
})
|
})
|
||||||
|
|
||||||
log('main', 'MAIN-WORKER', `Completed tasks for account ${account.email}`, 'log', 'green')
|
if (banned.status) {
|
||||||
|
this.bannedTriggered = { email: account.email, reason: banned.reason }
|
||||||
|
// Enter global standby: do not proceed to next accounts
|
||||||
|
this.globalStandby = { active: true, reason: `banned:${banned.reason}` }
|
||||||
|
await this.sendGlobalSecurityStandbyAlert(account.email, `Ban detected: ${banned.reason || 'unknown'}`)
|
||||||
|
}
|
||||||
|
|
||||||
|
await log('main', 'MAIN-WORKER', `Completed tasks for account ${account.email}`, 'log', 'green')
|
||||||
}
|
}
|
||||||
|
|
||||||
log(this.isMobile, 'MAIN-PRIMARY', 'Completed tasks for ALL accounts', 'log', 'green')
|
await log(this.isMobile, 'MAIN-PRIMARY', 'Completed tasks for ALL accounts', 'log', 'green')
|
||||||
// Extra diagnostic summary when verbose
|
// Extra diagnostic summary when verbose
|
||||||
if (process.env.DEBUG_REWARDS_VERBOSE === '1') {
|
if (process.env.DEBUG_REWARDS_VERBOSE === '1') {
|
||||||
for (const summary of this.accountSummaries) {
|
for (const summary of this.accountSummaries) {
|
||||||
log('main','SUMMARY-DEBUG',`Account ${summary.email} collected D:${summary.desktopCollected} M:${summary.mobileCollected} TOTAL:${summary.totalCollected} ERRORS:${summary.errors.length ? summary.errors.join(';') : 'none'}`)
|
log('main','SUMMARY-DEBUG',`Account ${summary.email} collected D:${summary.desktopCollected} M:${summary.mobileCollected} TOTAL:${summary.totalCollected} ERRORS:${summary.errors.length ? summary.errors.join(';') : 'none'}`)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// If any account is flagged compromised, do NOT exit; keep the process alive so the browser stays open
|
||||||
|
if (this.compromisedModeActive || this.globalStandby.active) {
|
||||||
|
log('main','SECURITY','Compromised or banned detected. Global standby engaged: we will NOT proceed to other accounts until resolved. Keeping process alive. Press CTRL+C to exit when done.','warn','yellow')
|
||||||
|
const standbyInterval = setInterval(() => {
|
||||||
|
log('main','SECURITY','Still in standby: session(s) held open for manual recovery / review...','warn','yellow')
|
||||||
|
}, 5 * 60 * 1000)
|
||||||
|
|
||||||
|
// Cleanup on process exit
|
||||||
|
process.once('SIGINT', () => { clearInterval(standbyInterval); process.exit(0) })
|
||||||
|
process.once('SIGTERM', () => { clearInterval(standbyInterval); process.exit(0) })
|
||||||
|
return
|
||||||
|
}
|
||||||
// If in worker mode (clusters>1) send summaries to primary
|
// If in worker mode (clusters>1) send summaries to primary
|
||||||
if (this.config.clusters > 1 && !cluster.isPrimary) {
|
if (this.config.clusters > 1 && !cluster.isPrimary) {
|
||||||
if (process.send) {
|
if (process.send) {
|
||||||
process.send({ type: 'summary', data: this.accountSummaries })
|
process.send({ type: 'summary', data: this.accountSummaries })
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Single process mode -> build and send conclusion directly
|
// Single process mode
|
||||||
await this.sendConclusion(this.accountSummaries)
|
|
||||||
}
|
}
|
||||||
process.exit()
|
process.exit()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Send immediate ban alert if configured. */
|
||||||
|
private async handleImmediateBanAlert(email: string, reason: string): Promise<void> {
|
||||||
|
try {
|
||||||
|
const h = this.config?.humanization
|
||||||
|
if (!h || h.immediateBanAlert === false) return
|
||||||
|
const { ConclusionWebhook } = await import('./util/ConclusionWebhook')
|
||||||
|
await ConclusionWebhook(
|
||||||
|
this.config,
|
||||||
|
'🚫 Ban Detected',
|
||||||
|
`**Account:** ${email}\n**Reason:** ${reason || 'detected by heuristics'}`,
|
||||||
|
undefined,
|
||||||
|
DISCORD.COLOR_RED
|
||||||
|
)
|
||||||
|
} catch (e) {
|
||||||
|
log('main','ALERT',`Failed to send ban alert: ${e instanceof Error ? e.message : e}`,'warn')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Compute milliseconds to wait until within one of the allowed windows (HH:mm-HH:mm). Returns 0 if already inside. */
|
||||||
|
private computeWaitForAllowedWindow(windows: string[]): number {
|
||||||
|
const now = new Date()
|
||||||
|
const minsNow = now.getHours() * 60 + now.getMinutes()
|
||||||
|
let nextStartMins: number | null = null
|
||||||
|
for (const w of windows) {
|
||||||
|
const [start, end] = w.split('-')
|
||||||
|
if (!start || !end) continue
|
||||||
|
const pStart = start.split(':').map(v=>parseInt(v,10))
|
||||||
|
const pEnd = end.split(':').map(v=>parseInt(v,10))
|
||||||
|
if (pStart.length !== 2 || pEnd.length !== 2) continue
|
||||||
|
const sh = pStart[0]!, sm = pStart[1]!
|
||||||
|
const eh = pEnd[0]!, em = pEnd[1]!
|
||||||
|
if ([sh,sm,eh,em].some(n=>Number.isNaN(n))) continue
|
||||||
|
const s = sh*60 + sm
|
||||||
|
const e = eh*60 + em
|
||||||
|
if (s <= e) {
|
||||||
|
// same-day window
|
||||||
|
if (minsNow >= s && minsNow <= e) return 0
|
||||||
|
if (minsNow < s) nextStartMins = Math.min(nextStartMins ?? s, s)
|
||||||
|
} else {
|
||||||
|
// wraps past midnight (e.g., 22:00-02:00)
|
||||||
|
if (minsNow >= s || minsNow <= e) return 0
|
||||||
|
// next start today is s
|
||||||
|
nextStartMins = Math.min(nextStartMins ?? s, s)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const msPerMin = 60*1000
|
||||||
|
if (nextStartMins != null) {
|
||||||
|
const targetTodayMs = (nextStartMins - minsNow) * msPerMin
|
||||||
|
return targetTodayMs > 0 ? targetTodayMs : (24*60 + nextStartMins - minsNow) * msPerMin
|
||||||
|
}
|
||||||
|
// No valid windows parsed -> do not block
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
// Desktop
|
// Desktop
|
||||||
async Desktop(account: Account) {
|
async Desktop(account: Account) {
|
||||||
log(false,'FLOW','Desktop() invoked')
|
log(false,'FLOW','Desktop() invoked')
|
||||||
@@ -267,8 +461,31 @@ export class MicrosoftRewardsBot {
|
|||||||
|
|
||||||
log(this.isMobile, 'MAIN', 'Starting browser')
|
log(this.isMobile, 'MAIN', 'Starting browser')
|
||||||
|
|
||||||
// Login into MS Rewards, then go to rewards homepage
|
// Login into MS Rewards, then optionally stop if compromised
|
||||||
await this.login.login(this.homePage, account.email, account.password)
|
await this.login.login(this.homePage, account.email, account.password, account.totp)
|
||||||
|
|
||||||
|
if (this.compromisedModeActive) {
|
||||||
|
// User wants the page to remain open for manual recovery. Do not proceed to tasks.
|
||||||
|
const reason = this.compromisedReason || 'security-issue'
|
||||||
|
log(this.isMobile, 'SECURITY', `Account flagged as compromised (${reason}). Leaving the browser open and skipping all activities for ${account.email}.`, 'warn', 'yellow')
|
||||||
|
try {
|
||||||
|
const { ConclusionWebhook } = await import('./util/ConclusionWebhook')
|
||||||
|
await ConclusionWebhook(
|
||||||
|
this.config,
|
||||||
|
'🔐 Security Alert (Post-Login)',
|
||||||
|
`**Account:** ${account.email}\n**Reason:** ${reason}\n**Action:** Leaving browser open; skipping tasks`,
|
||||||
|
undefined,
|
||||||
|
0xFFAA00
|
||||||
|
)
|
||||||
|
} catch {/* ignore */}
|
||||||
|
// Save session for convenience, but do not close the browser
|
||||||
|
try {
|
||||||
|
await saveSessionData(this.config.sessionPath, this.homePage.context(), account.email, this.isMobile)
|
||||||
|
} catch (e) {
|
||||||
|
log(this.isMobile, 'SECURITY', `Failed to save session: ${e instanceof Error ? e.message : String(e)}`, 'warn')
|
||||||
|
}
|
||||||
|
return { initialPoints: 0, collectedPoints: 0 }
|
||||||
|
}
|
||||||
|
|
||||||
await this.browser.func.goHome(this.homePage)
|
await this.browser.func.goHome(this.homePage)
|
||||||
|
|
||||||
@@ -288,6 +505,12 @@ export class MicrosoftRewardsBot {
|
|||||||
|
|
||||||
log(this.isMobile, 'MAIN-POINTS', `You can earn ${this.pointsCanCollect} points today`)
|
log(this.isMobile, 'MAIN-POINTS', `You can earn ${this.pointsCanCollect} points today`)
|
||||||
|
|
||||||
|
if (this.pointsCanCollect === 0) {
|
||||||
|
// Extra diagnostic breakdown so users know WHY it's zero
|
||||||
|
log(this.isMobile, 'MAIN-POINTS', `Breakdown (desktop): dailySet=${browserEnarablePoints.dailySetPoints} search=${browserEnarablePoints.desktopSearchPoints} promotions=${browserEnarablePoints.morePromotionsPoints}`)
|
||||||
|
log(this.isMobile, 'MAIN-POINTS', 'All desktop earnable buckets are zero. This usually means: tasks already completed today OR the daily reset has not happened yet for your time zone. If you still want to force run activities set execution.runOnZeroPoints=true in config.', 'log', 'yellow')
|
||||||
|
}
|
||||||
|
|
||||||
// If runOnZeroPoints is false and 0 points to earn, don't continue
|
// If runOnZeroPoints is false and 0 points to earn, don't continue
|
||||||
if (!this.config.runOnZeroPoints && this.pointsCanCollect === 0) {
|
if (!this.config.runOnZeroPoints && this.pointsCanCollect === 0) {
|
||||||
log(this.isMobile, 'MAIN', 'No points to earn and "runOnZeroPoints" is set to "false", stopping!', 'log', 'yellow')
|
log(this.isMobile, 'MAIN', 'No points to earn and "runOnZeroPoints" is set to "false", stopping!', 'log', 'yellow')
|
||||||
@@ -344,8 +567,28 @@ export class MicrosoftRewardsBot {
|
|||||||
|
|
||||||
log(this.isMobile, 'MAIN', 'Starting browser')
|
log(this.isMobile, 'MAIN', 'Starting browser')
|
||||||
|
|
||||||
// Login into MS Rewards, then go to rewards homepage
|
// Login into MS Rewards, then respect compromised mode
|
||||||
await this.login.login(this.homePage, account.email, account.password)
|
await this.login.login(this.homePage, account.email, account.password, account.totp)
|
||||||
|
if (this.compromisedModeActive) {
|
||||||
|
const reason = this.compromisedReason || 'security-issue'
|
||||||
|
log(this.isMobile, 'SECURITY', `Account flagged as compromised (${reason}). Leaving mobile browser open and skipping mobile activities for ${account.email}.`, 'warn', 'yellow')
|
||||||
|
try {
|
||||||
|
const { ConclusionWebhook } = await import('./util/ConclusionWebhook')
|
||||||
|
await ConclusionWebhook(
|
||||||
|
this.config,
|
||||||
|
'🔐 Security Alert (Mobile)',
|
||||||
|
`**Account:** ${account.email}\n**Reason:** ${reason}\n**Action:** Leaving mobile browser open; skipping tasks`,
|
||||||
|
undefined,
|
||||||
|
0xFFAA00
|
||||||
|
)
|
||||||
|
} catch {/* ignore */}
|
||||||
|
try {
|
||||||
|
await saveSessionData(this.config.sessionPath, this.homePage.context(), account.email, this.isMobile)
|
||||||
|
} catch (e) {
|
||||||
|
log(this.isMobile, 'SECURITY', `Failed to save session: ${e instanceof Error ? e.message : String(e)}`, 'warn')
|
||||||
|
}
|
||||||
|
return { initialPoints: 0, collectedPoints: 0 }
|
||||||
|
}
|
||||||
this.accessToken = await this.login.getMobileAccessToken(this.homePage, account.email)
|
this.accessToken = await this.login.getMobileAccessToken(this.homePage, account.email)
|
||||||
|
|
||||||
await this.browser.func.goHome(this.homePage)
|
await this.browser.func.goHome(this.homePage)
|
||||||
@@ -360,6 +603,11 @@ export class MicrosoftRewardsBot {
|
|||||||
|
|
||||||
log(this.isMobile, 'MAIN-POINTS', `You can earn ${this.pointsCanCollect} points today (Browser: ${browserEnarablePoints.mobileSearchPoints} points, App: ${appEarnablePoints.totalEarnablePoints} points)`)
|
log(this.isMobile, 'MAIN-POINTS', `You can earn ${this.pointsCanCollect} points today (Browser: ${browserEnarablePoints.mobileSearchPoints} points, App: ${appEarnablePoints.totalEarnablePoints} points)`)
|
||||||
|
|
||||||
|
if (this.pointsCanCollect === 0) {
|
||||||
|
log(this.isMobile, 'MAIN-POINTS', `Breakdown (mobile): browserSearch=${browserEnarablePoints.mobileSearchPoints} appTotal=${appEarnablePoints.totalEarnablePoints}`)
|
||||||
|
log(this.isMobile, 'MAIN-POINTS', 'All mobile earnable buckets are zero. Causes: mobile searches already maxed, daily set finished, or daily rollover not reached yet. You can force execution by setting execution.runOnZeroPoints=true.', 'log', 'yellow')
|
||||||
|
}
|
||||||
|
|
||||||
// If runOnZeroPoints is false and 0 points to earn, don't continue
|
// If runOnZeroPoints is false and 0 points to earn, don't continue
|
||||||
if (!this.config.runOnZeroPoints && this.pointsCanCollect === 0) {
|
if (!this.config.runOnZeroPoints && this.pointsCanCollect === 0) {
|
||||||
log(this.isMobile, 'MAIN', 'No points to earn and "runOnZeroPoints" is set to "false", stopping!', 'log', 'yellow')
|
log(this.isMobile, 'MAIN', 'No points to earn and "runOnZeroPoints" is set to "false", stopping!', 'log', 'yellow')
|
||||||
@@ -432,9 +680,12 @@ export class MicrosoftRewardsBot {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private async sendConclusion(summaries: AccountSummary[]) {
|
private async sendConclusion(summaries: AccountSummary[]) {
|
||||||
const { ConclusionWebhook } = await import('./util/ConclusionWebhook')
|
const { ConclusionWebhookEnhanced } = await import('./util/ConclusionWebhook')
|
||||||
const cfg = this.config
|
const cfg = this.config
|
||||||
if (!cfg.conclusionWebhook || !cfg.conclusionWebhook.enabled) return
|
|
||||||
|
const conclusionWebhookEnabled = !!(cfg.conclusionWebhook && cfg.conclusionWebhook.enabled)
|
||||||
|
const ntfyEnabled = !!(cfg.ntfy && cfg.ntfy.enabled)
|
||||||
|
const webhookEnabled = !!(cfg.webhook && cfg.webhook.enabled)
|
||||||
|
|
||||||
const totalAccounts = summaries.length
|
const totalAccounts = summaries.length
|
||||||
if (totalAccounts === 0) return
|
if (totalAccounts === 0) return
|
||||||
@@ -444,58 +695,108 @@ export class MicrosoftRewardsBot {
|
|||||||
let totalEnd = 0
|
let totalEnd = 0
|
||||||
let totalDuration = 0
|
let totalDuration = 0
|
||||||
let accountsWithErrors = 0
|
let accountsWithErrors = 0
|
||||||
|
let accountsBanned = 0
|
||||||
|
let successes = 0
|
||||||
|
|
||||||
const accountFields: any[] = []
|
// Calculate summary statistics
|
||||||
for (const s of summaries) {
|
for (const s of summaries) {
|
||||||
totalCollected += s.totalCollected
|
totalCollected += s.totalCollected
|
||||||
totalInitial += s.initialTotal
|
totalInitial += s.initialTotal
|
||||||
totalEnd += s.endTotal
|
totalEnd += s.endTotal
|
||||||
totalDuration += s.durationMs
|
totalDuration += s.durationMs
|
||||||
|
if (s.banned?.status) accountsBanned++
|
||||||
if (s.errors.length) accountsWithErrors++
|
if (s.errors.length) accountsWithErrors++
|
||||||
|
if (!s.banned?.status && !s.errors.length) successes++
|
||||||
const statusEmoji = s.errors.length ? '⚠️' : '✅'
|
|
||||||
const diff = s.totalCollected
|
|
||||||
const duration = formatDuration(s.durationMs)
|
|
||||||
const valueLines: string[] = [
|
|
||||||
`Points: ${s.initialTotal} → ${s.endTotal} ( +${diff} )`,
|
|
||||||
`Breakdown: 🖥️ ${s.desktopCollected} | 📱 ${s.mobileCollected}`,
|
|
||||||
`Duration: ⏱️ ${duration}`
|
|
||||||
]
|
|
||||||
if (s.errors.length) {
|
|
||||||
valueLines.push(`Errors: ${s.errors.slice(0,2).join(' | ')}`)
|
|
||||||
}
|
|
||||||
accountFields.push({
|
|
||||||
name: `${statusEmoji} ${s.email}`.substring(0, 256),
|
|
||||||
value: valueLines.join('\n').substring(0, 1024),
|
|
||||||
inline: false
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const avgDuration = totalDuration / totalAccounts
|
const avgDuration = totalDuration / totalAccounts
|
||||||
const embed = {
|
const avgPointsPerAccount = Math.round(totalCollected / totalAccounts)
|
||||||
title: '🎯 Microsoft Rewards Summary',
|
|
||||||
description: `Processed **${totalAccounts}** account(s)${accountsWithErrors ? ` • ${accountsWithErrors} with issues` : ''}`,
|
// Read package version
|
||||||
color: accountsWithErrors ? 0xFFAA00 : 0x32CD32,
|
let version = 'unknown'
|
||||||
fields: [
|
try {
|
||||||
{
|
const pkgPath = path.join(process.cwd(), 'package.json')
|
||||||
name: 'Global Totals',
|
if (fs.existsSync(pkgPath)) {
|
||||||
value: [
|
const raw = fs.readFileSync(pkgPath, 'utf-8')
|
||||||
`Total Points: ${totalInitial} → ${totalEnd} ( +${totalCollected} )`,
|
const pkg = JSON.parse(raw)
|
||||||
`Average Duration: ${formatDuration(avgDuration)}`,
|
version = pkg.version || version
|
||||||
`Cumulative Runtime: ${formatDuration(totalDuration)}`
|
|
||||||
].join('\n')
|
|
||||||
},
|
|
||||||
...accountFields
|
|
||||||
].slice(0, 25), // Discord max 25 fields
|
|
||||||
timestamp: new Date().toISOString(),
|
|
||||||
footer: {
|
|
||||||
text: 'Script conclusion webhook'
|
|
||||||
}
|
}
|
||||||
|
} catch { /* ignore */ }
|
||||||
|
|
||||||
|
// Send enhanced webhook
|
||||||
|
if (conclusionWebhookEnabled || ntfyEnabled || webhookEnabled) {
|
||||||
|
await ConclusionWebhookEnhanced(cfg, {
|
||||||
|
version,
|
||||||
|
runId: this.runId,
|
||||||
|
totalAccounts,
|
||||||
|
successes,
|
||||||
|
accountsWithErrors,
|
||||||
|
accountsBanned,
|
||||||
|
totalCollected,
|
||||||
|
totalInitial,
|
||||||
|
totalEnd,
|
||||||
|
avgPointsPerAccount,
|
||||||
|
totalDuration,
|
||||||
|
avgDuration,
|
||||||
|
summaries
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fallback plain text (rare) & embed send
|
// Write local JSON report
|
||||||
const fallback = `Microsoft Rewards Summary\nAccounts: ${totalAccounts}\nTotal: ${totalInitial} -> ${totalEnd} (+${totalCollected})\nRuntime: ${formatDuration(totalDuration)}`
|
try {
|
||||||
await ConclusionWebhook(cfg, fallback, { embeds: [embed] })
|
const fs = await import('fs')
|
||||||
|
const path = await import('path')
|
||||||
|
const now = new Date()
|
||||||
|
const day = `${now.getFullYear()}-${String(now.getMonth()+1).padStart(2,'0')}-${String(now.getDate()).padStart(2,'0')}`
|
||||||
|
const baseDir = path.join(process.cwd(), 'reports', day)
|
||||||
|
if (!fs.existsSync(baseDir)) fs.mkdirSync(baseDir, { recursive: true })
|
||||||
|
const file = path.join(baseDir, `summary_${this.runId}.json`)
|
||||||
|
const payload = {
|
||||||
|
runId: this.runId,
|
||||||
|
timestamp: now.toISOString(),
|
||||||
|
totals: { totalCollected, totalInitial, totalEnd, totalDuration, totalAccounts, accountsWithErrors },
|
||||||
|
perAccount: summaries
|
||||||
|
}
|
||||||
|
fs.writeFileSync(file, JSON.stringify(payload, null, 2), 'utf-8')
|
||||||
|
log('main','REPORT',`Saved report to ${file}`)
|
||||||
|
} catch (e) {
|
||||||
|
log('main','REPORT',`Failed to save report: ${e instanceof Error ? e.message : e}`,'warn')
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Optional community notice (shown randomly in ~15% of successful runs)
|
||||||
|
if (Math.random() > 0.85 && successes > 0 && accountsWithErrors === 0) {
|
||||||
|
log('main','INFO','Want faster updates & enhanced anti-detection? Community builds available: https://discord.gg/kn3695Kx32')
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/** Public entry-point to engage global security standby from other modules (idempotent). */
|
||||||
|
public async engageGlobalStandby(reason: string, email?: string): Promise<void> {
|
||||||
|
try {
|
||||||
|
if (this.globalStandby.active) return
|
||||||
|
this.globalStandby = { active: true, reason }
|
||||||
|
const who = email || this.currentAccountEmail || 'unknown'
|
||||||
|
await this.sendGlobalSecurityStandbyAlert(who, reason)
|
||||||
|
} catch {/* ignore */}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Send a strong alert to all channels and mention @everyone when entering global security standby. */
|
||||||
|
private async sendGlobalSecurityStandbyAlert(email: string, reason: string): Promise<void> {
|
||||||
|
try {
|
||||||
|
const { ConclusionWebhook } = await import('./util/ConclusionWebhook')
|
||||||
|
await ConclusionWebhook(
|
||||||
|
this.config,
|
||||||
|
'🚨 Global Security Standby Engaged',
|
||||||
|
`@everyone\n\n**Account:** ${email}\n**Reason:** ${reason}\n**Action:** Pausing all further accounts. We will not proceed until this is resolved.`,
|
||||||
|
undefined,
|
||||||
|
DISCORD.COLOR_RED
|
||||||
|
)
|
||||||
|
} catch (e) {
|
||||||
|
log('main','ALERT',`Failed to send standby alert: ${e instanceof Error ? e.message : e}`,'warn')
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -508,41 +809,69 @@ interface AccountSummary {
|
|||||||
initialTotal: number
|
initialTotal: number
|
||||||
endTotal: number
|
endTotal: number
|
||||||
errors: string[]
|
errors: string[]
|
||||||
|
banned?: { status: boolean; reason: string }
|
||||||
}
|
}
|
||||||
|
|
||||||
function shortErr(e: any): string {
|
function shortErr(e: unknown): string {
|
||||||
if (!e) return 'unknown'
|
if (e == null) return 'unknown'
|
||||||
if (e instanceof Error) return e.message.substring(0, 120)
|
if (e instanceof Error) return e.message.substring(0, 120)
|
||||||
const s = String(e)
|
const s = String(e)
|
||||||
return s.substring(0, 120)
|
return s.substring(0, 120)
|
||||||
}
|
}
|
||||||
|
|
||||||
function formatDuration(ms: number): string {
|
|
||||||
if (!ms || ms < 1000) return `${ms}ms`
|
|
||||||
const sec = Math.floor(ms / 1000)
|
|
||||||
const h = Math.floor(sec / 3600)
|
|
||||||
const m = Math.floor((sec % 3600) / 60)
|
|
||||||
const s = sec % 60
|
|
||||||
const parts: string[] = []
|
|
||||||
if (h) parts.push(`${h}h`)
|
|
||||||
if (m) parts.push(`${m}m`)
|
|
||||||
if (s) parts.push(`${s}s`)
|
|
||||||
return parts.join(' ') || `${ms}ms`
|
|
||||||
}
|
|
||||||
|
|
||||||
async function main() {
|
async function main() {
|
||||||
const rewardsBot = new MicrosoftRewardsBot(false)
|
const rewardsBot = new MicrosoftRewardsBot(false)
|
||||||
|
|
||||||
try {
|
const crashState = { restarts: 0 }
|
||||||
await rewardsBot.initialize()
|
const config = rewardsBot.config
|
||||||
await rewardsBot.run()
|
|
||||||
} catch (error) {
|
const attachHandlers = () => {
|
||||||
log(false, 'MAIN-ERROR', `Error running desktop bot: ${error}`, 'error')
|
process.on('unhandledRejection', (reason) => {
|
||||||
|
log('main','FATAL','UnhandledRejection: ' + (reason instanceof Error ? reason.message : String(reason)), 'error')
|
||||||
|
gracefulExit(1)
|
||||||
|
})
|
||||||
|
process.on('uncaughtException', (err) => {
|
||||||
|
log('main','FATAL','UncaughtException: ' + err.message, 'error')
|
||||||
|
gracefulExit(1)
|
||||||
|
})
|
||||||
|
process.on('SIGTERM', () => gracefulExit(0))
|
||||||
|
process.on('SIGINT', () => gracefulExit(0))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const gracefulExit = (code: number) => {
|
||||||
|
if (config?.crashRecovery?.autoRestart && code !== 0) {
|
||||||
|
const max = config.crashRecovery.maxRestarts ?? 2
|
||||||
|
if (crashState.restarts < max) {
|
||||||
|
const backoff = (config.crashRecovery.backoffBaseMs ?? 2000) * (crashState.restarts + 1)
|
||||||
|
log('main','CRASH-RECOVERY',`Scheduling restart in ${backoff}ms (attempt ${crashState.restarts + 1}/${max})`, 'warn','yellow')
|
||||||
|
setTimeout(() => {
|
||||||
|
crashState.restarts++
|
||||||
|
bootstrap()
|
||||||
|
}, backoff)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
process.exit(code)
|
||||||
|
}
|
||||||
|
|
||||||
|
const bootstrap = async () => {
|
||||||
|
try {
|
||||||
|
await rewardsBot.initialize()
|
||||||
|
await rewardsBot.run()
|
||||||
|
} catch (e) {
|
||||||
|
log('main','MAIN-ERROR','Fatal during run: ' + (e instanceof Error ? e.message : e),'error')
|
||||||
|
gracefulExit(1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
attachHandlers()
|
||||||
|
await bootstrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Start the bots
|
// Start the bots
|
||||||
main().catch(error => {
|
if (require.main === module) {
|
||||||
log('main', 'MAIN-ERROR', `Error running bots: ${error}`, 'error')
|
main().catch(error => {
|
||||||
process.exit(1)
|
log('main', 'MAIN-ERROR', `Error running bots: ${error}`, 'error')
|
||||||
})
|
process.exit(1)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,6 +1,12 @@
|
|||||||
export interface Account {
|
export interface Account {
|
||||||
|
/** Enable/disable this account (if false, account will be skipped during execution) */
|
||||||
|
enabled?: boolean;
|
||||||
email: string;
|
email: string;
|
||||||
password: string;
|
password: string;
|
||||||
|
/** Optional TOTP secret in Base32 (e.g., from Microsoft Authenticator setup) */
|
||||||
|
totp?: string;
|
||||||
|
/** Optional recovery email used to verify masked address on Microsoft login screens */
|
||||||
|
recoveryEmail?: string;
|
||||||
proxy: AccountProxy;
|
proxy: AccountProxy;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
21
src/interface/ActivityHandler.ts
Normal file
21
src/interface/ActivityHandler.ts
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
import type { MorePromotion, PromotionalItem } from './DashboardData'
|
||||||
|
import type { Page } from 'playwright'
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Activity handler contract for solving a single dashboard activity.
|
||||||
|
* Implementations should be stateless (or hold only a reference to the bot)
|
||||||
|
* and perform all required steps on the provided page.
|
||||||
|
*/
|
||||||
|
export interface ActivityHandler {
|
||||||
|
/** Optional identifier for diagnostics */
|
||||||
|
id?: string
|
||||||
|
/**
|
||||||
|
* Return true if this handler knows how to process the given activity.
|
||||||
|
*/
|
||||||
|
canHandle(activity: MorePromotion | PromotionalItem): boolean
|
||||||
|
/**
|
||||||
|
* Execute the activity on the provided page. The page is already
|
||||||
|
* navigated to the activity tab/window by the caller.
|
||||||
|
*/
|
||||||
|
run(page: Page, activity: MorePromotion | PromotionalItem): Promise<void>
|
||||||
|
}
|
||||||
@@ -2,6 +2,8 @@ export interface Config {
|
|||||||
baseURL: string;
|
baseURL: string;
|
||||||
sessionPath: string;
|
sessionPath: string;
|
||||||
headless: boolean;
|
headless: boolean;
|
||||||
|
browser?: ConfigBrowser; // Optional nested browser config
|
||||||
|
fingerprinting?: ConfigFingerprinting; // Optional nested fingerprinting config
|
||||||
parallel: boolean;
|
parallel: boolean;
|
||||||
runOnZeroPoints: boolean;
|
runOnZeroPoints: boolean;
|
||||||
clusters: number;
|
clusters: number;
|
||||||
@@ -10,11 +12,21 @@ export interface Config {
|
|||||||
searchOnBingLocalQueries: boolean;
|
searchOnBingLocalQueries: boolean;
|
||||||
globalTimeout: number | string;
|
globalTimeout: number | string;
|
||||||
searchSettings: ConfigSearchSettings;
|
searchSettings: ConfigSearchSettings;
|
||||||
|
humanization?: ConfigHumanization; // Anti-ban humanization controls
|
||||||
|
retryPolicy?: ConfigRetryPolicy; // Global retry/backoff policy
|
||||||
|
jobState?: ConfigJobState; // Persistence of per-activity checkpoints
|
||||||
logExcludeFunc: string[];
|
logExcludeFunc: string[];
|
||||||
webhookLogExcludeFunc: string[];
|
webhookLogExcludeFunc: string[];
|
||||||
|
logging?: ConfigLogging; // Preserve original logging object (for live webhook settings)
|
||||||
proxy: ConfigProxy;
|
proxy: ConfigProxy;
|
||||||
webhook: ConfigWebhook;
|
webhook: ConfigWebhook;
|
||||||
conclusionWebhook?: ConfigWebhook; // Optional secondary webhook for final summary
|
conclusionWebhook?: ConfigWebhook; // Optional secondary webhook for final summary
|
||||||
|
ntfy: ConfigNtfy;
|
||||||
|
vacation?: ConfigVacation; // Optional monthly contiguous off-days
|
||||||
|
crashRecovery?: ConfigCrashRecovery; // Automatic restart / graceful shutdown
|
||||||
|
riskManagement?: ConfigRiskManagement; // NEW: Risk-aware throttling and ban prediction
|
||||||
|
dryRun?: boolean; // NEW: Dry-run mode (simulate without executing)
|
||||||
|
queryDiversity?: ConfigQueryDiversity; // NEW: Multi-source query generation
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ConfigSaveFingerprint {
|
export interface ConfigSaveFingerprint {
|
||||||
@@ -22,12 +34,23 @@ export interface ConfigSaveFingerprint {
|
|||||||
desktop: boolean;
|
desktop: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface ConfigBrowser {
|
||||||
|
headless?: boolean;
|
||||||
|
globalTimeout?: number | string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ConfigFingerprinting {
|
||||||
|
saveFingerprint?: ConfigSaveFingerprint;
|
||||||
|
}
|
||||||
|
|
||||||
export interface ConfigSearchSettings {
|
export interface ConfigSearchSettings {
|
||||||
useGeoLocaleQueries: boolean;
|
useGeoLocaleQueries: boolean;
|
||||||
scrollRandomResults: boolean;
|
scrollRandomResults: boolean;
|
||||||
clickRandomResults: boolean;
|
clickRandomResults: boolean;
|
||||||
searchDelay: ConfigSearchDelay;
|
searchDelay: ConfigSearchDelay;
|
||||||
retryMobileSearchAmount: number;
|
retryMobileSearchAmount: number;
|
||||||
|
localFallbackCount?: number; // Number of local fallback queries to sample when trends fail
|
||||||
|
extraFallbackRetries?: number; // Additional mini-retry loops with fallback terms
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ConfigSearchDelay {
|
export interface ConfigSearchDelay {
|
||||||
@@ -38,6 +61,15 @@ export interface ConfigSearchDelay {
|
|||||||
export interface ConfigWebhook {
|
export interface ConfigWebhook {
|
||||||
enabled: boolean;
|
enabled: boolean;
|
||||||
url: string;
|
url: string;
|
||||||
|
username?: string; // Custom webhook username (default: "Microsoft Rewards")
|
||||||
|
avatarUrl?: string; // Custom webhook avatar URL
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ConfigNtfy {
|
||||||
|
enabled: boolean;
|
||||||
|
url: string;
|
||||||
|
topic: string;
|
||||||
|
authToken?: string; // Optional authentication token
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ConfigProxy {
|
export interface ConfigProxy {
|
||||||
@@ -45,6 +77,20 @@ export interface ConfigProxy {
|
|||||||
proxyBingTerms: boolean;
|
proxyBingTerms: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface ConfigVacation {
|
||||||
|
enabled?: boolean; // default false
|
||||||
|
minDays?: number; // default 3
|
||||||
|
maxDays?: number; // default 5
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ConfigCrashRecovery {
|
||||||
|
autoRestart?: boolean; // Restart the root process after fatal crash
|
||||||
|
maxRestarts?: number; // Max restart attempts (default 2)
|
||||||
|
backoffBaseMs?: number; // Base backoff before restart (default 2000)
|
||||||
|
restartFailedWorker?: boolean; // (future) attempt to respawn crashed worker
|
||||||
|
restartFailedWorkerAttempts?: number; // attempts per worker (default 1)
|
||||||
|
}
|
||||||
|
|
||||||
export interface ConfigWorkers {
|
export interface ConfigWorkers {
|
||||||
doDailySet: boolean;
|
doDailySet: boolean;
|
||||||
doMorePromotions: boolean;
|
doMorePromotions: boolean;
|
||||||
@@ -53,4 +99,76 @@ export interface ConfigWorkers {
|
|||||||
doMobileSearch: boolean;
|
doMobileSearch: boolean;
|
||||||
doDailyCheckIn: boolean;
|
doDailyCheckIn: boolean;
|
||||||
doReadToEarn: boolean;
|
doReadToEarn: boolean;
|
||||||
|
bundleDailySetWithSearch?: boolean; // If true, run desktop search right after Daily Set
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Anti-ban humanization
|
||||||
|
export interface ConfigHumanization {
|
||||||
|
// Master toggle for Human Mode. When false, humanization is minimized.
|
||||||
|
enabled?: boolean;
|
||||||
|
// If true, stop processing remaining accounts after a ban is detected
|
||||||
|
stopOnBan?: boolean;
|
||||||
|
// If true, send an immediate webhook/NTFY alert when a ban is detected
|
||||||
|
immediateBanAlert?: boolean;
|
||||||
|
// Additional random waits between actions
|
||||||
|
actionDelay?: { min: number | string; max: number | string };
|
||||||
|
// Probability [0..1] to perform micro mouse moves per step
|
||||||
|
gestureMoveProb?: number;
|
||||||
|
// Probability [0..1] to perform tiny scrolls per step
|
||||||
|
gestureScrollProb?: number;
|
||||||
|
// Allowed execution windows (local time). Each item is "HH:mm-HH:mm".
|
||||||
|
// If provided, runs outside these windows will be delayed until the next allowed window.
|
||||||
|
allowedWindows?: string[];
|
||||||
|
// Randomly skip N days per week to look more human (0-7). Default 1.
|
||||||
|
randomOffDaysPerWeek?: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Retry/backoff policy
|
||||||
|
export interface ConfigRetryPolicy {
|
||||||
|
maxAttempts?: number; // default 3
|
||||||
|
baseDelay?: number | string; // default 1000ms
|
||||||
|
maxDelay?: number | string; // default 30s
|
||||||
|
multiplier?: number; // default 2
|
||||||
|
jitter?: number; // 0..1; default 0.2
|
||||||
|
}
|
||||||
|
|
||||||
|
// Job state persistence
|
||||||
|
export interface ConfigJobState {
|
||||||
|
enabled?: boolean; // default true
|
||||||
|
dir?: string; // base directory; defaults to <sessionPath>/job-state
|
||||||
|
}
|
||||||
|
|
||||||
|
// Live logging configuration
|
||||||
|
export interface ConfigLoggingLive {
|
||||||
|
enabled?: boolean; // master switch for live webhook logs
|
||||||
|
redactEmails?: boolean; // if true, redact emails in outbound logs
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ConfigLogging {
|
||||||
|
excludeFunc?: string[];
|
||||||
|
webhookExcludeFunc?: string[];
|
||||||
|
live?: ConfigLoggingLive;
|
||||||
|
liveWebhookUrl?: string; // legacy/dedicated live webhook override
|
||||||
|
redactEmails?: boolean; // legacy top-level redaction flag
|
||||||
|
// Optional nested live.url support (already handled dynamically in Logger)
|
||||||
|
[key: string]: unknown; // forward compatibility
|
||||||
|
}
|
||||||
|
|
||||||
|
// CommunityHelp removed (privacy-first policy)
|
||||||
|
|
||||||
|
// NEW FEATURES: Risk Management, Query Diversity
|
||||||
|
export interface ConfigRiskManagement {
|
||||||
|
enabled?: boolean; // master toggle for risk-aware throttling
|
||||||
|
autoAdjustDelays?: boolean; // automatically increase delays when risk is high
|
||||||
|
stopOnCritical?: boolean; // halt execution if risk reaches critical level
|
||||||
|
banPrediction?: boolean; // enable ML-style ban prediction
|
||||||
|
riskThreshold?: number; // 0-100, pause if risk exceeds this
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ConfigQueryDiversity {
|
||||||
|
enabled?: boolean; // use multi-source query generation
|
||||||
|
sources?: Array<'google-trends' | 'reddit' | 'news' | 'wikipedia' | 'local-fallback'>; // which sources to use
|
||||||
|
maxQueriesPerSource?: number; // limit per source
|
||||||
|
cacheMinutes?: number; // cache duration
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
7
src/luxon.d.ts
vendored
Normal file
7
src/luxon.d.ts
vendored
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
/* Minimal ambient declarations to unblock TypeScript when @types/luxon is absent. */
|
||||||
|
declare module 'luxon' {
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
|
export const DateTime: any
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
|
export const IANAZone: any
|
||||||
|
}
|
||||||
@@ -1,7 +1,8 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
|
||||||
export PLAYWRIGHT_BROWSERS_PATH=/ms-playwright
|
export PATH="/usr/local/bin:/usr/bin:/bin"
|
||||||
|
export PLAYWRIGHT_BROWSERS_PATH=0
|
||||||
export TZ="${TZ:-UTC}"
|
export TZ="${TZ:-UTC}"
|
||||||
|
|
||||||
cd /usr/src/microsoft-rewards-script
|
cd /usr/src/microsoft-rewards-script
|
||||||
|
|||||||
25
src/util/AdaptiveThrottler.ts
Normal file
25
src/util/AdaptiveThrottler.ts
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
export class AdaptiveThrottler {
|
||||||
|
private errorCount = 0
|
||||||
|
private successCount = 0
|
||||||
|
private window: Array<{ ok: boolean; at: number }> = []
|
||||||
|
private readonly maxWindow = 50
|
||||||
|
|
||||||
|
record(ok: boolean) {
|
||||||
|
this.window.push({ ok, at: Date.now() })
|
||||||
|
if (ok) this.successCount++
|
||||||
|
else this.errorCount++
|
||||||
|
if (this.window.length > this.maxWindow) {
|
||||||
|
const removed = this.window.shift()
|
||||||
|
if (removed) removed.ok ? this.successCount-- : this.errorCount--
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Return a multiplier to apply to waits (1 = normal). */
|
||||||
|
getDelayMultiplier(): number {
|
||||||
|
const total = Math.max(1, this.successCount + this.errorCount)
|
||||||
|
const errRatio = this.errorCount / total
|
||||||
|
// 0% errors -> 1x; 50% errors -> ~1.8x; 80% -> ~2.5x (cap)
|
||||||
|
const mult = 1 + Math.min(1.5, errRatio * 2)
|
||||||
|
return Number(mult.toFixed(2))
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
import axios, { AxiosInstance, AxiosRequestConfig, AxiosResponse } from 'axios'
|
import axios, { AxiosError, AxiosInstance, AxiosRequestConfig, AxiosResponse } from 'axios'
|
||||||
import { HttpProxyAgent } from 'http-proxy-agent'
|
import { HttpProxyAgent } from 'http-proxy-agent'
|
||||||
import { HttpsProxyAgent } from 'https-proxy-agent'
|
import { HttpsProxyAgent } from 'https-proxy-agent'
|
||||||
import { SocksProxyAgent } from 'socks-proxy-agent'
|
import { SocksProxyAgent } from 'socks-proxy-agent'
|
||||||
@@ -24,14 +24,14 @@ class AxiosClient {
|
|||||||
const { url, port } = proxyConfig
|
const { url, port } = proxyConfig
|
||||||
|
|
||||||
switch (true) {
|
switch (true) {
|
||||||
case proxyConfig.url.startsWith('http'):
|
case proxyConfig.url.startsWith('http://'):
|
||||||
return new HttpProxyAgent(`${url}:${port}`)
|
return new HttpProxyAgent(`${url}:${port}`)
|
||||||
case proxyConfig.url.startsWith('https'):
|
case proxyConfig.url.startsWith('https://'):
|
||||||
return new HttpsProxyAgent(`${url}:${port}`)
|
return new HttpsProxyAgent(`${url}:${port}`)
|
||||||
case proxyConfig.url.startsWith('socks'):
|
case proxyConfig.url.startsWith('socks://') || proxyConfig.url.startsWith('socks4://') || proxyConfig.url.startsWith('socks5://'):
|
||||||
return new SocksProxyAgent(`${url}:${port}`)
|
return new SocksProxyAgent(`${url}:${port}`)
|
||||||
default:
|
default:
|
||||||
throw new Error(`Unsupported proxy protocol: ${url}`)
|
throw new Error(`Unsupported proxy protocol in "${url}". Supported: http://, https://, socks://, socks4://, socks5://`)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -42,7 +42,54 @@ class AxiosClient {
|
|||||||
return bypassInstance.request(config)
|
return bypassInstance.request(config)
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.instance.request(config)
|
let lastError: unknown
|
||||||
|
const maxAttempts = 2
|
||||||
|
|
||||||
|
for (let attempt = 1; attempt <= maxAttempts; attempt++) {
|
||||||
|
try {
|
||||||
|
return await this.instance.request(config)
|
||||||
|
} catch (err: unknown) {
|
||||||
|
lastError = err
|
||||||
|
const axiosErr = err as AxiosError | undefined
|
||||||
|
|
||||||
|
// Detect HTTP proxy auth failures (status 407) and retry without proxy
|
||||||
|
if (axiosErr && axiosErr.response && axiosErr.response.status === 407) {
|
||||||
|
if (attempt < maxAttempts) {
|
||||||
|
await this.sleep(1000 * attempt) // Exponential backoff
|
||||||
|
}
|
||||||
|
const bypassInstance = axios.create()
|
||||||
|
return bypassInstance.request(config)
|
||||||
|
}
|
||||||
|
|
||||||
|
// If proxied request fails with common proxy/network errors, retry with backoff
|
||||||
|
const e = err as { code?: string; cause?: { code?: string }; message?: string } | undefined
|
||||||
|
const code = e?.code || e?.cause?.code
|
||||||
|
const isNetErr = code === 'ECONNREFUSED' || code === 'ETIMEDOUT' || code === 'ECONNRESET' || code === 'ENOTFOUND'
|
||||||
|
const msg = String(e?.message || '')
|
||||||
|
const looksLikeProxyIssue = /proxy|tunnel|socks|agent/i.test(msg)
|
||||||
|
|
||||||
|
if (isNetErr || looksLikeProxyIssue) {
|
||||||
|
if (attempt < maxAttempts) {
|
||||||
|
// Exponential backoff: 1s, 2s, 4s, etc.
|
||||||
|
const delayMs = 1000 * Math.pow(2, attempt - 1)
|
||||||
|
await this.sleep(delayMs)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
// Last attempt: try without proxy
|
||||||
|
const bypassInstance = axios.create()
|
||||||
|
return bypassInstance.request(config)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Non-retryable error
|
||||||
|
throw err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
throw lastError
|
||||||
|
}
|
||||||
|
|
||||||
|
private sleep(ms: number): Promise<void> {
|
||||||
|
return new Promise(resolve => setTimeout(resolve, ms))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
16
src/util/BanDetector.ts
Normal file
16
src/util/BanDetector.ts
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
export type BanStatus = { status: boolean; reason: string }
|
||||||
|
|
||||||
|
const BAN_PATTERNS: Array<{ re: RegExp; reason: string }> = [
|
||||||
|
{ re: /suspend|suspended|suspension/i, reason: 'account suspended' },
|
||||||
|
{ re: /locked|lockout|serviceabuse|abuse/i, reason: 'locked or service abuse detected' },
|
||||||
|
{ re: /unusual.*activity|unusual activity/i, reason: 'unusual activity prompts' },
|
||||||
|
{ re: /verify.*identity|identity.*verification/i, reason: 'identity verification required' }
|
||||||
|
]
|
||||||
|
|
||||||
|
export function detectBanReason(input: unknown): BanStatus {
|
||||||
|
const s = input instanceof Error ? (input.message || '') : String(input || '')
|
||||||
|
for (const p of BAN_PATTERNS) {
|
||||||
|
if (p.re.test(s)) return { status: true, reason: p.reason }
|
||||||
|
}
|
||||||
|
return { status: false, reason: '' }
|
||||||
|
}
|
||||||
@@ -1,32 +1,335 @@
|
|||||||
import axios from 'axios'
|
import axios from 'axios'
|
||||||
|
|
||||||
import { Config } from '../interface/Config'
|
import { Config } from '../interface/Config'
|
||||||
|
import { Ntfy } from './Ntfy'
|
||||||
|
import { DISCORD } from '../constants'
|
||||||
|
import { log } from './Logger'
|
||||||
|
|
||||||
interface ConclusionPayload {
|
interface DiscordField {
|
||||||
content?: string
|
name: string
|
||||||
embeds?: any[]
|
value: string
|
||||||
|
inline?: boolean
|
||||||
|
}
|
||||||
|
|
||||||
|
interface DiscordEmbed {
|
||||||
|
title?: string
|
||||||
|
description?: string
|
||||||
|
color?: number
|
||||||
|
fields?: DiscordField[]
|
||||||
|
timestamp?: string
|
||||||
|
footer?: {
|
||||||
|
text: string
|
||||||
|
icon_url?: string
|
||||||
|
}
|
||||||
|
thumbnail?: {
|
||||||
|
url: string
|
||||||
|
}
|
||||||
|
author?: {
|
||||||
|
name: string
|
||||||
|
icon_url?: string
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
interface AccountSummary {
|
||||||
|
email: string
|
||||||
|
totalCollected: number
|
||||||
|
desktopCollected: number
|
||||||
|
mobileCollected: number
|
||||||
|
initialTotal: number
|
||||||
|
endTotal: number
|
||||||
|
durationMs: number
|
||||||
|
errors: string[]
|
||||||
|
banned?: { status: boolean; reason?: string }
|
||||||
|
}
|
||||||
|
|
||||||
|
interface ConclusionData {
|
||||||
|
version: string
|
||||||
|
runId: string
|
||||||
|
totalAccounts: number
|
||||||
|
successes: number
|
||||||
|
accountsWithErrors: number
|
||||||
|
accountsBanned: number
|
||||||
|
totalCollected: number
|
||||||
|
totalInitial: number
|
||||||
|
totalEnd: number
|
||||||
|
avgPointsPerAccount: number
|
||||||
|
totalDuration: number
|
||||||
|
avgDuration: number
|
||||||
|
summaries: AccountSummary[]
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Send a final structured summary to the dedicated conclusion webhook (if enabled),
|
* Send a clean, structured Discord webhook notification
|
||||||
* otherwise do nothing. Does NOT fallback to the normal logging webhook to avoid spam.
|
|
||||||
*/
|
*/
|
||||||
export async function ConclusionWebhook(configData: Config, content: string, embed?: ConclusionPayload) {
|
export async function ConclusionWebhook(
|
||||||
const webhook = configData.conclusionWebhook
|
config: Config,
|
||||||
|
title: string,
|
||||||
|
description: string,
|
||||||
|
fields?: DiscordField[],
|
||||||
|
color?: number
|
||||||
|
) {
|
||||||
|
const hasConclusion = config.conclusionWebhook?.enabled && config.conclusionWebhook.url
|
||||||
|
const hasWebhook = config.webhook?.enabled && config.webhook.url
|
||||||
|
|
||||||
if (!webhook || !webhook.enabled || webhook.url.length < 10) return
|
if (!hasConclusion && !hasWebhook) return
|
||||||
|
|
||||||
const body: ConclusionPayload = embed?.embeds ? { embeds: embed.embeds } : { content }
|
const embed: DiscordEmbed = {
|
||||||
if (content && !body.content && !body.embeds) body.content = content
|
title,
|
||||||
|
description,
|
||||||
const request = {
|
color: color || 0x0078D4,
|
||||||
method: 'POST',
|
timestamp: new Date().toISOString()
|
||||||
url: webhook.url,
|
|
||||||
headers: {
|
|
||||||
'Content-Type': 'application/json'
|
|
||||||
},
|
|
||||||
data: body
|
|
||||||
}
|
}
|
||||||
|
|
||||||
await axios(request).catch(() => { })
|
if (fields && fields.length > 0) {
|
||||||
|
embed.fields = fields
|
||||||
|
}
|
||||||
|
|
||||||
|
const postWebhook = async (url: string, label: string) => {
|
||||||
|
const maxAttempts = 3
|
||||||
|
let lastError: unknown = null
|
||||||
|
|
||||||
|
for (let attempt = 1; attempt <= maxAttempts; attempt++) {
|
||||||
|
try {
|
||||||
|
await axios.post(url,
|
||||||
|
{
|
||||||
|
embeds: [embed]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
headers: { 'Content-Type': 'application/json' },
|
||||||
|
timeout: 15000
|
||||||
|
})
|
||||||
|
log('main', 'WEBHOOK', `${label} notification sent successfully (attempt ${attempt})`)
|
||||||
|
return
|
||||||
|
} catch (error) {
|
||||||
|
lastError = error
|
||||||
|
if (attempt < maxAttempts) {
|
||||||
|
// Exponential backoff: 1s, 2s, 4s
|
||||||
|
const delayMs = 1000 * Math.pow(2, attempt - 1)
|
||||||
|
await new Promise(resolve => setTimeout(resolve, delayMs))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
log('main', 'WEBHOOK', `${label} failed after ${maxAttempts} attempts: ${lastError instanceof Error ? lastError.message : String(lastError)}`, 'error')
|
||||||
|
}
|
||||||
|
|
||||||
|
const urls = new Set<string>()
|
||||||
|
if (hasConclusion) urls.add(config.conclusionWebhook!.url)
|
||||||
|
if (hasWebhook) urls.add(config.webhook!.url)
|
||||||
|
|
||||||
|
await Promise.all(
|
||||||
|
Array.from(urls).map((url, index) => postWebhook(url, `webhook-${index + 1}`))
|
||||||
|
)
|
||||||
|
|
||||||
|
// Optional NTFY notification
|
||||||
|
if (config.ntfy?.enabled && config.ntfy.url && config.ntfy.topic) {
|
||||||
|
const message = `${title}\n${description}${fields ? '\n\n' + fields.map(f => `${f.name}: ${f.value}`).join('\n') : ''}`
|
||||||
|
const ntfyType = color === 0xFF0000 ? 'error' : color === 0xFFAA00 ? 'warn' : 'log'
|
||||||
|
|
||||||
|
try {
|
||||||
|
await Ntfy(message, ntfyType)
|
||||||
|
log('main', 'NTFY', 'Notification sent successfully')
|
||||||
|
} catch (error) {
|
||||||
|
log('main', 'NTFY', `Failed to send notification: ${error instanceof Error ? error.message : String(error)}`, 'error')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enhanced conclusion webhook with beautiful formatting and clear statistics
|
||||||
|
*/
|
||||||
|
export async function ConclusionWebhookEnhanced(config: Config, data: ConclusionData) {
|
||||||
|
const hasConclusion = config.conclusionWebhook?.enabled && config.conclusionWebhook.url
|
||||||
|
const hasWebhook = config.webhook?.enabled && config.webhook.url
|
||||||
|
|
||||||
|
if (!hasConclusion && !hasWebhook) return
|
||||||
|
|
||||||
|
// Helper to format duration
|
||||||
|
const formatDuration = (ms: number): string => {
|
||||||
|
const totalSeconds = Math.floor(ms / 1000)
|
||||||
|
const hours = Math.floor(totalSeconds / 3600)
|
||||||
|
const minutes = Math.floor((totalSeconds % 3600) / 60)
|
||||||
|
const seconds = totalSeconds % 60
|
||||||
|
|
||||||
|
if (hours > 0) return `${hours}h ${minutes}m ${seconds}s`
|
||||||
|
if (minutes > 0) return `${minutes}m ${seconds}s`
|
||||||
|
return `${seconds}s`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Helper to create progress bar (future use)
|
||||||
|
// const createProgressBar = (current: number, max: number, length: number = 10): string => {
|
||||||
|
// const percentage = Math.min(100, Math.max(0, (current / max) * 100))
|
||||||
|
// const filled = Math.round((percentage / 100) * length)
|
||||||
|
// const empty = length - filled
|
||||||
|
// return `${'█'.repeat(filled)}${'░'.repeat(empty)} ${percentage.toFixed(0)}%`
|
||||||
|
// }
|
||||||
|
|
||||||
|
// Determine overall status and color
|
||||||
|
let statusEmoji = '✅'
|
||||||
|
let statusText = 'Success'
|
||||||
|
let embedColor: number = DISCORD.COLOR_GREEN
|
||||||
|
|
||||||
|
if (data.accountsBanned > 0) {
|
||||||
|
statusEmoji = '🚫'
|
||||||
|
statusText = 'Banned Accounts Detected'
|
||||||
|
embedColor = DISCORD.COLOR_RED
|
||||||
|
} else if (data.accountsWithErrors > 0) {
|
||||||
|
statusEmoji = '⚠️'
|
||||||
|
statusText = 'Completed with Warnings'
|
||||||
|
embedColor = DISCORD.COLOR_ORANGE
|
||||||
|
}
|
||||||
|
|
||||||
|
// Build main summary description
|
||||||
|
const mainDescription = [
|
||||||
|
`**Status:** ${statusEmoji} ${statusText}`,
|
||||||
|
`**Version:** v${data.version} • **Run ID:** \`${data.runId}\``,
|
||||||
|
'',
|
||||||
|
'━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━'
|
||||||
|
].join('\n')
|
||||||
|
|
||||||
|
// Build global statistics field
|
||||||
|
const globalStats = [
|
||||||
|
'**💎 Total Points Earned**',
|
||||||
|
`\`${data.totalInitial.toLocaleString()}\` → \`${data.totalEnd.toLocaleString()}\` **(+${data.totalCollected.toLocaleString()})**`,
|
||||||
|
'',
|
||||||
|
'**📊 Accounts Processed**',
|
||||||
|
`✅ Success: **${data.successes}** | ⚠️ Errors: **${data.accountsWithErrors}** | 🚫 Banned: **${data.accountsBanned}**`,
|
||||||
|
`Total: **${data.totalAccounts}** ${data.totalAccounts === 1 ? 'account' : 'accounts'}`,
|
||||||
|
'',
|
||||||
|
'**⚡ Performance**',
|
||||||
|
`Average: **${data.avgPointsPerAccount}pts/account** in **${formatDuration(data.avgDuration)}**`,
|
||||||
|
`Total Runtime: **${formatDuration(data.totalDuration)}**`
|
||||||
|
].join('\n')
|
||||||
|
|
||||||
|
// Build per-account breakdown (split if too many accounts)
|
||||||
|
const accountFields: DiscordField[] = []
|
||||||
|
const maxAccountsPerField = 5
|
||||||
|
const accountChunks: AccountSummary[][] = []
|
||||||
|
|
||||||
|
for (let i = 0; i < data.summaries.length; i += maxAccountsPerField) {
|
||||||
|
accountChunks.push(data.summaries.slice(i, i + maxAccountsPerField))
|
||||||
|
}
|
||||||
|
|
||||||
|
accountChunks.forEach((chunk, chunkIndex) => {
|
||||||
|
const accountLines: string[] = []
|
||||||
|
|
||||||
|
chunk.forEach((acc) => {
|
||||||
|
const statusIcon = acc.banned?.status ? '🚫' : (acc.errors.length > 0 ? '⚠️' : '✅')
|
||||||
|
const emailShort = acc.email.length > 25 ? acc.email.substring(0, 22) + '...' : acc.email
|
||||||
|
|
||||||
|
accountLines.push(`${statusIcon} **${emailShort}**`)
|
||||||
|
accountLines.push(`└ Points: **+${acc.totalCollected}** (🖥️ ${acc.desktopCollected} • 📱 ${acc.mobileCollected})`)
|
||||||
|
accountLines.push(`└ Duration: ${formatDuration(acc.durationMs)}`)
|
||||||
|
|
||||||
|
if (acc.banned?.status) {
|
||||||
|
accountLines.push(`└ 🚫 **Banned:** ${acc.banned.reason || 'Account suspended'}`)
|
||||||
|
} else if (acc.errors.length > 0) {
|
||||||
|
const errorPreview = acc.errors.slice(0, 1).join(', ')
|
||||||
|
accountLines.push(`└ ⚠️ **Error:** ${errorPreview.length > 50 ? errorPreview.substring(0, 47) + '...' : errorPreview}`)
|
||||||
|
}
|
||||||
|
|
||||||
|
accountLines.push('') // Empty line between accounts
|
||||||
|
})
|
||||||
|
|
||||||
|
const fieldName = accountChunks.length > 1
|
||||||
|
? `📈 Account Details (${chunkIndex + 1}/${accountChunks.length})`
|
||||||
|
: '📈 Account Details'
|
||||||
|
|
||||||
|
accountFields.push({
|
||||||
|
name: fieldName,
|
||||||
|
value: accountLines.join('\n').trim(),
|
||||||
|
inline: false
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
// Create embeds
|
||||||
|
const embeds: DiscordEmbed[] = []
|
||||||
|
|
||||||
|
// Main embed with summary
|
||||||
|
embeds.push({
|
||||||
|
title: '🎯 Microsoft Rewards — Daily Summary',
|
||||||
|
description: mainDescription,
|
||||||
|
color: embedColor,
|
||||||
|
fields: [
|
||||||
|
{
|
||||||
|
name: '📊 Global Statistics',
|
||||||
|
value: globalStats,
|
||||||
|
inline: false
|
||||||
|
}
|
||||||
|
],
|
||||||
|
footer: {
|
||||||
|
text: `Microsoft Rewards Bot v${data.version} • Completed at`
|
||||||
|
},
|
||||||
|
timestamp: new Date().toISOString()
|
||||||
|
})
|
||||||
|
|
||||||
|
// Add account details in separate embed(s) if needed
|
||||||
|
if (accountFields.length > 0) {
|
||||||
|
// If we have multiple fields, split into multiple embeds
|
||||||
|
accountFields.forEach((field, index) => {
|
||||||
|
if (index === 0 && embeds[0] && embeds[0].fields) {
|
||||||
|
// Add first field to main embed
|
||||||
|
embeds[0].fields.push(field)
|
||||||
|
} else {
|
||||||
|
// Create additional embeds for remaining fields
|
||||||
|
embeds.push({
|
||||||
|
color: embedColor,
|
||||||
|
fields: [field],
|
||||||
|
timestamp: new Date().toISOString()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
const postWebhook = async (url: string, label: string) => {
|
||||||
|
const maxAttempts = 3
|
||||||
|
let lastError: unknown = null
|
||||||
|
|
||||||
|
for (let attempt = 1; attempt <= maxAttempts; attempt++) {
|
||||||
|
try {
|
||||||
|
await axios.post(url, {
|
||||||
|
embeds: embeds
|
||||||
|
}, {
|
||||||
|
headers: { 'Content-Type': 'application/json' },
|
||||||
|
timeout: 15000
|
||||||
|
})
|
||||||
|
log('main', 'WEBHOOK', `${label} conclusion sent successfully (${data.totalAccounts} accounts, +${data.totalCollected}pts)`)
|
||||||
|
return
|
||||||
|
} catch (error) {
|
||||||
|
lastError = error
|
||||||
|
if (attempt < maxAttempts) {
|
||||||
|
const delayMs = 1000 * Math.pow(2, attempt - 1)
|
||||||
|
await new Promise(resolve => setTimeout(resolve, delayMs))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
log('main', 'WEBHOOK', `${label} failed after ${maxAttempts} attempts: ${lastError instanceof Error ? lastError.message : String(lastError)}`, 'error')
|
||||||
|
}
|
||||||
|
|
||||||
|
const urls = new Set<string>()
|
||||||
|
if (hasConclusion) urls.add(config.conclusionWebhook!.url)
|
||||||
|
if (hasWebhook) urls.add(config.webhook!.url)
|
||||||
|
|
||||||
|
await Promise.all(
|
||||||
|
Array.from(urls).map((url, index) => postWebhook(url, `conclusion-webhook-${index + 1}`))
|
||||||
|
)
|
||||||
|
|
||||||
|
// Optional NTFY notification (simplified summary)
|
||||||
|
if (config.ntfy?.enabled && config.ntfy.url && config.ntfy.topic) {
|
||||||
|
const message = [
|
||||||
|
'🎯 Microsoft Rewards Summary',
|
||||||
|
`Status: ${statusText}`,
|
||||||
|
`Points: ${data.totalInitial} → ${data.totalEnd} (+${data.totalCollected})`,
|
||||||
|
`Accounts: ${data.successes}/${data.totalAccounts} successful`,
|
||||||
|
`Duration: ${formatDuration(data.totalDuration)}`
|
||||||
|
].join('\n')
|
||||||
|
|
||||||
|
const ntfyType = embedColor === DISCORD.COLOR_RED ? 'error' : embedColor === DISCORD.COLOR_ORANGE ? 'warn' : 'log'
|
||||||
|
|
||||||
|
try {
|
||||||
|
await Ntfy(message, ntfyType)
|
||||||
|
log('main', 'NTFY', 'Conclusion notification sent successfully')
|
||||||
|
} catch (error) {
|
||||||
|
log('main', 'NTFY', `Failed to send conclusion notification: ${error instanceof Error ? error.message : String(error)}`, 'error')
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
481
src/util/ConfigValidator.ts
Normal file
481
src/util/ConfigValidator.ts
Normal file
@@ -0,0 +1,481 @@
|
|||||||
|
import fs from 'fs'
|
||||||
|
import { Config } from '../interface/Config'
|
||||||
|
import { Account } from '../interface/Account'
|
||||||
|
|
||||||
|
export interface ValidationIssue {
|
||||||
|
severity: 'error' | 'warning' | 'info'
|
||||||
|
field: string
|
||||||
|
message: string
|
||||||
|
suggestion?: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ValidationResult {
|
||||||
|
valid: boolean
|
||||||
|
issues: ValidationIssue[]
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ConfigValidator performs intelligent validation of config.json and accounts.json
|
||||||
|
* before execution to catch common mistakes, conflicts, and security issues.
|
||||||
|
*/
|
||||||
|
export class ConfigValidator {
|
||||||
|
/**
|
||||||
|
* Validate the main config file
|
||||||
|
*/
|
||||||
|
static validateConfig(config: Config): ValidationResult {
|
||||||
|
const issues: ValidationIssue[] = []
|
||||||
|
|
||||||
|
// Check baseURL
|
||||||
|
if (!config.baseURL || !config.baseURL.startsWith('https://')) {
|
||||||
|
issues.push({
|
||||||
|
severity: 'error',
|
||||||
|
field: 'baseURL',
|
||||||
|
message: 'baseURL must be a valid HTTPS URL',
|
||||||
|
suggestion: 'Use https://rewards.bing.com'
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check sessionPath
|
||||||
|
if (!config.sessionPath || config.sessionPath.trim() === '') {
|
||||||
|
issues.push({
|
||||||
|
severity: 'error',
|
||||||
|
field: 'sessionPath',
|
||||||
|
message: 'sessionPath cannot be empty'
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check clusters
|
||||||
|
if (config.clusters < 1) {
|
||||||
|
issues.push({
|
||||||
|
severity: 'error',
|
||||||
|
field: 'clusters',
|
||||||
|
message: 'clusters must be at least 1'
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if (config.clusters > 10) {
|
||||||
|
issues.push({
|
||||||
|
severity: 'warning',
|
||||||
|
field: 'clusters',
|
||||||
|
message: 'High cluster count may consume excessive resources',
|
||||||
|
suggestion: 'Consider using 2-4 clusters for optimal performance'
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check globalTimeout
|
||||||
|
const timeout = this.parseTimeout(config.globalTimeout)
|
||||||
|
if (timeout < 10000) {
|
||||||
|
issues.push({
|
||||||
|
severity: 'warning',
|
||||||
|
field: 'globalTimeout',
|
||||||
|
message: 'Very short timeout may cause frequent failures',
|
||||||
|
suggestion: 'Use at least 15s for stability'
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if (timeout > 120000) {
|
||||||
|
issues.push({
|
||||||
|
severity: 'warning',
|
||||||
|
field: 'globalTimeout',
|
||||||
|
message: 'Very long timeout may slow down execution',
|
||||||
|
suggestion: 'Use 30-60s for optimal balance'
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check search settings
|
||||||
|
if (config.searchSettings) {
|
||||||
|
const searchDelay = config.searchSettings.searchDelay
|
||||||
|
const minDelay = this.parseTimeout(searchDelay.min)
|
||||||
|
const maxDelay = this.parseTimeout(searchDelay.max)
|
||||||
|
|
||||||
|
if (minDelay >= maxDelay) {
|
||||||
|
issues.push({
|
||||||
|
severity: 'error',
|
||||||
|
field: 'searchSettings.searchDelay',
|
||||||
|
message: 'min delay must be less than max delay'
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
if (minDelay < 10000) {
|
||||||
|
issues.push({
|
||||||
|
severity: 'warning',
|
||||||
|
field: 'searchSettings.searchDelay.min',
|
||||||
|
message: 'Very short search delays increase ban risk',
|
||||||
|
suggestion: 'Use at least 30s between searches'
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
if (config.searchSettings.retryMobileSearchAmount > 5) {
|
||||||
|
issues.push({
|
||||||
|
severity: 'warning',
|
||||||
|
field: 'searchSettings.retryMobileSearchAmount',
|
||||||
|
message: 'Too many retries may waste time',
|
||||||
|
suggestion: 'Use 2-3 retries maximum'
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check humanization
|
||||||
|
if (config.humanization) {
|
||||||
|
if (config.humanization.enabled === false && config.humanization.stopOnBan === true) {
|
||||||
|
issues.push({
|
||||||
|
severity: 'warning',
|
||||||
|
field: 'humanization',
|
||||||
|
message: 'stopOnBan is enabled but humanization is disabled',
|
||||||
|
suggestion: 'Enable humanization for better ban protection'
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
const actionDelay = config.humanization.actionDelay
|
||||||
|
if (actionDelay) {
|
||||||
|
const minAction = this.parseTimeout(actionDelay.min)
|
||||||
|
const maxAction = this.parseTimeout(actionDelay.max)
|
||||||
|
if (minAction >= maxAction) {
|
||||||
|
issues.push({
|
||||||
|
severity: 'error',
|
||||||
|
field: 'humanization.actionDelay',
|
||||||
|
message: 'min action delay must be less than max'
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (config.humanization.allowedWindows && config.humanization.allowedWindows.length > 0) {
|
||||||
|
for (const window of config.humanization.allowedWindows) {
|
||||||
|
if (!/^\d{2}:\d{2}-\d{2}:\d{2}$/.test(window)) {
|
||||||
|
issues.push({
|
||||||
|
severity: 'error',
|
||||||
|
field: 'humanization.allowedWindows',
|
||||||
|
message: `Invalid time window format: ${window}`,
|
||||||
|
suggestion: 'Use format HH:mm-HH:mm (e.g., 09:00-17:00)'
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check proxy config
|
||||||
|
if (config.proxy) {
|
||||||
|
if (config.proxy.proxyGoogleTrends === false && config.proxy.proxyBingTerms === false) {
|
||||||
|
issues.push({
|
||||||
|
severity: 'info',
|
||||||
|
field: 'proxy',
|
||||||
|
message: 'All proxy options disabled - outbound requests will use direct connection'
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check webhooks
|
||||||
|
if (config.webhook?.enabled && (!config.webhook.url || config.webhook.url.trim() === '')) {
|
||||||
|
issues.push({
|
||||||
|
severity: 'error',
|
||||||
|
field: 'webhook.url',
|
||||||
|
message: 'Webhook enabled but URL is empty'
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
if (config.conclusionWebhook?.enabled && (!config.conclusionWebhook.url || config.conclusionWebhook.url.trim() === '')) {
|
||||||
|
issues.push({
|
||||||
|
severity: 'error',
|
||||||
|
field: 'conclusionWebhook.url',
|
||||||
|
message: 'Conclusion webhook enabled but URL is empty'
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check ntfy
|
||||||
|
if (config.ntfy?.enabled) {
|
||||||
|
if (!config.ntfy.url || config.ntfy.url.trim() === '') {
|
||||||
|
issues.push({
|
||||||
|
severity: 'error',
|
||||||
|
field: 'ntfy.url',
|
||||||
|
message: 'NTFY enabled but URL is empty'
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if (!config.ntfy.topic || config.ntfy.topic.trim() === '') {
|
||||||
|
issues.push({
|
||||||
|
severity: 'error',
|
||||||
|
field: 'ntfy.topic',
|
||||||
|
message: 'NTFY enabled but topic is empty'
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Check workers
|
||||||
|
if (config.workers) {
|
||||||
|
const allDisabled = !config.workers.doDailySet &&
|
||||||
|
!config.workers.doMorePromotions &&
|
||||||
|
!config.workers.doPunchCards &&
|
||||||
|
!config.workers.doDesktopSearch &&
|
||||||
|
!config.workers.doMobileSearch &&
|
||||||
|
!config.workers.doDailyCheckIn &&
|
||||||
|
!config.workers.doReadToEarn
|
||||||
|
|
||||||
|
if (allDisabled) {
|
||||||
|
issues.push({
|
||||||
|
severity: 'warning',
|
||||||
|
field: 'workers',
|
||||||
|
message: 'All workers are disabled - bot will not perform any tasks',
|
||||||
|
suggestion: 'Enable at least one worker type'
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
const valid = !issues.some(i => i.severity === 'error')
|
||||||
|
return { valid, issues }
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Validate accounts.json
|
||||||
|
*/
|
||||||
|
static validateAccounts(accounts: Account[]): ValidationResult {
|
||||||
|
const issues: ValidationIssue[] = []
|
||||||
|
|
||||||
|
if (accounts.length === 0) {
|
||||||
|
issues.push({
|
||||||
|
severity: 'error',
|
||||||
|
field: 'accounts',
|
||||||
|
message: 'No accounts found in accounts.json'
|
||||||
|
})
|
||||||
|
return { valid: false, issues }
|
||||||
|
}
|
||||||
|
|
||||||
|
const seenEmails = new Set<string>()
|
||||||
|
const seenProxies = new Map<string, string[]>() // proxy -> [emails]
|
||||||
|
|
||||||
|
for (let i = 0; i < accounts.length; i++) {
|
||||||
|
const acc = accounts[i]
|
||||||
|
const prefix = `accounts[${i}]`
|
||||||
|
|
||||||
|
if (!acc) continue
|
||||||
|
|
||||||
|
// Check email
|
||||||
|
if (!acc.email || acc.email.trim() === '') {
|
||||||
|
issues.push({
|
||||||
|
severity: 'error',
|
||||||
|
field: `${prefix}.email`,
|
||||||
|
message: 'Account email is empty'
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
if (seenEmails.has(acc.email)) {
|
||||||
|
issues.push({
|
||||||
|
severity: 'error',
|
||||||
|
field: `${prefix}.email`,
|
||||||
|
message: `Duplicate email: ${acc.email}`
|
||||||
|
})
|
||||||
|
}
|
||||||
|
seenEmails.add(acc.email)
|
||||||
|
|
||||||
|
if (!/@/.test(acc.email)) {
|
||||||
|
issues.push({
|
||||||
|
severity: 'error',
|
||||||
|
field: `${prefix}.email`,
|
||||||
|
message: 'Invalid email format'
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check password
|
||||||
|
if (!acc.password || acc.password.trim() === '') {
|
||||||
|
issues.push({
|
||||||
|
severity: 'error',
|
||||||
|
field: `${prefix}.password`,
|
||||||
|
message: 'Account password is empty'
|
||||||
|
})
|
||||||
|
} else if (acc.password.length < 8) {
|
||||||
|
issues.push({
|
||||||
|
severity: 'warning',
|
||||||
|
field: `${prefix}.password`,
|
||||||
|
message: 'Very short password - verify it\'s correct'
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check proxy
|
||||||
|
if (acc.proxy) {
|
||||||
|
const proxyUrl = acc.proxy.url
|
||||||
|
if (proxyUrl && proxyUrl.trim() !== '') {
|
||||||
|
if (!acc.proxy.port) {
|
||||||
|
issues.push({
|
||||||
|
severity: 'error',
|
||||||
|
field: `${prefix}.proxy.port`,
|
||||||
|
message: 'Proxy URL specified but port is missing'
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// Track proxy reuse
|
||||||
|
const proxyKey = `${proxyUrl}:${acc.proxy.port}`
|
||||||
|
if (!seenProxies.has(proxyKey)) {
|
||||||
|
seenProxies.set(proxyKey, [])
|
||||||
|
}
|
||||||
|
seenProxies.get(proxyKey)?.push(acc.email)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check TOTP
|
||||||
|
if (acc.totp && acc.totp.trim() !== '') {
|
||||||
|
if (acc.totp.length < 16) {
|
||||||
|
issues.push({
|
||||||
|
severity: 'warning',
|
||||||
|
field: `${prefix}.totp`,
|
||||||
|
message: 'TOTP secret seems too short - verify it\'s correct'
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Warn about excessive proxy reuse
|
||||||
|
for (const [proxyKey, emails] of seenProxies) {
|
||||||
|
if (emails.length > 3) {
|
||||||
|
issues.push({
|
||||||
|
severity: 'warning',
|
||||||
|
field: 'accounts.proxy',
|
||||||
|
message: `Proxy ${proxyKey} used by ${emails.length} accounts - may trigger rate limits`,
|
||||||
|
suggestion: 'Use different proxies per account for better safety'
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const valid = !issues.some(i => i.severity === 'error')
|
||||||
|
return { valid, issues }
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Validate both config and accounts together (cross-checks)
|
||||||
|
*/
|
||||||
|
static validateAll(config: Config, accounts: Account[]): ValidationResult {
|
||||||
|
const configResult = this.validateConfig(config)
|
||||||
|
const accountsResult = this.validateAccounts(accounts)
|
||||||
|
|
||||||
|
const issues = [...configResult.issues, ...accountsResult.issues]
|
||||||
|
|
||||||
|
// Cross-validation: clusters vs accounts
|
||||||
|
if (accounts.length > 0 && config.clusters > accounts.length) {
|
||||||
|
issues.push({
|
||||||
|
severity: 'info',
|
||||||
|
field: 'clusters',
|
||||||
|
message: `${config.clusters} clusters configured but only ${accounts.length} account(s)`,
|
||||||
|
suggestion: 'Reduce clusters to match account count for efficiency'
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// Cross-validation: parallel mode with single account
|
||||||
|
if (config.parallel && accounts.length === 1) {
|
||||||
|
issues.push({
|
||||||
|
severity: 'info',
|
||||||
|
field: 'parallel',
|
||||||
|
message: 'Parallel mode enabled with single account has no effect',
|
||||||
|
suggestion: 'Disable parallel mode or add more accounts'
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
const valid = !issues.some(i => i.severity === 'error')
|
||||||
|
return { valid, issues }
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Load and validate from file paths
|
||||||
|
*/
|
||||||
|
static validateFromFiles(configPath: string, accountsPath: string): ValidationResult {
|
||||||
|
try {
|
||||||
|
if (!fs.existsSync(configPath)) {
|
||||||
|
return {
|
||||||
|
valid: false,
|
||||||
|
issues: [{
|
||||||
|
severity: 'error',
|
||||||
|
field: 'config',
|
||||||
|
message: `Config file not found: ${configPath}`
|
||||||
|
}]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!fs.existsSync(accountsPath)) {
|
||||||
|
return {
|
||||||
|
valid: false,
|
||||||
|
issues: [{
|
||||||
|
severity: 'error',
|
||||||
|
field: 'accounts',
|
||||||
|
message: `Accounts file not found: ${accountsPath}`
|
||||||
|
}]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const configRaw = fs.readFileSync(configPath, 'utf-8')
|
||||||
|
const accountsRaw = fs.readFileSync(accountsPath, 'utf-8')
|
||||||
|
|
||||||
|
const configJson = configRaw.replace(/\/\*[\s\S]*?\*\/|\/\/.*/g, '')
|
||||||
|
const config: Config = JSON.parse(configJson)
|
||||||
|
const accounts: Account[] = JSON.parse(accountsRaw)
|
||||||
|
|
||||||
|
return this.validateAll(config, accounts)
|
||||||
|
} catch (error) {
|
||||||
|
return {
|
||||||
|
valid: false,
|
||||||
|
issues: [{
|
||||||
|
severity: 'error',
|
||||||
|
field: 'parse',
|
||||||
|
message: `Failed to parse files: ${error instanceof Error ? error.message : String(error)}`
|
||||||
|
}]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Print validation results to console with color
|
||||||
|
* Note: This method intentionally uses console.log for CLI output formatting
|
||||||
|
*/
|
||||||
|
static printResults(result: ValidationResult): void {
|
||||||
|
if (result.valid) {
|
||||||
|
console.log('✅ Configuration validation passed\n')
|
||||||
|
} else {
|
||||||
|
console.log('❌ Configuration validation failed\n')
|
||||||
|
}
|
||||||
|
|
||||||
|
if (result.issues.length === 0) {
|
||||||
|
console.log('No issues found.')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
const errors = result.issues.filter(i => i.severity === 'error')
|
||||||
|
const warnings = result.issues.filter(i => i.severity === 'warning')
|
||||||
|
const infos = result.issues.filter(i => i.severity === 'info')
|
||||||
|
|
||||||
|
if (errors.length > 0) {
|
||||||
|
console.log(`\n🚫 ERRORS (${errors.length}):`)
|
||||||
|
for (const issue of errors) {
|
||||||
|
console.log(` ${issue.field}: ${issue.message}`)
|
||||||
|
if (issue.suggestion) {
|
||||||
|
console.log(` → ${issue.suggestion}`)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (warnings.length > 0) {
|
||||||
|
console.log(`\n⚠️ WARNINGS (${warnings.length}):`)
|
||||||
|
for (const issue of warnings) {
|
||||||
|
console.log(` ${issue.field}: ${issue.message}`)
|
||||||
|
if (issue.suggestion) {
|
||||||
|
console.log(` → ${issue.suggestion}`)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (infos.length > 0) {
|
||||||
|
console.log(`\nℹ️ INFO (${infos.length}):`)
|
||||||
|
for (const issue of infos) {
|
||||||
|
console.log(` ${issue.field}: ${issue.message}`)
|
||||||
|
if (issue.suggestion) {
|
||||||
|
console.log(` → ${issue.suggestion}`)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log()
|
||||||
|
}
|
||||||
|
|
||||||
|
private static parseTimeout(value: number | string): number {
|
||||||
|
if (typeof value === 'number') return value
|
||||||
|
const str = String(value).toLowerCase()
|
||||||
|
if (str.endsWith('ms')) return parseInt(str, 10)
|
||||||
|
if (str.endsWith('s')) return parseInt(str, 10) * 1000
|
||||||
|
if (str.endsWith('min')) return parseInt(str, 10) * 60000
|
||||||
|
return parseInt(str, 10) || 30000
|
||||||
|
}
|
||||||
|
}
|
||||||
54
src/util/Humanizer.ts
Normal file
54
src/util/Humanizer.ts
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
import { Page } from 'rebrowser-playwright'
|
||||||
|
import Util from './Utils'
|
||||||
|
import type { ConfigHumanization } from '../interface/Config'
|
||||||
|
|
||||||
|
export class Humanizer {
|
||||||
|
private util: Util
|
||||||
|
private cfg: ConfigHumanization | undefined
|
||||||
|
|
||||||
|
constructor(util: Util, cfg?: ConfigHumanization) {
|
||||||
|
this.util = util
|
||||||
|
this.cfg = cfg
|
||||||
|
}
|
||||||
|
|
||||||
|
async microGestures(page: Page): Promise<void> {
|
||||||
|
if (this.cfg && this.cfg.enabled === false) return
|
||||||
|
const moveProb = this.cfg?.gestureMoveProb ?? 0.4
|
||||||
|
const scrollProb = this.cfg?.gestureScrollProb ?? 0.2
|
||||||
|
try {
|
||||||
|
if (Math.random() < moveProb) {
|
||||||
|
const x = Math.floor(Math.random() * 40) + 5
|
||||||
|
const y = Math.floor(Math.random() * 30) + 5
|
||||||
|
await page.mouse.move(x, y, { steps: 2 }).catch(() => {})
|
||||||
|
}
|
||||||
|
if (Math.random() < scrollProb) {
|
||||||
|
const dy = (Math.random() < 0.5 ? 1 : -1) * (Math.floor(Math.random() * 150) + 50)
|
||||||
|
await page.mouse.wheel(0, dy).catch(() => {})
|
||||||
|
}
|
||||||
|
} catch {/* noop */}
|
||||||
|
}
|
||||||
|
|
||||||
|
async actionPause(): Promise<void> {
|
||||||
|
if (this.cfg && this.cfg.enabled === false) return
|
||||||
|
const defMin = 150
|
||||||
|
const defMax = 450
|
||||||
|
let min = defMin
|
||||||
|
let max = defMax
|
||||||
|
if (this.cfg?.actionDelay) {
|
||||||
|
const parse = (v: number | string) => {
|
||||||
|
if (typeof v === 'number') return v
|
||||||
|
try {
|
||||||
|
const n = this.util.stringToMs(String(v))
|
||||||
|
return Math.max(0, Math.min(n, 10_000))
|
||||||
|
} catch { return defMin }
|
||||||
|
}
|
||||||
|
min = parse(this.cfg.actionDelay.min)
|
||||||
|
max = parse(this.cfg.actionDelay.max)
|
||||||
|
if (min > max) [min, max] = [max, min]
|
||||||
|
max = Math.min(max, 5_000)
|
||||||
|
}
|
||||||
|
await this.util.wait(this.util.randomNumber(min, max))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default Humanizer
|
||||||
58
src/util/JobState.ts
Normal file
58
src/util/JobState.ts
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
import fs from 'fs'
|
||||||
|
import path from 'path'
|
||||||
|
import type { Config } from '../interface/Config'
|
||||||
|
|
||||||
|
type DayState = {
|
||||||
|
doneOfferIds: string[]
|
||||||
|
}
|
||||||
|
|
||||||
|
type FileState = {
|
||||||
|
days: Record<string, DayState>
|
||||||
|
}
|
||||||
|
|
||||||
|
export class JobState {
|
||||||
|
private baseDir: string
|
||||||
|
|
||||||
|
constructor(cfg: Config) {
|
||||||
|
const dir = cfg.jobState?.dir || path.join(process.cwd(), cfg.sessionPath, 'job-state')
|
||||||
|
this.baseDir = dir
|
||||||
|
if (!fs.existsSync(this.baseDir)) fs.mkdirSync(this.baseDir, { recursive: true })
|
||||||
|
}
|
||||||
|
|
||||||
|
private fileFor(email: string): string {
|
||||||
|
const safe = email.replace(/[^a-z0-9._-]/gi, '_')
|
||||||
|
return path.join(this.baseDir, `${safe}.json`)
|
||||||
|
}
|
||||||
|
|
||||||
|
private load(email: string): FileState {
|
||||||
|
const file = this.fileFor(email)
|
||||||
|
if (!fs.existsSync(file)) return { days: {} }
|
||||||
|
try {
|
||||||
|
const raw = fs.readFileSync(file, 'utf-8')
|
||||||
|
const parsed = JSON.parse(raw)
|
||||||
|
return parsed && typeof parsed === 'object' && parsed.days ? parsed as FileState : { days: {} }
|
||||||
|
} catch { return { days: {} } }
|
||||||
|
}
|
||||||
|
|
||||||
|
private save(email: string, state: FileState): void {
|
||||||
|
const file = this.fileFor(email)
|
||||||
|
fs.writeFileSync(file, JSON.stringify(state, null, 2), 'utf-8')
|
||||||
|
}
|
||||||
|
|
||||||
|
isDone(email: string, day: string, offerId: string): boolean {
|
||||||
|
const st = this.load(email)
|
||||||
|
const d = st.days[day]
|
||||||
|
if (!d) return false
|
||||||
|
return d.doneOfferIds.includes(offerId)
|
||||||
|
}
|
||||||
|
|
||||||
|
markDone(email: string, day: string, offerId: string): void {
|
||||||
|
const st = this.load(email)
|
||||||
|
if (!st.days[day]) st.days[day] = { doneOfferIds: [] }
|
||||||
|
const d = st.days[day]
|
||||||
|
if (!d.doneOfferIds.includes(offerId)) d.doneOfferIds.push(offerId)
|
||||||
|
this.save(email, st)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default JobState
|
||||||
229
src/util/Load.ts
229
src/util/Load.ts
@@ -8,38 +8,219 @@ import { Account } from '../interface/Account'
|
|||||||
import { Config, ConfigSaveFingerprint } from '../interface/Config'
|
import { Config, ConfigSaveFingerprint } from '../interface/Config'
|
||||||
|
|
||||||
let configCache: Config
|
let configCache: Config
|
||||||
|
let configSourcePath = ''
|
||||||
|
|
||||||
|
|
||||||
|
// Normalize both legacy (flat) and new (nested) config schemas into the flat Config interface
|
||||||
|
function normalizeConfig(raw: unknown): Config {
|
||||||
|
// Using any here is necessary to support both legacy flat config and new nested config structures
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
|
const n = (raw || {}) as any
|
||||||
|
|
||||||
|
// Browser / execution
|
||||||
|
const headless = n.browser?.headless ?? n.headless ?? false
|
||||||
|
const globalTimeout = n.browser?.globalTimeout ?? n.globalTimeout ?? '30s'
|
||||||
|
const parallel = n.execution?.parallel ?? n.parallel ?? false
|
||||||
|
const runOnZeroPoints = n.execution?.runOnZeroPoints ?? n.runOnZeroPoints ?? false
|
||||||
|
const clusters = n.execution?.clusters ?? n.clusters ?? 1
|
||||||
|
|
||||||
|
// Search
|
||||||
|
const useLocalQueries = n.search?.useLocalQueries ?? n.searchOnBingLocalQueries ?? false
|
||||||
|
const searchSettingsSrc = n.search?.settings ?? n.searchSettings ?? {}
|
||||||
|
const delaySrc = searchSettingsSrc.delay ?? searchSettingsSrc.searchDelay ?? { min: '3min', max: '5min' }
|
||||||
|
const searchSettings = {
|
||||||
|
useGeoLocaleQueries: !!(searchSettingsSrc.useGeoLocaleQueries ?? false),
|
||||||
|
scrollRandomResults: !!(searchSettingsSrc.scrollRandomResults ?? false),
|
||||||
|
clickRandomResults: !!(searchSettingsSrc.clickRandomResults ?? false),
|
||||||
|
retryMobileSearchAmount: Number(searchSettingsSrc.retryMobileSearchAmount ?? 2),
|
||||||
|
searchDelay: {
|
||||||
|
min: delaySrc.min ?? '3min',
|
||||||
|
max: delaySrc.max ?? '5min'
|
||||||
|
},
|
||||||
|
localFallbackCount: Number(searchSettingsSrc.localFallbackCount ?? 25),
|
||||||
|
extraFallbackRetries: Number(searchSettingsSrc.extraFallbackRetries ?? 1)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Workers
|
||||||
|
const workers = n.workers ?? {
|
||||||
|
doDailySet: true,
|
||||||
|
doMorePromotions: true,
|
||||||
|
doPunchCards: true,
|
||||||
|
doDesktopSearch: true,
|
||||||
|
doMobileSearch: true,
|
||||||
|
doDailyCheckIn: true,
|
||||||
|
doReadToEarn: true,
|
||||||
|
bundleDailySetWithSearch: false
|
||||||
|
}
|
||||||
|
// Ensure missing flag gets a default
|
||||||
|
if (typeof workers.bundleDailySetWithSearch !== 'boolean') workers.bundleDailySetWithSearch = false
|
||||||
|
|
||||||
|
// Logging
|
||||||
|
const logging = n.logging ?? {}
|
||||||
|
const logExcludeFunc = Array.isArray(logging.excludeFunc) ? logging.excludeFunc : (n.logExcludeFunc ?? [])
|
||||||
|
const webhookLogExcludeFunc = Array.isArray(logging.webhookExcludeFunc) ? logging.webhookExcludeFunc : (n.webhookLogExcludeFunc ?? [])
|
||||||
|
|
||||||
|
// Notifications
|
||||||
|
const notifications = n.notifications ?? {}
|
||||||
|
const webhook = notifications.webhook ?? n.webhook ?? { enabled: false, url: '' }
|
||||||
|
const conclusionWebhook = notifications.conclusionWebhook ?? n.conclusionWebhook ?? { enabled: false, url: '' }
|
||||||
|
const ntfy = notifications.ntfy ?? n.ntfy ?? { enabled: false, url: '', topic: '', authToken: '' }
|
||||||
|
|
||||||
|
|
||||||
|
// Fingerprinting
|
||||||
|
const saveFingerprint = (n.fingerprinting?.saveFingerprint ?? n.saveFingerprint) ?? { mobile: false, desktop: false }
|
||||||
|
|
||||||
|
// Humanization defaults (single on/off)
|
||||||
|
if (!n.humanization) n.humanization = {}
|
||||||
|
if (typeof n.humanization.enabled !== 'boolean') n.humanization.enabled = true
|
||||||
|
if (typeof n.humanization.stopOnBan !== 'boolean') n.humanization.stopOnBan = false
|
||||||
|
if (typeof n.humanization.immediateBanAlert !== 'boolean') n.humanization.immediateBanAlert = true
|
||||||
|
if (typeof n.humanization.randomOffDaysPerWeek !== 'number') {
|
||||||
|
n.humanization.randomOffDaysPerWeek = 1
|
||||||
|
}
|
||||||
|
// Strong default gestures when enabled (explicit values still win)
|
||||||
|
if (typeof n.humanization.gestureMoveProb !== 'number') {
|
||||||
|
n.humanization.gestureMoveProb = n.humanization.enabled === false ? 0 : 0.5
|
||||||
|
}
|
||||||
|
if (typeof n.humanization.gestureScrollProb !== 'number') {
|
||||||
|
n.humanization.gestureScrollProb = n.humanization.enabled === false ? 0 : 0.25
|
||||||
|
}
|
||||||
|
|
||||||
|
// Vacation mode (monthly contiguous off-days)
|
||||||
|
if (!n.vacation) n.vacation = {}
|
||||||
|
if (typeof n.vacation.enabled !== 'boolean') n.vacation.enabled = false
|
||||||
|
const vMin = Number(n.vacation.minDays)
|
||||||
|
const vMax = Number(n.vacation.maxDays)
|
||||||
|
n.vacation.minDays = isFinite(vMin) && vMin > 0 ? Math.floor(vMin) : 3
|
||||||
|
n.vacation.maxDays = isFinite(vMax) && vMax > 0 ? Math.floor(vMax) : 5
|
||||||
|
if (n.vacation.maxDays < n.vacation.minDays) {
|
||||||
|
const t = n.vacation.minDays; n.vacation.minDays = n.vacation.maxDays; n.vacation.maxDays = t
|
||||||
|
}
|
||||||
|
|
||||||
|
const cfg: Config = {
|
||||||
|
baseURL: n.baseURL ?? 'https://rewards.bing.com',
|
||||||
|
sessionPath: n.sessionPath ?? 'sessions',
|
||||||
|
headless,
|
||||||
|
parallel,
|
||||||
|
runOnZeroPoints,
|
||||||
|
clusters,
|
||||||
|
saveFingerprint,
|
||||||
|
workers,
|
||||||
|
searchOnBingLocalQueries: !!useLocalQueries,
|
||||||
|
globalTimeout,
|
||||||
|
searchSettings,
|
||||||
|
humanization: n.humanization,
|
||||||
|
retryPolicy: n.retryPolicy,
|
||||||
|
jobState: n.jobState,
|
||||||
|
logExcludeFunc,
|
||||||
|
webhookLogExcludeFunc,
|
||||||
|
logging, // retain full logging object for live webhook usage
|
||||||
|
proxy: n.proxy ?? { proxyGoogleTrends: true, proxyBingTerms: true },
|
||||||
|
webhook,
|
||||||
|
conclusionWebhook,
|
||||||
|
ntfy,
|
||||||
|
vacation: n.vacation,
|
||||||
|
crashRecovery: n.crashRecovery || {}
|
||||||
|
}
|
||||||
|
|
||||||
|
return cfg
|
||||||
|
}
|
||||||
|
|
||||||
export function loadAccounts(): Account[] {
|
export function loadAccounts(): Account[] {
|
||||||
try {
|
try {
|
||||||
|
// 1) CLI dev override
|
||||||
let file = 'accounts.json'
|
let file = 'accounts.json'
|
||||||
|
|
||||||
// If dev mode, use dev account(s)
|
|
||||||
if (process.argv.includes('-dev')) {
|
if (process.argv.includes('-dev')) {
|
||||||
file = 'accounts.dev.json'
|
file = 'accounts.dev.json'
|
||||||
}
|
}
|
||||||
|
|
||||||
const accountDir = path.join(__dirname, '../', file)
|
// 2) Docker-friendly env overrides
|
||||||
const accounts = fs.readFileSync(accountDir, 'utf-8')
|
const envJson = process.env.ACCOUNTS_JSON
|
||||||
|
const envFile = process.env.ACCOUNTS_FILE
|
||||||
|
|
||||||
return JSON.parse(accounts)
|
let json: string | undefined
|
||||||
|
if (envJson && envJson.trim().startsWith('[')) {
|
||||||
|
json = envJson
|
||||||
|
} else if (envFile && envFile.trim()) {
|
||||||
|
const full = path.isAbsolute(envFile) ? envFile : path.join(process.cwd(), envFile)
|
||||||
|
if (!fs.existsSync(full)) {
|
||||||
|
throw new Error(`ACCOUNTS_FILE not found: ${full}`)
|
||||||
|
}
|
||||||
|
json = fs.readFileSync(full, 'utf-8')
|
||||||
|
} else {
|
||||||
|
// Try multiple locations to support both root mounts and dist mounts
|
||||||
|
// Support both .json and .json extensions
|
||||||
|
const candidates = [
|
||||||
|
path.join(__dirname, '../', file),
|
||||||
|
path.join(__dirname, '../src', file),
|
||||||
|
path.join(process.cwd(), file),
|
||||||
|
path.join(process.cwd(), 'src', file),
|
||||||
|
path.join(__dirname, file)
|
||||||
|
]
|
||||||
|
let chosen: string | null = null
|
||||||
|
for (const p of candidates) {
|
||||||
|
try { if (fs.existsSync(p)) { chosen = p; break } } catch { /* ignore */ }
|
||||||
|
}
|
||||||
|
if (!chosen) throw new Error(`accounts file not found in: ${candidates.join(' | ')}`)
|
||||||
|
json = fs.readFileSync(chosen, 'utf-8')
|
||||||
|
}
|
||||||
|
|
||||||
|
// Support comments in accounts file (same as config)
|
||||||
|
const parsedUnknown = JSON.parse(json)
|
||||||
|
// Accept either a root array or an object with an `accounts` array, ignore `_note`
|
||||||
|
const parsed = Array.isArray(parsedUnknown) ? parsedUnknown : (parsedUnknown && typeof parsedUnknown === 'object' && Array.isArray((parsedUnknown as { accounts?: unknown }).accounts) ? (parsedUnknown as { accounts: unknown[] }).accounts : null)
|
||||||
|
if (!Array.isArray(parsed)) throw new Error('accounts must be an array')
|
||||||
|
// minimal shape validation
|
||||||
|
for (const a of parsed) {
|
||||||
|
if (!a || typeof a.email !== 'string' || typeof a.password !== 'string') {
|
||||||
|
throw new Error('each account must have email and password strings')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Filter out disabled accounts (enabled: false)
|
||||||
|
const allAccounts = parsed as Account[]
|
||||||
|
const enabledAccounts = allAccounts.filter(acc => acc.enabled !== false)
|
||||||
|
return enabledAccounts
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw new Error(error as string)
|
throw new Error(error as string)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function getConfigPath(): string { return configSourcePath }
|
||||||
|
|
||||||
export function loadConfig(): Config {
|
export function loadConfig(): Config {
|
||||||
try {
|
try {
|
||||||
if (configCache) {
|
if (configCache) {
|
||||||
return configCache
|
return configCache
|
||||||
}
|
}
|
||||||
|
|
||||||
const configDir = path.join(__dirname, '../', 'config.json')
|
// Resolve configuration file from common locations
|
||||||
const config = fs.readFileSync(configDir, 'utf-8')
|
const names = ['config.json']
|
||||||
|
const bases = [
|
||||||
|
path.join(__dirname, '../'), // dist root when compiled
|
||||||
|
path.join(__dirname, '../src'), // fallback: running dist but config still in src
|
||||||
|
process.cwd(), // repo root
|
||||||
|
path.join(process.cwd(), 'src'), // repo/src when running ts-node
|
||||||
|
__dirname // dist/util
|
||||||
|
]
|
||||||
|
const candidates: string[] = []
|
||||||
|
for (const base of bases) {
|
||||||
|
for (const name of names) {
|
||||||
|
candidates.push(path.join(base, name))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let cfgPath: string | null = null
|
||||||
|
for (const p of candidates) {
|
||||||
|
try { if (fs.existsSync(p)) { cfgPath = p; break } } catch { /* ignore */ }
|
||||||
|
}
|
||||||
|
if (!cfgPath) throw new Error(`config.json not found in: ${candidates.join(' | ')}`)
|
||||||
|
const config = fs.readFileSync(cfgPath, 'utf-8')
|
||||||
|
const json = config.replace(/^\uFEFF/, '')
|
||||||
|
const raw = JSON.parse(json)
|
||||||
|
const normalized = normalizeConfig(raw)
|
||||||
|
configCache = normalized // Set as cache
|
||||||
|
configSourcePath = cfgPath
|
||||||
|
|
||||||
const configData = JSON.parse(config)
|
return normalized
|
||||||
configCache = configData // Set as cache
|
|
||||||
|
|
||||||
return configData
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw new Error(error as string)
|
throw new Error(error as string)
|
||||||
}
|
}
|
||||||
@@ -56,13 +237,19 @@ export async function loadSessionData(sessionPath: string, email: string, isMobi
|
|||||||
cookies = JSON.parse(cookiesData)
|
cookies = JSON.parse(cookiesData)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fetch fingerprint file
|
// Fetch fingerprint file (support both legacy typo "fingerpint" and corrected "fingerprint")
|
||||||
const fingerprintFile = path.join(__dirname, '../browser/', sessionPath, email, `${isMobile ? 'mobile_fingerpint' : 'desktop_fingerpint'}.json`)
|
const baseDir = path.join(__dirname, '../browser/', sessionPath, email)
|
||||||
|
const legacyFile = path.join(baseDir, `${isMobile ? 'mobile_fingerpint' : 'desktop_fingerpint'}.json`)
|
||||||
|
const correctFile = path.join(baseDir, `${isMobile ? 'mobile_fingerprint' : 'desktop_fingerprint'}.json`)
|
||||||
|
|
||||||
let fingerprint!: BrowserFingerprintWithHeaders
|
let fingerprint!: BrowserFingerprintWithHeaders
|
||||||
if (((saveFingerprint.desktop && !isMobile) || (saveFingerprint.mobile && isMobile)) && fs.existsSync(fingerprintFile)) {
|
const shouldLoad = (saveFingerprint.desktop && !isMobile) || (saveFingerprint.mobile && isMobile)
|
||||||
const fingerprintData = await fs.promises.readFile(fingerprintFile, 'utf-8')
|
if (shouldLoad) {
|
||||||
fingerprint = JSON.parse(fingerprintData)
|
const chosen = fs.existsSync(correctFile) ? correctFile : (fs.existsSync(legacyFile) ? legacyFile : '')
|
||||||
|
if (chosen) {
|
||||||
|
const fingerprintData = await fs.promises.readFile(chosen, 'utf-8')
|
||||||
|
fingerprint = JSON.parse(fingerprintData)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
@@ -96,7 +283,7 @@ export async function saveSessionData(sessionPath: string, browser: BrowserConte
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function saveFingerprintData(sessionPath: string, email: string, isMobile: boolean, fingerpint: BrowserFingerprintWithHeaders): Promise<string> {
|
export async function saveFingerprintData(sessionPath: string, email: string, isMobile: boolean, fingerprint: BrowserFingerprintWithHeaders): Promise<string> {
|
||||||
try {
|
try {
|
||||||
// Fetch path
|
// Fetch path
|
||||||
const sessionDir = path.join(__dirname, '../browser/', sessionPath, email)
|
const sessionDir = path.join(__dirname, '../browser/', sessionPath, email)
|
||||||
@@ -106,8 +293,12 @@ export async function saveFingerprintData(sessionPath: string, email: string, is
|
|||||||
await fs.promises.mkdir(sessionDir, { recursive: true })
|
await fs.promises.mkdir(sessionDir, { recursive: true })
|
||||||
}
|
}
|
||||||
|
|
||||||
// Save fingerprint to a file
|
// Save fingerprint to files (write both legacy and corrected names for compatibility)
|
||||||
await fs.promises.writeFile(path.join(sessionDir, `${isMobile ? 'mobile_fingerpint' : 'desktop_fingerpint'}.json`), JSON.stringify(fingerpint))
|
const legacy = path.join(sessionDir, `${isMobile ? 'mobile_fingerpint' : 'desktop_fingerpint'}.json`)
|
||||||
|
const correct = path.join(sessionDir, `${isMobile ? 'mobile_fingerprint' : 'desktop_fingerprint'}.json`)
|
||||||
|
const payload = JSON.stringify(fingerprint)
|
||||||
|
await fs.promises.writeFile(correct, payload)
|
||||||
|
try { await fs.promises.writeFile(legacy, payload) } catch { /* ignore */ }
|
||||||
|
|
||||||
return sessionDir
|
return sessionDir
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|||||||
@@ -1,45 +1,249 @@
|
|||||||
|
import axios from 'axios'
|
||||||
import chalk from 'chalk'
|
import chalk from 'chalk'
|
||||||
|
|
||||||
import { Webhook } from './Webhook'
|
import { Ntfy } from './Ntfy'
|
||||||
import { loadConfig } from './Load'
|
import { loadConfig } from './Load'
|
||||||
|
import { DISCORD } from '../constants'
|
||||||
|
|
||||||
|
type WebhookBuffer = {
|
||||||
|
lines: string[]
|
||||||
|
sending: boolean
|
||||||
|
timer?: NodeJS.Timeout
|
||||||
|
}
|
||||||
|
|
||||||
export function log(isMobile: boolean | 'main', title: string, message: string, type: 'log' | 'warn' | 'error' = 'log', color?: keyof typeof chalk): void {
|
const webhookBuffers = new Map<string, WebhookBuffer>()
|
||||||
|
|
||||||
|
// Periodic cleanup of old/idle webhook buffers to prevent memory leaks
|
||||||
|
setInterval(() => {
|
||||||
|
const now = Date.now()
|
||||||
|
const BUFFER_MAX_AGE_MS = 3600000 // 1 hour
|
||||||
|
|
||||||
|
for (const [url, buf] of webhookBuffers.entries()) {
|
||||||
|
if (!buf.sending && buf.lines.length === 0) {
|
||||||
|
const lastActivity = (buf as unknown as { lastActivity?: number }).lastActivity || 0
|
||||||
|
if (now - lastActivity > BUFFER_MAX_AGE_MS) {
|
||||||
|
webhookBuffers.delete(url)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, 600000) // Check every 10 minutes
|
||||||
|
|
||||||
|
function getBuffer(url: string): WebhookBuffer {
|
||||||
|
let buf = webhookBuffers.get(url)
|
||||||
|
if (!buf) {
|
||||||
|
buf = { lines: [], sending: false }
|
||||||
|
webhookBuffers.set(url, buf)
|
||||||
|
}
|
||||||
|
// Track last activity for cleanup
|
||||||
|
(buf as unknown as { lastActivity: number }).lastActivity = Date.now()
|
||||||
|
return buf
|
||||||
|
}
|
||||||
|
|
||||||
|
async function sendBatch(url: string, buf: WebhookBuffer) {
|
||||||
|
if (buf.sending) return
|
||||||
|
buf.sending = true
|
||||||
|
|
||||||
|
while (buf.lines.length > 0) {
|
||||||
|
const chunk: string[] = []
|
||||||
|
let currentLength = 0
|
||||||
|
while (buf.lines.length > 0) {
|
||||||
|
const next = buf.lines[0]!
|
||||||
|
const projected = currentLength + next.length + (chunk.length > 0 ? 1 : 0)
|
||||||
|
if (projected > DISCORD.MAX_EMBED_LENGTH && chunk.length > 0) break
|
||||||
|
buf.lines.shift()
|
||||||
|
chunk.push(next)
|
||||||
|
currentLength = projected
|
||||||
|
}
|
||||||
|
|
||||||
|
const content = chunk.join('\n').slice(0, DISCORD.MAX_EMBED_LENGTH)
|
||||||
|
if (!content) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
// Enhanced webhook payload with embed, username and avatar
|
||||||
|
const payload = {
|
||||||
|
embeds: [{
|
||||||
|
description: `\`\`\`\n${content}\n\`\`\``,
|
||||||
|
color: determineColorFromContent(content),
|
||||||
|
timestamp: new Date().toISOString()
|
||||||
|
}]
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
await axios.post(url, payload, { headers: { 'Content-Type': 'application/json' }, timeout: DISCORD.WEBHOOK_TIMEOUT })
|
||||||
|
await new Promise(resolve => setTimeout(resolve, DISCORD.RATE_LIMIT_DELAY))
|
||||||
|
} catch (error) {
|
||||||
|
// Re-queue failed batch at front and exit loop
|
||||||
|
buf.lines = chunk.concat(buf.lines)
|
||||||
|
console.error('[Webhook] live log delivery failed:', error)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
buf.sending = false
|
||||||
|
}
|
||||||
|
|
||||||
|
function determineColorFromContent(content: string): number {
|
||||||
|
const lower = content.toLowerCase()
|
||||||
|
// Security/Ban alerts - Red
|
||||||
|
if (lower.includes('[banned]') || lower.includes('[security]') || lower.includes('suspended') || lower.includes('compromised')) {
|
||||||
|
return DISCORD.COLOR_RED
|
||||||
|
}
|
||||||
|
// Errors - Dark Red
|
||||||
|
if (lower.includes('[error]') || lower.includes('✗')) {
|
||||||
|
return DISCORD.COLOR_CRIMSON
|
||||||
|
}
|
||||||
|
// Warnings - Orange/Yellow
|
||||||
|
if (lower.includes('[warn]') || lower.includes('⚠')) {
|
||||||
|
return DISCORD.COLOR_ORANGE
|
||||||
|
}
|
||||||
|
// Success - Green
|
||||||
|
if (lower.includes('[ok]') || lower.includes('✓') || lower.includes('complet')) {
|
||||||
|
return DISCORD.COLOR_GREEN
|
||||||
|
}
|
||||||
|
// Info/Main - Blue
|
||||||
|
if (lower.includes('[main]')) {
|
||||||
|
return DISCORD.COLOR_BLUE
|
||||||
|
}
|
||||||
|
// Default - Gray
|
||||||
|
return 0x95A5A6 // Gray
|
||||||
|
}
|
||||||
|
|
||||||
|
function enqueueWebhookLog(url: string, line: string) {
|
||||||
|
const buf = getBuffer(url)
|
||||||
|
buf.lines.push(line)
|
||||||
|
if (!buf.timer) {
|
||||||
|
buf.timer = setTimeout(() => {
|
||||||
|
buf.timer = undefined
|
||||||
|
void sendBatch(url, buf)
|
||||||
|
}, DISCORD.DEBOUNCE_DELAY)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Synchronous logger that returns an Error when type === 'error' so callers can `throw log(...)` safely.
|
||||||
|
export function log(isMobile: boolean | 'main', title: string, message: string, type: 'log' | 'warn' | 'error' = 'log', color?: keyof typeof chalk): Error | void {
|
||||||
const configData = loadConfig()
|
const configData = loadConfig()
|
||||||
|
|
||||||
if (configData.logExcludeFunc.some(x => x.toLowerCase() === title.toLowerCase())) {
|
// Access logging config with fallback for backward compatibility
|
||||||
|
const configAny = configData as unknown as Record<string, unknown>
|
||||||
|
const logging = configAny.logging as { excludeFunc?: string[]; logExcludeFunc?: string[] } | undefined
|
||||||
|
const logExcludeFunc = logging?.excludeFunc ?? (configData as { logExcludeFunc?: string[] }).logExcludeFunc ?? []
|
||||||
|
|
||||||
|
if (logExcludeFunc.some((x: string) => x.toLowerCase() === title.toLowerCase())) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
const currentTime = new Date().toLocaleString()
|
const currentTime = new Date().toLocaleString()
|
||||||
const platformText = isMobile === 'main' ? 'MAIN' : isMobile ? 'MOBILE' : 'DESKTOP'
|
const platformText = isMobile === 'main' ? 'MAIN' : isMobile ? 'MOBILE' : 'DESKTOP'
|
||||||
const chalkedPlatform = isMobile === 'main' ? chalk.bgCyan('MAIN') : isMobile ? chalk.bgBlue('MOBILE') : chalk.bgMagenta('DESKTOP')
|
|
||||||
|
|
||||||
// Clean string for the Webhook (no chalk)
|
// Clean string for notifications (no chalk, structured)
|
||||||
const cleanStr = `[${currentTime}] [PID: ${process.pid}] [${type.toUpperCase()}] ${platformText} [${title}] ${message}`
|
type LoggingCfg = { excludeFunc?: string[]; webhookExcludeFunc?: string[]; redactEmails?: boolean }
|
||||||
|
const loggingCfg: LoggingCfg = (configAny.logging || {}) as LoggingCfg
|
||||||
|
const shouldRedact = !!loggingCfg.redactEmails
|
||||||
|
const redact = (s: string) => shouldRedact ? s.replace(/[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}/ig, (m) => {
|
||||||
|
const [u, d] = m.split('@'); return `${(u || '').slice(0, 2)}***@${d || ''}`
|
||||||
|
}) : s
|
||||||
|
const cleanStr = redact(`[${currentTime}] [PID: ${process.pid}] [${type.toUpperCase()}] ${platformText} [${title}] ${message}`)
|
||||||
|
|
||||||
// Send the clean string to the Webhook
|
// Define conditions for sending to NTFY
|
||||||
if (!configData.webhookLogExcludeFunc.some(x => x.toLowerCase() === title.toLowerCase())) {
|
const ntfyConditions = {
|
||||||
Webhook(configData, cleanStr)
|
log: [
|
||||||
|
message.toLowerCase().includes('started tasks for account'),
|
||||||
|
message.toLowerCase().includes('press the number'),
|
||||||
|
message.toLowerCase().includes('no points to earn')
|
||||||
|
],
|
||||||
|
error: [],
|
||||||
|
warn: [
|
||||||
|
message.toLowerCase().includes('aborting'),
|
||||||
|
message.toLowerCase().includes('didn\'t gain')
|
||||||
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
// Formatted string with chalk for terminal logging
|
// Check if the current log type and message meet the NTFY conditions
|
||||||
const str = `[${currentTime}] [PID: ${process.pid}] [${type.toUpperCase()}] ${chalkedPlatform} [${title}] ${message}`
|
try {
|
||||||
|
if (type in ntfyConditions && ntfyConditions[type as keyof typeof ntfyConditions].some(condition => condition)) {
|
||||||
|
// Fire-and-forget
|
||||||
|
Promise.resolve(Ntfy(cleanStr, type)).catch(() => { /* ignore ntfy errors */ })
|
||||||
|
}
|
||||||
|
} catch { /* ignore */ }
|
||||||
|
|
||||||
|
// Console output with better formatting and contextual icons
|
||||||
|
const typeIndicator = type === 'error' ? '✗' : type === 'warn' ? '⚠' : '✓'
|
||||||
|
const platformColor = isMobile === 'main' ? chalk.cyan : isMobile ? chalk.blue : chalk.magenta
|
||||||
|
const typeColor = type === 'error' ? chalk.red : type === 'warn' ? chalk.yellow : chalk.green
|
||||||
|
|
||||||
|
// Add contextual icon based on title/message (ASCII-safe for Windows PowerShell)
|
||||||
|
const titleLower = title.toLowerCase()
|
||||||
|
const msgLower = message.toLowerCase()
|
||||||
|
|
||||||
|
// ASCII-safe icons for Windows PowerShell compatibility
|
||||||
|
const iconMap: Array<[RegExp, string]> = [
|
||||||
|
[/security|compromised/i, '[SECURITY]'],
|
||||||
|
[/ban|suspend/i, '[BANNED]'],
|
||||||
|
[/error/i, '[ERROR]'],
|
||||||
|
[/warn/i, '[WARN]'],
|
||||||
|
[/success|complet/i, '[OK]'],
|
||||||
|
[/login/i, '[LOGIN]'],
|
||||||
|
[/point/i, '[POINTS]'],
|
||||||
|
[/search/i, '[SEARCH]'],
|
||||||
|
[/activity|quiz|poll/i, '[ACTIVITY]'],
|
||||||
|
[/browser/i, '[BROWSER]'],
|
||||||
|
[/main/i, '[MAIN]']
|
||||||
|
]
|
||||||
|
|
||||||
|
let icon = ''
|
||||||
|
for (const [pattern, symbol] of iconMap) {
|
||||||
|
if (pattern.test(titleLower) || pattern.test(msgLower)) {
|
||||||
|
icon = chalk.dim(symbol)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const iconPart = icon ? icon + ' ' : ''
|
||||||
|
|
||||||
|
const formattedStr = [
|
||||||
|
chalk.gray(`[${currentTime}]`),
|
||||||
|
chalk.gray(`[${process.pid}]`),
|
||||||
|
typeColor(`${typeIndicator}`),
|
||||||
|
platformColor(`[${platformText}]`),
|
||||||
|
chalk.bold(`[${title}]`),
|
||||||
|
iconPart + redact(message)
|
||||||
|
].join(' ')
|
||||||
|
|
||||||
const applyChalk = color && typeof chalk[color] === 'function' ? chalk[color] as (msg: string) => string : null
|
const applyChalk = color && typeof chalk[color] === 'function' ? chalk[color] as (msg: string) => string : null
|
||||||
|
|
||||||
// Log based on the type
|
// Log based on the type
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case 'warn':
|
case 'warn':
|
||||||
applyChalk ? console.warn(applyChalk(str)) : console.warn(str)
|
applyChalk ? console.warn(applyChalk(formattedStr)) : console.warn(formattedStr)
|
||||||
break
|
break
|
||||||
|
|
||||||
case 'error':
|
case 'error':
|
||||||
applyChalk ? console.error(applyChalk(str)) : console.error(str)
|
applyChalk ? console.error(applyChalk(formattedStr)) : console.error(formattedStr)
|
||||||
break
|
break
|
||||||
|
|
||||||
default:
|
default:
|
||||||
applyChalk ? console.log(applyChalk(str)) : console.log(str)
|
applyChalk ? console.log(applyChalk(formattedStr)) : console.log(formattedStr)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Webhook streaming (live logs)
|
||||||
|
try {
|
||||||
|
const loggingCfg: Record<string, unknown> = (configAny.logging || {}) as Record<string, unknown>
|
||||||
|
const webhookCfg = configData.webhook
|
||||||
|
const liveUrlRaw = typeof loggingCfg.liveWebhookUrl === 'string' ? loggingCfg.liveWebhookUrl.trim() : ''
|
||||||
|
const liveUrl = liveUrlRaw || (webhookCfg?.enabled && webhookCfg.url ? webhookCfg.url : '')
|
||||||
|
const webhookExclude = Array.isArray(loggingCfg.webhookExcludeFunc) ? loggingCfg.webhookExcludeFunc : configData.webhookLogExcludeFunc || []
|
||||||
|
const webhookExcluded = Array.isArray(webhookExclude) && webhookExclude.some((x: string) => x.toLowerCase() === title.toLowerCase())
|
||||||
|
if (liveUrl && !webhookExcluded) {
|
||||||
|
enqueueWebhookLog(liveUrl, cleanStr)
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error('[Logger] Failed to enqueue webhook log:', error)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Return an Error when logging an error so callers can `throw log(...)`
|
||||||
|
if (type === 'error') {
|
||||||
|
// CommunityReporter disabled per project policy
|
||||||
|
return new Error(cleanStr)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
27
src/util/Ntfy.ts
Normal file
27
src/util/Ntfy.ts
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
import { loadConfig } from './Load'
|
||||||
|
import axios from 'axios'
|
||||||
|
|
||||||
|
const NOTIFICATION_TYPES = {
|
||||||
|
error: { priority: 'max', tags: 'rotating_light' }, // Customize the ERROR icon here, see: https://docs.ntfy.sh/emojis/
|
||||||
|
warn: { priority: 'high', tags: 'warning' }, // Customize the WARN icon here, see: https://docs.ntfy.sh/emojis/
|
||||||
|
log: { priority: 'default', tags: 'medal_sports' } // Customize the LOG icon here, see: https://docs.ntfy.sh/emojis/
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function Ntfy(message: string, type: keyof typeof NOTIFICATION_TYPES = 'log'): Promise<void> {
|
||||||
|
const config = loadConfig().ntfy
|
||||||
|
if (!config?.enabled || !config.url || !config.topic) return
|
||||||
|
|
||||||
|
try {
|
||||||
|
const { priority, tags } = NOTIFICATION_TYPES[type]
|
||||||
|
const headers = {
|
||||||
|
Title: 'Microsoft Rewards Script',
|
||||||
|
Priority: priority,
|
||||||
|
Tags: tags,
|
||||||
|
...(config.authToken && { Authorization: `Bearer ${config.authToken}` })
|
||||||
|
}
|
||||||
|
|
||||||
|
await axios.post(`${config.url}/${config.topic}`, message, { headers })
|
||||||
|
} catch (error) {
|
||||||
|
// Silently fail - NTFY is a non-critical notification service
|
||||||
|
}
|
||||||
|
}
|
||||||
340
src/util/QueryDiversityEngine.ts
Normal file
340
src/util/QueryDiversityEngine.ts
Normal file
@@ -0,0 +1,340 @@
|
|||||||
|
import axios from 'axios'
|
||||||
|
|
||||||
|
export interface QuerySource {
|
||||||
|
name: string
|
||||||
|
weight: number // 0-1, probability of selection
|
||||||
|
fetchQueries: () => Promise<string[]>
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface QueryDiversityConfig {
|
||||||
|
sources: Array<'google-trends' | 'reddit' | 'news' | 'wikipedia' | 'local-fallback'>
|
||||||
|
deduplicate: boolean
|
||||||
|
mixStrategies: boolean // Mix different source types in same session
|
||||||
|
maxQueriesPerSource: number
|
||||||
|
cacheMinutes: number
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* QueryDiversityEngine fetches search queries from multiple sources to avoid patterns.
|
||||||
|
* Supports Google Trends, Reddit, News APIs, Wikipedia, and local fallbacks.
|
||||||
|
*/
|
||||||
|
export class QueryDiversityEngine {
|
||||||
|
private config: QueryDiversityConfig
|
||||||
|
private cache: Map<string, { queries: string[]; expires: number }> = new Map()
|
||||||
|
|
||||||
|
constructor(config?: Partial<QueryDiversityConfig>) {
|
||||||
|
this.config = {
|
||||||
|
sources: config?.sources || ['google-trends', 'reddit', 'local-fallback'],
|
||||||
|
deduplicate: config?.deduplicate !== false,
|
||||||
|
mixStrategies: config?.mixStrategies !== false,
|
||||||
|
maxQueriesPerSource: config?.maxQueriesPerSource || 10,
|
||||||
|
cacheMinutes: config?.cacheMinutes || 30
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fetch diverse queries from configured sources
|
||||||
|
*/
|
||||||
|
async fetchQueries(count: number): Promise<string[]> {
|
||||||
|
const allQueries: string[] = []
|
||||||
|
|
||||||
|
for (const sourceName of this.config.sources) {
|
||||||
|
try {
|
||||||
|
const queries = await this.getFromSource(sourceName)
|
||||||
|
allQueries.push(...queries.slice(0, this.config.maxQueriesPerSource))
|
||||||
|
} catch (error) {
|
||||||
|
// Silently fail and try other sources
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Deduplicate
|
||||||
|
let final = this.config.deduplicate ? Array.from(new Set(allQueries)) : allQueries
|
||||||
|
|
||||||
|
// Mix strategies: interleave queries from different sources
|
||||||
|
if (this.config.mixStrategies && this.config.sources.length > 1) {
|
||||||
|
final = this.interleaveQueries(final, count)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Shuffle and limit to requested count
|
||||||
|
final = this.shuffleArray(final).slice(0, count)
|
||||||
|
|
||||||
|
return final.length > 0 ? final : this.getLocalFallback(count)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fetch from a specific source with caching
|
||||||
|
*/
|
||||||
|
private async getFromSource(source: string): Promise<string[]> {
|
||||||
|
const cached = this.cache.get(source)
|
||||||
|
if (cached && Date.now() < cached.expires) {
|
||||||
|
return cached.queries
|
||||||
|
}
|
||||||
|
|
||||||
|
let queries: string[] = []
|
||||||
|
|
||||||
|
switch (source) {
|
||||||
|
case 'google-trends':
|
||||||
|
queries = await this.fetchGoogleTrends()
|
||||||
|
break
|
||||||
|
case 'reddit':
|
||||||
|
queries = await this.fetchReddit()
|
||||||
|
break
|
||||||
|
case 'news':
|
||||||
|
queries = await this.fetchNews()
|
||||||
|
break
|
||||||
|
case 'wikipedia':
|
||||||
|
queries = await this.fetchWikipedia()
|
||||||
|
break
|
||||||
|
case 'local-fallback':
|
||||||
|
queries = this.getLocalFallback(20)
|
||||||
|
break
|
||||||
|
default:
|
||||||
|
// Unknown source, skip silently
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
this.cache.set(source, {
|
||||||
|
queries,
|
||||||
|
expires: Date.now() + (this.config.cacheMinutes * 60000)
|
||||||
|
})
|
||||||
|
|
||||||
|
return queries
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fetch from Google Trends (existing logic can be reused)
|
||||||
|
*/
|
||||||
|
private async fetchGoogleTrends(): Promise<string[]> {
|
||||||
|
try {
|
||||||
|
const response = await axios.get('https://trends.google.com/trends/api/dailytrends?geo=US', {
|
||||||
|
timeout: 10000
|
||||||
|
})
|
||||||
|
|
||||||
|
const data = response.data.toString().replace(')]}\',', '')
|
||||||
|
const parsed = JSON.parse(data)
|
||||||
|
|
||||||
|
const queries: string[] = []
|
||||||
|
for (const item of parsed.default.trendingSearchesDays || []) {
|
||||||
|
for (const search of item.trendingSearches || []) {
|
||||||
|
if (search.title?.query) {
|
||||||
|
queries.push(search.title.query)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return queries.slice(0, 20)
|
||||||
|
} catch {
|
||||||
|
return []
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fetch from Reddit (top posts from popular subreddits)
|
||||||
|
*/
|
||||||
|
private async fetchReddit(): Promise<string[]> {
|
||||||
|
try {
|
||||||
|
const subreddits = ['news', 'worldnews', 'todayilearned', 'askreddit', 'technology']
|
||||||
|
const randomSub = subreddits[Math.floor(Math.random() * subreddits.length)]
|
||||||
|
|
||||||
|
const response = await axios.get(`https://www.reddit.com/r/${randomSub}/hot.json?limit=15`, {
|
||||||
|
timeout: 10000,
|
||||||
|
headers: {
|
||||||
|
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36'
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
const posts = response.data.data.children || []
|
||||||
|
const queries: string[] = []
|
||||||
|
|
||||||
|
for (const post of posts) {
|
||||||
|
const title = post.data?.title
|
||||||
|
if (title && title.length > 10 && title.length < 100) {
|
||||||
|
queries.push(title)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return queries
|
||||||
|
} catch {
|
||||||
|
return []
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fetch from News API (requires API key - fallback to headlines scraping)
|
||||||
|
*/
|
||||||
|
private async fetchNews(): Promise<string[]> {
|
||||||
|
try {
|
||||||
|
// Using NewsAPI.org free tier (limited requests)
|
||||||
|
const apiKey = process.env.NEWS_API_KEY
|
||||||
|
if (!apiKey) {
|
||||||
|
return this.fetchNewsFallback()
|
||||||
|
}
|
||||||
|
|
||||||
|
const response = await axios.get('https://newsapi.org/v2/top-headlines', {
|
||||||
|
params: {
|
||||||
|
country: 'us',
|
||||||
|
pageSize: 15,
|
||||||
|
apiKey
|
||||||
|
},
|
||||||
|
timeout: 10000
|
||||||
|
})
|
||||||
|
|
||||||
|
const articles = response.data.articles || []
|
||||||
|
return articles.map((a: { title?: string }) => a.title).filter((t: string | undefined) => t && t.length > 10)
|
||||||
|
} catch {
|
||||||
|
return this.fetchNewsFallback()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fallback news scraper (BBC/CNN headlines)
|
||||||
|
*/
|
||||||
|
private async fetchNewsFallback(): Promise<string[]> {
|
||||||
|
try {
|
||||||
|
const response = await axios.get('https://www.bbc.com/news', {
|
||||||
|
timeout: 10000,
|
||||||
|
headers: {
|
||||||
|
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36'
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
const html = response.data
|
||||||
|
const regex = /<h3[^>]*>(.*?)<\/h3>/gi
|
||||||
|
const matches: RegExpMatchArray[] = []
|
||||||
|
let match
|
||||||
|
while ((match = regex.exec(html)) !== null) {
|
||||||
|
matches.push(match)
|
||||||
|
}
|
||||||
|
|
||||||
|
return matches
|
||||||
|
.map(m => m[1]?.replace(/<[^>]+>/g, '').trim())
|
||||||
|
.filter((t: string | undefined) => t && t.length > 10 && t.length < 100)
|
||||||
|
.slice(0, 10) as string[]
|
||||||
|
} catch {
|
||||||
|
return []
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fetch from Wikipedia (featured articles / trending topics)
|
||||||
|
*/
|
||||||
|
private async fetchWikipedia(): Promise<string[]> {
|
||||||
|
try {
|
||||||
|
const response = await axios.get('https://en.wikipedia.org/w/api.php', {
|
||||||
|
params: {
|
||||||
|
action: 'query',
|
||||||
|
list: 'random',
|
||||||
|
rnnamespace: 0,
|
||||||
|
rnlimit: 15,
|
||||||
|
format: 'json'
|
||||||
|
},
|
||||||
|
timeout: 10000
|
||||||
|
})
|
||||||
|
|
||||||
|
const pages = response.data.query?.random || []
|
||||||
|
return pages.map((p: { title?: string }) => p.title).filter((t: string | undefined) => t && t.length > 3)
|
||||||
|
} catch {
|
||||||
|
return []
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Local fallback queries (curated list)
|
||||||
|
*/
|
||||||
|
private getLocalFallback(count: number): string[] {
|
||||||
|
const fallback = [
|
||||||
|
'weather forecast',
|
||||||
|
'news today',
|
||||||
|
'stock market',
|
||||||
|
'sports scores',
|
||||||
|
'movie reviews',
|
||||||
|
'recipes',
|
||||||
|
'travel destinations',
|
||||||
|
'health tips',
|
||||||
|
'technology news',
|
||||||
|
'best restaurants near me',
|
||||||
|
'how to cook pasta',
|
||||||
|
'python tutorial',
|
||||||
|
'world events',
|
||||||
|
'climate change',
|
||||||
|
'electric vehicles',
|
||||||
|
'space exploration',
|
||||||
|
'artificial intelligence',
|
||||||
|
'cryptocurrency',
|
||||||
|
'gaming news',
|
||||||
|
'fashion trends',
|
||||||
|
'fitness workout',
|
||||||
|
'home improvement',
|
||||||
|
'gardening tips',
|
||||||
|
'pet care',
|
||||||
|
'book recommendations',
|
||||||
|
'music charts',
|
||||||
|
'streaming shows',
|
||||||
|
'historical events',
|
||||||
|
'science discoveries',
|
||||||
|
'education resources'
|
||||||
|
]
|
||||||
|
|
||||||
|
return this.shuffleArray(fallback).slice(0, count)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Interleave queries from different sources for diversity
|
||||||
|
*/
|
||||||
|
private interleaveQueries(queries: string[], targetCount: number): string[] {
|
||||||
|
const result: string[] = []
|
||||||
|
const sourceMap = new Map<string, string[]>()
|
||||||
|
|
||||||
|
// Group queries by estimated source (simple heuristic)
|
||||||
|
for (const q of queries) {
|
||||||
|
const source = this.guessSource(q)
|
||||||
|
if (!sourceMap.has(source)) {
|
||||||
|
sourceMap.set(source, [])
|
||||||
|
}
|
||||||
|
sourceMap.get(source)?.push(q)
|
||||||
|
}
|
||||||
|
|
||||||
|
const sources = Array.from(sourceMap.values())
|
||||||
|
let index = 0
|
||||||
|
|
||||||
|
while (result.length < targetCount && sources.some(s => s.length > 0)) {
|
||||||
|
const source = sources[index % sources.length]
|
||||||
|
if (source && source.length > 0) {
|
||||||
|
const q = source.shift()
|
||||||
|
if (q) result.push(q)
|
||||||
|
}
|
||||||
|
index++
|
||||||
|
}
|
||||||
|
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Guess which source a query came from (basic heuristic)
|
||||||
|
*/
|
||||||
|
private guessSource(query: string): string {
|
||||||
|
if (/^[A-Z]/.test(query) && query.includes(' ')) return 'news'
|
||||||
|
if (query.length > 80) return 'reddit'
|
||||||
|
if (/how to|what is|why/i.test(query)) return 'local'
|
||||||
|
return 'trends'
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Shuffle array (Fisher-Yates)
|
||||||
|
*/
|
||||||
|
private shuffleArray<T>(array: T[]): T[] {
|
||||||
|
const shuffled = [...array]
|
||||||
|
for (let i = shuffled.length - 1; i > 0; i--) {
|
||||||
|
const j = Math.floor(Math.random() * (i + 1));
|
||||||
|
[shuffled[i], shuffled[j]] = [shuffled[j]!, shuffled[i]!]
|
||||||
|
}
|
||||||
|
return shuffled
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clear cache (call between runs)
|
||||||
|
*/
|
||||||
|
clearCache(): void {
|
||||||
|
this.cache.clear()
|
||||||
|
}
|
||||||
|
}
|
||||||
63
src/util/Retry.ts
Normal file
63
src/util/Retry.ts
Normal file
@@ -0,0 +1,63 @@
|
|||||||
|
import type { ConfigRetryPolicy } from '../interface/Config'
|
||||||
|
import Util from './Utils'
|
||||||
|
|
||||||
|
type NumericPolicy = {
|
||||||
|
maxAttempts: number
|
||||||
|
baseDelay: number
|
||||||
|
maxDelay: number
|
||||||
|
multiplier: number
|
||||||
|
jitter: number
|
||||||
|
}
|
||||||
|
|
||||||
|
export type Retryable<T> = () => Promise<T>
|
||||||
|
|
||||||
|
export class Retry {
|
||||||
|
private policy: NumericPolicy
|
||||||
|
|
||||||
|
constructor(policy?: ConfigRetryPolicy) {
|
||||||
|
const def: NumericPolicy = {
|
||||||
|
maxAttempts: 3,
|
||||||
|
baseDelay: 1000,
|
||||||
|
maxDelay: 30000,
|
||||||
|
multiplier: 2,
|
||||||
|
jitter: 0.2
|
||||||
|
}
|
||||||
|
const merged: ConfigRetryPolicy = { ...(policy || {}) }
|
||||||
|
// normalize string durations
|
||||||
|
const util = new Util()
|
||||||
|
const parse = (v: number | string) => {
|
||||||
|
if (typeof v === 'number') return v
|
||||||
|
try { return util.stringToMs(String(v)) } catch { return def.baseDelay }
|
||||||
|
}
|
||||||
|
this.policy = {
|
||||||
|
maxAttempts: (merged.maxAttempts as number) ?? def.maxAttempts,
|
||||||
|
baseDelay: parse(merged.baseDelay ?? def.baseDelay),
|
||||||
|
maxDelay: parse(merged.maxDelay ?? def.maxDelay),
|
||||||
|
multiplier: (merged.multiplier as number) ?? def.multiplier,
|
||||||
|
jitter: (merged.jitter as number) ?? def.jitter
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async run<T>(fn: Retryable<T>, isRetryable?: (e: unknown) => boolean): Promise<T> {
|
||||||
|
let attempt = 0
|
||||||
|
let delay = this.policy.baseDelay
|
||||||
|
let lastErr: unknown
|
||||||
|
while (attempt < this.policy.maxAttempts) {
|
||||||
|
try {
|
||||||
|
return await fn()
|
||||||
|
} catch (e) {
|
||||||
|
lastErr = e
|
||||||
|
attempt += 1
|
||||||
|
const retry = isRetryable ? isRetryable(e) : true
|
||||||
|
if (!retry || attempt >= this.policy.maxAttempts) break
|
||||||
|
const jitter = 1 + (Math.random() * 2 - 1) * this.policy.jitter
|
||||||
|
const sleep = Math.min(this.policy.maxDelay, Math.max(0, Math.floor(delay * jitter)))
|
||||||
|
await new Promise((r) => setTimeout(r, sleep))
|
||||||
|
delay = Math.min(this.policy.maxDelay, Math.floor(delay * (this.policy.multiplier || 2)))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
throw lastErr instanceof Error ? lastErr : new Error(String(lastErr))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default Retry
|
||||||
84
src/util/Totp.ts
Normal file
84
src/util/Totp.ts
Normal file
@@ -0,0 +1,84 @@
|
|||||||
|
import crypto from 'crypto'
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Decode Base32 (RFC 4648) to a Buffer.
|
||||||
|
* Accepts lowercase/uppercase, optional padding.
|
||||||
|
*/
|
||||||
|
function base32Decode(input: string): Buffer {
|
||||||
|
const alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ234567'
|
||||||
|
const clean = input.toUpperCase().replace(/=+$/g, '').replace(/[^A-Z2-7]/g, '')
|
||||||
|
let bits = 0
|
||||||
|
let value = 0
|
||||||
|
const bytes: number[] = []
|
||||||
|
|
||||||
|
for (const char of clean) {
|
||||||
|
const idx = alphabet.indexOf(char)
|
||||||
|
if (idx < 0) continue
|
||||||
|
value = (value << 5) | idx
|
||||||
|
bits += 5
|
||||||
|
if (bits >= 8) {
|
||||||
|
bits -= 8
|
||||||
|
bytes.push((value >>> bits) & 0xff)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return Buffer.from(bytes)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generate an HMAC using Node's crypto and return Buffer.
|
||||||
|
*/
|
||||||
|
function hmac(algorithm: string, key: Buffer, data: Buffer): Buffer {
|
||||||
|
return crypto.createHmac(algorithm, key).update(data).digest()
|
||||||
|
}
|
||||||
|
|
||||||
|
export type TotpOptions = { digits?: number; step?: number; algorithm?: 'SHA1' | 'SHA256' | 'SHA512' }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generate TOTP per RFC 6238.
|
||||||
|
* @param secretBase32 - shared secret in Base32
|
||||||
|
* @param time - Unix time in seconds (defaults to now)
|
||||||
|
* @param options - { digits, step, algorithm }
|
||||||
|
* @returns numeric TOTP as string (zero-padded)
|
||||||
|
*/
|
||||||
|
export function generateTOTP(
|
||||||
|
secretBase32: string,
|
||||||
|
time: number = Math.floor(Date.now() / 1000),
|
||||||
|
options?: TotpOptions
|
||||||
|
): string {
|
||||||
|
const digits = options?.digits ?? 6
|
||||||
|
const step = options?.step ?? 30
|
||||||
|
const alg = (options?.algorithm ?? 'SHA1').toUpperCase()
|
||||||
|
|
||||||
|
const key = base32Decode(secretBase32)
|
||||||
|
const counter = Math.floor(time / step)
|
||||||
|
|
||||||
|
// 8-byte big-endian counter
|
||||||
|
const counterBuffer = Buffer.alloc(8)
|
||||||
|
counterBuffer.writeBigUInt64BE(BigInt(counter), 0)
|
||||||
|
|
||||||
|
let hmacAlg: string
|
||||||
|
if (alg === 'SHA1') hmacAlg = 'sha1'
|
||||||
|
else if (alg === 'SHA256') hmacAlg = 'sha256'
|
||||||
|
else if (alg === 'SHA512') hmacAlg = 'sha512'
|
||||||
|
else throw new Error('Unsupported algorithm. Use SHA1, SHA256 or SHA512.')
|
||||||
|
|
||||||
|
const hash = hmac(hmacAlg, key, counterBuffer)
|
||||||
|
if (!hash || hash.length < 20) {
|
||||||
|
// Minimal sanity check; for SHA1 length is 20
|
||||||
|
throw new Error('Invalid HMAC output for TOTP')
|
||||||
|
}
|
||||||
|
|
||||||
|
// Dynamic truncation
|
||||||
|
const offset = hash[hash.length - 1]! & 0x0f
|
||||||
|
if (offset + 3 >= hash.length) {
|
||||||
|
throw new Error('Invalid dynamic truncation offset')
|
||||||
|
}
|
||||||
|
const code =
|
||||||
|
((hash[offset]! & 0x7f) << 24) |
|
||||||
|
((hash[offset + 1]! & 0xff) << 16) |
|
||||||
|
((hash[offset + 2]! & 0xff) << 8) |
|
||||||
|
(hash[offset + 3]! & 0xff)
|
||||||
|
|
||||||
|
const otp = (code % 10 ** digits).toString().padStart(digits, '0')
|
||||||
|
return otp
|
||||||
|
}
|
||||||
@@ -2,10 +2,21 @@ import axios from 'axios'
|
|||||||
import { BrowserFingerprintWithHeaders } from 'fingerprint-generator'
|
import { BrowserFingerprintWithHeaders } from 'fingerprint-generator'
|
||||||
|
|
||||||
import { log } from './Logger'
|
import { log } from './Logger'
|
||||||
|
import Retry from './Retry'
|
||||||
|
|
||||||
import { ChromeVersion, EdgeVersion } from '../interface/UserAgentUtil'
|
import { ChromeVersion, EdgeVersion, Architecture, Platform } from '../interface/UserAgentUtil'
|
||||||
|
|
||||||
const NOT_A_BRAND_VERSION = '99'
|
const NOT_A_BRAND_VERSION = '99'
|
||||||
|
const EDGE_VERSION_URL = 'https://edgeupdates.microsoft.com/api/products'
|
||||||
|
const EDGE_VERSION_CACHE_TTL_MS = 1000 * 60 * 60
|
||||||
|
|
||||||
|
type EdgeVersionResult = {
|
||||||
|
android?: string
|
||||||
|
windows?: string
|
||||||
|
}
|
||||||
|
|
||||||
|
let edgeVersionCache: { data: EdgeVersionResult; expiresAt: number } | null = null
|
||||||
|
let edgeVersionInFlight: Promise<EdgeVersionResult> | null = null
|
||||||
|
|
||||||
export async function getUserAgent(isMobile: boolean) {
|
export async function getUserAgent(isMobile: boolean) {
|
||||||
const system = getSystemComponents(isMobile)
|
const system = getSystemComponents(isMobile)
|
||||||
@@ -18,6 +29,7 @@ export async function getUserAgent(isMobile: boolean) {
|
|||||||
const platformVersion = `${isMobile ? Math.floor(Math.random() * 5) + 9 : Math.floor(Math.random() * 15) + 1}.0.0`
|
const platformVersion = `${isMobile ? Math.floor(Math.random() * 5) + 9 : Math.floor(Math.random() * 15) + 1}.0.0`
|
||||||
|
|
||||||
const uaMetadata = {
|
const uaMetadata = {
|
||||||
|
mobile: isMobile,
|
||||||
isMobile,
|
isMobile,
|
||||||
platform: isMobile ? 'Android' : 'Windows',
|
platform: isMobile ? 'Android' : 'Windows',
|
||||||
fullVersionList: [
|
fullVersionList: [
|
||||||
@@ -33,7 +45,8 @@ export async function getUserAgent(isMobile: boolean) {
|
|||||||
platformVersion,
|
platformVersion,
|
||||||
architecture: isMobile ? '' : 'x86',
|
architecture: isMobile ? '' : 'x86',
|
||||||
bitness: isMobile ? '' : '64',
|
bitness: isMobile ? '' : '64',
|
||||||
model: ''
|
model: '',
|
||||||
|
uaFullVersion: app['chrome_version']
|
||||||
}
|
}
|
||||||
|
|
||||||
return { userAgent: uaTemplate, userAgentMetadata: uaMetadata }
|
return { userAgent: uaTemplate, userAgentMetadata: uaMetadata }
|
||||||
@@ -59,38 +72,49 @@ export async function getChromeVersion(isMobile: boolean): Promise<string> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function getEdgeVersions(isMobile: boolean) {
|
export async function getEdgeVersions(isMobile: boolean) {
|
||||||
try {
|
const now = Date.now()
|
||||||
const request = {
|
if (edgeVersionCache && edgeVersionCache.expiresAt > now) {
|
||||||
url: 'https://edgeupdates.microsoft.com/api/products',
|
return edgeVersionCache.data
|
||||||
method: 'GET',
|
|
||||||
headers: {
|
|
||||||
'Content-Type': 'application/json'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const response = await axios(request)
|
|
||||||
const data: EdgeVersion[] = response.data
|
|
||||||
const stable = data.find(x => x.Product == 'Stable') as EdgeVersion
|
|
||||||
return {
|
|
||||||
android: stable.Releases.find(x => x.Platform == 'Android')?.ProductVersion,
|
|
||||||
windows: stable.Releases.find(x => (x.Platform == 'Windows' && x.Architecture == 'x64'))?.ProductVersion
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
} catch (error) {
|
|
||||||
throw log(isMobile, 'USERAGENT-EDGE-VERSION', 'An error occurred:' + error, 'error')
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (edgeVersionInFlight) {
|
||||||
|
try {
|
||||||
|
return await edgeVersionInFlight
|
||||||
|
} catch (error) {
|
||||||
|
if (edgeVersionCache) {
|
||||||
|
log(isMobile, 'USERAGENT-EDGE-VERSION', 'Using cached Edge versions after in-flight failure: ' + formatEdgeError(error), 'warn')
|
||||||
|
return edgeVersionCache.data
|
||||||
|
}
|
||||||
|
throw error
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const fetchPromise = fetchEdgeVersionsWithRetry(isMobile)
|
||||||
|
.then(result => {
|
||||||
|
edgeVersionCache = { data: result, expiresAt: Date.now() + EDGE_VERSION_CACHE_TTL_MS }
|
||||||
|
edgeVersionInFlight = null
|
||||||
|
return result
|
||||||
|
})
|
||||||
|
.catch(error => {
|
||||||
|
edgeVersionInFlight = null
|
||||||
|
if (edgeVersionCache) {
|
||||||
|
log(isMobile, 'USERAGENT-EDGE-VERSION', 'Falling back to cached Edge versions: ' + formatEdgeError(error), 'warn')
|
||||||
|
return edgeVersionCache.data
|
||||||
|
}
|
||||||
|
throw log(isMobile, 'USERAGENT-EDGE-VERSION', 'Failed to fetch Edge versions: ' + formatEdgeError(error), 'error')
|
||||||
|
})
|
||||||
|
|
||||||
|
edgeVersionInFlight = fetchPromise
|
||||||
|
return fetchPromise
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getSystemComponents(mobile: boolean): string {
|
export function getSystemComponents(mobile: boolean): string {
|
||||||
const osId: string = mobile ? 'Linux' : 'Windows NT 10.0'
|
|
||||||
const uaPlatform: string = mobile ? `Android 1${Math.floor(Math.random() * 5)}` : 'Win64; x64'
|
|
||||||
|
|
||||||
if (mobile) {
|
if (mobile) {
|
||||||
return `${uaPlatform}; ${osId}; K`
|
const androidVersion = 10 + Math.floor(Math.random() * 5)
|
||||||
|
return `Linux; Android ${androidVersion}; K`
|
||||||
}
|
}
|
||||||
|
|
||||||
return `${uaPlatform}; ${osId}`
|
return 'Windows NT 10.0; Win64; x64'
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getAppComponents(isMobile: boolean) {
|
export async function getAppComponents(isMobile: boolean) {
|
||||||
@@ -113,12 +137,127 @@ export async function getAppComponents(isMobile: boolean) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function fetchEdgeVersionsWithRetry(isMobile: boolean): Promise<EdgeVersionResult> {
|
||||||
|
const retry = new Retry()
|
||||||
|
return retry.run(async () => {
|
||||||
|
const versions = await fetchEdgeVersionsOnce(isMobile)
|
||||||
|
if (!versions.android && !versions.windows) {
|
||||||
|
throw new Error('Stable Edge releases did not include Android or Windows versions')
|
||||||
|
}
|
||||||
|
return versions
|
||||||
|
}, () => true)
|
||||||
|
}
|
||||||
|
|
||||||
|
async function fetchEdgeVersionsOnce(isMobile: boolean): Promise<EdgeVersionResult> {
|
||||||
|
try {
|
||||||
|
const response = await axios<EdgeVersion[]>({
|
||||||
|
url: EDGE_VERSION_URL,
|
||||||
|
method: 'GET',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
'User-Agent': 'Mozilla/5.0 (compatible; rewards-bot/2.1)' // Provide UA to avoid stricter servers
|
||||||
|
},
|
||||||
|
timeout: 10000
|
||||||
|
})
|
||||||
|
return mapEdgeVersions(response.data)
|
||||||
|
|
||||||
|
} catch (primaryError) {
|
||||||
|
const fallback = await tryNativeFetchFallback(isMobile)
|
||||||
|
if (fallback) {
|
||||||
|
log(isMobile, 'USERAGENT-EDGE-VERSION', 'Axios failed, native fetch succeeded: ' + formatEdgeError(primaryError), 'warn')
|
||||||
|
return fallback
|
||||||
|
}
|
||||||
|
throw primaryError
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function tryNativeFetchFallback(isMobile: boolean): Promise<EdgeVersionResult | null> {
|
||||||
|
let timeoutHandle: NodeJS.Timeout | undefined
|
||||||
|
try {
|
||||||
|
const controller = new AbortController()
|
||||||
|
timeoutHandle = setTimeout(() => controller.abort(), 10000)
|
||||||
|
const response = await fetch(EDGE_VERSION_URL, {
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
'User-Agent': 'Mozilla/5.0 (compatible; rewards-bot/2.1)'
|
||||||
|
},
|
||||||
|
signal: controller.signal
|
||||||
|
})
|
||||||
|
clearTimeout(timeoutHandle)
|
||||||
|
timeoutHandle = undefined
|
||||||
|
if (!response.ok) {
|
||||||
|
throw new Error('HTTP ' + response.status)
|
||||||
|
}
|
||||||
|
const data = await response.json() as EdgeVersion[]
|
||||||
|
return mapEdgeVersions(data)
|
||||||
|
} catch (error) {
|
||||||
|
if (timeoutHandle) clearTimeout(timeoutHandle)
|
||||||
|
log(isMobile, 'USERAGENT-EDGE-VERSION', 'Native fetch fallback failed: ' + formatEdgeError(error), 'warn')
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function mapEdgeVersions(data: EdgeVersion[]): EdgeVersionResult {
|
||||||
|
const stable = data.find(entry => entry.Product.toLowerCase() === 'stable')
|
||||||
|
?? data.find(entry => /stable/i.test(entry.Product))
|
||||||
|
if (!stable) {
|
||||||
|
throw new Error('Stable Edge channel not found in response payload')
|
||||||
|
}
|
||||||
|
|
||||||
|
const androidRelease = stable.Releases.find(release => release.Platform === Platform.Android)
|
||||||
|
const windowsRelease = stable.Releases.find(release => release.Platform === Platform.Windows && release.Architecture === Architecture.X64)
|
||||||
|
?? stable.Releases.find(release => release.Platform === Platform.Windows)
|
||||||
|
|
||||||
|
return {
|
||||||
|
android: androidRelease?.ProductVersion,
|
||||||
|
windows: windowsRelease?.ProductVersion
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function formatEdgeError(error: unknown): string {
|
||||||
|
if (isAggregateErrorLike(error)) {
|
||||||
|
const inner = error.errors
|
||||||
|
.map(innerErr => formatEdgeError(innerErr))
|
||||||
|
.filter(Boolean)
|
||||||
|
.join('; ')
|
||||||
|
const message = error.message || 'AggregateError'
|
||||||
|
return inner ? `${message} | causes: ${inner}` : message
|
||||||
|
}
|
||||||
|
|
||||||
|
if (error instanceof Error) {
|
||||||
|
const parts = [`${error.name}: ${error.message}`]
|
||||||
|
const cause = getErrorCause(error)
|
||||||
|
if (cause) {
|
||||||
|
parts.push('cause => ' + formatEdgeError(cause))
|
||||||
|
}
|
||||||
|
return parts.join(' | ')
|
||||||
|
}
|
||||||
|
|
||||||
|
return String(error)
|
||||||
|
}
|
||||||
|
|
||||||
|
type AggregateErrorLike = { message?: string; errors: unknown[] }
|
||||||
|
|
||||||
|
function isAggregateErrorLike(error: unknown): error is AggregateErrorLike {
|
||||||
|
if (!error || typeof error !== 'object') {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
const candidate = error as { errors?: unknown }
|
||||||
|
return Array.isArray(candidate.errors)
|
||||||
|
}
|
||||||
|
|
||||||
|
function getErrorCause(error: { cause?: unknown } | Error): unknown {
|
||||||
|
if (typeof (error as { cause?: unknown }).cause === 'undefined') {
|
||||||
|
return undefined
|
||||||
|
}
|
||||||
|
return (error as { cause?: unknown }).cause
|
||||||
|
}
|
||||||
|
|
||||||
export async function updateFingerprintUserAgent(fingerprint: BrowserFingerprintWithHeaders, isMobile: boolean): Promise<BrowserFingerprintWithHeaders> {
|
export async function updateFingerprintUserAgent(fingerprint: BrowserFingerprintWithHeaders, isMobile: boolean): Promise<BrowserFingerprintWithHeaders> {
|
||||||
try {
|
try {
|
||||||
const userAgentData = await getUserAgent(isMobile)
|
const userAgentData = await getUserAgent(isMobile)
|
||||||
const componentData = await getAppComponents(isMobile)
|
const componentData = await getAppComponents(isMobile)
|
||||||
|
|
||||||
//@ts-expect-error Errors due it not exactly matching
|
|
||||||
fingerprint.fingerprint.navigator.userAgentData = userAgentData.userAgentMetadata
|
fingerprint.fingerprint.navigator.userAgentData = userAgentData.userAgentMetadata
|
||||||
fingerprint.fingerprint.navigator.userAgent = userAgentData.userAgent
|
fingerprint.fingerprint.navigator.userAgent = userAgentData.userAgent
|
||||||
fingerprint.fingerprint.navigator.appVersion = userAgentData.userAgent.replace(`${fingerprint.fingerprint.navigator.appCodeName}/`, '')
|
fingerprint.fingerprint.navigator.appVersion = userAgentData.userAgent.replace(`${fingerprint.fingerprint.navigator.appCodeName}/`, '')
|
||||||
|
|||||||
@@ -3,11 +3,24 @@ import ms from 'ms'
|
|||||||
export default class Util {
|
export default class Util {
|
||||||
|
|
||||||
async wait(ms: number): Promise<void> {
|
async wait(ms: number): Promise<void> {
|
||||||
|
// Safety check: prevent extremely long or negative waits
|
||||||
|
const MAX_WAIT_MS = 3600000 // 1 hour max
|
||||||
|
const safeMs = Math.min(Math.max(0, ms), MAX_WAIT_MS)
|
||||||
|
|
||||||
|
if (ms !== safeMs) {
|
||||||
|
console.warn(`[Utils] wait() clamped from ${ms}ms to ${safeMs}ms (max: ${MAX_WAIT_MS}ms)`)
|
||||||
|
}
|
||||||
|
|
||||||
return new Promise<void>((resolve) => {
|
return new Promise<void>((resolve) => {
|
||||||
setTimeout(resolve, ms)
|
setTimeout(resolve, safeMs)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async waitRandom(minMs: number, maxMs: number): Promise<void> {
|
||||||
|
const delta = this.randomNumber(minMs, maxMs)
|
||||||
|
return this.wait(delta)
|
||||||
|
}
|
||||||
|
|
||||||
getFormattedDate(ms = Date.now()): string {
|
getFormattedDate(ms = Date.now()): string {
|
||||||
const today = new Date(ms)
|
const today = new Date(ms)
|
||||||
const month = String(today.getMonth() + 1).padStart(2, '0') // January is 0
|
const month = String(today.getMonth() + 1).padStart(2, '0') // January is 0
|
||||||
@@ -28,7 +41,17 @@ export default class Util {
|
|||||||
}
|
}
|
||||||
|
|
||||||
chunkArray<T>(arr: T[], numChunks: number): T[][] {
|
chunkArray<T>(arr: T[], numChunks: number): T[][] {
|
||||||
const chunkSize = Math.ceil(arr.length / numChunks)
|
// Validate input to prevent division by zero or invalid chunks
|
||||||
|
if (numChunks <= 0) {
|
||||||
|
throw new Error(`Invalid numChunks: ${numChunks}. Must be a positive integer.`)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (arr.length === 0) {
|
||||||
|
return []
|
||||||
|
}
|
||||||
|
|
||||||
|
const safeNumChunks = Math.max(1, Math.floor(numChunks))
|
||||||
|
const chunkSize = Math.ceil(arr.length / safeNumChunks)
|
||||||
const chunks: T[][] = []
|
const chunks: T[][] = []
|
||||||
|
|
||||||
for (let i = 0; i < arr.length; i += chunkSize) {
|
for (let i = 0; i < arr.length; i += chunkSize) {
|
||||||
|
|||||||
@@ -1,23 +0,0 @@
|
|||||||
import axios from 'axios'
|
|
||||||
|
|
||||||
|
|
||||||
import { Config } from '../interface/Config'
|
|
||||||
|
|
||||||
export async function Webhook(configData: Config, content: string) {
|
|
||||||
const webhook = configData.webhook
|
|
||||||
|
|
||||||
if (!webhook.enabled || webhook.url.length < 10) return
|
|
||||||
|
|
||||||
const request = {
|
|
||||||
method: 'POST',
|
|
||||||
url: webhook.url,
|
|
||||||
headers: {
|
|
||||||
'Content-Type': 'application/json'
|
|
||||||
},
|
|
||||||
data: {
|
|
||||||
'content': content
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
await axios(request).catch(() => { })
|
|
||||||
}
|
|
||||||
@@ -41,7 +41,6 @@
|
|||||||
/* Module Resolution Options */
|
/* Module Resolution Options */
|
||||||
"moduleResolution":"node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
|
"moduleResolution":"node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
|
||||||
"types": ["node"],
|
"types": ["node"],
|
||||||
"typeRoots": ["./node_modules/@types"],
|
|
||||||
// Keep explicit typeRoots to ensure resolution in environments that don't auto-detect before full install.
|
// Keep explicit typeRoots to ensure resolution in environments that don't auto-detect before full install.
|
||||||
// "baseUrl": "./", /* Base directory to resolve non-absolute module names. */
|
// "baseUrl": "./", /* Base directory to resolve non-absolute module names. */
|
||||||
// "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
|
// "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
|
||||||
@@ -66,9 +65,8 @@
|
|||||||
"resolveJsonModule": true
|
"resolveJsonModule": true
|
||||||
},
|
},
|
||||||
"include": [
|
"include": [
|
||||||
"src/**/*.ts",
|
"src/**/*.ts",
|
||||||
"src/accounts.json",
|
"src/**/*.d.ts",
|
||||||
"src/config.json",
|
|
||||||
"src/functions/queries.json"
|
"src/functions/queries.json"
|
||||||
],
|
],
|
||||||
"exclude": [
|
"exclude": [
|
||||||
|
|||||||
Reference in New Issue
Block a user