├── requirements.txt ├── vercel.json ├── package.json ├── README.md ├── LICENSE ├── main.py ├── index.js └── Kuki.js /requirements.txt: -------------------------------------------------------------------------------- 1 | pymongo 2 | requests 3 | dnspython 4 | tgcrypto==1.2.2 5 | pyrogram==1.4.16 6 | lxml==4.6.2 7 | requests_html 8 | fastapi==0.63.0 9 | uvicorn 10 | -------------------------------------------------------------------------------- /vercel.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": 2, 3 | "env": { 4 | }, 5 | "builds": [ 6 | { 7 | "src": "index.js", 8 | "use": "@vercel/node" 9 | }, 10 | { 11 | "src": "main.py", 12 | "use": "@vercel/python" 13 | } 14 | ], 15 | "routes": [ 16 | { 17 | "src": "/chatbot/(.*)", 18 | "dest": "index.js" 19 | }, 20 | { 21 | "src": "/api/(.*)", 22 | "dest": "main.py" 23 | } 24 | ] 25 | } 26 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Kukiapi", 3 | "version": "1.0.0", 4 | "description": "kuki chatbot api", 5 | "main": "main.js", 6 | "private": true, 7 | "scripts": { 8 | "build": "node index.js" 9 | }, 10 | "author": "moezilla", 11 | "license": "ISC", 12 | "dependencies": { 13 | "axios": "^0.21.1", 14 | "jaro-winkler": "^0.2.8", 15 | "cors": "^2.8.5", 16 | "dotenv": "^10.0.0", 17 | "express": "^4.17.1", 18 | "node-cache": "^5.1.2", 19 | "node-fetch": "^2.6.1", 20 | "md5": "^2.2.1", 21 | "superagent": "^5.1.0", 22 | "nodemon": "^2.0.12" 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # KukiApi.xyz 2 | KukiApi.xyz Open Source ❤ 3 | 4 | # Features 5 | 1. Setup Owner Name 6 | 2. Setup Bot Name 7 | 3. Setup Gender Name 8 | 4. Free Cleverbot Chat 9 | 10 | ## Support 11 | 12 |

13 | 14 |

15 | 16 | ## © Copyright - MetaVoid (Moezilla) 17 | 18 | 19 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 Pranav Ajay 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /main.py: -------------------------------------------------------------------------------- 1 | from fastapi import FastAPI, Request, Response 2 | from fastapi.responses import HTMLResponse, FileResponse 3 | import requests 4 | import json 5 | import random 6 | from pyrogram import * 7 | import secrets 8 | from dateutil import parser 9 | import requests 10 | import os 11 | from pymongo import MongoClient 12 | 13 | MONGO_URL = "mongo db url" # https://www.mongodb.com/ 14 | 15 | API_ID = "1267i" # telegram api I'd my.telegram.org 16 | API_HASH = "jsksko12i0" # telegram api hash my.telegram.org 17 | TOKEN = "bot token" # telegram bot token 18 | hosturl = "site url" 19 | CHAT_ID = -1001787468565 # telegram channel id 20 | 21 | async def clientbot(): 22 | bot = Client( 23 | ':memory:', 24 | api_id=API_ID, 25 | api_hash=API_HASH, 26 | bot_token=TOKEN 27 | ) 28 | await bot.start() 29 | return bot 30 | 31 | app = FastAPI() 32 | 33 | @app.get('/api/apikey={api}/{botname}/{owner}/message={msg}') 34 | async def chatbot(api, botname, owner, msg): 35 | leveldb = MongoClient(MONGO_URL) 36 | toggle = leveldb["myFirstDatabase"]["jsons"] 37 | is_token = toggle.find_one({"ID": api}) 38 | result = f"https://{hosturl}/chatbot/{botname}/{owner}/message={msg}" 39 | result = requests.get(result) 40 | result = result.json() 41 | if not is_token: 42 | url = f"https://{hosturl}/api/apikey={api}/{botname}/{owner}/message={msg}" 43 | bot = await clientbot() 44 | await bot.send_message(CHAT_ID, f"Invalid Token\n - {url}") 45 | ret = { 46 | "reply": "Invalid Token Please Ask @metavoidsupport" 47 | } 48 | return ret 49 | if is_token: 50 | ret = { 51 | "reply": result["reply"] 52 | } 53 | return ret 54 | 55 | 56 | @app.get('/api/apikey={api}/message={msg}') 57 | async def simplechatbot(api, msg): 58 | leveldb = MongoClient(MONGO_URL) 59 | toggle = leveldb["myFirstDatabase"]["jsons"] 60 | is_token = toggle.find_one({"ID": api}) 61 | result = f"https://{hosturl}/chatbot/kuki/moezilla/message={msg}" 62 | result = requests.get(result) 63 | result = result.json() 64 | if not is_token: 65 | url = f"https://{hosturl}/api/apikey={api}/message={msg}" 66 | bot = await clientbot() 67 | await bot.send_message(CHAT_ID, f"Invalid Token\n - {url}") 68 | ret = { 69 | "reply": "Invalid Token Please Ask @metavoidsupport" 70 | } 71 | return ret 72 | if is_token: 73 | ret = { 74 | "reply": result["reply"] 75 | } 76 | return ret 77 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | const express = require('express') // Import NPM Package 2 | const app = express(); 3 | const bot = require("./Kuki.js"); 4 | const cors = require('cors') 5 | const NodeCache = require('node-cache') 6 | const fetch = require('node-fetch') 7 | const { default: axios } = require('axios'); 8 | const port = process.env.PORT || 5000 9 | const cache = new NodeCache({ stdTTL: 5 }) // time format is seconds 10 | 11 | app.use(cors()) 12 | app.use(express.json()) 13 | app.use(express.urlencoded({ extended: false })) 14 | 15 | 16 | 17 | // https://expressjs.com/en/starter/basic-routing.html 18 | 19 | app.get('/', (req, res) => { 20 | res.sendFile('public/index.html', { root: __dirname }); 21 | }); 22 | 23 | 24 | app.get("/", (req, res) => { 25 | res.status(200).json({ 26 | "Kuki": "kukiapi.xyz/api/docs", 27 | 28 | 29 | }); 30 | }); 31 | 32 | 33 | 34 | 35 | 36 | 37 | app.get('/chatbot/message=:reply', async function(request, response) { 38 | 39 | const reply = request.params.reply 40 | 41 | 42 | bot(reply).then(bot_response => { 43 | 44 | response.status(200) 45 | response.header("Content-Type",'application/json') 46 | response.end(JSON.stringify({reply : bot_response.replace('Gumnaam', `kuki`).replace('Sarah', `kuki`).replace('Chris', `kuki`).replace('CASTIEL', `kuki`).replace('clever', `kuki`).replace('Alex', `kuki`).replace('Edwin', `kuki`).replace('David', `kuki`).replace('Jeff', `kuki`).replace('Anh', `kuki`).replace('Adam', `kuki`).replace('deanna', `kuki`).replace('Owen', `kuki`).replace('Tanya', `kuki`).replace('My mother and Father', `MoeZilla`).replace('My mother and my father made me.', `@PranavAjay Made Me.`).replace('cleverbot.com', `github.com/moezilla`).replace('My parents.', `MoeZilla`).replace('cleverbot', `MoeZilla`).replace('Cleverbot', `MoeZilla`)})) 47 | 48 | }) 49 | 50 | 51 | }) 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | app.get('/chatbot/:name/:owner/message=:reply', async function(request, response) { 60 | 61 | const reply = request.params.reply 62 | const owner = request.params.owner 63 | const name = request.params.name 64 | 65 | bot(reply).then(bot_response => { 66 | 67 | response.status(200) 68 | response.header("Content-Type",'application/json') 69 | response.end(JSON.stringify({reply : bot_response.replace('Gumnaam', `${name}`).replace('Sarah', `${name}`).replace('Chris', `${name}`).replace('CASTIEL', `${name}`).replace('Nat', `${name}`).replace('Alex', `${name}`).replace('clever', `kuki`).replace('David', `${name}`).replace('Jeff', `${name}`).replace('Anh', `${name}`).replace('Adam', `${name}`).replace('deanna', `${name}`).replace('Owen', `${name}`).replace('Tanya', `${name}`).replace('My mother and Father', `${owner}`).replace('My mother and my father made me.', `MoeZilla`).replace('cleverbot.com', `github.com/moezilla`).replace('My parents.', `${owner}`).replace('cleverbot', `${owner}`).replace('Cleverbot', `${owner}`).replace('my parents', `${owner}`)})) 70 | 71 | }) 72 | 73 | 74 | }) 75 | 76 | 77 | app.get("/api/stats", (req, res) => { 78 | res.status(200).json({ 79 | "success": true, 80 | "message": "The kuki has launched", 81 | }); 82 | }); 83 | 84 | 85 | app.listen( port, () => { 86 | console.log(`Connected to port ${port}`) 87 | } ) 88 | -------------------------------------------------------------------------------- /Kuki.js: -------------------------------------------------------------------------------- 1 | const superagent = require("superagent"); 2 | const md5 = require("md5"); 3 | 4 | const userAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.4844.84 Safari/537.36"; 5 | 6 | let cookies; 7 | let cbsid; 8 | let xai; 9 | let lastResponse; 10 | let lastCookieUpdate = 0; 11 | 12 | /** 13 | * Sends a mesasage to Cleverbot 14 | * @param {string} stimulus The message to be sent 15 | * @param {string[]?} context An array of previous messages and responses 16 | * @param {string?} language The language of the message (null for auto detect) 17 | * @returns {Promise} The response 18 | */ 19 | module.exports = async (stimulus, context = [], language) => { 20 | const _context = context.slice(); // clone array to prevent subsequent calls from modifying it 21 | 22 | if (cookies == null || Date.now() - lastCookieUpdate >= 86400000) { 23 | // we must get the XVIS cookie before we can make requests to the API 24 | const date = new Date(); 25 | const req = await superagent.get(`https://www.cleverbot.com/extras/conversation-social-min.js?${date.getFullYear()}${date.getMonth().toString().padStart(2, "0")}${date.getDate().toString().padStart(2, "0")}`).set("User-Agent", userAgent); 26 | cookies = req.header["set-cookie"]; // eslint-disable-line require-atomic-updates 27 | lastCookieUpdate = Date.now(); 28 | } 29 | 30 | // why, cleverbot, why do you do need me to do this 31 | let payload = `stimulus=${escape(stimulus).includes("%u") ? escape(escape(stimulus).replace(/%u/g, "|")) : escape(stimulus)}&`; 32 | 33 | // we're going to assume that the first item in the array is the first message sent 34 | const reverseContext = _context.reverse(); 35 | 36 | for (let i = 0; i < _context.length; i++) { 37 | // we're going to assume that the context hasn't been escaped 38 | payload += `vText${i + 2}=${escape(reverseContext[i]).includes("%u") ? escape(escape(reverseContext[i]).replace(/%u/g, "|")) : escape(reverseContext[i])}&`; 39 | } 40 | 41 | payload += `${language ? `cb_settings_language=${language}&` : ""}cb_settings_scripting=no&islearning=1&icognoid=wsf&icognocheck=`; 42 | 43 | payload += md5(payload.substring(7, 33)); 44 | 45 | for (let i = 0; i < 15; i++) { 46 | try { 47 | const req = await superagent.post(`https://www.cleverbot.com/webservicemin?uc=UseOfficialCleverbotAPI${cbsid ? `&out=${encodeURIComponent(lastResponse)}&in=${encodeURIComponent(stimulus)}&bot=c&cbsid=${cbsid}&xai=${xai}&ns=2&al=&dl=&flag=&user=&mode=1&alt=0&reac=&emo=&sou=website&xed=&` : ""}`) 48 | .timeout({ 49 | response: 10000, 50 | deadline: 60000, 51 | }) 52 | .set("Cookie", `${cookies[0].split(";")[0]}; _cbsid=-1`) 53 | .set("User-Agent", userAgent) 54 | .type("text/plain") 55 | .send(payload); 56 | 57 | cbsid = req.text.split("\r")[1]; 58 | xai = `${cbsid.substring(0, 3)},${req.text.split("\r")[2]}`; 59 | lastResponse = req.text.split("\r")[0]; 60 | return lastResponse; 61 | } catch (err) { 62 | if (err.status === 503) { 63 | // retry after a bit 64 | await new Promise(resolve => setTimeout(resolve, 1000)); 65 | } else { 66 | throw err; 67 | } 68 | } 69 | } 70 | 71 | throw "Failed to get a response after 15 tries"; 72 | }; 73 | --------------------------------------------------------------------------------