Skip to content

Commit

Permalink
Merge pull request #17 from anjannair/main [skip ci]
Browse files Browse the repository at this point in the history
[Added] Feature to check if user is bot or not
  • Loading branch information
theabbie authored Nov 12, 2020
2 parents c4d228f + 3b50b15 commit 5bba986
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
13 changes: 7 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# DevRant Bot
An NPM package to create DevRant Bots,
Super easy to Implement,
Never Care about Implementation again, just focus on functionality.
An NPM package to create DevRant bots,
Super easy to implement,
Never care about implementation again, just focus on functionality.



![image](https://user-images.githubusercontent.com/17960677/96278822-9703a480-0ff3-11eb-804e-859ef31be175.png)
## How To Use
This Package can be used to create Bots which will act when someone mentions it.
This package can be used to create bots which will act when someone mentions it.
It can then Reply to that mention with some text or image.
```js
var Bot = require('devrant-bot');
Expand All @@ -19,13 +19,14 @@ var mentions = await bot.get();
console.log(mentions);
})();
```
Which Produces,
Which produces,

```js
[
{
"rid": 2821893, //rant ID
"cid": 3308364, //comment ID
"is_bot": false, //User who has called is a bot or not
"text": "some message", //Message
"user": "theabbie", //Username of user who called
"time": 1603281044 //Timestamp of comment
Expand Down Expand Up @@ -53,7 +54,7 @@ for (msg of mentions) {
})();
```

This Makes Bot Development Really easy and you can safely focus only on the functionality rather than the implementation of the Bot.
This makes bot development really easy and you can safely focus only on the functionality rather than the implementation of the DevRant bot.

## Contributing

Expand Down
5 changes: 4 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,18 @@ module.exports = class Bot {
var bots = (await axios("https://raw.githubusercontent.com/C0D4-101/devrant-bots/master/bots.json")).data.map(b=>b.name);
var notifs = (await rs.notifications(this.token)).data.items;
var ums = [];
let is_boolean = true;
for (var notif of notifs) {
if (notif.type=="comment_mention" && notif.read==0) {
var comments = (await rs.rant(notif["rant_id"])).comments;
for (var i in comments) {
if (comments[i].id==notif["comment_id"] && bots.indexOf(comments[i]["user_username"])==-1) {
if (comments[i].id==notif["comment_id"]) {
if(bots.indexOf(comments[i]["user_username"])==-1) is_boolean = false;
var rto = comments.slice(0,i).filter(c => c["user_username"]==this.username).map(c=>{return {text: c.body, id: c.id, time: c["created_time"]}});
ums.push({
rid: notif["rant_id"],
cid: notif["comment_id"],
is_bot: is_boolean,
text: comments[i].body.split("@"+this.username).reverse()[0],
user: comments[i]["user_username"],
rto: rto,
Expand Down

0 comments on commit 5bba986

Please sign in to comment.