kik-node-api
Advanced tools
Comparing version 0.1.0 to 0.2.0
@@ -45,5 +45,9 @@ const KikClient = require("./src/kikClient") | ||
console.log(`GROUP:${group.code}: ${user.displayName} left the group`) | ||
//ban anyone once they leave | ||
Kik.setBanned(group.jid, user.jid, true) | ||
}) | ||
Kik.on("userjoinedgroup", (group, user, invitedBy) => { | ||
console.log(`GROUP:${group.code}: ${user.displayName} joined the group`) | ||
//kicking anyone once they join | ||
Kik.setGroupMember(group.jid, user.jid, false) | ||
}) | ||
@@ -50,0 +54,0 @@ |
{ | ||
"name": "kik-node-api", | ||
"version": "0.1.0", | ||
"version": "0.2.0", | ||
"description": "An API for creating kik bots (and other stuff)", | ||
@@ -18,3 +18,3 @@ "repository": { | ||
"author": "Yassien", | ||
"license": "ISC", | ||
"license": "AGPL-3.0-only", | ||
"dependencies": { | ||
@@ -21,0 +21,0 @@ "big-integer": "^1.6.40", |
@@ -5,13 +5,11 @@ # Kik Node API | ||
**THIS IS NOT AN OFFICIAL API** | ||
## Installation | ||
For now you will need to simply download the repository, NPM installation coming soon | ||
NPM: | ||
<!-- | ||
Use NPM to install foobar: | ||
```bash | ||
npm install kik-node-api | ||
npm i kik-node-api | ||
``` | ||
--> | ||
@@ -31,2 +29,3 @@ ## Usage | ||
* [Received Group Message](#received-group-message) | ||
* [Received Group Image](#received-group-image) | ||
* [Group Is Typing](#group-is-typing) | ||
@@ -37,2 +36,3 @@ * [User Left Group](#user-left-group) | ||
* [Received Private Message](#received-private-message) | ||
* [Received Private Image](#received-private-image) | ||
* [Private Is Typing](#private-is-typing) | ||
@@ -44,2 +44,5 @@ | ||
* [Send Group Message](#send-group-message) | ||
* [Kick/Add](#kick/add) | ||
* [Promote/Demote](#promote/demote) | ||
* [Ban/Unban](#ban/unban) | ||
2. [Private Requests](#private-requests) | ||
@@ -55,3 +58,3 @@ * [Send Private Message](#send-private-message) | ||
```javascript | ||
const KikClient = require("./src/kikClient") | ||
const KikClient = require("kik-node-api") | ||
@@ -96,2 +99,3 @@ Kik = new KikClient({ | ||
``` | ||
private groups have a code of null | ||
@@ -164,2 +168,16 @@ ### Events | ||
##### Received Group Image | ||
```javascript | ||
Kik.on("receivedgroupimg", (group, sender, img) => { | ||
console.log(`Received image from ${sender.jid} in group ${group.jid}`) | ||
}) | ||
``` | ||
`group`: a [`group`](#getting-started) object representing the group where the message was sent | ||
`sender`: a [`user`](#getting-started) object representing the message sender | ||
`img`: a [`buffer`](https://nodejs.org/api/buffer.html) object representing the image | ||
##### Group is Typing | ||
@@ -220,2 +238,13 @@ | ||
##### Received Private Image | ||
```javascript | ||
Kik.on("receivedprivateimg", (sender, img) => { | ||
console.log(`Received image from ${sender.jid}`) | ||
}) | ||
``` | ||
`sender`: a [`user`](#getting-started) object representing the message sender | ||
`img`: a [`buffer`](https://nodejs.org/api/buffer.html) object representing the image | ||
##### Private Is Typing | ||
@@ -253,2 +282,20 @@ | ||
##### Kick/Add | ||
```javascript | ||
Kik.setGroupMember(groupJid, userJid, bool) | ||
``` | ||
##### Promote/Demote | ||
```javascript | ||
Kik.setAdmin(groupJid, userJid, bool) | ||
``` | ||
##### Ban/Unban | ||
```javascript | ||
Kik.setBanned(groupJid, userJid, bool) | ||
``` | ||
#### Private Requests | ||
@@ -265,9 +312,3 @@ ##### Send Private Message | ||
``` | ||
<!-- | ||
## Contributing | ||
## License | ||
[MIT](https://choosealicense.com/licenses/mit/) | ||
--> | ||
[GNU AGPLv3](https://choosealicense.com/licenses/agpl-3.0/) |
@@ -7,4 +7,6 @@ module.exports = (client, callbacks, id, data) => { | ||
client.setNode(data.find("node").text) | ||
}else if(data.find("captcha-url")){ | ||
client.emit("receivedcaptcha", data.find("captcha-url").text) | ||
}else{ | ||
client.emit("receivedcaptcha", data.find("captcha-url").text) | ||
//handle others | ||
} | ||
@@ -29,3 +31,3 @@ }else if(xmlns === "jabber:iq:roster"){ | ||
jid: group.attrs.jid, | ||
code: group.find("code").text, | ||
code: group.find("code")? group.find("code").text : null, | ||
name: group.find("n").text, | ||
@@ -32,0 +34,0 @@ users: users |
@@ -6,4 +6,19 @@ module.exports = (client, callbacks, id, data) => { | ||
let group = client.groups.find((group) => {return group.jid === data.find("g").attrs.jid}) | ||
let user = client.users.find((user) => {return user.jid === data.find("message").attrs.from}) | ||
let user = { | ||
jid: data.find("message").attrs.from, | ||
username: null, | ||
displayName: null, | ||
pic: null | ||
} | ||
//status message froms contain the group JID not the user JID, ignore them | ||
if(client.params.trackUserInfo && !data.find("status")){ | ||
let userSearch = client.users.find((user) => {return user.jid === data.find("message").attrs.from}) | ||
user = (userSearch? userSearch : user) | ||
} | ||
if(client.params.trackFriendInfo && !data.find("status")){ | ||
let userSearch = client.friends.find((user) => {return user.jid === data.find("message").attrs.from}) | ||
user = (userSearch? userSearch : user) | ||
} | ||
if(data.find("body")){ | ||
@@ -13,7 +28,10 @@ client.emit("receivedgroupmsg", group, user, data.find("body").text) | ||
client.emit("grouptyping", group, user, data.find("is-typing").attrs.val === "true") | ||
}else if(data.find("images")){ | ||
client.emit("receivedgroupimg", group, user, client.imgManager.getImg(data.find("file-url").text, false)) | ||
}else if(data.find("status")){ | ||
let status = data.find("status") | ||
//user's jid is in the status here, if it wasn't set, set it | ||
user = (user.jid? user : {...user, jid: status.attrs.jid}) | ||
if(status.text.includes("left") || status.text.includes("removed")){ | ||
user = client.users.find((user) => {return user.jid === status.attrs.jid}) | ||
let kickedBy = (status.text.includes("removed")? status.text.split("has")[0].trim() : null) | ||
@@ -23,43 +41,48 @@ | ||
}else if(status.text.includes("joined")){ | ||
client.getJidInfo(data.find("status").attrs.jid) | ||
let invitedBy = (status.text.includes("invited")? status.text.split("by")[1].trim() : null) | ||
//i can't return user info since i have to recieve the getJidInfo response first for a user that just joined, | ||
//return the JID until i find a way | ||
client.emit("userjoinedgroup", group, data.find("status").attrs.jid, null) | ||
if(client.params.trackUserInfo){ | ||
client.getJidInfo(status.attrs.jid,(users) => { | ||
client.emit("userjoinedgroup", group, users[0], invitedBy) | ||
}) | ||
}else{ | ||
client.emit("userjoinedgroup", group, user, invitedBy) | ||
} | ||
} | ||
} | ||
}else if(type === "chat"){ | ||
if(data.find("xiphias-mobileremote-call")){ | ||
//safetynet message | ||
}else{ | ||
let jid = data.find("message").attrs.from | ||
}else if(type === "chat" || type === "is-typing"){ | ||
let jid = data.find("message").attrs.from | ||
let user = {jid: jid, username: null, displayName: null} | ||
let user = {jid: jid, username: null, displayName: null} | ||
if(client.params.trackFriendInfo /*|| client.params.trackUserInfo*/){ | ||
//try to find the user data in friends first | ||
let userSearch = client.friends.find(friend => {return friend.jid === jid}) | ||
if(client.params.trackFriendInfo /*|| client.params.trackUserInfo*/){ | ||
//try to find the user data in friends first | ||
let userSearch = client.friends.find(friend => {return friend.jid === jid}) | ||
user = (userSearch? userSearch : user) | ||
user = (userSearch? userSearch : user) | ||
/*if(!user){ | ||
//try to find the user data in users | ||
user = client.users.find(user => {return user.jid === jid}) | ||
//if we don't find the user in users, and user tracking is on, get his jid info (this automatically | ||
//adds him//to users), otherwise we return what we found | ||
if(!user && client.params.trackUserInfo){ | ||
client.getJidInfo(data.find("message").attrs.from, (users) => { | ||
client.emit("receivedprivatemsg", users[0], data.find("body").text) | ||
}) | ||
}else{ | ||
client.emit("receivedprivatemsg", user, data.find("body").text) | ||
} | ||
}else{ | ||
client.emit("receivedprivatemsg", user, data.find("body").text) | ||
}*/ | ||
} | ||
/* if(!user){ | ||
//try to find the user data in users | ||
user = client.users.find(user => {return user.jid === jid}) | ||
//if we don't find the user in users, and user tracking is on, get his jid info (this automatically | ||
//adds him//to users), otherwise we return what we found | ||
if(!user && client.params.trackUserInfo){ | ||
client.getJidInfo(data.find("message").attrs.from, (users) => { | ||
client.emit("receivedprivatemsg", users[0], data.find("body").text) | ||
}) | ||
}else{ | ||
client.emit("receivedprivatemsg", user, data.find("body").text) | ||
} | ||
}else{ | ||
client.emit("receivedprivatemsg", user, data.find("body").text) | ||
}*/ | ||
} | ||
if(data.find("xiphias-mobileremote-call")){ | ||
//safetynet message | ||
}else if(data.find("body")){ | ||
client.emit("receivedprivatemsg", user, data.find("body").text) | ||
}else if(type === "is-typing"){ | ||
client.emit("privatetyping", user, data.find("is-typing").attrs.val === "true") | ||
}else if(data.find("images")){ | ||
client.emit("receivedprivateimg", user, client.imgManager.getImg(data.find("file-url").text, true)) | ||
} | ||
}else if(type === "is-typing"){ | ||
let user = client.friends.find((friend) => {return friend.jid === data.find("message").attrs.from}) | ||
client.emit("privatetyping", user, data.find("is-typing").attrs.val === "true") | ||
}else if(type === "receipt"){ | ||
@@ -66,0 +89,0 @@ let receipt = data.find("receipt").attrs.type |
@@ -5,2 +5,3 @@ const EventEmitter = require("events"), | ||
Logger = require("./logger"), | ||
ImageManager = require("./imgManager") | ||
sessionUtils = require("./sessionUtils"), | ||
@@ -14,3 +15,8 @@ initialRequest = require("./requests/initialRequest"), | ||
removeFriend = require("./requests/removeFriend"), | ||
addFriend = require("./requests/addFriend") | ||
addFriend = require("./requests/addFriend"), | ||
joinGroup = require("./requests/joinGroup"), | ||
leaveGroup = require("./requests/leaveGroup"), | ||
setAdmin = require("./requests/setAdmin"), | ||
setBanned = require("./requests/setBanned"), | ||
setGroupMember = require("./requests/setGroupMember") | ||
@@ -24,2 +30,3 @@ class KikClient extends EventEmitter { | ||
this.logger = new Logger(["info", "warning", "error"], this.params.username) | ||
this.imgManager = new ImageManager(this.params.username, true) | ||
@@ -32,10 +39,8 @@ //used for tracking | ||
this.on("receivedroster", (groups, friends) => { | ||
if(this.params.trackGroupInfo){ | ||
this.groups = groups | ||
if(this.params.trackUserInfo){ | ||
//perhaps i could combine and send to make it more efficient, depending on the rate limit | ||
this.groups.forEach((group) => { | ||
this.getJidInfo(group.users) | ||
}) | ||
} | ||
this.groups = groups | ||
if(this.params.trackUserInfo){ | ||
//perhaps i could combine and send to make it more efficient, depending on the rate limit | ||
this.groups.forEach((group) => { | ||
this.getJidInfo(group.users) | ||
}) | ||
} | ||
@@ -154,4 +159,24 @@ if(this.params.trackFriendInfo){ | ||
} | ||
joinGroup(jid){ | ||
this.logger.log("info", `Joining group ${jid}`) | ||
this.connection.sendXmlFromJs(joinGroup(jid)) | ||
} | ||
leaveGroup(jid){ | ||
this.logger.log("info", `Leaving group ${jid}`) | ||
this.connection.sendXmlFromJs(leaveGroup(jid)) | ||
} | ||
setAdmin(groupJid, userJid, bool){ | ||
this.logger.log("info", `Setting admin = ${bool} for jid ${userJid} in group ${groupJid}`) | ||
this.connection.sendXmlFromJs(setAdmin(groupJid, userJid, bool)) | ||
} | ||
setBanned(groupJid, userJid, bool){ | ||
this.logger.log("info", `Setting banned = ${bool} for jid ${userJid} in group ${groupJid}`) | ||
this.connection.sendXmlFromJs(setBanned(groupJid, userJid, bool)) | ||
} | ||
setGroupMember(groupJid, userJid, bool){ | ||
this.logger.log("info", `Setting member = ${bool} for jid ${userJid} in group ${groupJid}`) | ||
this.connection.sendXmlFromJs(setGroupMember(groupJid, userJid, bool)) | ||
} | ||
} | ||
module.exports = KikClient | ||
@@ -14,8 +14,10 @@ const fs = require("fs") | ||
log(type, msg){ | ||
let date = new Date() | ||
let logTxt = `[${date.getHours()}:${date.getMinutes()}] ${type.toUpperCase()}: ${msg}` | ||
if(this.types.includes(type)){ | ||
console.log(`${type.toUpperCase()}: ${msg}`) | ||
console.log(logTxt) | ||
} | ||
fs.appendFileSync(`./logs/${this.username}.txt`, `${type.toUpperCase()}: ${msg}\n`) | ||
fs.appendFileSync(`./logs/${this.username}.txt`, `${logTxt}\n`) | ||
} | ||
} | ||
module.exports = Logger |
@@ -1,6 +0,4 @@ | ||
const config = require("../config"), | ||
crypto = require("../cryptoUtils") | ||
const crypto = require("../cryptoUtils") | ||
//true adds user, false removes him | ||
module.exports = (groupJid, userJid, bool) => { | ||
module.exports = (groupJid) => { | ||
return({ | ||
@@ -20,8 +18,3 @@ iq: { | ||
}, | ||
m: { | ||
_attributes: { | ||
r: (bool? "0": "1") | ||
}, | ||
_text: userJid | ||
} | ||
l: {} | ||
} | ||
@@ -28,0 +21,0 @@ } |
@@ -1,6 +0,4 @@ | ||
const config = require("../config"), | ||
crypto = require("../cryptoUtils") | ||
const crypto = require("../cryptoUtils") | ||
//true adds user, false removes him | ||
module.exports = (groupJid, userJid, bool) => { | ||
module.exports = (groupJid) => { | ||
return({ | ||
@@ -20,8 +18,3 @@ iq: { | ||
}, | ||
m: { | ||
_attributes: { | ||
r: (bool? "0": "1") | ||
}, | ||
_text: userJid | ||
} | ||
l: {} | ||
} | ||
@@ -28,0 +21,0 @@ } |
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
Copyleft License
License(Experimental) Copyleft license information was found.
Found 1 instance in 1 package
Mixed license
License(Experimental) Package contains multiple licenses.
Found 1 instance in 1 package
Non-permissive License
License(Experimental) A license not known to be considered permissive was found.
Found 1 instance in 1 package
82249
28
1069
305
3
70
3
2