Skip to content

Commit

Permalink
v2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
alfathdirk committed Sep 2, 2017
1 parent 4841acf commit c208455
Show file tree
Hide file tree
Showing 9 changed files with 8,194 additions and 2,419 deletions.
5,833 changes: 4,063 additions & 1,770 deletions curve-thrift/TalkService.js

Large diffs are not rendered by default.

1,168 changes: 592 additions & 576 deletions curve-thrift/line_types.js

Large diffs are not rendered by default.

2,746 changes: 2,746 additions & 0 deletions line.thrift

Large diffs are not rendered by default.

668 changes: 668 additions & 0 deletions package-lock.json

Large diffs are not rendered by default.

33 changes: 24 additions & 9 deletions src/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@ class LineAPI {
protocol: thrift.TCompactProtocol,
transport: thrift.TBufferedTransport,
headers: this.config.Headers,
path: this.config.LINE_HTTP_URL
path: this.config.LINE_HTTP_URL,
https: true
}) {
options.headers['X-Line-Application'] = 'DESKTOPMAC 10.10.2-YOSEMITE-x64 MAC 4.5.0';
this.options = options;
this.connection =
thrift.createHttpConnection(this.config.LINE_DOMAIN, 443, this.options);
Expand All @@ -36,6 +38,7 @@ class LineAPI {
return err;
});
this._client = thrift.createHttpClient(TalkService, this.connection);

}

_tokenLogin(authToken, certificate) {
Expand All @@ -48,14 +51,16 @@ class LineAPI {
this.setTHttpClient();
return new Promise((resolve, reject) => {
this._client.getAuthQrcode(true, 'Alfathdirk-PC',(err, result) => {
// console.log('here')
const qrcodeUrl = `line://au/q/${result.verifier}`;
qrcode.generate(qrcodeUrl,{small: true});
console.log(`\n\nlink qr code is: ${qrcodeUrl}`)
console.info(`\n\nlink qr code is: ${qrcodeUrl}`)
Object.assign(this.config.Headers,{ 'X-Line-Access': result.verifier });
unirest.get('http://gd2.line.naver.jp/Q')
unirest.get('https://gd2.line.naver.jp/Q')
.headers(this.config.Headers)
.timeout(120000)
.end(async (res) => {
console.log(res);
const verifiedQr = res.body.result.verifier;
const { authToken, certificate } =
await this._client.loginWithVerifierForCerificate(verifiedQr);
Expand All @@ -64,7 +69,7 @@ class LineAPI {
this.setTHttpClient(this.options);
resolve({ authToken, certificate });
});
});
});
});
}

Expand All @@ -81,12 +86,12 @@ class LineAPI {
this.provider, rsaCrypto.keyname, rsaCrypto.credentials,
true, this.config.ip, 'purple-line', '',
(err, result) => {
console.log
if (err) {
console.log('LoginFailed');
console.error(err);
return reject(err);
}
console.log(result);
this._client.pinCode = result.pinCode;
this.alertOrConsoleLog(
`Enter Pincode ${result.pinCode}
Expand Down Expand Up @@ -177,13 +182,24 @@ class LineAPI {
return this._client.inviteIntoGroup(0, group, member)
}

async _updateGroup(group) {
return await this._client.updateGroup(0, group)
}

_getContacts(mid) {
return this._client.getContacts(mid)
}

async _getGroups(groupId) {
const g = await this._client.getGroups(groupId);
return g;
return await this._client.getGroups(groupId);
}

async _getGroup(groupId) {
return await this._client.getGroup(groupId);
}

async _reissueGroupTicket(groupId) {
return await this._client.reissueGroupTicket(groupId);
}

async _sendImage(message,filepaths, filename = 'media') {
Expand Down Expand Up @@ -231,8 +247,7 @@ class LineAPI {
}

_fetchOperations(revision, count = 5) {
this.options.path = this.config.LINE_POLL_URL
this.setTHttpClient();
// this.options.path = this.config.LINE_POLL_URL
return this._client.fetchOperations(revision, count);
}

Expand Down
7 changes: 6 additions & 1 deletion src/bot.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
const LineConnect = require('./connect');
let LINE = require('./main.js');

let client = new LineConnect();
const auth = {
authToken: 'EkhKpJrY4uAEW0eLJtQb.DJL32RkCVw/GY+QFfzT2IW.Glp/DCyaiJSF7+yDbCsP9OHsXzdJvE/cHOhGu6pqDAA=',
certificate: '2c0a5dbde000c76c2fa05510742ac44ac6f44a26cb78dd83304caf5da0273371'
}

let client = new LineConnect(auth);

client.startx().then(async (res) => {
let ops;
Expand Down
3 changes: 2 additions & 1 deletion src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const { hostname, platform } = require('os');
const whichPlatform = platform() === 'darwin' ? 'MAC' : 'win32';

const config = {
// LINE_DOMAIN: 'gf.line.naver.jp',
LINE_DOMAIN: 'gd2.line.naver.jp',
LINE_OS_URL: 'os.line.naver.jp',
LINE_HTTP_URL: '/api/v4/TalkService.do',
Expand All @@ -21,7 +22,7 @@ const config = {
platform: whichPlatform,
EMAIL_REGEX: /[^@]+@[^@]+\.[^@]+/,
Headers: {
'User-Agent': 'LINE for Alfath'
'User-Agent':'DESKTOP:MAC:10.10.2-YOSEMITE-x64(4.5.0)'
}
};

Expand Down
20 changes: 7 additions & 13 deletions src/connect.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,10 @@ class LineConnect extends LineAPI {
constructor(options) {
super();

this.config.Headers['X-Line-Application'] =
'IOSIPAD 6.0.0 iPhone OS 9.0.2';
this.config.Headers['X-Line-Access'] = '';

if (typeof options !== 'undefined') {
this.authToken = options.authToken;
this.certificate = options.certificate;
this.config.Headers['X-Line-Access'] = options.authToken;
} else {

}
}

Expand All @@ -23,14 +17,14 @@ class LineConnect extends LineAPI {
this._qrCodeLogin().then(async (res) => {
this.authToken = res.authToken;
this.certificate = res.certificate;
console.log(`[*] Token: ${this.authToken}`);
console.log(`[*] Certificate: ${res.certificate}\n`);
console.info(`[*] Token: ${this.authToken}`);
console.info(`[*] Certificate: ${res.certificate}\n`);
let { mid, displayName } = await this._client.getProfile();
console.log(`[*] mid: ${mid}\n`);
console.log(`[*] Name: ${displayName}\n`);
console.log(`NOTE: Dont forget , put your mid and admin on variable 'myBot' in main.js \n`);
console.log(`Regrads Alfathdirk and thx for TCR Team \n`);
console.log(`=======BOT RUNNING======\n`);
console.info(`[*] mid: ${mid}\n`);
console.info(`[*] Name: ${displayName}\n`);
console.info(`NOTE: Dont forget , put your mid and admin on variable 'myBot' in main.js \n`);
console.info(`Regrads Alfathdirk and thx for TCR Team \n`);
console.info(`=======BOT RUNNING======\n`);
await this._tokenLogin(this.authToken, this.certificate);
resolve();
});
Expand Down
135 changes: 86 additions & 49 deletions src/main.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const LineAPI = require('./api');
const { Message, OperationType } = require('../curve-thrift/line_types');
const { Message, OpType, Location } = require('../curve-thrift/line_types');
let exec = require('child_process').exec;

const myBot = ['u78b179f959eba71ec2de09233281c49e','uc93c736a8b385208c2aa7aed58de2ceb','u236b88bf1eac2b90e848a6198152e647','u763977dab29cbd6fa0cbfa9f159b768b'];
Expand All @@ -22,10 +22,10 @@ class LINE extends LineAPI {
}

getOprationType(operations) {
for (let key in OperationType) {
if(operations.type == OperationType[key]) {
for (let key in OpType) {
if(operations.type == OpType[key]) {
if(key !== 'NOTIFIED_UPDATE_PROFILE') {
console.log(`[* ${operations.type} ] ${key} `);
console.info(`[* ${operations.type} ] ${key} `);
}
}
}
Expand Down Expand Up @@ -57,22 +57,25 @@ class LINE extends LineAPI {

}

if(operation.type == 28){ //ada reader
let checkReader = this.checkReader;
for (let i = 0; i < checkReader.length; i++) {
for (let key in checkReader[i]) {
let oparam2 = operation.param2.split('\u001e');
if(oparam2.includes(checkReader[i].messageId)) {
let usersList = checkReader[i].users;
let timeList = checkReader[i].timeSeen;
if(!usersList.includes(operation.param1)){
usersList.push(operation.param1);
timeList.push(operation.createdTime.toString());
if(operation.type == 55){ //ada reader

const idx = this.checkReader.findIndex((v) => {
if(v.group == operation.param1) {
return v
}
})
if(this.checkReader.length < 1 || idx == -1) {
this.checkReader.push({ group: operation.param1, users: [operation.param2], timeSeen: [operation.param3] });
} else {
for (var i = 0; i < this.checkReader.length; i++) {
if(this.checkReader[i].group == operation.param1) {
if(!this.checkReader[i].users.includes(operation.param2)) {
this.checkReader[i].users.push(operation.param2);
this.checkReader[i].timeSeen.push(operation.param3);
}
}
}
}
}

}

if(operation.type == 13) { // diinvite
Expand All @@ -85,21 +88,6 @@ class LINE extends LineAPI {
this.getOprationType(operation);
}

searchReader(seq) {
const messageID = seq.id;
let groupID = seq.to;
let dataReader = {
messageId: messageID,
group: groupID,
users: [],
timeSeen: [],
};

if(myBot.includes('uc93c736a8b385208c2aa7aed58de2ceb')) {
this.checkReader.push(dataReader);
}
}

async cancelAll(gid) {
let { listPendingInvite } = await this.searchGroup(gid);
if(listPendingInvite.length > 0){
Expand All @@ -125,16 +113,6 @@ class LINE extends LineAPI {
}
}

removeReaderByGroup(groupID) {
let i = 0;
this.checkReader.map((v) => {
if(v.group == groupID) {
this.checkReader.splice(i,1);
}
i++
})
}

setState(seq) {
if(isAdminOrBot(seq.from)){
let [ actions , status ] = seq.text.split(' ');
Expand All @@ -154,14 +132,27 @@ class LINE extends LineAPI {
users = cs[i].users;
}
}

let contactMember = await this._getContacts(users);
return contactMember.map((z) => {
return z.displayName;
}).join(',');
});
}

removeReaderByGroup(groupID) {
const groupIndex = this.checkReader.findIndex(v => {
if(v.group == groupID) {
return v
}
})

if(groupIndex != -1) {
this.checkReader.splice(groupIndex,1);
}
}

async textMessage(txt, seq) {
const [ cmd, payload ] = txt.split(' ');
const messageID = seq.id;

if(txt == 'cancel' && this.stateStatus.cancel == 1) {
Expand All @@ -185,7 +176,7 @@ class LINE extends LineAPI {
})
}

if(txt === 'kickall' && this.stateStatus.kick == 1) {
if(txt === 'kickall' && this.stateStatus.kick == 1 && isAdminOrBot(seq.from)) {
let { listMember } = await this.searchGroup(seq.to);
for (var i = 0; i < listMember.length; i++) {
if(!isAdminOrBot(listMember[i].mid)){
Expand All @@ -195,15 +186,17 @@ class LINE extends LineAPI {
}

if(txt == 'setpoint') {
this._sendMessage(seq, `SetPoint for check Reader .`);
this._sendMessage(seq, `SetPoint for check Reader.`);
this.removeReaderByGroup(seq.to);
}

if(txt == 'clear') {
this.checkReader = []
}

if(txt == 'recheck'){
console.log(this.checkReader);
let rec = await this.recheck(this.checkReader,seq.to);
let xz = rec.split(',');
this._sendMessage(seq, `== tukang bengong ==\n${xz.join('\n')}`);
this._sendMessage(seq, `== tukang bengong ==\n${rec.join('\n')}`);

}

Expand Down Expand Up @@ -239,6 +232,50 @@ class LINE extends LineAPI {
this._sendMessage(seq,res)
})
}

const joinByUrl = ['ourl','curl'];
if(joinByUrl.includes(txt)) {
this._sendMessage(seq,`Updating group ...`);
let updateGroup = await this._getGroup(seq.to);
updateGroup.preventJoinByTicket = true;
if(txt == 'ourl') {
updateGroup.preventJoinByTicket = false;
const groupUrl = await this._reissueGroupTicket(seq.to)
this._sendMessage(seq,`Line group = line://ti/g/${groupUrl}`);
}
await this._updateGroup(updateGroup);
}

if(cmd === 'ip') {
exec(`curl ipinfo.io/${payload}`,(err, res) => {
const result = JSON.parse(res);
if(typeof result.error == 'undefined') {
const { org, country, loc, city, region } = result;
try {
const [latitude, longitude ] = loc.split(',');
let location = new Location();
Object.assign(location,{
title: `Location:`,
address: `${org} ${city} [ ${region} ]\n${payload}`,
latitude: latitude,
longitude: longitude,
phone: null
})
const Obj = {
text: 'Location',
location : location,
contentType: 0,
}
Object.assign(seq,Obj)
this._sendMessage(seq,'Location');
} catch (err) {
this._sendMessage(seq,'Not Found');
}
} else {
this._sendMessage(seq,'Location Not Found , Maybe di dalem goa');
}
})
}
}

}
Expand Down

0 comments on commit c208455

Please sign in to comment.