import Ptt from 'ptt-client';
import {Article, Board} from 'ptt-client/sites/ptt/model';
global.WebSocket = require('ws');
(async function() {
const ptt = new Ptt();
ptt.once('connect', () => {
const kickOther = true;
if (!await ptt.login('username', 'password', kickOther))
return;
let query = ptt.select(Article).where('boardname', 'C_Chat');
let article = await query.get();
let offset = articles[article.length-1].id - 1;
query.where('id', offset);
let articles2 = await query.get();
query = ptt.select(Article)
.where('boardname', 'C_Chat')
.where('title', '閒聊')
.where('title', '京阿尼')
.where('push', '20');
articles = await query.get();
query.where('id', articles[articles.length-1].id);
let article = await query.getOne();
query = ptt.select(Board).where('entry', 'class');
let classBoards = await query.get();
query = ptt.select(Board).where('entry', 'hot');
let hotBoards = await query.get();
query = ptt.select(Board).where('entry', 'favorite');
let favorites = await query.get();
query = ptt.select(Board).where('prefix', 'c_cha');
let boards = await query.get();
if (favorites[0].folder) {
query.where('offsets', [favorites[0].id]);
let favorites2 = await query.get();
}
let mails = await ptt.getMails();
let mail = await ptt.getMail(mails[0].sn);
await ptt.logout();
});
})();