Skip to content

Commit 9cf9b29

Browse files
author
Newmcpe
committed
feat: ability to disable modules
fix: launch in docker chore: added README in english language fix: default requirement fields if doesn't exists
1 parent 41f651c commit 9cf9b29

9 files changed

+145
-16
lines changed

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ private/
88
*.log
99
*.tsbuildinfo
1010
.env
11-
config.json
11+
cfg

README.en.md

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
[<img src="https://img.shields.io/badge/Telegram-%40Me-orange">](https://t.me/Newmcpe)
2+
3+
# fuflomuskempire
4+
5+
Bot for automatically leveling up an account in Musk Empire
6+
7+
## Modules
8+
9+
| Модуль | Статус |
10+
|--------------------------------------------------------------------------|:------:|
11+
| Auto-clicker ||
12+
| Purchase of the most cost-effective upgrades ||
13+
| Automatic collection of offline income (no need to log in every 3 hours) ||
14+
| Automatic battles in PvP mode ||
15+
16+
## Functionality
17+
18+
| Функция | Статус |
19+
|-------------------------------------|:------:|
20+
| Включение и отключение модулей бота ||
21+
| Настройка задержек ||
22+
23+
## Launch
24+
25+
Requirements:
26+
27+
- [Node.js](https://nodejs.org/)
28+
- [pnpm](https://pnpm.io/)
29+
- [Docker](https://www.docker.com/)
30+
- Create a Telegram app [here](https://my.telegram.org/)
31+
32+
### Without Docker
33+
34+
```bash
35+
pnpm install
36+
copy .env-example .env # Specify the API_ID and API_HASH of your Telegram app
37+
pnpm start
38+
```
39+
40+
### С Docker
41+
42+
Add to environment variables
43+
```
44+
CONFIG_PATH=cfg/
45+
```
46+
47+
Create a cfg folder inside the project and move your config, created during the launch without Docker, there. This action is necessary due to a bug in one of the libraries.
48+
49+
Then run docker-compose
50+
```bash
51+
docker compose up -d
52+
```
53+
54+
## Acknowledgment
55+
56+
✨ If you liked the bot and want to support the author, you can do so by registering via the author's [referral link](https://t.me/muskempire_bot/game?startapp=hero277588744). Thank you :3 ❤️

README.md

+34-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
[<img src="https://img.shields.io/badge/Telegram-%40Me-orange">](https://t.me/Newmcpe)
2+
[<img src="https://img.shields.io/badge/Language-English-red?style=flat">](https://github.com/Newmcpe/fuflomuskempire/blob/master/README.en.md)
3+
4+
15
# fuflomuskempire
26

37
Бот, автоматически прокачивающий аккаунт в Musk Empire
@@ -9,20 +13,49 @@
913
| Автокликер ||
1014
| Покупка наиболее выгодных улучшений ||
1115
| Автоматический сбор оффлайн-дохода (не нужно заходить каждые 3 часа) ||
16+
| Автоматические сражения в PvP-режиме ||
17+
18+
## Функционал
19+
20+
| Функция | Статус |
21+
|-------------------------------------|:------:|
22+
| Включение и отключение модулей бота ||
23+
| Настройка задержек ||
1224

1325
## Запуск
1426

1527
Требования:
1628

1729
- [Node.js](https://nodejs.org/)
1830
- [pnpm](https://pnpm.io/)
31+
- [Docker](https://www.docker.com/)
1932
- Создать Telegram-приложение [здесь](https://my.telegram.org/)
2033

34+
### Без Docker
35+
2136
```bash
2237
pnpm install
2338
copy .env-example .env # Укажите API_ID и API_HASH своего приложения в Telegram
2439
pnpm start
2540
```
2641

42+
### С Docker
43+
44+
Добавьте в переменные среды
45+
46+
```
47+
CONFIG_PATH=cfg/
48+
```
49+
50+
Создайте внутри проекта папку cfg и переместите туда свой конфиг, созданный при запуске без Docker. Такое действие необходимо из-за бага одной из библиотек.
51+
52+
Далее запустите docker-compose
53+
54+
```bash
55+
docker compose up -d
56+
```
57+
2758
## Благодарность
28-
✨ Если вам понравился бот и вы хотите поддержать автора, вы можете сделать это зарегистрировавшись по [реферальной ссылке](https://t.me/muskempire_bot/game?startapp=hero277588744) автора. Спасибо :3 ❤️
59+
60+
✨ Если вам понравился бот и вы хотите поддержать автора, вы можете сделать это зарегистрировавшись
61+
по [реферальной ссылке](https://t.me/muskempire_bot/game?startapp=hero277588744) автора. Спасибо :3 ❤️

docker-compose.yaml

+1-4
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,4 @@ services:
88
- .env
99
volumes:
1010
- ./bot-data:/app/bot-data
11-
- ./.config.json.tmp:/app/.config.json.tmp
12-
- type: bind
13-
source: ./config.json
14-
target: /app/config.json
11+
- ./cfg:/app/cfg

src/index.ts

+31-2
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,42 @@
11
import enquirer from 'enquirer';
22
import { JSONFileSyncPreset } from 'lowdb/node';
33
import { setupNewAccount } from './onboarding.js';
4-
import { Config, defaultConfig } from './util/config-schema.js';
4+
import {
5+
Config,
6+
defaultConfig,
7+
defaultMuskEmpireAccount,
8+
MuskEmpireAccount,
9+
} from './util/config-schema.js';
510
import { startHeartbeat } from 'modules/heartbeat.js';
611
import axios from 'axios';
712
import * as process from 'node:process';
8-
export const storage = JSONFileSyncPreset<Config>('config.json', defaultConfig);
13+
14+
export const storage = JSONFileSyncPreset<Config>(
15+
process.env.CONFIG_PATH + 'config.json',
16+
defaultConfig
17+
);
18+
// storage.update((data) => {
19+
// Object.entries(data.accounts).forEach(([key, account]) => {
20+
// Object.keys(defaultMuskEmpireAccount).forEach((defaultKey) => {
21+
// const keyOfAccount = defaultKey as keyof MuskEmpireAccount;
22+
//
23+
// // Check if the current key is undefined in the account
24+
// if (account[keyOfAccount] === undefined) {
25+
// // If undefined, assign the value from defaultMuskEmpireAccounts
26+
// account[keyOfAccount] = defaultMuskEmpireAccount[
27+
// keyOfAccount
28+
// ] as any;
29+
// }
30+
// });
31+
// // Update the account in storage
32+
// data.accounts[key] = account;
33+
// });
34+
// });
35+
936
if (!storage.data.accounts) {
1037
await setupNewAccount(true);
1138
}
39+
1240
axios.interceptors.response.use(
1341
function (response) {
1442
// Any status code that lie within the range of 2xx cause this function to trigger
@@ -47,6 +75,7 @@ const menuResponse = !!process.env.ACTION
4775

4876
switch (menuResponse.action) {
4977
case 'run':
78+
console.log('запуск бота');
5079
await startHeartbeat();
5180
break;
5281
case 'add':

src/modules/heartbeat.ts

+10-3
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@ import { combater } from './combater.js';
1010

1111
const log = Logger.create('[HEARTBEAT]');
1212

13+
const modules = {
14+
upgrader: upgrader,
15+
'offline-bonus-claimer': offlineBonusClaimer,
16+
combater: combater,
17+
};
18+
1319
export async function startHeartbeat() {
1420
for (const account of Object.values(storage.data.accounts)) {
1521
const authData = await getMuskEmpireApiKey(account.clientName);
@@ -20,9 +26,10 @@ export async function startHeartbeat() {
2026

2127
async function accountHeartbeat(account: MuskEmpireAccount, apiKey: string) {
2228
try {
23-
await offlineBonusClaimer(account, apiKey);
24-
await upgrader(account, apiKey);
25-
await combater(account, apiKey);
29+
for (const module of account.modules) {
30+
const key = module as keyof typeof modules;
31+
await modules[key](account, apiKey);
32+
}
2633
} catch (e) {
2734
log.error(
2835
Logger.color(account.clientName, Color.Cyan),

src/modules/upgrader.ts

+7-2
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,13 @@ export const upgrader = async (account: MuskEmpireAccount, apiKey: string) => {
2929
const requirement =
3030
upgrade.levels.find(
3131
(requirement) => requirement.level >= nextLevel
32-
) || upgrade.levels[upgrade.levels.length - 1];
32+
) || upgrade.levels.length > 0
33+
? upgrade.levels[upgrade.levels.length - 1]
34+
: {
35+
requiredHeroLevel: 0,
36+
requiredFriends: 0,
37+
requiredSkills: {},
38+
};
3339

3440
try {
3541
return (
@@ -44,7 +50,6 @@ export const upgrader = async (account: MuskEmpireAccount, apiKey: string) => {
4450
);
4551
} catch (e) {
4652
console.log(e, upgrade);
47-
process.exit(1);
4853
}
4954
})
5055
.reduce(

src/onboarding.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { BaseTelegramClientOptions, TelegramClient } from '@mtcute/node';
33
import { API_HASH, API_ID } from './env.js';
44
import { v4 as uuidv4 } from 'uuid';
55
import { DC_MAPPING_PROD } from '@mtcute/convert';
6-
import { defaultHamsterAccount, Proxy } from './util/config-schema.js';
6+
import { defaultMuskEmpireAccount, Proxy } from './util/config-schema.js';
77
import { toInputUser } from '@mtcute/node/utils.js';
88
import { storage } from './index.js';
99
import { authByTelegramWebApp } from './api/muskempire/musk-empire-api.js';
@@ -151,7 +151,7 @@ async function saveAccount(clientName: string) {
151151
data.accounts = {
152152
...data.accounts,
153153
[clientName]: {
154-
...defaultHamsterAccount,
154+
...defaultMuskEmpireAccount,
155155
clientName,
156156
},
157157
};

src/util/config-schema.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export type Proxy = {
1212
export type MuskEmpireAccount = {
1313
clientName: string;
1414
currentCooldowns: Cooldowns;
15+
modules: string[];
1516
};
1617

1718
export type Cooldowns = {
@@ -24,11 +25,12 @@ export const defaultConfig: Config = {
2425
accounts: {},
2526
};
2627

27-
export const defaultHamsterAccount = {
28+
export const defaultMuskEmpireAccount = {
2829
clientName: '',
2930
currentCooldowns: {
3031
noUpgradesUntil: 0,
3132
noOfflineBonusUntil: 0,
3233
noPvpUntil: 0,
3334
},
35+
modules: ['upgrader', 'offline-bonus-claimer', 'combater'],
3436
};

0 commit comments

Comments
 (0)