Commit c6c7d654 authored by nanahira's avatar nanahira

first

parents
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
# Runtime data
pids
*.pid
*.seed
*.pid.lock
# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov
# Coverage directory used by tools like istanbul
coverage
*.lcov
# nyc test coverage
.nyc_output
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt
# Bower dependency directory (https://bower.io/)
bower_components
# node-waf configuration
.lock-wscript
# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release
# Dependency directories
node_modules/
jspm_packages/
# TypeScript v1 declaration files
typings/
# TypeScript cache
*.tsbuildinfo
# Optional npm cache directory
.npm
# Optional eslint cache
.eslintcache
# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/
# Optional REPL history
.node_repl_history
# Output of 'npm pack'
*.tgz
# Yarn Integrity file
.yarn-integrity
# dotenv environment variables file
.env
.env.test
# parcel-bundler cache (https://parceljs.org/)
.cache
# Next.js build output
.next
# Nuxt.js build / generate output
.nuxt
dist
# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and *not* Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public
# vuepress build output
.vuepress/dist
# Serverless directories
.serverless/
# FuseBox cache
.fusebox/
# DynamoDB Local files
.dynamodb/
# TernJS port file
.tern-port
/build
/output
.git*
.dockerignore
Dockerfile
.gitlab-ci.yml
/config.yaml
.idea
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
# Runtime data
pids
*.pid
*.seed
*.pid.lock
# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov
# Coverage directory used by tools like istanbul
coverage
*.lcov
# nyc test coverage
.nyc_output
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt
# Bower dependency directory (https://bower.io/)
bower_components
# node-waf configuration
.lock-wscript
# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release
# Dependency directories
node_modules/
jspm_packages/
# TypeScript v1 declaration files
typings/
# TypeScript cache
*.tsbuildinfo
# Optional npm cache directory
.npm
# Optional eslint cache
.eslintcache
# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/
# Optional REPL history
.node_repl_history
# Output of 'npm pack'
*.tgz
# Yarn Integrity file
.yarn-integrity
# dotenv environment variables file
.env
.env.test
# parcel-bundler cache (https://parceljs.org/)
.cache
# Next.js build output
.next
# Nuxt.js build / generate output
.nuxt
dist
# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and *not* Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public
# vuepress build output
.vuepress/dist
# Serverless directories
.serverless/
# FuseBox cache
.fusebox/
# DynamoDB Local files
.dynamodb/
# TernJS port file
.tern-port
/build
/output
/config.yaml
.idea
stages:
- build
- deploy
variables:
GIT_DEPTH: "1"
CONTAINER_TEST_IMAGE: $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG
CONTAINER_RELEASE_IMAGE: $CI_REGISTRY_IMAGE:latest
before_script:
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
build:
stage: build
tags:
- docker
script:
- docker build --pull -t $CONTAINER_TEST_IMAGE .
- docker push $CONTAINER_TEST_IMAGE
deploy_latest:
stage: deploy
tags:
- docker
script:
- docker pull $CONTAINER_TEST_IMAGE
- docker tag $CONTAINER_TEST_IMAGE $CONTAINER_RELEASE_IMAGE
- docker push $CONTAINER_RELEASE_IMAGE
only:
- master
deploy_tag:
stage: deploy
tags:
- docker
variables:
CONTAINER_TAG_IMAGE: $CI_REGISTRY_IMAGE:$CI_COMMIT_TAG
script:
- docker pull $CONTAINER_TEST_IMAGE
- docker tag $CONTAINER_TEST_IMAGE $CONTAINER_TAG_IMAGE
- docker push $CONTAINER_TAG_IMAGE
only:
- tags
FROM node:buster-slim
RUN apt update && apt -y install python3 build-essential && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
WORKDIR /usr/src/app
COPY ./package*.json ./
RUN npm ci
COPY . ./
RUN npm run build
CMD ["npm", "run", "start"]
This diff is collapsed.
This diff is collapsed.
{
"name": "wolfx-money",
"version": "1.0.0",
"description": "Offers money to a specific account",
"main": "build/run.js",
"scripts": {
"test": "node build/run.js Irrlicht"
},
"repository": {
"type": "git",
"url": "https://code.mycard.moe/nanahira/wolfx-money"
},
"author": "Nanahira",
"license": "AGPL-3.0",
"dependencies": {
"@types/node": "^14.14.20",
"@types/q": "^1.5.4",
"@types/underscore": "^1.10.24",
"mineflayer": "^2.40.1",
"q": "^1.5.1",
"typescript": "^4.1.3",
"underscore": "^1.12.0"
}
}
import { Bot, ChatMessage, createBot } from "mineflayer";
import crypto from "crypto";
import { delay } from "q";
const messageWaitForRegister = '请输入“/register <密码> <再输入一次以确定密码>”以注册';
const messageWaitForLogin = '请输入“/login <密码>”以登录';
const messageRegisterFailed = '当前IP注册量达到上限,如果是校园网玩家请联系服主解决!';
const messageLoggedIn = '已成功登录!';
function randomString(len: number) {
return crypto.randomBytes(Math.ceil(len / 2)).toString('hex').slice(0, len);
};
async function waitBotLogin(bot: Bot) {
return new Promise(done => {
bot.once("spawn", () => {
done();
})
})
}
function getChatMessageTexts(rawMessage: ChatMessage): string[] {
const messageObjects = (rawMessage.json as any).extra as any[];
if (!messageObjects) {
return [];
}
return messageObjects.map(messageObject => messageObject.text as string);
}
type MessageQueueMap = Map<string, (message: string) => void>;
function waitForMessage(messageWaitQueue: MessageQueueMap, messageToResolve: string, messageToReject?: string): Promise<string> {
return new Promise((resolve, reject) => {
messageWaitQueue.set(messageToResolve, (message: string) => {
resolve(message);
});
if (messageToReject) {
messageWaitQueue.set(messageToReject, (message: string) => {
reject(message);
});
}
});
}
async function runOnce(targetUser: string) {
const username = randomString(10);
const password = randomString(8);
const messageWaitQueue: MessageQueueMap = new Map();
console.log(`Creating bot ${username} ${password}.`);
const bot = createBot({
username,
host: '43.248.187.76',
port: 25565
});
bot.on('message', (message) => {
const messageLines = getChatMessageTexts(message);
for (let line of messageLines) {
console.log(`Message: ${line}`);
if (line.match(/已发送到/)) {
line = '_send_success';
}
if (messageWaitQueue.has(line)) {
const fun = messageWaitQueue.get(line);
messageWaitQueue.delete(line);
fun(line);
}
}
});
bot.on('end', () => {
console.error(`Bot disconnected.`);
});
//await waitBotLogin(bot);
//await delay(1000);
try {
console.log(`Waiting for connect.`);
await waitForMessage(messageWaitQueue, messageWaitForRegister, messageWaitForLogin);
console.log(`Registering.`);
bot.chat(`/reg ${password} ${password}`);
await waitForMessage(messageWaitQueue, messageLoggedIn, messageRegisterFailed);
console.log(`Paying 1000 to ${targetUser}.`);
bot.chat(`/pay ${targetUser} 1000`);
await waitForMessage(messageWaitQueue, '_send_success');
console.log(`Success.`);
} catch (e) {
console.error(`Failed: ${e.toString()}`);
} finally {
bot.end();
console.log(`Finished.`);
}
}
runOnce(process.argv[2]);
{
"compilerOptions": {
"outDir": "build",
"module": "commonjs",
"target": "esnext",
"esModuleInterop": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"sourceMap": true
},
"compileOnSave": true,
"allowJs": true,
"include": [
"*.ts",
"src/*.ts"
]
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment