import { ClaimDailyRewardMessage } from '../networking/packets/outgoing/claim-daily-reward-message';
import { GoToQuestRoomPacket } from '../networking/packets/outgoing/go-to-quest-room-packet';
import { Http } from '../services/http';
import { Client, Log, LogLevel, NrPlugin } from './../core/plugin-module';
const KEY_REGEX = /<key>(\w+)<\/key>/g;
@NRPlugin({
name: 'Collector',
author: 'tcrane+kiwi5',
enabled: true
})
class CollectorPlugin {
constructor() {
Client.on('ready', (pd, client: Client) => {
if (client.mapInfo.name === 'Nexus') {
Log('Collector', `Sending ${client.alias} to quest room`);
const gotoQuestRoom = new GoToQuestRoomPacket();
client.packetio.sendPacket(gotoQuestRoom);
} else {
Log('Collector', `Fetching calendar for ${client.alias}`);
Http.get('http://realmofthemadgodhrd.appspo*****m/dailyLogin/fetchCalendar', {
guid: client.guid,
password: client.password
}).then((response) => {
Log('Collector', `Received calendar for ${client.alias}`, LogLevel.Success);
const items = this.getKeys(response);
if (items.length === 0) {
Log('Collector', `Nothing to collect for ${client.alias}!`, LogLevel.Success);
} else {
Log('Collector', `Collecting ${items.length} item${items.length === 1 ? '' : 's'} for ${client.alias}`);
this.collect(items, client)
.then(() => Log('Collector', `Finished collecting items for ${client.alias}!`, LogLevel.Success));
}
}).catch((error) => {
Log('Collector', `Error fetching calendar for ${client.alias}`);
Log('Collector', error.message, LogLevel.Warning);
});
}
});
}
private getKeys(xml: string): string[] {
const items: string[] = [];
let match = KEY_REGEX.exec(xml);
while (match !== null) {
items.push(match[1]);
match = KEY_REGEX.exec(xml);
}
return items;
}
private collect(collectables: string[], client: Client): Promise<void> {
return new Promise((resolve, reject) => {
const collect = (item: string) => {
Log('Collector', `Collecting item(s) for ${client.alias}`, LogLevel.Info);
const claim = new ClaimDailyRewardMessage();
claim.claimKey = item;
claim.claimType = 'nonconsecutive';
client.packetio.sendPacket(claim);
if (collectables.length > 0) {
setTimeout(() => {
collect(collectables.shift());
}, 1500);
} else {
resolve();
}
};
collect(collectables.shift());
});
}
}
Nice contribution. +Rep.Change (Line 8): NRPlugin to NrPlugin, Change (Line 23): https to http
import { ClaimDailyRewardMessage } from '../networking/packets/outgoing/claim-daily-reward-message';
import { GoToQuestRoomPacket } from '../networking/packets/outgoing/go-to-quest-room-packet';
import { HttpClient } from '../services/http';
import {Library} from "../decorators/library";
import {LogLevel} from "../services/logger";
import {Logger} from "../services/logger";
import {Client} from "../core";
const KEY_REGEX = /<key>(\w+)<\/key>/g;
@Library({
name: 'Collector',
author: 'tcrane+kiwi5',
enabled: true
})
class CollectorPlugin {
constructor() {
Client.on('ready', (client: Client) => {
if (client.mapInfo.name === 'Nexus') {
Logger.log('Collector', `Sending ${client.alias} to quest room`);
const gotoQuestRoom = new GoToQuestRoomPacket();
client.packetio.sendPacket(gotoQuestRoom);
} else {
Logger.log('Collector', `Fetching calendar for ${client.alias}`);
HttpClient.get('https://realmofthemadgodhrd.appspo*****m/dailyLogin/fetchCalendar', { query: {
guid: client.guid,
password: client.password
}})
.then((response:any) => {
Logger.log('Collector', `Received calendar for ${client.alias}`, LogLevel.Success);
const items = this.getKeys(response);
if (items.length === 0) {
Logger.log('Collector', `Nothing to collect for ${client.alias}!`, LogLevel.Success);
} else {
Logger.log('Collector', `Collecting ${items.length} item${items.length === 1 ? '' : 's'} for ${client.alias}`);
this.collect(items, client)
.then(() => Logger.log('Collector', `Finished collecting items for ${client.alias}!`, LogLevel.Success));
}
}).catch((error:any) => {
Logger.log('Collector', `Error fetching calendar for ${client.alias}`);
Logger.log('Collector', error.message, LogLevel.Warning);
});
}
});
}
private getKeys(xml: string): string[] {
const items: string[] = [];
let match = KEY_REGEX.exec(xml);
while (match !== null) {
items.push(match[1]);
match = KEY_REGEX.exec(xml);
}
return items;
}
private collect(collectables: string[], client: Client): Promise<void> {
return new Promise((resolve, reject) => {
const collect = (item: string) => {
Logger.log('Collector', `Collecting item(s) for ${client.alias}`, LogLevel.Info);
const claim = new ClaimDailyRewardMessage();
claim.claimKey = item;
claim.claimType = 'nonconsecutive';
client.packetio.sendPacket(claim);
if (collectables.length > 0) {
setTimeout(() => {
collect(collectables.shift());
}, 1500);
} else {
resolve();
}
};
collect(collectables.shift());
});
}
}
import {
Client,
Library,
Runtime,
Events,
Logger,
LogLevel,
HttpClient,
GoToQuestRoomPacket,
ClaimDailyRewardMessage
} from 'nrelay';
@Library({
name: 'Auto claim daily rewards',
author: 'tcrane, kiwi5, headlesspiranha, d00dguy1337',
enabled: true
})
class CollectorPlugin {
constructor(runtime: Runtime) {
runtime.on(Events.ClientReady, (client: Client) => {
switch(client.mapInfo.name) {
case 'Nexus':
this.GoToQuestRoom(client);
break;
case 'Daily Quest Room':
this.ClaimDailyRewards(client);
break;
default:
Logger.log('Collector', `Unknown map ${client.mapInfo.name}!`, LogLevel.Error);
this.logOut(client);
};
});
}
private GoToQuestRoom(client: Client) {
Logger.log('Collector', `Sending ${client.alias} to quest room...`);
const gotoQuestRoom = new GoToQuestRoomPacket();
client.io.send(gotoQuestRoom);
}
private ClaimDailyRewards(client: Client) {
Logger.log('Collector', `Fetching calendar for ${client.alias}...`);
HttpClient
.get('https://realmofthemadgodhrd.appspo*****m/dailyLogin/fetchCalendar', {
query: {
guid: client.guid,
password: client.password
}
})
.then((response) => {
const items = this.getKeys(response);
if (items.length === 0) {
Logger.log('Collector', `Nothing to collect for ${client.alias}!`);
this.logOut(client);
} else {
Logger.log('Collector', `Collecting ${items.length} item${items.length === 1 ? '' : 's'} for ${client.alias}`);
this
.collect(items, client)
.then(() => {
Logger.log('Collector', `Finished collecting items for ${client.alias}!`)
setTimeout(() => this.logOut(client), 2000);
});
}
})
.catch((error) => {
Logger.log('Collector', `Error fetching calendar for ${client.alias}!`);
Logger.log('Collector', error.message, LogLevel.Error);
this.logOut(client);
});
}
private logOut(client: Client) {
Logger.log('Collector', `Loging out ${client.alias}`);
client.destroy();
}
private getKeys(xml: string): string[] {
const items: string[] = [];
const parseString = require("xml2js").parseString;
parseString(xml,
{
mergeAttrs: true,
trim: true,
explicitArray: false
},
function (err: any, result: any) {
const json = JSON.stringify(result);
const parsedJson = JSON.parse(json);
for (const loginReward of parsedJson.LoginRewards.NonConsecutive.Login) {
if (loginReward.key) {
items.push(loginReward.key);
}
}
}
);
return items;
}
private collect(collectables: string[], client: Client): Promise<void> {
return new Promise((resolve, reject) => {
const collect = (item: string) => {
const claim = new ClaimDailyRewardMessage();
claim.claimKey = item;
claim.claimType = 'nonconsecutive';
client.io.send(claim);
if (collectables.length > 0) {
setTimeout(() => {
collect(collectables.shift());
}, 1500);
} else {
resolve();
}
};
collect(collectables.shift());
});
}
}
{
"assetVersion": "1587115536",
"clientVersion": "1587115536",
"buildVersion": "X33.0.1",
"clientToken": "XTeP7hERdchV5jrBZEYNebAqDPU6tKU6"
}