├── test.js
├── configFiles
├── test.json
├── poll_voters_Config.json
├── poll_Config.json
└── userStat.json
├── .gitignore
├── .idea
├── .gitignore
├── misc.xml
├── vcs.xml
├── modules.xml
└── aqua-wa-automate.iml
├── Procfile
├── image.png
├── resources.js
├── package.json
├── README.md
├── role.js
├── server.js
└── features.js
/test.js:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/configFiles/test.json:
--------------------------------------------------------------------------------
1 | {"name":"shubham"}
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Project exclude paths
2 | /node_modules/
--------------------------------------------------------------------------------
/.idea/.gitignore:
--------------------------------------------------------------------------------
1 | # Default ignored files
2 | /workspace.xml
--------------------------------------------------------------------------------
/Procfile:
--------------------------------------------------------------------------------
1 | "scripts": {
2 | "start": "node server.js"
3 | },
--------------------------------------------------------------------------------
/configFiles/poll_voters_Config.json:
--------------------------------------------------------------------------------
1 | {"list":["testentry","919325410051@c.us"]}
--------------------------------------------------------------------------------
/image.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shubham8550/aqua-wa-automate/Working/image.png
--------------------------------------------------------------------------------
/resources.js:
--------------------------------------------------------------------------------
1 | module.exports = { test }
2 |
3 | function test() {
4 | console.log("hiiii")
5 | }
--------------------------------------------------------------------------------
/configFiles/poll_Config.json:
--------------------------------------------------------------------------------
1 | {"title":" best anime","polldate":"2020-09-02","candis":[{"name":" craig","votes":1}]}
--------------------------------------------------------------------------------
/configFiles/userStat.json:
--------------------------------------------------------------------------------
1 | {"users":{"Shubham":{"totalmsgs":1500,"repoted":1},"Shu2ham":{"totalmsgs":320,"repoted":1},"lol":{"totalmsgs":200,"repoted":1},"lol3":{"totalmsgs":8,"repoted":1}}}
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/.idea/aqua-wa-automate.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "aqua-wa-automate",
3 | "version": "1.0.0",
4 | "description": "",
5 | "main": "server.js",
6 | "scripts": {
7 | "test": "node test.js",
8 | "start": "node server.js"
9 | },
10 | "author": "Shubham Badgujar",
11 | "license": "ISC",
12 | "dependencies": {
13 | "@open-wa/wa-automate": "^2.0.12",
14 | "@open-wa/wa-decrypt": "^2.0.1",
15 | "multer": "^1.4.2",
16 | "request": "^2.88.2"
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # aqua-wa-automate
2 | Aqua Bot
3 |
4 | note: use jikan="https://api.jikan.moe/v3/" in feature.js in debug environment
5 | Status :working
6 |
7 | Todo:
8 | -
9 | - Update This Readme
10 | - Reset Structure
11 | - Gif To Sticker
12 | - Plugin System
13 | - Express Control Panel
14 | - Moderation System(Non priortized)
15 |
16 | ---
17 |
18 | Use:
19 | -
20 | - npm install
21 | - node server.js
22 | (After this scan qr in console )
23 |
24 |
25 |
26 | Issues:
27 | -
28 | No Issues
29 |
30 | ## Prerequisites
31 | - Node.js
32 |
33 |
34 |
--------------------------------------------------------------------------------
/role.js:
--------------------------------------------------------------------------------
1 | // const nodeHtmlToImage = require('node-html-to-image')
2 | //
3 | // const wa = require('@open-wa/wa-automate');
4 | // const request = require('request');
5 | //
6 | //
7 | //
8 | //
9 | // client.toBase64(request(""))
10 | const feature = require('./features.js');
11 | const statFile="userStat.json";
12 | //init
13 | // var data={
14 | // users:{
15 | // user_id:{
16 | // totalmsgs:0,
17 | // repoted: 0,
18 | //
19 | // }
20 | // }
21 | // }
22 | // feature.saveJsonFile("userStat.json",data)
23 |
24 | var obj=feature.readJsonFile(statFile)
25 |
26 | function getRank(sender){
27 | let msg= obj.users[sender].totalmsgs;
28 | //delete obj.users[sender];
29 | let rank=1;
30 | for (user in obj.users) {
31 | if(obj.users[user].totalmsgs>msg){
32 | rank=rank+1;
33 |
34 | }
35 | }
36 | return rank;
37 | }
38 |
39 | console.log("Rank is "+getRank("Shu2ham"))
40 |
41 |
42 | //console.log(obj.users.hasOwnProperty("lol3"))
43 |
44 | //obj.users["lol3"]={totalmsgs:320,repoted: 1, };
45 | //feature.saveJsonFile(statFile,obj)
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 | // const fs = require('fs');
69 | // nodeHtmlToImage({
70 | // output: './image.png',
71 | // html: '
Trying is a part of failing
2020-08-13 | Category: Life
'
108 | // })
109 | // .then(() => console.log('The image was created successfully!'))
110 | //
111 |
--------------------------------------------------------------------------------
/server.js:
--------------------------------------------------------------------------------
1 |
2 |
3 | const feature = require('./features.js');
4 | const wa = require('@open-wa/wa-automate');
5 | const request = require('request');
6 | const fs = require('fs');
7 | const jikan="https://api.jikan.moe/v3/";
8 | //const jikan="http://192.168.0.108:8000/v3/";
9 | const launchConfig = {
10 | useChrome: true,
11 | autoRefresh:true,
12 | disableSpins: true,
13 | blockCrashlogs: true,
14 | headless: true,
15 | // cacheEnabled:false,
16 | executablePath: "/usr/bin/chromium-browser",
17 | // customUserAgent:"Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.121 Safari/537.36",
18 | // cacheEnabled: false,
19 | // chromiumArgs: [
20 | // '--no-sandbox',
21 | // '--disable-setuid-sandbox'
22 | // ]
23 | };
24 | wa.create(launchConfig).then(client => start(client));
25 |
26 |
27 | function start(client) {
28 | client.onMessage(message => {
29 | // if(message.isGroupMsg ){
30 | if (message.body.startsWith("/anime")) {
31 | feature.animeSearch(client,message,message.body.slice(6))
32 | }else if (message.body.startsWith("/manga")) {
33 | feature.mangaSearch(client,message,message.body.slice(6))
34 | }else if (message.body.startsWith("/sauce")) {
35 | feature.souceAdapter(client,message)
36 | }else if (message.body.startsWith("/poll")) {
37 | feature.getpoll(client,message)
38 | } else if (message.body.startsWith("/vote")) {
39 | feature.voteadapter(client,message)
40 | } else if (message.body.startsWith("/resetpoll")) {
41 | feature.adminpollreset(client,message,message.body.slice(10))
42 | } else if (message.body.startsWith("/add")) {
43 | feature.addcandidate(client,message,message.body.slice(4))
44 | } else if (message.body.toLowerCase().startsWith("/art")){
45 | feature.redditContent(client,message,"awwnime");
46 | } else if (message.body.toLowerCase().startsWith("/meme")){
47 | feature.redditContent(client,message,"");
48 | } else if (message.body.toLowerCase().startsWith("/wall")){
49 | feature.redditContent(client,message,"Animewallpaper");
50 | } else if (message.body.toLowerCase().startsWith("/help")){
51 | feature.helpContent(client,message,);
52 | } else if (message.body.toLowerCase().startsWith("/sticker") || message.body.toLowerCase().startsWith("/stiker")){
53 | feature.sticker(client,message,);
54 | } else if (message.body.toLowerCase().includes("chat.whatsapp.com/")){
55 | client.reply(message.from,"*WARNING*\n Invite links not Allowed",message.id);
56 | } else if (message.body.toLowerCase().startsWith("/rules")){
57 | //rulesContent(client,message,);
58 | // saveJsonFile("test.json",{name:"shubham"})
59 | // console.log(readJsonFile("test.json").name)
60 | client.getChatById(message.chatId).then(value => {
61 | const { desc } = value.groupMetadata
62 | client.reply(message.from, '*' + message.chat.name + '*\n🌠️\n✨️ Description:\n ' + `${desc}`,message.id,true)
63 | })
64 |
65 | //client.sendStickerfromUrl(message.from,"https://svg2png1.glitch.me/?u="+message.sender.pushname+"&rank=12&level=307");
66 | //client.reply(message.chatId,message.sender.formattedName+" | "+message.sender.name+" | "+message.sender.shortName+" | "+message.sender.pushname,message.id);//Shubham Badgujar Jio | Shubham Badgujar Jio | Shubham | Magician Master
67 | }
68 |
69 | // }
70 |
71 |
72 |
73 | // if (message.body === 'Hi') {
74 | // // client.sendStickerfromUrl(message.from,"https://raw.githubusercontent.com/open-wa/wa-automate-nodejs/master/release.png")
75 | //
76 | // client.sendImageAsSticker(message.from,)
77 | // //client.sendText(message.from, '👋 Hello!');
78 | // }
79 | });
80 | }
81 |
82 |
83 |
84 | // client.getGroupInviteLink(message.chatId).then(value => {
85 | // console.log(value)
86 | // }).catch(reason => {
87 | // console.log(reason)
88 | // })
89 |
90 | // client.inviteInfo("https://chat.whatsapp.com/LJYGah65GKtBChoIttot3W").then(value => {
91 | // console.log(value)
92 | // })
93 |
94 |
95 | // client.getGroupAdmins(message.chatId).then(value => {
96 | // console.log(value+message.author)
97 | // console.log(value.toString().includes(message.author))
98 | // });
99 |
--------------------------------------------------------------------------------
/features.js:
--------------------------------------------------------------------------------
1 | const request = require('request');
2 | const fs = require('fs');
3 | const dm = require('@open-wa/wa-decrypt');
4 | const multer = require('multer');
5 | const upload = multer();
6 |
7 | const jikan="https://api.jikan.moe/v3/";
8 | module.exports = { helpContent,souceAdapter,sticker,addcandidate,voteadapter ,helpContent,getpoll ,adminpollreset,animeSearch ,mangaSearch,redditContent,readJsonFile,saveJsonFile}
9 | const pollfile="poll_Config.json";
10 | const voterslistfile="poll_voters_Config.json";
11 |
12 | function voteadapter(client,message){
13 | console.log("flag1")
14 |
15 | //voteadapter
16 | if (isvoted(message)){
17 | client.reply(message.chatId,"*you already voted for this poll*",message.id,true);
18 | return;
19 | }
20 | //console.log("flag2")
21 | let data=readJsonFile(pollfile)
22 |
23 | if(data["candis"]==="null") {
24 | client.reply(message.chatId,"No candidates Added In Poll",message.id,true);
25 | return;
26 | }
27 |
28 | let arr=data["candis"]
29 | // console.log(arr)
30 | for (let i = 0; i < arr.length; i++) {
31 | if(message.body.includes((i+1).toString())){
32 | //console.log(i)
33 | addvote(client,message,i);
34 | return;
35 | }
36 | }
37 | console.log("here")
38 | client.reply(message.chatId,"Wrong Format",message.id,true);
39 |
40 | }
41 | async function souceAdapter(client,message){
42 | let { type, body, from, t, sender, isGroupMsg, chat, caption, isMedia, mimetype, quotedMsg, chatId, Contact, author } = message
43 | if (quotedMsg && quotedMsg.type == 'image') {
44 | const mediaData = await dm.decryptMedia(quotedMsg)
45 |
46 |
47 | const url = 'https://trace.moe/api/search';
48 |
49 |
50 | var formData = {
51 | image: {
52 | value: mediaData, // Upload the first file in the multi-part post
53 | options: {
54 | filename: 'image'
55 | }
56 | }
57 | };
58 |
59 | const options = {
60 | uri: url,
61 | formData: formData,
62 | method: 'POST'
63 | }
64 |
65 | request(options, (err, response, body) => {
66 | let daten;
67 | if (err) {
68 | console.log('Error!');
69 | } else {
70 | console.log('URL: ' + body);
71 | try {
72 | daten = JSON.parse(body);
73 | } catch (error) {
74 | // console.log("keine Sauce gefunden")
75 | client.sendText(message.from, "Could not find source");
76 | return
77 | }
78 |
79 | var anime = "Sauce Search Result:\n"
80 | for (let index = 1; index < daten.docs.length; index++) {
81 |
82 | var anime = anime + index + ". result " + daten.docs[index].title_english + "\n"
83 |
84 | }
85 | console.log(anime)
86 | client.reply(message.from, anime, message.id, true);
87 | }
88 | })
89 |
90 |
91 | // form.append('image','', {
92 | // filename: 'myfile.txt',
93 | // contentType: 'text/plain'
94 | // }, fs.createReadStream(mediaData));
95 |
96 | } else {
97 | client.sendText(from, 'You did not quote a picture, Baka! To Search For Sauce, reply/quote an image with "/sauce" as caption')
98 | }
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 | }
110 |
111 | async function addcandidate(client,message, candi){
112 | if(await isGroupAdmin(client,message,message,message.author)){
113 | // console.log("admin logging")
114 | }else {
115 |
116 | client.reply(message.chatId,"Ask Admin to add "+candi,message.id,true);
117 | return;
118 | }
119 | let data = readJsonFile(pollfile)
120 |
121 | if(data["candis"]==="null"){
122 | // let arra=[];
123 | let cd={
124 | name:candi,
125 | votes:0
126 | };
127 | // cd.put("name",candi);
128 | // cd.put("votes",0);
129 | // arra.push(cd);
130 | delete data["candis"];
131 | // data.put("candis",arra);
132 | data["candis"]=[cd,]
133 |
134 | }else {
135 | if(data["candis"].length >= 9){
136 | client.reply(message.chatId,"*you cant add more than 9 candidates in poll*",message.id,true);
137 | return;
138 | }
139 |
140 | let cd={
141 | name:candi,
142 | votes:0
143 | };
144 |
145 |
146 | data["candis"].push(cd);
147 |
148 | }
149 |
150 |
151 |
152 |
153 | //l(base.toString());
154 | saveJsonFile(pollfile,data)
155 | client.reply(message.chatId,"Poll Candidate "+candi+" Added Successfully",message.id,true);
156 |
157 | }
158 |
159 |
160 | function addvote(client,message,num) {
161 | console.log(num)
162 |
163 | let data = readJsonFile(pollfile)
164 |
165 | let vts=data["candis"][num]["votes"];
166 |
167 | vts=vts+1;
168 |
169 | delete data["candis"][num]["votes"];
170 | data["candis"][num]["votes"]=vts
171 | console.log(data)
172 | saveJsonFile(pollfile,data)
173 | let op;
174 | op="*Voted successfully on "+data["candis"][num]["name"]+"*\n*Anime Guild of Maharashtra*\n*Title : "+data["title"]+"*\n";
175 | let ls="";
176 | let arr=data["candis"];
177 | for (let i = 0; i < arr.length; i++) {
178 | let cd=arr[i];
179 | ls= ls+((i+1).toString())+")"+cd["name"]+" : ["+cd["votes"]+" Votes] \n";
180 |
181 | }
182 |
183 | op=op+ls;
184 | op=op+"\n For voting use command */vote candidate-number* \n Example */vote 2*";
185 |
186 | client.reply(message.chatId,op,message.id,true);
187 | addvotedlog(message);
188 |
189 |
190 | }
191 |
192 | function isvoted(message) {
193 |
194 | let data=readJsonFile(voterslistfile)
195 | // console.log(data["list"])
196 | return data["list"].includes(message.author);
197 |
198 | }
199 | function addvotedlog(message) {
200 | let data=readJsonFile(voterslistfile)
201 | data["list"].push(message.author)
202 | saveJsonFile(voterslistfile,data);
203 | }
204 |
205 |
206 |
207 | function getpoll(client,message){
208 |
209 | let data=readJsonFile(pollfile)
210 | //console.log(data)
211 | let op="";
212 | if(data["candis"]=="null"){
213 | op="*Anime Guild of Maharashtra*\n*Title : "+data["title"]+"*\n No candidates Added \n use (*\\add candidate-name*) to add candidate";
214 | }else {
215 | op="*Anime Guild of Maharashtra*\n*Title : "+data["title"]+"*\n";
216 | let ls="";
217 | let arr=data["candis"];
218 | for (let i = 0; i < arr.length; i++) {
219 | let cd=arr[i];
220 | ls= ls+(i+1).toString()+")"+cd["name"]+" : ["+cd["votes"]+" Votes] \n";
221 |
222 | }
223 |
224 | op=op+ls;
225 | op=op+"\n For voting use command */vote candidate-number* \n Example */vote 2*";
226 |
227 | }
228 | client.reply(message.chatId,op,message.id,true)
229 |
230 | }
231 | async function adminpollreset(client,message,polltitle) {
232 | if(await isGroupAdmin(client,message,message.author)){
233 | var datetime = new Date();
234 | // savefile(todaysdate+".json",getFile(pollfile));
235 | try{
236 | saveJsonFile("poll_logs.json",readJsonFile(pollfile))
237 | }catch (e) {
238 | console.log("poll file not eist for backup")
239 | }
240 |
241 | let base={
242 | title:polltitle,
243 | polldate:datetime.toISOString().slice(0,10),
244 | candis:"null"
245 | }
246 | //l(base.toString());
247 | saveJsonFile(pollfile,base)
248 |
249 | client.reply(message.chatId,"*Poll Created Successfully*\n Title : "+polltitle+"\n use (\\add candidate-name) to add candidate",message.id);
250 |
251 | //voterresetter
252 |
253 | let data={
254 | list:["testentry"]
255 | }
256 |
257 | saveJsonFile(voterslistfile,data);
258 | }else {
259 | client.reply(message.chatId,"*Admin Only Command*",message.id)
260 | }
261 |
262 |
263 | }
264 |
265 | async function sticker(client,message) {
266 | let { type, body, from, t, sender, isGroupMsg, chat, caption, isMedia, mimetype, quotedMsg, chatId, Contact, author } = message
267 | let args = body.trim().split(' ')
268 | let isUrl = new RegExp(/https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)/gi)
269 | if (isMedia) {
270 | const mediaData = await dm.decryptMedia(message)
271 | const imageBase64 = `data:${mimetype};base64,${mediaData.toString('base64')}`
272 | await client.sendImageAsSticker(from, imageBase64)
273 | } else if (quotedMsg && quotedMsg.type == 'image') {
274 | const mediaData = await dm.decryptMedia(quotedMsg)
275 | const imageBase64 = `data:${quotedMsg.mimetype};base64,${mediaData.toString('base64')}`
276 | await client.sendImageAsSticker(from, imageBase64)
277 | } else if (args.length == 2) {
278 | const url = args[1]
279 |
280 | url.match(isUrl) ? await client.sendStickerfromUrl(from, url, { method: 'get' })
281 | .then(r => { if (!r) client.sendText(from, 'The URL is not walid') })
282 | .catch(err => console.log('Caught exception: ', err)) : client.sendText(from, 'Sorry The URL is not valid')
283 | } else {
284 | client.sendText(from, 'You did not quote a picture, Baka! To make a sticker, send an image with "/sticker" as caption')
285 | }
286 |
287 | }
288 | function helpContent(client, message) {
289 | var helptext="*Anime Guild Of Maharastra*\n" +
290 | "\nUseless AQua B0T\n" +
291 | "*Commands & Usage*\n" +
292 | " 1) */art*\n" +
293 | " 2) */meme*\n" +
294 | " 3) */anime [anime-name]*\n" +
295 | " 4) */manga [manga-name]*\n" +
296 | "\n" +
297 | "Note :old commands will start work as soon as i finish porting them[Admin]"
298 | client.reply(message.chatId,helptext,message.id,true).catch(console.log)
299 |
300 | }
301 | function redditContent(client,message,rchannel){
302 | request({
303 | url: 'http://meme-api.herokuapp.com/gimme/'+rchannel,
304 | json: true
305 | }, function(error, response, body) {
306 |
307 | client.sendFileFromUrl(message.from,body.url,body.url.split('/').pop(),body.title,);
308 |
309 | });
310 | }
311 |
312 | function animeSearch(client,message,query) {
313 | request({
314 | url: jikan+'search/anime?q='+query+'&limit=1',
315 | json: true
316 | }, function(error, response, body) {
317 | console.log(body.results[0].title);
318 | //client.sendStickerfromUrl(message.from,body.results[0].image_url);
319 | let caption="*Anime Guild of Maharashtra*\n"+
320 | "Anime Search Result:-"+"\n\n"+
321 | "*Title : "+body.results[0].title+"*\n"+
322 | "Type : "+body.results[0].type+"\n"+
323 | "Score: *"+body.results[0].score+"* Episodes: *"+body.results[0].episodes+"*\n"+
324 | "*Synopsis* : "+body.results[0].synopsis+"\n"+"\n"+body.results[0].url;
325 |
326 |
327 | client.sendFileFromUrl(message.from,body.results[0].image_url,body.results[0].image_url.split('/').pop(),caption);
328 | });
329 | }
330 | function mangaSearch(client,message,query) {
331 | request({
332 | url: jikan+'search/manga?q='+query+'&limit=1',
333 | json: true
334 | }, function(error, response, body) {
335 | console.log(body.results[0].title);
336 | //client.sendStickerfromUrl(message.from,body.results[0].image_url);
337 | let caption="*Anime Guild of Maharashtra*\n"+
338 | "Manga Search Result:-"+"\n\n"+
339 | "*Title : "+body.results[0].title+"*\n"+
340 | "Publishing : "+body.results[0].publishing+"\n"+
341 | "Score: *"+body.results[0].score+"* Chapters: *"+body.results[0].chapters+"*\n"+
342 | "*Synopsis* : "+body.results[0].synopsis+"\n"+"\n"+body.results[0].url;
343 |
344 |
345 | client.sendFileFromUrl(message.from,body.results[0].image_url,body.results[0].image_url.split('/').pop(),caption);
346 | });
347 | }
348 |
349 | function rulesContent(client, message) {
350 | if(message.isGroupMsg){
351 | console.log("pokemon "+client.DESCRIPTION)
352 | client.glob
353 | }else {
354 | client.reply(message.from,"*This Command only Works Inside group's*")
355 | }
356 | }
357 |
358 |
359 |
360 |
361 |
362 | var configFiles=__dirname+"\\configFiles\\";
363 | function readJsonFile(filename) {
364 | filename=configFiles+filename;
365 | let rawdata = fs.readFileSync(filename);
366 | return JSON.parse(rawdata);
367 |
368 | }
369 | function saveJsonFile(filename,object) {
370 | filename=configFiles+filename;
371 | // console.log("pokelog "+filename)
372 | var jsonContent = JSON.stringify(object);
373 | fs.writeFile(filename, jsonContent, 'utf8', function (err) {
374 | if (err) {
375 | console.log("An error occured while writing JSON Object to File."+filename);
376 | return console.log(err);
377 | }
378 |
379 |
380 | });
381 | }
382 | async function isGroupAdmin(client,message,author) {
383 | let value=await client.getGroupAdmins(message.chatId)
384 | return value.toString().includes(message.author)
385 | }
386 |
387 |
--------------------------------------------------------------------------------