Skip to content

Commit

Permalink
Added checking for wrong mentions in trending tags and tags commonly …
Browse files Browse the repository at this point in the history
…used by the author
  • Loading branch information
RagePeanut committed Oct 14, 2018
1 parent 1a5c4c3 commit f95fa93
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README.md
@@ -1,4 +1,4 @@
# checky (0.1.10)
# checky (0.1.11)
A Steem bot that checks if the users mentioned in a post exist on the blockchain. If they don't, it indicates to authors that they may have made a typo or it suggests them some existing usernames close to the wrong ones.

See this bot in action here: https://steemit.com/@checky/comments
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "checky",
"version": "0.1.10",
"version": "0.1.11",
"description": "A bot that checks if mentioned Steem users exist.",
"main": "app.js",
"scripts": {
Expand Down
59 changes: 59 additions & 0 deletions utils/username-checker.js
Expand Up @@ -90,6 +90,7 @@ function correct(username, author, otherMentions, tags) {
} else if(await exists('the' + username)) return resolve('@<em></em><strong>the</strong>' + username);
// Testing for tags written as mentions
else if(tags.includes(username)) return resolve('#' + username);
else if(await isTag(author, username, tags)) return resolve('#' + username);
// No suggestion
else return resolve(null);
});
Expand Down Expand Up @@ -174,6 +175,64 @@ function inserts(username, edits, characters, mustBeValid) {
}
}

/**
* Checks if a received word is a popular tag or has been used by the author as a tag
* @param {string} author The author of the post
* @param {string} word The word to check
* @param {string[]} tags The tags of the post
* @returns {Promise<boolean>} Whether or not the word actually is a tag
*/
function isTag(author, word, tags) {
return new Promise(resolve => {
if(tags.includes(word)) return resolve(true);
resolve(isTrendingTag());
});

/**
* Checks if the word is in the 1000 first trending tags
* If not, returns whether or not it has been used by the author as a tag
* @returns {Promise<boolean>} Whether or not the word is a trending tag or has been used by the author as a tag
*/
function isTrendingTag() {
return new Promise(resolve => {
steem.api.getTrendingTags('', 1000, (err, tags) => {
if(err) {
if(log_errors) console.error(`Request error (getTrendingTags): ${ err.message } with ${ request_nodes[0] }`);
// Putting the node where the error comes from at the end of the array
request_nodes.push(request_nodes.shift());
steem.api.setOptions({ url: request_nodes[0] });
if(log_errors) console.log(`Retrying with ${ request_nodes[0] }`);
return resolve(isTrendingTag());
}
if(tags.some(tag => tag.name === word)) return resolve(true);
resolve(isTagUsedByAuthor());
});
});
}

/**
* Checks if the word has been used by the author as a tag
* @return {Promise<boolean>} Whether or not the word has been used by the author as a tag
*/
function isTagUsedByAuthor() {
return new Promise(resolve => {
steem.api.getTagsUsedByAuthor(author, (err, tags) => {
if(err) {
if(log_errors) console.error(`Request error (getTagsUsedByAuthor): ${ err.message } with ${ request_nodes[0] }`);
// Putting the node where the error comes from at the end of the array
request_nodes.push(request_nodes.shift());
steem.api.setOptions({ url: request_nodes[0] });
if(log_errors) console.log(`Retrying with ${ request_nodes[0] }`);
return resolve(isTagUsedByAuthor());
}
// Not sure how the array items are structured
if(tags.some(tag => tag === word || tag.name === word)) return resolve(true);
resolve(false);
});
});
}
}

/**
* Generates all the variations of `username` with one character replaced
* @param {string} username The username
Expand Down

0 comments on commit f95fa93

Please sign in to comment.