Skip to content

Commit

Permalink
filter out spam posts
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Osman committed Feb 10, 2018
1 parent c362f3c commit 2fcd261
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
7 changes: 4 additions & 3 deletions src/blockchainAPI/steemAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@ export class SteemAPI {
return new Promise((resolve, reject) => {
steem.api.getDiscussionsByCreated({
"tag": tag,
"limit": 100
"limit": 10
}, (err, result) => {
if (err) {
reject(err)
} else {
resolve(
result.map(post => ({
resolve(result
.filter(x => x.category === tag)
.map(post => ({
author: post.author,
permlink: post.permlink,
created: post.created,
Expand Down
10 changes: 7 additions & 3 deletions src/bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,13 @@ export class Bot {
console.log(this._blockchainAPI)
const posts = await this._blockchainAPI.getPosts(this.communityName)
const write = await this._database.writePosts(posts, async post => {
const comment = await this._broadcaster.makeComment(post)
const vote = await this._broadcaster.makeVote(post)
return { comment, vote }
try {
const comment = await this._broadcaster.makeComment(post)
} catch(e) { }
try {
const vote = await this._broadcaster.makeVote(post)
} catch(e) { }
return { }
})
console.log(write)
} catch(e) {
Expand Down
8 changes: 5 additions & 3 deletions src/database/sqlDatabase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export class sqlDatabase {
}

async getUsers(): Promise < User[] > {
const users: Array < any > = await this._con.query('SELECT * FROM posts');
const users: Array < any > = await this._con.query('SELECT * FROM posts WHERE is_approved=1');
return users
.map(data => ({
author: data.author,
Expand All @@ -40,7 +40,7 @@ export class sqlDatabase {
}

async getPosts(): Promise < Post[] > {
const posts: Array < any > = await this._con.query('SELECT * FROM posts');
const posts: Array < any > = await this._con.query('SELECT * FROM posts WHERE is_approved=1');
return posts.map(d => ({
author: d.author,
permlink: d.permlink,
Expand All @@ -52,6 +52,7 @@ export class sqlDatabase {
}

async writePosts(posts: Post[], onInsert: (post: Post) => Promise<any>): Promise<any> {
let count = 0;
try {
const insertResponses: { post: Post, result: any }[] = await Promise.all(
posts.map(async post => {
Expand All @@ -60,7 +61,8 @@ export class sqlDatabase {
}
try {
result = await this._con.query('INSERT INTO posts SET ?', [post])
result.onInsert = await onInsert(post)
setTimeout(() => onInsert(post), 20*1000*count)
count++;
} catch (e) {
// console.log('error inserting prolly cause im there already')
}
Expand Down

0 comments on commit 2fcd261

Please sign in to comment.