forked from shomq/discordcaptcha
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.min.js
1 lines (1 loc) · 4.96 KB
/
index.min.js
1
const Discord=require('discord.js');const client=new Discord['Client']();const fs=require('fs');const snekfetch=require('snekfetch');const jimp=require('jimp');const sql=require('sqlite');sql['open']('./src/db.sqlite');class Captcha{constructor(c,d,e){this['_captcha']=c;}['generate'](){let f=Math['random']()['toString'](0x24)['substr'](0x2,0x6);this['captcha']=f;return this['captcha'];}get['captcha'](){return this['_captcha'];}set['captcha'](g){this['_captcha']=g;}}const config=require('./src/config.json');const callback_=h=>{if(h)console['log'](h);};let queue=[],latestVersion;snekfetch['get']('https://raw.githubusercontent.com/y21/discordcaptcha/master/src/config.json')['then'](i=>{if(JSON['parse'](i['body'])['version']!=config['version']){console['log']('###\x20A\x20new\x20version\x20of\x20discordcaptcha\x20is\x20available!\x20\x20(Latest:\x20'+JSON['parse'](i['body'])['version']+')\x0a\x0a');}latestVersion=JSON['parse'](i['body'])['version'];})['catch'](console['log']);client['on']('ready',()=>{try{console['log']('Logged\x20in!');client['user']['setActivity'](config['streamingGame'],{'url':config['streamingLink'],'type':'STREAMING'});if(client['guilds']['size']>0x1){console['log']('It\x20looks\x20like\x20this\x20bot\x20is\x20on\x20more\x20than\x20one\x20guild.\x20It\x20is\x20recommended\x20not\x20to\x20have\x20this\x20bot\x20on\x20more\x20than\x20one\x20since\x20it\x20could\x20do\x20random\x20stuff.');}client['guilds']['forEach'](j=>{if(!j['roles']['get'](config['userrole']))console['log'](j['name']+'\x20has\x20no\x20userrole\x20or\x20the\x20snowflake\x20that\x20was\x20given\x20in\x20the\x20config\x20file\x20is\x20invalid.');});}catch(k){console['log']('[DISCORDCAPTCHA-readyEvent]\x20>>\x20'+k);}});client['on']('warn',console['warn']);client['on']('error',console['error']);client['on']('disconnect',()=>console['log']('Bot\x20disconnected\x20from\x20WebSocket!'));client['on']('reconnect',()=>console['log']('Reconnecting\x20to\x20WebSocket\x20...'));client['on']('message',async l=>{try{let m=await sql['get']('select\x20*\x20from\x20blocked\x20where\x20id=\x22'+l['author']['id']+'\x22');if(m)l['member']['kick']();if(l['channel']['name']==='verify'){if(l['author']['id']!=client['user']['id'])l['delete']();else setTimeout(()=>l['delete'](),0x9c4);if(l['content']===config['prefix']+'verify'){if((await sql['get']('select\x20*\x20from\x20queries\x20where\x20id=\x22'+l['author']['id']+'\x22'))||l['member']['roles']['has'](config['userrole']))return l['reply']('Already\x20verified\x20or\x20in\x20queue!');let n=new Captcha(null,l['author']);let o=n['generate']();if(config['captchaType']=='image'){let p=await jimp['read']('https://i.imgur.com/mkoc2Fh.png');let q=await jimp['loadFont'](jimp['FONT_SANS_64_BLACK']);let r=[Math['random']()*0x190,Math['random']()*0x190];p['resize'](0x2ee,0x2ee);p['print'](q,r[0x0],r[0x1],o);l['author']['send'](new Discord['RichEmbed']()['setTitle']('Verification')['setDescription']('This\x20guild\x20is\x20protected\x20by\x20discordcaptcha,\x20an\x20open-source\x20verification\x20bot\x20made\x20by\x20y21#0909.')['addField']('Instructions','In\x20a\x20few\x20seconds\x20an\x20image\x20will\x20be\x20sent\x20to\x20you\x20which\x20includes\x20a\x20number.\x20Please\x20send\x20'+config['prefix']+'verify\x20<captcha>\x20into\x20the\x20channel\x20'+l['channel']['name']+'\x20('+l['channel']+')')['setColor']('RANDOM')['setTimestamp']())['catch'](s=>s['toString']()['includes']('Cannot\x20send\x20messages\x20to\x20this\x20user')?l['reply']('please\x20turn\x20on\x20dms'):null);p['getBuffer'](jimp['MIME_PNG'],(t,u)=>{l['author']['send'](new Discord['Attachment'](u,'captcha.png'));});}else if(config['captchaType']=='text'){l['author']['send'](new Discord['RichEmbed']()['setDescription']('Paste\x20the\x20code\x20below\x20in\x20the\x20verify\x20channel\x20to\x20get\x20verified.\x0a\x0a**Verification\x20Bot\x20made\x20by\x20y21#0909**'));l['author']['send']('```'+config['prefix']+'verify\x20'+n['captcha']+'```');}sql['run']('insert\x20into\x20queries\x20values\x20(\x22'+l['author']['id']+'\x22)');l['channel']['awaitMessages'](v=>v['content']===config['prefix']+'verify\x20'+n['captcha']&&v['author']===l['author'],{'max':0x1,'errors':['time']})['then'](()=>{l['author']['send']({'embed':{'color':0xff00,'description':'Successfully\x20verified\x20on\x20`'+l['guild']['name']+'`'}});let w=client['channels']['get'](config['chat'])||client['channels']['find']('name',config['chat']);if(w&&w['type']==='text')w['send'](l['author']['toString']()+'\x20was\x20successfully\x20verified.');if(config['logging'])sql['run']('insert\x20into\x20logs\x20values\x20(\x22'+l['author']['id']+'\x22,\x20\x22'+Date['now']()+'\x22)');sql['run']('delete\x20from\x20queries\x20where\x20id=\x22'+l['author']['id']+'\x22');queue['pop']();l['member']['addRole'](config['userrole'])['catch'](console['log']);delete n;})['catch'](console['log']);}}require('./src/Commands.js')(l,config,Discord,fs,latestVersion);}catch(x){console['log'](x);}});process['on']('unhandledRejection',console['log']);client['login'](config['token']);