├── Procfile ├── src ├── lib │ ├── ML │ │ ├── index.ts │ │ └── nsfw.ts │ ├── YT │ │ ├── index.ts │ │ ├── search.ts │ │ └── download.ts │ ├── index.ts │ ├── lyrics.ts │ ├── wallpaper.ts │ ├── reddit.ts │ ├── help.ts │ ├── getGify.ts │ ├── endpoints.json │ ├── info.ts │ ├── sticker.ts │ ├── anime.ts │ ├── commands.json │ ├── responses.json │ └── group.ts ├── Web │ ├── Routes │ │ ├── index.ts │ │ └── Base.ts │ ├── index.ts │ └── Web.ts ├── Mongo │ ├── index.ts │ └── Models │ │ ├── index.ts │ │ ├── Session.ts │ │ ├── User.ts │ │ └── Group.ts ├── Client │ ├── Validation │ │ ├── index.ts │ │ └── validate.ts │ ├── index.ts │ ├── ML.ts │ ├── Group.ts │ └── Utils.ts ├── Handler │ ├── index.ts │ ├── Events.ts │ └── Message.ts ├── Typings │ ├── index.d.ts │ ├── Mongo.d.ts │ ├── Message.d.ts │ └── Client.d.ts ├── index.ts ├── Utils │ ├── Embed.ts │ └── index.ts └── Main.ts ├── .github ├── FUNDING.yml └── workflows │ └── codeql-analysis.yml ├── .gitignore ├── assets ├── images │ ├── 18+.jpg │ ├── yui.jpg │ ├── Error-404.jpg │ ├── Error-500.gif │ └── broadcast.png └── videos │ └── Error-500.mp4 ├── .prettierrc ├── .env.example ├── .eslintrc.js ├── views └── index.ejs ├── tsconfig.json ├── app.json ├── package.json ├── README.md ├── Self-Hosting.md ├── Heroku_Atlas_Guide.md └── LICENSE /Procfile: -------------------------------------------------------------------------------- 1 | web: npm start 2 | -------------------------------------------------------------------------------- /src/lib/ML/index.ts: -------------------------------------------------------------------------------- 1 | export * from './nsfw' 2 | -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | patreon: whatsapp_botto_xre 2 | -------------------------------------------------------------------------------- /src/Web/Routes/index.ts: -------------------------------------------------------------------------------- 1 | export * from './Base' 2 | -------------------------------------------------------------------------------- /src/Mongo/index.ts: -------------------------------------------------------------------------------- 1 | export * as schema from './Models' 2 | -------------------------------------------------------------------------------- /src/Client/Validation/index.ts: -------------------------------------------------------------------------------- 1 | export * from './validate' 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | dist 3 | .env 4 | **/*_session.json 5 | -------------------------------------------------------------------------------- /src/Web/index.ts: -------------------------------------------------------------------------------- 1 | export * from './Web' 2 | export * from './Routes' 3 | -------------------------------------------------------------------------------- /src/Client/index.ts: -------------------------------------------------------------------------------- 1 | export * from './Group' 2 | export * from './Validation' 3 | -------------------------------------------------------------------------------- /src/Handler/index.ts: -------------------------------------------------------------------------------- 1 | export * from './Message' 2 | export * from './Events' 3 | -------------------------------------------------------------------------------- /src/lib/YT/index.ts: -------------------------------------------------------------------------------- 1 | export * from './search' 2 | export * from './download' 3 | -------------------------------------------------------------------------------- /assets/images/18+.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shubham8550/Whatsapp-Botto-Xre/master/assets/images/18+.jpg -------------------------------------------------------------------------------- /assets/images/yui.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shubham8550/Whatsapp-Botto-Xre/master/assets/images/yui.jpg -------------------------------------------------------------------------------- /src/Mongo/Models/index.ts: -------------------------------------------------------------------------------- 1 | export * from './Group' 2 | export * from './User' 3 | export * from './Session' 4 | -------------------------------------------------------------------------------- /assets/images/Error-404.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shubham8550/Whatsapp-Botto-Xre/master/assets/images/Error-404.jpg -------------------------------------------------------------------------------- /assets/images/Error-500.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shubham8550/Whatsapp-Botto-Xre/master/assets/images/Error-500.gif -------------------------------------------------------------------------------- /assets/images/broadcast.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shubham8550/Whatsapp-Botto-Xre/master/assets/images/broadcast.png -------------------------------------------------------------------------------- /assets/videos/Error-500.mp4: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shubham8550/Whatsapp-Botto-Xre/master/assets/videos/Error-500.mp4 -------------------------------------------------------------------------------- /src/Typings/index.d.ts: -------------------------------------------------------------------------------- 1 | export * from './Client' 2 | export * from './Message' 3 | export * from './Mongo' 4 | export * from './info' 5 | -------------------------------------------------------------------------------- /.prettierrc: -------------------------------------------------------------------------------- 1 | { 2 | "semi": false, 3 | "trailingComma": "none", 4 | "singleQuote": true, 5 | "printWidth": 120, 6 | "tabWidth": 4 7 | } -------------------------------------------------------------------------------- /src/Client/ML.ts: -------------------------------------------------------------------------------- 1 | import { MlNsfw } from '../lib' 2 | import { Client as Base } from './Utils' 3 | 4 | export class Client extends Base { 5 | ML = { 6 | nsfw: new MlNsfw() 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /.env.example: -------------------------------------------------------------------------------- 1 | BOT_NAME=Xre 2 | PREFIX=# 3 | CRON= 4 | ADMINS=[] 5 | MONGO_URI=mongodb://localhost/wabottoxreDB2 6 | EIF=https://express-is-fun.herokuapp.com/api 7 | ADMIN_GROUP_JID= 8 | SESSION_ID=BOTTO-XRE -------------------------------------------------------------------------------- /src/lib/index.ts: -------------------------------------------------------------------------------- 1 | export * from './group' 2 | export * from './help' 3 | export * from './anime' 4 | export * from './YT' 5 | export * from './sticker' 6 | export * from './ML' 7 | export * from './lyrics' 8 | export * from './getGify' 9 | -------------------------------------------------------------------------------- /src/index.ts: -------------------------------------------------------------------------------- 1 | import { start } from './Main' 2 | import { config } from 'dotenv' 3 | import { validate } from './Client' 4 | config() 5 | validate() 6 | const PORT = Number(process.env.PORT) || 4001 7 | const MONGO_URI = String(process.env.MONGO_URI) || 'mongodb://localhost/localdb' 8 | start(PORT, MONGO_URI) 9 | -------------------------------------------------------------------------------- /.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | parser: '@typescript-eslint/parser', 3 | extends: [ 4 | 'plugin:@typescript-eslint/recommended', 5 | ], 6 | parserOptions: { 7 | ecmaVersion: 2020, 8 | sourceType: 'module', 9 | }, 10 | rules: { 11 | 12 | }, 13 | } -------------------------------------------------------------------------------- /src/Typings/Mongo.d.ts: -------------------------------------------------------------------------------- 1 | import { Document } from 'mongoose' 2 | import { IGroup, IUser } from './Client' 3 | 4 | export interface IGroupModel extends IGroup, Document {} 5 | 6 | export interface IUserModel extends IUser, Document {} 7 | 8 | export interface ISessionModel extends Document { 9 | ID: string 10 | session: ISession 11 | } 12 | -------------------------------------------------------------------------------- /views/index.ejs: -------------------------------------------------------------------------------- 1 |

Xre - <%= (typeof name !== 'undefined') ? name : '' %>

2 | <%= (typeof error !== 'undefined') ? error : ''%> 3 |
4 |
5 | 6 | 7 |
8 | 9 |
-------------------------------------------------------------------------------- /src/Mongo/Models/Session.ts: -------------------------------------------------------------------------------- 1 | import { Schema, model } from 'mongoose' 2 | import { ISessionModel } from '../../Typings' 3 | 4 | const SessionSchema = new Schema({ 5 | ID: { 6 | type: String, 7 | required: true, 8 | unique: true 9 | }, 10 | session: { 11 | type: Object, 12 | required: false, 13 | unique: true 14 | } 15 | }) 16 | 17 | export const session = model('session', SessionSchema) 18 | -------------------------------------------------------------------------------- /src/Web/Web.ts: -------------------------------------------------------------------------------- 1 | import express from 'express' 2 | import { EventEmitter } from 'events' 3 | import { Client } from '../Client' 4 | 5 | export class Web extends EventEmitter { 6 | app: express.Express 7 | 8 | QR: null | Buffer = null 9 | 10 | constructor(public client: Client, public PORT: number) { 11 | super() 12 | this.app = express() 13 | this.app.listen(this.PORT, () => this.emit('web-open', this.PORT)) 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/lib/lyrics.ts: -------------------------------------------------------------------------------- 1 | import responses from './responses.json' 2 | import Utils from '../Utils' 3 | export const lyrics = async (term: string): Promise => { 4 | if (!process.env.EIF) return responses.warnings.EIF 5 | if (!term) responses['empty-query'] 6 | const data = await Utils.fetch(`${process.env.EIF}/lyrics?term=${encodeURI(term)}`, {}) 7 | return data.status !== 200 8 | ? data.error 9 | : responses.lyrics.replace(`{T}`, Utils.capitalize(data.term)).replace(`{L}`, data.lyrics) 10 | } 11 | -------------------------------------------------------------------------------- /src/Mongo/Models/User.ts: -------------------------------------------------------------------------------- 1 | import { Schema, model } from 'mongoose' 2 | import { IUserModel } from '../../Typings' 3 | 4 | const UserSchema = new Schema({ 5 | jid: { 6 | type: String, 7 | required: true, 8 | unique: true 9 | }, 10 | ban: { 11 | type: Boolean, 12 | required: true, 13 | default: false 14 | }, 15 | warnings: { 16 | type: Number, 17 | required: true, 18 | default: 0 19 | } 20 | }) 21 | export const user = model('users', UserSchema) 22 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es6", 4 | "lib": [ 5 | "ESNext" 6 | ], 7 | "module": "commonjs", 8 | "declaration": true, 9 | "declarationMap": true, 10 | "sourceMap": true, 11 | "outDir": "./dist", 12 | "resolveJsonModule": true, 13 | "strict": true, 14 | "esModuleInterop": true, 15 | "skipLibCheck": true, 16 | "forceConsistentCasingInFileNames": true 17 | }, 18 | "include": [ 19 | "src/**/*" 20 | ] 21 | } 22 | -------------------------------------------------------------------------------- /src/Client/Group.ts: -------------------------------------------------------------------------------- 1 | import { GroupEx } from '../lib' 2 | import { IGroupInfo } from '../Typings' 3 | import { Client as Base } from './ML' 4 | 5 | export class Client extends Base { 6 | group = new GroupEx(this) 7 | 8 | async getGroupInfo(jid: string): Promise { 9 | const metadata = await this.groupMetadata(jid) 10 | const admins: string[] = [] 11 | metadata.participants.forEach((user) => (user.isAdmin ? admins.push(user.jid) : '')) 12 | let data = await this.GroupModel.findOne({ jid }) 13 | if (!data) data = await new this.GroupModel({ jid }).save() 14 | return { metadata, admins, data } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/lib/ML/nsfw.ts: -------------------------------------------------------------------------------- 1 | import * as tf from '@tensorflow/tfjs-node' 2 | import * as nsfw from 'nsfwjs' 3 | 4 | export class MlNsfw { 5 | nsfwModel!: nsfw.NSFWJS 6 | 7 | constructor() { 8 | nsfw.load().then((m) => { 9 | this.nsfwModel = m 10 | }) 11 | } 12 | 13 | check = async (image: Buffer): Promise => { 14 | const decodedImage = await tf.node.decodeImage(image, 3) 15 | const pre = await this.nsfwModel.classify(decodedImage as tf.Tensor3D) 16 | decodedImage.dispose() 17 | if (pre[0].className === 'Hentai' || pre[0].className === 'Porn') return true 18 | return false 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/lib/YT/search.ts: -------------------------------------------------------------------------------- 1 | import yts from 'yt-search' 2 | import responses from '../responses.json' 3 | 4 | export const ytSearch = async (term: string): Promise => { 5 | if (!term) return responses['wrong-format'] 6 | const { videos } = await yts(term) 7 | if (!videos || videos.length <= 0) return responses['no-search-results'].replace('{T}', term) 8 | const length = videos.length < 10 ? videos.length : 10 9 | let base = `Search Term: *${term}*\n\n🔎 *Results*\n\n` 10 | for (let i = 0; i < length; i++) { 11 | base += `#${i + 1}\n📗 *Title:* ${videos[i].title}\n📙 *Description:* ${videos[i].description.slice( 12 | 50 13 | )}\n📘 *URL:* ${videos[i].url}\n\n` 14 | } 15 | return base 16 | } 17 | -------------------------------------------------------------------------------- /src/Mongo/Models/Group.ts: -------------------------------------------------------------------------------- 1 | import { model, Schema } from 'mongoose' 2 | import { IGroupModel } from '../../Typings' 3 | 4 | const GroupSchema = new Schema({ 5 | jid: { 6 | type: String, 7 | required: true, 8 | unique: true 9 | }, 10 | events: { 11 | type: Boolean, 12 | required: false, 13 | default: false 14 | }, 15 | nsfw: { 16 | type: Boolean, 17 | required: false, 18 | default: false 19 | }, 20 | safe: { 21 | type: Boolean, 22 | required: false, 23 | default: false 24 | }, 25 | mod: { 26 | type: Boolean, 27 | required: false, 28 | default: false 29 | } 30 | }) 31 | 32 | export const group = model('groups', GroupSchema) 33 | -------------------------------------------------------------------------------- /src/Typings/Message.d.ts: -------------------------------------------------------------------------------- 1 | import { Mimetype, WAGroupMetadata } from '@adiwajshing/baileys' 2 | 3 | export interface IParsedArgs { 4 | args: string[] 5 | flags: string[] 6 | } 7 | 8 | export interface ICommandList { 9 | [category: string]: command[] 10 | } 11 | 12 | export interface IEmbed { 13 | header?: string 14 | body?: string 15 | footer?: string 16 | } 17 | 18 | export interface stickerOptions { 19 | animated?: boolean 20 | crop?: boolean 21 | author?: string 22 | pack?: string 23 | } 24 | 25 | export interface IReply { 26 | body: string | Buffer 27 | type?: MessageType 28 | caption?: string 29 | mime?: Mimetype 30 | } 31 | 32 | export interface IGroupInfo { 33 | metadata: WAGroupMetadata 34 | admins: string[] 35 | data: IGroup 36 | } 37 | -------------------------------------------------------------------------------- /src/Client/Validation/validate.ts: -------------------------------------------------------------------------------- 1 | import chalk from 'chalk' 2 | 3 | export const validate = (): void => { 4 | const missing: string[] = [] 5 | if (!process.env.SESSION_ID) missing.push('SESSION_ID') 6 | if (!process.env.MONGO_URI) missing.push('MONGO_URI') 7 | if (missing.length > 0) { 8 | console.log( 9 | chalk.redBright(`[${missing.length}] Missing Config Vars`), 10 | chalk.yellow(`\nSpecify the following config vars in your ".env" file or add them to your env variables`), 11 | chalk.blue(`\n${missing.join('\n')}`), 12 | chalk.green( 13 | `\nNeed help? Read the self-hosting guide. https://github.com/Synthesized-Infinity/Whatsapp-Botto-Xre/blob/master/Self-Hosting.md` 14 | ) 15 | ) 16 | process.exit() 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/Utils/Embed.ts: -------------------------------------------------------------------------------- 1 | import { IEmbed } from '../Typings' 2 | 3 | export default class Embed implements IEmbed { 4 | header = `ᴇᴍʙᴇᴅ ᴛᴇxᴛ` 5 | 6 | body = '' 7 | 8 | footer = 'ᴡᴀ-ʙᴏᴛᴛᴏ-xʀᴇ' 9 | 10 | constructor(config?: IEmbed) { 11 | if (config?.header) this.setHeader(config.header) 12 | if (config?.body) this.setBody(config.body) 13 | if (config?.footer) this.setFooter(config.footer) 14 | } 15 | 16 | setHeader = (header: string): void => { 17 | this.header = header 18 | } 19 | 20 | setBody = (body: string): void => { 21 | const args = body.split('\n') 22 | body = '' 23 | args.forEach((text) => (body += `┠≽ ${text}`)) 24 | } 25 | 26 | setFooter = (footer: string): void => { 27 | this.footer = footer 28 | } 29 | 30 | get = (): string => { 31 | return `┏〈 ${this.header} 〉\n ╽\n${this.body}\n╿\n╰╼≽` 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/Typings/Client.d.ts: -------------------------------------------------------------------------------- 1 | import { WAParticipantAction, WAContact } from '@adiwajshing/baileys' 2 | import { IUserModel } from './Mongo' 3 | 4 | export interface IConfig { 5 | name: string 6 | prefix: string 7 | admins: string[] 8 | cron: string | null 9 | } 10 | 11 | export interface IEvent { 12 | jid: string 13 | participants: string[] 14 | actor?: string | undefined 15 | action: WAParticipantAction 16 | } 17 | 18 | export interface ICommand { 19 | command: string 20 | description: string 21 | usage: string 22 | flags?: string[] 23 | } 24 | 25 | export interface IGroup { 26 | jid: string 27 | events: boolean 28 | nsfw: boolean 29 | safe: boolean 30 | mod: boolean 31 | } 32 | 33 | export interface IUser { 34 | jid: string 35 | ban: boolean 36 | warnings: number 37 | } 38 | 39 | export interface IUserInfo { 40 | user: WAContact 41 | data: IUserModel 42 | } 43 | 44 | export interface ISession { 45 | clientID: string 46 | serverToken: string 47 | clientToken: string 48 | encKey: string 49 | macKey: string 50 | } 51 | -------------------------------------------------------------------------------- /src/Utils/index.ts: -------------------------------------------------------------------------------- 1 | import axios, { AxiosRequestConfig } from 'axios' 2 | import Embed from './Embed' 3 | 4 | export default class Utils { 5 | /* eslint-disable @typescript-eslint/no-explicit-any*/ 6 | static fetch = async (url: string, options: AxiosRequestConfig): Promise => 7 | (await axios.get(url, options)).data 8 | 9 | static download = async (url: string): Promise => await Utils.fetch(url, { responseType: 'arraybuffer' }) 10 | 11 | static randomNumber = (min: number, max: number): number => Math.floor(Math.random() * max) + min 12 | 13 | static capitalize = (text: string): string => `${text.charAt(0).toUpperCase()}${text.slice(1)}` 14 | 15 | static Embed = Embed 16 | 17 | static emojis = ['📗', '👑', '⚓', '〽', '⭕', '⏳'] 18 | 19 | static urlRegExp = /(https?:\/\/(?:www\.|(?!www))[a-zA-Z0-9][a-zA-Z0-9-]+[a-zA-Z0-9]\.[^\s]{2,}|www\.[a-zA-Z0-9][a-zA-Z0-9-]+[a-zA-Z0-9]\.[^\s]{2,}|https?:\/\/(?:www\.|(?!www))[a-zA-Z0-9]+\.[^\s]{2,}|www\.[a-zA-Z0-9]+\.[^\s]{2,})/ 20 | 21 | static urlMatch = (text: string): RegExpMatchArray | null => text.match(Utils.urlRegExp) 22 | } 23 | -------------------------------------------------------------------------------- /src/lib/wallpaper.ts: -------------------------------------------------------------------------------- 1 | import { MessageType } from '@adiwajshing/baileys' 2 | import { AnimeWallpaper } from 'anime-wallpaper' 3 | import { IReply } from '../Typings' 4 | import Utils from '../Utils' 5 | import responses from './responses.json' 6 | const wallClient = new AnimeWallpaper() 7 | 8 | const alphacoders = async (term: string): Promise => { 9 | try { 10 | return Utils.download((await wallClient.getAnimeWall1({ search: term, page: 1 }))[0].image) 11 | } catch (err) { 12 | return null 13 | } 14 | } 15 | 16 | const wallpapercave = async (term: string): Promise => { 17 | try { 18 | return Utils.download((await wallClient.getAnimeWall2(term))[0].image) 19 | } catch (err) { 20 | return null 21 | } 22 | } 23 | export const wallpaper = async (term: string): Promise => { 24 | if (!term) return { body: responses['wrong-format'] } 25 | const alpha = await alphacoders(term) 26 | if (alpha) return { body: alpha, type: MessageType.image } 27 | const cave = await wallpapercave(term) 28 | if (cave) return { body: cave, type: MessageType.image } 29 | return { body: responses['no-search-results'].replace('{T}', term) } 30 | } 31 | -------------------------------------------------------------------------------- /src/lib/reddit.ts: -------------------------------------------------------------------------------- 1 | import { MessageType } from '@adiwajshing/baileys' 2 | import { readFile } from 'fs-extra' 3 | import { join } from 'path' 4 | import { IReply } from '../Typings' 5 | import Utils from '../Utils' 6 | import responses from './responses.json' 7 | 8 | export const reddit = async (subreddit: string, safe: boolean): Promise => { 9 | if (!subreddit) return { body: responses['wrong-format'] } 10 | try { 11 | const post = await Utils.fetch(`https://meme-api.herokuapp.com/gimme/${encodeURI(subreddit.trim())}`, {}) 12 | if (post.nsfw && safe) 13 | return { 14 | body: await readFile(join(__dirname, '..', '..', 'assets', 'images', '18+.jpg')), 15 | caption: responses.mod['no-nsfw'], 16 | type: MessageType.image 17 | } 18 | return { 19 | body: await Utils.download(post.url), 20 | caption: `📗 *Title:* ${post.title}\n📘 *Author:* ${post.author}\n📙 *Post:* ${post.postLink}`, 21 | type: MessageType.image 22 | } 23 | } catch (err) { 24 | return { 25 | body: `🎯 *The given subreddit possibly is Invalid or this subreddit does not have any posts containing images*` 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/lib/help.ts: -------------------------------------------------------------------------------- 1 | import { Client } from '../Client' 2 | import commands from './commands.json' 3 | import Utils from '../Utils' 4 | import responses from './responses.json' 5 | import { ICommandList } from '../Typings' 6 | 7 | export const help = (client: Client, command?: string): string => { 8 | if (command) { 9 | for (const category in commands) { 10 | for (const index of (commands as ICommandList)[category]) { 11 | if (index.command === command) { 12 | return `*📗 Command:* ${index.command}\n📙 *Description:* ${index.description}\n📘 *Usage:* ${client._config.prefix}${index.usage}` 13 | } 14 | } 15 | } 16 | return responses['invalid-command-short'].replace('{C}', command) 17 | } 18 | let base = `🤖 ${client._config.name} Command List 🤖\n\n💡 *Prefix:* ${client._config.prefix}\n\n` 19 | const cmds = commands as ICommandList 20 | const cats = Object.keys(cmds) 21 | for (const cat in cmds) { 22 | base += `*${Utils.capitalize(cat)}* ${Utils.emojis[cats.indexOf(cat)]}\n\`\`\`` 23 | cmds[cat].forEach((cmd) => { 24 | base += `${cmd.command}${cmds[cat][cmds[cat].length - 1] === cmd ? '' : ', '}` 25 | }) 26 | base += '```\n\n' 27 | } 28 | return `${base}📚 Use ${client._config.prefix}help to view the full info. \n🔖 _Eg: ${client._config.prefix}help promote_` 29 | } 30 | -------------------------------------------------------------------------------- /src/lib/getGify.ts: -------------------------------------------------------------------------------- 1 | import { MessageType, Mimetype } from '@adiwajshing/baileys' 2 | import { IReply } from '../Typings' 3 | import Utils from '../Utils' 4 | 5 | /** Side-note 6 | * To get gif in other formats, I'd recommed you exploring the json itself which provided link returns. 7 | * This stability of the url and API_KEY is not guaranteed 8 | * Regards ~ Somnath Das 9 | */ 10 | const getGify = async (keyword: string): Promise => { 11 | // Fetching gif json by providing keyword 12 | const data: { results: IGifyResponse[] } = await Utils.fetch( 13 | `https://g.tenor.com/v1/search?q=${keyword}&key=LIVDSRZULELA&limit=8`, 14 | {} 15 | ) 16 | return data.results?.[Math.floor(Math.random() * data.results.length)]?.media[0]?.mp4?.url 17 | } 18 | 19 | export const getGifReply = async (query: string, users?: [string, string]): Promise => { 20 | if (!query) return { body: `Please Provide the query to search for!` } 21 | const gif = await getGify(query) 22 | if (!gif) return { body: 'No GIF Found!' } 23 | const [body, type, mime] = [await Utils.download(gif), MessageType.video, Mimetype.gif] 24 | return { 25 | body, 26 | type, 27 | mime, 28 | caption: !users ? `*Query: ${query}*` : `${users[0]} _${Utils.capitalize(query)}ed_ ${users[1]}` 29 | } 30 | } 31 | 32 | interface IGifyResponse { 33 | media: { 34 | mp4: { 35 | url: string 36 | } 37 | }[] 38 | } 39 | -------------------------------------------------------------------------------- /src/lib/YT/download.ts: -------------------------------------------------------------------------------- 1 | import { MessageType, Mimetype } from '@adiwajshing/baileys' 2 | import { createWriteStream, readFile } from 'fs-extra' 3 | import { tmpdir } from 'os' 4 | import ytdl, { getInfo, validateURL } from 'ytdl-core' 5 | import { IReply } from '../../Typings' 6 | import responses from '../responses.json' 7 | 8 | export const download = async (url: string, type: 'video' | 'audio'): Promise => { 9 | if (!validateURL(url)) return responses['invalid-url'].replace('{W}', 'YT').replace('{U}', url) 10 | const video = type === 'video' 11 | let filename = `${tmpdir()}/${Math.random().toString(30)}.${video ? 'mp4' : 'mp3'}` 12 | const { videoDetails: info } = await getInfo(url) 13 | if (Number(info.lengthSeconds) > 600) return responses['video-duration-clause'] 14 | const stream = createWriteStream(filename) 15 | ytdl(url, { quality: !video ? 'highestaudio' : 'highest' }).pipe(stream) 16 | filename = await new Promise((resolve, reject) => { 17 | stream.on('finish', () => resolve(filename)) 18 | stream.on('error', (err) => reject(err && console.log(err))) 19 | }) 20 | const caption = `📗 *Title:* ${info.title}\n📙 *Description:* ${info.description}\n📘 *Author:* ${info.author}` 21 | return { body: await readFile(filename), caption, mime: video ? Mimetype.mp4 : Mimetype.mp4Audio } 22 | } 23 | 24 | export const getYTMediaFromUrl = async (url: string, type: 'video' | 'audio'): Promise => { 25 | if (!url) return { body: responses['wrong-format'] } 26 | const media = await download(url, type) 27 | if (typeof media === 'string') return { body: media } 28 | return { ...media, type: type === 'audio' ? MessageType.audio : MessageType.video } 29 | } 30 | -------------------------------------------------------------------------------- /app.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "WhatsApp-Botto-xRe", 3 | "description": "Well....", 4 | "keywords": [ 5 | "bot", 6 | "whatsapp", 7 | "stickers", 8 | "whatsapp-stickers", 9 | "anime", 10 | "whatsapp-bot", 11 | "whatsapp-anime-bot", 12 | "whatsapp-botto" 13 | ], 14 | "website": "https://github.com/Synthesized-Infinity/Whatsapp-Botto-Xre#readme", 15 | "repository": "https://github.com/Synthesized-Infinity/Whatsapp-Botto-Xre.git", 16 | "logo": "https://i.ibb.co/F3sc7Nb/Purple-Music-Store-Etsy-Banner.png", 17 | "success_url": "/", 18 | "env": { 19 | "BOT_NAME": { 20 | "description": "Name of your bot" 21 | }, 22 | "PREFIX": { 23 | "description": "Prefix of your bot" 24 | }, 25 | "CRON": { 26 | "description": "\"Cron\" string to clear all chats of the bot at specified time", 27 | "required": false 28 | }, 29 | "SESSION_ID": { 30 | "description": "A string for the session to be classified and to get access to the server endpoints" 31 | }, 32 | "ADMINS": { 33 | "description": "The phone numbers of the users who you want to be admin for the bot (separated by a comma \",\")", 34 | "required": false 35 | }, 36 | "MONGO_URI": { 37 | "description": "A secret String for Mongodb Connection.(Required)" 38 | }, 39 | "EIF": "https://express-is-fun.herokuapp.com/api", 40 | "ADMIN_GROUP_JID": { 41 | "required": false 42 | } 43 | }, 44 | "buildpacks": [ 45 | { 46 | "url": "heroku/nodejs" 47 | }, 48 | { 49 | "url": "https://github.com/AlenSaito1/heroku-buildpack-imagemagick.git" 50 | }, 51 | 52 | { 53 | "url": "https://github.com/clhuang/heroku-buildpack-webp-binaries.git" 54 | }, 55 | { 56 | "url": "https://github.com/jonathanong/heroku-buildpack-ffmpeg-latest.git" 57 | } 58 | ] 59 | } 60 | -------------------------------------------------------------------------------- /src/lib/endpoints.json: -------------------------------------------------------------------------------- 1 | { 2 | "Note":"Never Share this URL and the SESSION_ID with anyone! Make sure to include the \"session\" query with every request", 3 | "client":{ 4 | "baseurl": "/client", 5 | "endpoints":[ 6 | { 7 | "endpoint":"/", 8 | "method":"GET", 9 | "query":null, 10 | "description":"Main endpoint" 11 | }, 12 | { 13 | "endpoint":"/qr", 14 | "method":"GET", 15 | "query":[ 16 | "session" 17 | ], 18 | "description":"Displays the Auth QR" 19 | }, 20 | { 21 | "endpoint":"/config", 22 | "method":"GET", 23 | "query":[ 24 | "session" 25 | ], 26 | "description":"Main endpoint" 27 | }, 28 | { 29 | "endpoint":"/wa", 30 | "method":"GET", 31 | "query":[ 32 | "state" 33 | ], 34 | "description":"turn on or off the client" 35 | }, 36 | { 37 | "endpoint":"user", 38 | "method":"GET", 39 | "query":[ 40 | "session", 41 | "jid" 42 | ], 43 | "description":"retrieves the given user's info" 44 | }, 45 | { 46 | "endpoint":"/pfp", 47 | "method":"GET", 48 | "query":[ 49 | "session", 50 | "jid" 51 | ], 52 | "description":"Retrieves the pfp of the given JID" 53 | }, 54 | { 55 | "endpoint":"/client", 56 | "method":"GET", 57 | "query":[ 58 | "state" 59 | ], 60 | "description":"turn on or off the client" 61 | } 62 | ] 63 | } 64 | } -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "whatsapp-botto-xre", 3 | "version": "1.0.0", 4 | "description": "Well....", 5 | "main": "dist/index.js", 6 | "files": [ 7 | "src", 8 | "dist" 9 | ], 10 | "scripts": { 11 | "build": "tsc -p .", 12 | "start": "node dist", 13 | "lint": "eslint \"src/**/*.ts\"", 14 | "postinstall": "npm run build", 15 | "prettier-format": "prettier --config .prettierrc \"src/**/*.ts\" --write" 16 | }, 17 | "repository": { 18 | "type": "git", 19 | "url": "git+https://github.com/Synthesized-Infinity/Whatsapp-Botto-Xre.git" 20 | }, 21 | "keywords": [ 22 | "bot", 23 | "whatsapp", 24 | "stickers", 25 | "whatsapp-stickers", 26 | "anime", 27 | "whatsapp-bot", 28 | "whatsapp-anime-bot", 29 | "whatsapp-botto" 30 | ], 31 | "author": "EWH", 32 | "license": "GNU General Public License v3.0", 33 | "bugs": { 34 | "url": "https://github.com/Synthesized-Infinity/Whatsapp-Botto-Xre/issues" 35 | }, 36 | "homepage": "https://github.com/Synthesized-Infinity/Whatsapp-Botto-Xre#readme", 37 | "devDependencies": { 38 | "@types/express": "^4.17.11", 39 | "@types/fs-extra": "^9.0.9", 40 | "@types/node": "^14.14.37", 41 | "@types/node-cron": "^2.0.3", 42 | "@types/qr-image": "^3.2.3", 43 | "@types/yt-search": "^2.3.0", 44 | "@typescript-eslint/eslint-plugin": "^4.20.0", 45 | "@typescript-eslint/parser": "^4.20.0", 46 | "eslint": "^7.23.0", 47 | "prettier": "^2.2.1", 48 | "typescript": "^4.2.3" 49 | }, 50 | "dependencies": { 51 | "@adiwajshing/baileys": "^3.5.1", 52 | "@tensorflow/tfjs-node": "^3.3.0", 53 | "anime-wallpaper": "^1.0.0", 54 | "axios": "^0.21.1", 55 | "chalk": "^4.1.0", 56 | "dotenv": "^8.2.0", 57 | "ejs": "^3.1.6", 58 | "express": "^4.17.1", 59 | "fs-extra": "^9.1.0", 60 | "moment-timezone": "^0.5.33", 61 | "mongoose": "^5.12.2", 62 | "node-cron": "^3.0.0", 63 | "node-webpmux": "^2.0.1", 64 | "nsfwjs": "^2.4.0", 65 | "qr-image": "^3.2.0", 66 | "wa-sticker-formatter": "^3.6.0", 67 | "yt-search": "^2.7.6", 68 | "ytdl-core": "^4.8.3" 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /src/lib/info.ts: -------------------------------------------------------------------------------- 1 | import { MessageType } from '@adiwajshing/baileys' 2 | import { join } from 'path' 3 | import { IReply } from '../Typings' 4 | import Utils from '../Utils' 5 | 6 | const xre = `https://opengraph.githubassets.com/e3ea92ae0b9155ea89ae7afad6a83898b4555bf33b7c0abeef478ba694de5e1f/Synthesized-Infinity/Whatsapp-Botto-Xre` 7 | export const info = async (): Promise => { 8 | //eslint-disable-next-line @typescript-eslint/no-var-requires 9 | const pkg = require(join(__dirname, '..', '..', 'package.json')) 10 | const deps = Object.keys(pkg.dependencies) 11 | return { 12 | body: await Utils.download(xre), 13 | caption: `🤖 ${process.env.BOT_NAME} 🤖\n\n🌟 *Homepage:* ${pkg.homepage}\n\n🍀 *Repository:* ${ 14 | pkg.repository.url 15 | }\n\n🍁 *Dependencies:*\n${deps.join( 16 | '\n' 17 | )}\n\n🌇 *Stickers:* https://www.npmjs.com/package/wa-sticker-formatter\n\n🛠️ *APIs & Tools:* https://express-is-fun.herokuapp.com/api/endpoints\n\n*-ᴡᴀ-ʙᴏᴛᴛᴏ-xʀᴇ-*`, 18 | type: MessageType.image 19 | } 20 | } 21 | 22 | export const getRepoInfo = async (type: 'issues' | 'commits'): Promise => { 23 | const data = await Utils.fetch(`https://api.github.com/repos/Synthesized-Infinity/Whatsapp-Botto-Xre/${type}`, {}) 24 | if (!data[0]) return { body: '💮 *No Issues open* 💮' } 25 | let body = `🌟 *WhatsApp Botto Xre-Recent ${Utils.capitalize(type)}* 🌟\n\n` 26 | const len = data.length < 5 ? data.length : 5 27 | if (type === 'commits') { 28 | for (let c = 0; c < len; c++) { 29 | body += `*#${c + 1}.*\n✉️ *Commit Message:* ${data[c].commit.message}\n📅 *Date:* ${ 30 | data[c].commit.author.date 31 | }\n🔱 *Author:* ${data[c].commit.author.name}\n🍀 *URL*: ${data[c]['html_url']}\n\n` 32 | } 33 | return { caption: body, body: await Utils.download(`${xre}/commit/${data[0].sha}`), type: MessageType.image } 34 | } 35 | for (let i = 0; i < data.length; i++) { 36 | body += `*#${i + 1}.*\n\n🔴 *Title: ${data[i].title}*\n🔱 *User:* ${data[i].user.login}\n〽️ URL: ${ 37 | data[i].url 38 | }\n\n` 39 | } 40 | return { body } 41 | } 42 | -------------------------------------------------------------------------------- /src/lib/sticker.ts: -------------------------------------------------------------------------------- 1 | import { MessageType, Mimetype } from '@adiwajshing/baileys' 2 | import { exec } from 'child_process' 3 | import { Sticker } from 'wa-sticker-formatter' 4 | import { IReply } from '../Typings' 5 | import { promisify } from 'util' 6 | import { tmpdir } from 'os' 7 | import { promises as fs } from 'fs' 8 | const execute = promisify(exec) 9 | const webp = require('node-webpmux') 10 | 11 | export const createSticker = async ( 12 | data: Buffer, 13 | crop: boolean, 14 | author = 'Xre', 15 | pack = 'WhatsApp Botto' 16 | ): Promise => { 17 | const sticker = new Sticker(data, { 18 | crop, 19 | author, 20 | pack 21 | }) 22 | await sticker.build() 23 | return { body: await sticker.get(), type: MessageType.sticker } 24 | } 25 | 26 | export const convertStickerToImage = async (filename: string): Promise => { 27 | const out = `${tmpdir()}/${Math.random().toString(36)}.png` 28 | await execute(`dwebp "${filename}" -o "${out}"`) 29 | return { body: await fs.readFile(out), type: MessageType.image, caption: `Here you go.` } 30 | } 31 | 32 | // this could probably be made better, but it works for now 33 | export const convertStickerToVideo = async (filename: string): Promise => { 34 | const img = new webp.Image() 35 | const temp = tmpdir() 36 | const out = `${temp}/${Math.random().toString(36)}.mp4` 37 | 38 | // load sticker 39 | await img.load(filename) 40 | 41 | // get amount of frames 42 | let frames = img.anim.frames.length 43 | 44 | for (let i = 0; frames > i; i++) { 45 | await execute(`webpmux -get frame ${i} ${filename} -o ${temp}/${i}.webp`) 46 | await execute(`dwebp ${temp}/${i}.webp -o ${temp}/${i}.png`) 47 | } 48 | 49 | // build frames into mp4 50 | await execute(`ffmpeg -framerate 22 -i ${temp}/%d.png -y -c:v libx264 -pix_fmt yuv420p -loop 4 ${out}`) 51 | 52 | // delete frames 53 | for (frames === 0; frames--; ) { 54 | fs.unlink(`${temp}/${frames}.webp`) 55 | fs.unlink(`${temp}/${frames}.png`) 56 | } 57 | 58 | return { body: await fs.readFile(out), type: MessageType.video, mime: Mimetype.gif, caption: `Here you go.` } 59 | } 60 | -------------------------------------------------------------------------------- /src/Handler/Events.ts: -------------------------------------------------------------------------------- 1 | import { MessageType } from '@adiwajshing/baileys' 2 | import chalk from 'chalk' 3 | import { Client } from '../Client' 4 | import Utils from '../Utils' 5 | import moment from 'moment-timezone' 6 | import { IEvent, IGroupInfo } from '../Typings' 7 | export class EventHandler { 8 | constructor(public client: Client) {} 9 | 10 | handle = async (event: IEvent): Promise => { 11 | const group = await this.client.getGroupInfo(event.jid) 12 | if (!group.data.events) return 13 | console.log( 14 | chalk.green('[EVENT]'), 15 | chalk.blue(moment(Date.now() * 1000).format('DD/MM HH:mm:ss')), 16 | chalk.blueBright(event.action), 17 | chalk.yellow('in'), 18 | chalk.blueBright(group.metadata.subject) 19 | ) 20 | 21 | if (event.action === 'add') return void this.add(event, group) 22 | if (event.action === 'remove') return this.leave(event) 23 | } 24 | 25 | add = async (event: IEvent, group: IGroupInfo): Promise => { 26 | const participants = event.participants.map( 27 | (user) => 28 | `${ 29 | this.client.contacts?.[user]?.['notify'] || 30 | this.client.contacts?.[user]?.['vname'] || 31 | this.client.contacts?.[user]?.['name'] || 32 | user.split('@')[0] 33 | } ` 34 | ) 35 | 36 | const picture = await this.client.getPfp(event.jid) 37 | const text = `Welcome to ${group.metadata.subject}\n\n${group.metadata.desc}\n\n${participants}` 38 | if (picture) 39 | return void this.client.sendMessage(event.jid, await Utils.download(picture), MessageType.image, { 40 | caption: text 41 | }) 42 | return void this.client.sendMessage(event.jid, text, MessageType.text) 43 | } 44 | 45 | leave = async (event: IEvent): Promise => { 46 | const user = event.participants[0] 47 | return void this.client.sendMessage( 48 | event.jid, 49 | `Goodbye ${ 50 | this.client.contacts?.[user]?.['notify'] || 51 | this.client.contacts?.[user]?.['vname'] || 52 | this.client.contacts?.[user]?.['name'] || 53 | user.split('@')[0] 54 | }`, 55 | MessageType.text 56 | ) 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |
2 | WhatsApp-Botto-Xre 3 | 4 | # **WhatsApp-Botto-xRe** 5 | [![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2FSomnathDas%2FWhatsapp-Botto-Xre.svg?type=shield)](https://app.fossa.com/projects/git%2Bgithub.com%2FSomnathDas%2FWhatsapp-Botto-Xre?ref=badge_shield) 6 | 7 | [![Deploy](https://www.herokucdn.com/deploy/button.png)](https://heroku.com/deploy) 8 | 9 | ## [![WhatsApp Group](https://img.shields.io/badge/WhatsApp-25D366?style=for-the-badge&logo=whatsapp&logoColor=white)](https://chat.whatsapp.com/I4m8zLPwTme9II9aZWRZJ1) [![TypeScript](https://img.shields.io/badge/TypeScript-007ACC?style=for-the-badge&logo=typescript&logoColor=white)](https://www.typescriptlang.org/) [![NodeJs](https://img.shields.io/badge/Node.js-43853D?style=for-the-badge&logo=node.js&logoColor=white)](https://nodejs.org/en/) 10 | 11 | > A Lightweight & Efficient WhatsApp Bot Packed With Features
12 | 13 |

14 |
15 | 16 | ## ✨ Highlights 17 | - 💖 Object Oriented 18 | - 💙 Written in [TypeScript](https://www.typescriptlang.org/) 19 | - 💛 Event-Based 20 | - 💚 [Express](https://expressjs.com/) Control Panel 21 | - 💜 Self-Resoting Auth 22 | - 💝 Built with [Baileys](https://github.com/adiwajshing/baileys) (The Best WhatsApp Library Out There) 23 | - 🖤 Integrated NSFW(Not Safe For Work) detection based on TensorFlow ML 24 | 25 | ## 💮 Self-Hosting 26 | 27 | - See the [Self-Hosting Guide](https://github.com/Synthesized-Infinity/Whatsapp-Botto-Xre/blob/master/Self-Hosting.md) 28 | - See the [Heroku Deploy Guide](https://github.com/Synthesized-Infinity/Whatsapp-Botto-Xre/blob/master/Heroku_Atlas_Guide.md) 29 | 30 | ## 💪 Contribution 31 | 32 | + Feel free to open issues regarding any problems or if you have any feature requests 33 | + Make sure to follow the ESLint Rules while editing the code and run `npm run prettier-format` before opening PRs 34 | 35 | ## 🌐 Join Us 36 | ### Discord Server 37 | [![DISCORD](https://invidget.switchblade.xyz/Nzsb5weQFg)](https://discord.gg/Nzsb5weQFg) 38 | ### WhatsApp Group 39 | # [![WhatsApp Group](https://img.shields.io/badge/WhatsApp-25D366?style=for-the-badge&logo=whatsapp&logoColor=white)](https://chat.whatsapp.com/I4m8zLPwTme9II9aZWRZJ1) 40 | 41 | ## 📑 License 42 | 43 | [![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2FSomnathDas%2FWhatsapp-Botto-Xre.svg?type=large)](https://app.fossa.com/projects/git%2Bgithub.com%2FSomnathDas%2FWhatsapp-Botto-Xre?ref=badge_large) 44 | -------------------------------------------------------------------------------- /src/lib/anime.ts: -------------------------------------------------------------------------------- 1 | import { MessageType } from '@adiwajshing/baileys' 2 | import responses from './responses.json' 3 | import Utils from '../Utils' 4 | import { IReply } from '../Typings' 5 | 6 | export const getWById = async (id: string, type: 'anime' | 'manga' | 'character' = 'character'): Promise => { 7 | if (!id) return { body: responses['empty-query'] } 8 | try { 9 | const r = await Utils.fetch(`https://api.jikan.moe/v3/${type}/${id}`, {}) 10 | const sim = r 11 | const n = 12 | type !== 'character' 13 | ? r.score 14 | : sim.animeography[0] 15 | ? sim.animeography[0]['name'] 16 | : sim.mangaography[0]['name'] 17 | const dt = `📙 *${type === 'anime' || type === 'manga' ? 'Title' : 'Name'}:* ${ 18 | sim[type === 'manga' || type === 'anime' ? 'title' : 'name'] 19 | }\n\n🔖 *ID:* ${sim.mal_id}\n\n☄ *${type === 'anime' || type === 'manga' ? 'Rating' : 'Series'}: ${n}*\n\n❄️ ${ 20 | type === 'anime' || type === 'manga' 21 | ? `*Synopsis:* ${sim.synopsis.replace(/\\n/g, '')}` 22 | : `*About:* ${sim.About.replace(/\\n/g, '')}` 23 | }\n\n🌐 *URL:* ${sim.url}` 24 | return { 25 | caption: dt, 26 | body: await Utils.download(sim.image_url), 27 | type: MessageType.image 28 | } 29 | } catch (err) { 30 | return { body: `Couldn't find *${id}*` } 31 | } 32 | } 33 | 34 | export const wSearch = async ( 35 | q: string, 36 | prefix: string, 37 | type: 'anime' | 'manga' | 'character' = 'character' 38 | ): Promise => { 39 | if (!q) return { body: responses['empty-query'] } 40 | try { 41 | const res = await Utils.fetch(`https://api.jikan.moe/v3/search/${type}?q=${q}`, {}) 42 | let z = `🎋 *${Utils.capitalize(type)} Search* 🎋\n\n` 43 | const sim = res.results 44 | let n = 10 45 | if (sim.length < 10) n = sim.length 46 | for (let i = 0; i < n; i++) { 47 | z += `📗 *${ 48 | type === 'anime' || type === 'manga' ? `Title:* ${sim[i].title}` : `Name:* ${sim[i].name}` 49 | }:\n🌐 *URL:* ${sim[i].url}\n🎀 *Full Info:* ${prefix}${ 50 | type === 'anime' ? 'aid' : type === 'manga' ? 'mid' : 'chid' 51 | } ${sim[i].mal_id}\n\n` 52 | } 53 | return { 54 | caption: z, 55 | body: await Utils.download(sim[0].image_url), 56 | type: MessageType.image 57 | } 58 | } catch (err) { 59 | return { body: "Couldn't find" } 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /.github/workflows/codeql-analysis.yml: -------------------------------------------------------------------------------- 1 | # For most projects, this workflow file will not need changing; you simply need 2 | # to commit it to your repository. 3 | # 4 | # You may wish to alter this file to override the set of languages analyzed, 5 | # or to provide custom queries or build logic. 6 | # 7 | # ******** NOTE ******** 8 | # We have attempted to detect the languages in your repository. Please check 9 | # the `language` matrix defined below to confirm you have the correct set of 10 | # supported CodeQL languages. 11 | # 12 | name: "CodeQL" 13 | 14 | on: 15 | push: 16 | branches: [ master ] 17 | pull_request: 18 | # The branches below must be a subset of the branches above 19 | branches: [ master ] 20 | schedule: 21 | - cron: '31 6 * * 5' 22 | 23 | jobs: 24 | analyze: 25 | name: Analyze 26 | runs-on: ubuntu-latest 27 | permissions: 28 | actions: read 29 | contents: read 30 | security-events: write 31 | 32 | strategy: 33 | fail-fast: false 34 | matrix: 35 | language: [ 'typescript' ] 36 | # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python' ] 37 | # Learn more: 38 | # https://docs.github.com/en/free-pro-team@latest/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#changing-the-languages-that-are-analyzed 39 | 40 | steps: 41 | - name: Checkout repository 42 | uses: actions/checkout@v2 43 | 44 | # Initializes the CodeQL tools for scanning. 45 | - name: Initialize CodeQL 46 | uses: github/codeql-action/init@v1 47 | with: 48 | languages: ${{ matrix.language }} 49 | # If you wish to specify custom queries, you can do so here or in a config file. 50 | # By default, queries listed here will override any specified in a config file. 51 | # Prefix the list here with "+" to use these queries and those in the config file. 52 | # queries: ./path/to/local/query, your-org/your-repo/queries@main 53 | 54 | # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). 55 | # If this step fails, then you should remove it and run the build manually (see below) 56 | - name: Autobuild 57 | uses: github/codeql-action/autobuild@v1 58 | 59 | # ℹ️ Command-line programs to run using the OS shell. 60 | # 📚 https://git.io/JvXDl 61 | 62 | # ✏️ If the Autobuild fails above, remove it and uncomment the following three lines 63 | # and modify them (or add more) to build your code if your project 64 | # uses a compiled language 65 | 66 | #- run: | 67 | # make bootstrap 68 | # make release 69 | 70 | - name: Perform CodeQL Analysis 71 | uses: github/codeql-action/analyze@v1 72 | -------------------------------------------------------------------------------- /Self-Hosting.md: -------------------------------------------------------------------------------- 1 | # WhatsApp-Botto-Xre Self-hosting Guide 2 | 3 | 4 | ## ⛵ Prerequisites 5 | 6 | - [Git](https://git-scm.com/) 7 | - [Node.JS](https://nodejs.org/en/) 8 | - [WebP](https://developers.google.com/speed/webp/download) 9 | - [FFMpeg](https://ffmpeg.org/download.html) 10 | - [ImageMagick-Legacy](https://imagemagick.org/index.php) 11 | 12 | ## 🍀 Installation 13 | 14 | Run the following code to clone the repo 15 | ```SH 16 | > git clone https://github.com/Synthesized-Infinity/Whatsapp-Botto-Xre 17 | > cd Whatsapp-Botto-Xre 18 | ``` 19 | Run this to install the depencencies 20 | 21 | ```SH 22 | > npm i && npm i -D 23 | ``` 24 | 25 | ## ✍ Configuration 26 | 27 | Create a file named `.env` then add the following fields 28 | 29 | ```env 30 | BOTNAME=Xre 31 | PREFIX=! 32 | CRON=null 33 | SESSION_ID=PROD 34 | ADMINS= 35 | MONGO_URI=YOUR_CLUSTER_URI 36 | EIF=https://express-is-fun.herokuapp.com/ 37 | ADMIN_GROUP_JID= 38 | ``` 39 | `BOT_NAME` The name of the Bot
40 | `PREFIX` The Prefix of the Bot
41 | `CRON` Cron schedule for clearing all chats (Default: `"0 */6 * * *"`. Every 6 Hours). change this field to `null` if you don't want to schedule. [Learn More](https://www.npmjs.com/package/node-cron)
42 | `SESSION_ID` A string to keep track of your session. 43 | `ADMINS` The phone numbers of users wo you want to be the bot's Admins separated by a comma and must the numbers must be in the following format: `[cc][number]`. eg: `919744******`
44 | `MONGO_URI` is the Connection URL to your DB 45 | To get the connection URL there are two ways 46 | 47 | #1 [Mongo Atlas](http://mongodb.com/cloud/atlas) and create an account \ 48 | After you set up your account create a new Cluster \ 49 | Then copy the connection url to your cluster 50 | 51 | #2 If you don't want to use Mongo Atlas you can install MongoDB in your system and use the URI provided in `.env.example` 52 | Follow the instructions [here](https://docs.mongodb.com/manual/installation/) to install MongoDB in your system 53 | 54 | `EIF` is the main endpoint of the [Express-is-fun APIs](https://express-is-fun.herokuapp.com/api). \ 55 | If you want the chatbot functionality add this url there: `https://express-is-fun.herokuapp.com`. Leave it empty if you don't want the chatbot functionality 56 | 57 | `ADMIN_GROUP_JID` If this field is provided, the members of this group will automatically become admins (use the command `id` to get the jid) 58 | 59 | ## ⌨ Building 60 | 61 | Run `npm run build` and the Compiled JS files, Deceleration Files, Maps and Declaration Maps with their folder will appear in the `dist` folder 62 | 63 | ## 💻 Running 64 | 65 | ```SH 66 | npm start 67 | ``` 68 | Running the above command will start the bot. 69 | To authenticate scan the QR which shows up in the terminal or the link which is logged when the QR event fires using the WA-Web Scanner on your WhatsApp. 70 | Now you're on your own. Good Luck! 71 | 72 | ## 🤡 Don't want to do the hassle of setting up on your own PC? 73 | [Set it up on Heroku](https://github.com/Synthesized-Infinity/Whatsapp-Botto-Xre/blob/master/Heroku_Atlas_Guide.md) 74 | -------------------------------------------------------------------------------- /Heroku_Atlas_Guide.md: -------------------------------------------------------------------------------- 1 | # 🖤️ WhatsApp Botto: Xre 🖤️ 2 | ## 🤖️ Heroku Deployment Guide 🤖️ 3 | 4 | ### Pre-requisite 5 | - 🌐️ Internet 🌐️️ 6 | - 🧠️ Brain 🧠️ 7 | - 🎵️ Music 🎵️ 8 | 9 | ### Notice! 10 | - I'd recommend using 🦊️ the Firefox browser 11 | - I'd recommend disabling extreme ad-blocking extension or settings as it may cause some sites to break 12 | 13 | ## 💚️ Let's set up Mongo Atlas first 💚️ 14 | 1. Go to [MongoDB cloud atlas](https://www.mongodb.com/cloud/atlas) 15 | 16 | 2. Sign up if you don't have an account already or log in if you have one already. 17 | PS: If you don't want to use your email, go to https://temp-mail.org/en/ and generate a temporary disposable email address uwu)/ 18 | 3. Create a new cluster on Mongo Atlas. [It takes time, so don't worry] 19 | 4. After creating a cluster, click on the 'CONNECT' button on the cluster which you've created. 20 | 5. On Setup connection security, I'd recommend you to add 'Your Current IP Address' for security concerns but if you are not willing to go through a little bit of pain, then simply add 'Access from anywhere. Also, you can change this anytime by opening your "IP Access list tab". 21 | 6. Then, create a database user, fill up the name and password and MAKE SURE TO REMEMBER THEM. 22 | 7. Click on the "Choose a connection method" and then click on the "Connect Your Application" option. 23 | 8. Finally, on the "Connect" tab select "Nodejs" as _DRIVER_ with "3.6 or later" in _VERSION_. 24 | 9. Copy the connection string that is provided below and paste it somewhere and replace with 'the password you added while creating database user', also make sure to remove '< >' these from . This will be your _MONGO CLUSTER URI_. 25 | #### Example [Mongo Atlas Cluster URI] 26 | ```mongodb+srv://NekoDaKamiSama:kamisamaofdaculture@cluster0.v93qb.mongodb.net/myFirstDatabase?retryWrites=true&w=majority``` 27 | 28 | 10. That's it for this section, please proceed down below. 29 | 30 | 31 | ## 💗️ Steps to deploy your own Botto on Heroku cloud 32 | 1. [Whatsapp-Botto-Xre](https://github.com/Synthesized-Infinity/Whatsapp-Botto-Xre) - Go there 33 | 2. Scroll down a bit and you will see the "Deploy To Heroku" button in purple color (sorry if you are color blind) 34 | 3. Click on it and login or sign up for Heroku 35 | 4. Enter the following fields 36 | | KEY | VALUE | 37 | | --- | ----------- | 38 | | BOTNAME | Xre | 39 | | PREFIX | ! | 40 | | CRON | 'null' | 41 | | SESSION_ID | Any text you want but make sure to remember and don't share it | 42 | | ADMINS | | 43 | | MONGO_URI | YOUR CLUSTER URI | 44 | | EIF | https://express-is-fun.herokuapp.com/api | 45 | | ADMIN_GROUP_JID | | 46 | 47 | `BOT_NAME` The name of the Bot
48 | `PREFIX` The Prefix of the Bot
49 | `CRON` Cron schedule for clearing all chats (Default: `"0 */6 * * *"`. Every 6 Hours). change this field to `null` if you don't want to schedule. [Learn More](https://www.npmjs.com/package/node-cron)
50 | `SESSION_ID` A string to keep track of your session. 51 | `ADMINS` The phone numbers of users who you want to be the bot's Admins separated by a comma and must the numbers must be in the following format: `[cc][number]`. eg: `919744******` 52 | `MONGO_URI` is the Connection URL to your DB 53 | 5. Wait for the building to finish, you should always keep an eye on log messages, you can find log messages in the Dashboard -> More -> View logs 54 | 6. After it builds, click on the "View" or "Open App" 55 | 7. Authenticate By Providing Your SESSION_ID and a QR Code Will Show Up 56 | 8. Open WhatsApp on your phone -> Click on the 3 Dots on the top Right -> Click on WhatsApp Web -> Click on "Link a Device" and scan the QR from the previous step 57 | 9. Profit! 58 | 59 | ### 😼️ Enjoy and make sure to study! 60 | ## 💜️ Support us on: 61 | ## 💰️ [Patreon](https://www.patreon.com/whatsapp_botto_xre) 62 | -------------------------------------------------------------------------------- /src/Main.ts: -------------------------------------------------------------------------------- 1 | import { Client } from './Client' 2 | import chalk from 'chalk' 3 | import mongoose from 'mongoose' 4 | import qr from 'qr-image' 5 | import moment from 'moment-timezone' 6 | import { writeFileSync } from 'fs-extra' 7 | 8 | import { Web, BaseRoutes } from './Web' 9 | import { Message } from './Handler' 10 | import { EventHandler as EvHandler } from './Handler' 11 | import { schema } from './Mongo' 12 | 13 | export const start = async (PORT: number, MONGO_URI: string): Promise => { 14 | const client = new Client(schema.group, schema.user, schema.session) 15 | 16 | const db = mongoose.connection 17 | 18 | db.once('open', async () => 19 | console.log( 20 | chalk.green('[SERVER]'), 21 | chalk.blue(moment(Date.now() * 1000).format('DD/MM HH:mm:ss')), 22 | chalk.yellow('Connected to Database') 23 | ) 24 | ) 25 | 26 | await mongoose.connect(encodeURI(MONGO_URI), { 27 | useNewUrlParser: true, 28 | useUnifiedTopology: true, 29 | useCreateIndex: true 30 | }) 31 | 32 | client.logger.level = 'fatal' 33 | const auth = await client.getSession(process.env.SESSION_ID || 'PROD') 34 | if (auth) client.loadAuthInfo(auth) 35 | 36 | const web = new Web(client, PORT) 37 | 38 | web.on('web-open', (PORT) => 39 | console.log( 40 | chalk.green('[WEB]'), 41 | chalk.blue(moment(Date.now() * 1000).format('DD/MM HH:mm:ss')), 42 | chalk.yellow( 43 | `Web Server Started on`, 44 | `http://localhost:${PORT}?session=${ 45 | process.env.SESSION_ID || 'PROD' 46 | } | http://localhost:${PORT}/endpoints?session=${process.env.SESSION_ID || 'PROD'}` 47 | ) 48 | ) 49 | ) 50 | 51 | new BaseRoutes(client, web) 52 | const MessageHandler = new Message(client) 53 | const EventHandler = new EvHandler(client) 54 | //Events 55 | 56 | client.on('config', (config) => { 57 | console.log( 58 | chalk.green('[SERVER]'), 59 | chalk.blue(moment(Date.now() * 1000).format('DD/MM HH:mm:ss')), 60 | chalk.yellow('Config Loaded') 61 | ), 62 | console.table(chalk.yellow(config)) 63 | }) 64 | 65 | client.on('qr', (QR) => { 66 | web.QR = qr.imageSync(QR) 67 | console.log( 68 | chalk.green('[SERVER]'), 69 | chalk.blue(moment(Date.now() * 1000).format('DD/MM HH:mm:ss')), 70 | chalk.yellow('Scan the QR Code to Proceed You can also Authenticate at'), 71 | chalk.blueBright(`http://localhost:${web.PORT}/client/qr?session=${process.env.SESSION_ID || 'PROD'}`) 72 | ) 73 | }) 74 | 75 | client.on('open', () => { 76 | web.QR = null 77 | console.log( 78 | chalk.green('[SERVER]'), 79 | chalk.blue(moment(Date.now() * 1000).format('DD/MM HH:mm:ss')), 80 | chalk.yellow('Up and Ready to Go!') 81 | ) 82 | client.updateSession(process.env.SESSION_ID || 'PROD') 83 | writeFileSync( 84 | `./${process.env.SESSION_ID || 'PROD'}_session.json`, 85 | JSON.stringify(client.base64EncodedAuthInfo(), null, '\t') 86 | ) 87 | }) 88 | 89 | client.on('chat-update', (update) => { 90 | if (!update.messages) return 91 | const { messages } = update 92 | const all = messages.all() 93 | const validatedMessage = MessageHandler.validate(all[0]) 94 | if (!validatedMessage) return 95 | if (validatedMessage.chat === 'group') return void MessageHandler.handleGroupMessage(all[0]) 96 | return void MessageHandler.handleDirectMessage(all[0]) 97 | }) 98 | 99 | client.on('chats-received', (update) => { 100 | if (update.hasNewChats) 101 | console.log( 102 | chalk.green('[SERVER]'), 103 | chalk.blue(moment(Date.now() * 1000).format('DD/MM HH:mm:ss')), 104 | chalk.yellow('Chats Received and Cached') 105 | ) 106 | }) 107 | 108 | client.on('contacts-received', () => { 109 | console.log( 110 | chalk.green('[SERVER]'), 111 | chalk.blue(moment(Date.now() * 1000).format('DD/MM HH:mm:ss')), 112 | chalk.yellow('Contacts Received and Cached') 113 | ) 114 | }) 115 | 116 | client.on('group-participants-update', (event) => EventHandler.handle(event)) 117 | 118 | await client.connect() 119 | } 120 | -------------------------------------------------------------------------------- /src/Web/Routes/Base.ts: -------------------------------------------------------------------------------- 1 | import chalk from 'chalk' 2 | import { Router, Request, urlencoded } from 'express' 3 | import { Client } from '../../Client' 4 | import { Web } from '../Web' 5 | import endpoints from '../../lib/endpoints.json' 6 | import moment from 'moment-timezone' 7 | import { unlinkSync } from 'fs-extra' 8 | export class BaseRoutes { 9 | clientRouter = Router() 10 | 11 | constructor(public client: Client, public web: Web) { 12 | this.web.app.use('/client', this.clientRouter) 13 | this.web.app.use('/', urlencoded({ extended: false })) 14 | this.web.app.set('view-engine', 'ejs') 15 | 16 | this.web.app.post('/auth', (req, res) => { 17 | if (req.body.auth !== process.env.SESSION_ID) 18 | return res.render('index.ejs', { error: 'Incorrect Session ID', name: this.client._config.name }) 19 | res.redirect(`/client/qr?session=${process.env.SESSION_ID}`) 20 | }) 21 | 22 | this.web.app.get('/', (req, res) => res.render('index.ejs', { name: this.client._config.name })) 23 | 24 | this.web.app.get('/wakemydyno.txt', async (req, res) => { 25 | res.setHeader('Content-disposition', 'attachment; filename=wakemydyno.txt') 26 | res.setHeader('Content-type', 'text/plain') 27 | res.charset = 'UTF-8' 28 | res.send( 29 | 'Oneechan This Endpoint Is Not For You (づ。◕‿‿◕。)づ. This is for http://wakemydyno.com/ to ping me' 30 | ) 31 | }) 32 | this.clientRouter.use((req, res, next) => { 33 | const auth = this.auth(req) 34 | const t = typeof auth === 'boolean' 35 | console.log( 36 | chalk[!t ? 'red' : 'green']('[WEB]'), 37 | chalk.blue(moment(Date.now() * 1000).format('DD/MM HH:mm:ss')), 38 | req.url 39 | ) 40 | if (!t) return res.json(auth) 41 | next() 42 | this.clientRouter.get('/', (req, res) => { 43 | res.json({ message: 'Hi there' }) 44 | }) 45 | this.clientRouter.get('/qr', async (req, res) => { 46 | if (!this.web.QR) { 47 | if (this.client.state === 'open') return res.json({ message: `You're already authenticated` }) 48 | return res.json({ message: `QR code is not generated Yet` }) 49 | } 50 | res.contentType('image/png') 51 | return res.send(this.web.QR) 52 | }) 53 | 54 | this.clientRouter.get('/state', (req, res) => { 55 | res.json({ state: this.client.state }) 56 | }) 57 | this.web.app.get('/endpoints', (req, res) => { 58 | res.json(endpoints) 59 | }) 60 | 61 | this.clientRouter.get('/config', (req, res) => { 62 | res.json(this.client._config) 63 | }) 64 | 65 | this.clientRouter.get('/user', (req, res) => { 66 | const json = req.query.jid ? this.client.contacts[String(req.query.jid)] || {} : this.client.user 67 | res.json(json) 68 | }) 69 | 70 | this.clientRouter.get('/wa', async (req, res) => { 71 | const query = req.query 72 | if (query?.state === this.connectionOptions[1]) { 73 | if (this.client.state === 'close') 74 | return res.json({ 75 | message: 'The client is not connected to WhatsApp' 76 | }) 77 | this.client.close() 78 | return res.json({ 79 | message: 'WhatsApp Connection Has Been Closed', 80 | connect: `${req.url.replace(this.connectionOptions[1], this.connectionOptions[0])}` 81 | }) 82 | } else if (query?.state === this.connectionOptions[0]) { 83 | if (this.client.state === 'open') 84 | return res.json({ 85 | message: 'The client is already connected to WhatsApp' 86 | }) 87 | await this.client.connect() 88 | return res.json({ 89 | message: 'Successfully Connected to WhatsApp' 90 | }) 91 | } 92 | return res.json({ message: 'Invalid Query' }) 93 | }) 94 | 95 | this.clientRouter.get('/session', async (req, res) => { 96 | if (req.query.delete) { 97 | const ID = process.env.SESSION_ID || 'PROD' 98 | await this.client.SessionModel.deleteOne({ ID }) 99 | unlinkSync(`./${ID}_session.json`) 100 | return res.json({ message: 'Session Deleted' }) 101 | } 102 | return res.json(this.client.base64EncodedAuthInfo()) 103 | }) 104 | 105 | this.clientRouter.get('/pfp', async (req, res) => { 106 | const auth = this.auth(req) 107 | if (typeof auth === 'object') return res.json(auth) 108 | if (!req.query.id) return res.json({ message: 'Not Found' }) 109 | return res.json({ pfp: await this.client.getPfp(req.query.id as string) }) 110 | }) 111 | }) 112 | } 113 | 114 | auth = (req: Request): true | { error: string } => { 115 | const { query } = req 116 | if (!query.session) return { error: `Session ID not Provided` } 117 | if ((query.session as string) !== (process.env.SESSION_ID || 'PROD')) return { error: `Session ID is invalid` } 118 | return true 119 | } 120 | 121 | connectionOptions = ['on', 'off'] 122 | } 123 | -------------------------------------------------------------------------------- /src/lib/commands.json: -------------------------------------------------------------------------------- 1 | { 2 | "general": [ 3 | { 4 | "command": "help", 5 | "description": "Well....", 6 | "usage": "help" 7 | }, 8 | { 9 | "command": "profile", 10 | "description": "Displays the profile of the tagged user", 11 | "usage": "profile (tag) | (@mention)" 12 | }, 13 | { 14 | "command": "group", 15 | "description": "Displays the group info", 16 | "usage": "group" 17 | }, 18 | { 19 | "command": "info", 20 | "description": "Displays my info", 21 | "usage": "info" 22 | }, 23 | { 24 | "command": "commits", 25 | "description": "Displays all the latest code commits on me", 26 | "usage": "commits" 27 | }, 28 | { 29 | "command": "issues", 30 | "description": "Displays the issues with the Xre Repository", 31 | "usage": "issues" 32 | } 33 | ], 34 | "admin": [ 35 | { 36 | "command": "promote", 37 | "description": "Makes the tagged user admin", 38 | "usage": "promote @tag" 39 | }, 40 | { 41 | "command": "demote", 42 | "description": "Demotes the tagged from admin", 43 | "usage": "demote @tag" 44 | }, 45 | { 46 | "command": "remove", 47 | "description": "removes the tagged person", 48 | "usage": "removes @tag" 49 | }, 50 | { 51 | "command": "open", 52 | "description": "opens the group", 53 | "usage": "open" 54 | }, 55 | { 56 | "command": "close", 57 | "description": "closes the group", 58 | "usage": "close" 59 | }, 60 | { 61 | "command": "delete", 62 | "description": "Deletes the quoted message", 63 | "usage": "delete [quoted]" 64 | }, 65 | { 66 | "command": "register", 67 | "description": "registers certain features on the group chat", 68 | "usage": "register feature" 69 | }, 70 | { 71 | "command": "unregister", 72 | "description": "unregister certain features on the group chat", 73 | "usage": "unregister feature" 74 | }, 75 | { 76 | "command": "everyone", 77 | "description": "Tags everyone in the chat", 78 | "usage": "everyone" 79 | }, 80 | { 81 | "command": "purge", 82 | "description": "removes everyone from the group [Note: Only the group creator can use this cmd]", 83 | "usage": "purge" 84 | } 85 | ], 86 | "media": [ 87 | { 88 | "command": "sticker", 89 | "description": "Converts images/videos into sticker", 90 | "usage": "sticker as caption of an image/video" 91 | }, 92 | { 93 | "command": "img", 94 | "description": "Converts static sticker into an image", 95 | "usage": "img while tagging sticker" 96 | }, 97 | { 98 | "command": "subred", 99 | "description": "Fetches a random post from the given subreddit", 100 | "usage": "subred subreddit" 101 | }, 102 | { 103 | "command": "gify", 104 | "description": "Fetches random gifs from a given keyword", 105 | "usages": "gify neko" 106 | }, 107 | { 108 | "command": "yts", 109 | "description": "Searches for videos on https://youtube.com", 110 | "usage": "yts search_term" 111 | }, 112 | { 113 | "command": "ytv", 114 | "description": "Downloads and sends the given YouTube Video URL", 115 | "usage": "ytv url" 116 | }, 117 | { 118 | "command": "yta", 119 | "description": "Downloads and sends the given YouTube Video URL as audio", 120 | "usage": "yta url" 121 | }, 122 | { 123 | "command": "lyrics", 124 | "description": "Fetches lyrics from the given song title", 125 | "usage": "lyrics term" 126 | } 127 | ], 128 | "fun": [ 129 | { 130 | "command": "pat", 131 | "description": "Pats the mentioned or quoted person", 132 | "usage": "pat" 133 | }, 134 | { 135 | "command": "punch", 136 | "description": "Punches the mentioned or quoted person", 137 | "usage": "punch" 138 | }, 139 | { 140 | "command": "slap", 141 | "description": "slaps the mentioned or quoted person", 142 | "usage": "slap" 143 | } 144 | ], 145 | "weeb": [ 146 | { 147 | "command": "wallpaper", 148 | "description": "Fetches an anime-styled-wallpaper on the given term", 149 | "usage": "wallpaper term" 150 | }, 151 | { 152 | "command": "anime", 153 | "description": "Searches for anime based on the given query", 154 | "usage": "anime title" 155 | }, 156 | { 157 | "command": "manga", 158 | "description": "Searches for manga based on the given query", 159 | "usage": "manga title" 160 | }, 161 | { 162 | "command": "character", 163 | "description": "Searches for character based on the given query", 164 | "usage": "character name" 165 | }, 166 | { 167 | "command": "aid", 168 | "description": "Displays the info of the given Anime ID", 169 | "usage": "aid anime_id" 170 | }, 171 | { 172 | "command": "mid", 173 | "description": "Displays the info of the given Manga ID", 174 | "usage": "mid manga_id" 175 | }, 176 | { 177 | "command": "chid", 178 | "description": "Displays the info of the given Character ID", 179 | "usage": "chid character_id" 180 | } 181 | ] 182 | } 183 | -------------------------------------------------------------------------------- /src/lib/responses.json: -------------------------------------------------------------------------------- 1 | { 2 | "invalid-command": "❗ Couldn't find any matching commands. Try again with the commands from the help list", 3 | "wrong-format": "❌ Wrong Format", 4 | "wrong-format-media": "❌ Couldn't find any Image/Video in context", 5 | "empty-query": "❌ No query provided!", 6 | "user-lacks-permission": "❌ This is an Admin only Command", 7 | "no-permission": "❌ Cannot execute without being admin", 8 | "already-enabled": "🎋 *{T}* is already enabled", 9 | "enable-successful": "💮 Successfully Enabled *{T}*", 10 | "not-enabled": "🌟 *{T}* is not Enabled", 11 | "disable-successful": "🧩 Successfully Disabled *{T}*", 12 | "invalid-command-short": "Invalid Command: *{C}*", 13 | "banned-user": "Successfully Banned {U} from Using Commands", 14 | "unbanned-user": "{U} is now allowed to use Commands again", 15 | "already-banned": "{U} is already Banned from Using Commands", 16 | "already-unbanned": "{U} is not banned", 17 | "banned": "You are banned from using commands ❌", 18 | "options": "...", 19 | "invalid-context": "Request Failed. Invalid Context. Try again", 20 | "join-request": "{U} Wants me to join \n{L}", 21 | "join-req-forwarded": "Your Join request has been forwarded", 22 | "no-url-provided": "No URL was provided in your request", 23 | "cannot-process-request": "Couldn't process the request", 24 | "failed-to-join": "Failed to join group. Check the invite url and try again", 25 | "cannot-execute": "Cannot execute this command in this chat", 26 | "invalid-group-action": "Invalid Group Action: {T}", 27 | "direct-message-cmd": "*Commands cannot be used in Direct Messages.* Send a text without the prefix to have a chat", 28 | "no-command-after-prefix": "❗Provide a command from the help list after the prefix\n*Eg: {P}help*", 29 | "no-search-results": "❌ Couldn't find any results on the term *{T}*", 30 | "invalid-url": "Invalid {W} 📘 *URL: {U}*", 31 | "video-duration-clause": "🕐 Cannot fetch videos longer than *10 Minutes*", 32 | "nsfw-detected": "*NSFW Detected*❗", 33 | "not-owner": "The user of this command must be the owner of thr group", 34 | "lyrics": "🔍 *Search Term:* {T}\n\n🎋 *Fetched Lyrics:* \n{L}", 35 | "mod": { 36 | "no-nsfw": "❌ Cannot Display NSFW Content. Register *NSFW* to allow sending *_Explicit content_*", 37 | "group-invite": "❌ *[MOD]* Group Invite Link Detected! Removing..." 38 | }, 39 | "warnings":{ 40 | "purge": "Are you sure? This command will kick everyone from thr group. Use this command again if this is what you want.", 41 | "EIF": "This feature is disabled. If you're the host, Please provide the EIF Main endpoint in your config vars" 42 | }, 43 | "error": { 44 | "500": { 45 | "mod": "{M} | Report this at https://github.com/Synthesized-Infinity/Whatsapp-Botto-Xre/issues if you are using the latest commit", 46 | "regular": "An Error Occurred [Code: 500]" 47 | } 48 | }, 49 | "ads": { 50 | "sticker": "*Sticker Creation Powered By https://npmjs.com/package/wa-sticker-formatter*" 51 | }, 52 | "spoilers": { 53 | "base":" ​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​" 54 | } 55 | } -------------------------------------------------------------------------------- /src/Client/Utils.ts: -------------------------------------------------------------------------------- 1 | import { MessageType, WAConnection, WAGroupMetadata, WAMessage } from '@adiwajshing/baileys/' 2 | import { Model } from 'mongoose' 3 | import responses from '../lib/responses.json' 4 | import { schedule, validate } from 'node-cron' 5 | import chalk from 'chalk' 6 | import moment from 'moment-timezone' 7 | import { IReply, IConfig, IGroupModel, IUserModel, ISessionModel, ISession, IUserInfo } from '../Typings' 8 | import { existsSync } from 'fs-extra' 9 | import { join } from 'path' 10 | import Utils from '../Utils' 11 | const browser: [string, string, string] = ['WhatsApp-Botto-Xre', 'Well', 'Indeed'] 12 | export class Client extends WAConnection { 13 | assets = join(__dirname, '..', '..', 'assets') 14 | 15 | browserDescription = browser 16 | private config: IConfig = { 17 | name: process.env.BOT_NAME || 'Xre', 18 | prefix: process.env.PREFIX || '!', 19 | admins: this.getMods(), 20 | cron: process.env.CRON || null 21 | } 22 | 23 | constructor( 24 | public GroupModel: Model, 25 | public UserModel: Model, 26 | public SessionModel: Model 27 | ) { 28 | super() 29 | if (this.config.cron) this.clearCycle(this.config.cron) 30 | if (process.env.ADMIN_GROUP_JID) 31 | this.groupMetadata(process.env.ADMIN_GROUP_JID).then((info) => 32 | info.participants.filter((u) => u.isAdmin).map((admin) => void this.config.admins.push(admin.jid)) 33 | ) 34 | this.emit('config', this.config) 35 | } 36 | 37 | getMods(): string[] { 38 | if (!process.env.ADMINS) return [] 39 | if (process.env.ADMINS.includes(',')) 40 | return process.env.ADMINS.replace(/\+/g, '') 41 | .split(',') 42 | .map((num) => `${num}@s.whatsapp.net`) 43 | return [`${process.env.ADMINS}@s.whatsapp.net`] 44 | } 45 | 46 | async getSession(ID: string): Promise { 47 | if (existsSync(`./${ID}_session.json`)) return require(join(__dirname, '..', '..', `./${ID}_session.json`)) 48 | const session = await this.SessionModel.findOne({ ID }) 49 | if (!session) return false 50 | return session.session 51 | } 52 | 53 | async updateSession(ID: string): Promise { 54 | const session = await this.SessionModel.findOne({ ID }) 55 | if (!session) return void (await new this.SessionModel({ ID, session: this.base64EncodedAuthInfo() }).save()) 56 | return void (await this.SessionModel.updateOne({ ID }, { $set: { session: this.base64EncodedAuthInfo() } })) 57 | } 58 | 59 | async reply(jid: string, options: IReply, quote?: WAMessage): Promise { 60 | return await this.sendMessage(jid, options.body, options.type || MessageType.text, { 61 | quoted: quote, 62 | caption: options.caption, 63 | mimetype: options.mime 64 | }) 65 | } 66 | 67 | get _config(): IConfig { 68 | return this.config 69 | } 70 | 71 | async getUser(jid: string): Promise { 72 | let data: IUserModel | null = await this.UserModel.findOne({ jid }) 73 | if (!data) data = await new this.UserModel({ jid }).save() 74 | return { user: this.contacts[jid], data } 75 | } 76 | 77 | async banUser(jid: string, ban: boolean): Promise { 78 | let data = await this.UserModel.findOne({ jid }) 79 | if (!data) data = await new this.UserModel({ jid }).save() 80 | if ((ban && data.ban) || (!ban && !data.ban)) return false 81 | await this.UserModel.updateOne({ jid }, { $set: { ban } }) 82 | return true 83 | } 84 | 85 | async everyone( 86 | jid: string, 87 | metadata: WAGroupMetadata, 88 | admin: boolean, 89 | hidden: boolean, 90 | M?: WAMessage 91 | ): Promise { 92 | if (!admin) return void this.reply(jid, { body: responses['no-permission'] }, M) 93 | const mentionedJid = metadata.participants.map((participant) => participant.jid) 94 | const text = `🎀 *${metadata.subject}* 🎀\n${ 95 | hidden 96 | ? `🗣 *[TAGS HIDDEN]* 🗣` 97 | : `${responses.spoilers.base}\n💮 ${mentionedJid 98 | .map((participant) => `@${participant.split('@')[0]}`) 99 | .join('\n💮 ')}` 100 | }` 101 | this.sendMessage(jid, text, MessageType.extendedText, { quoted: M, contextInfo: { mentionedJid } }) 102 | } 103 | 104 | async getPfp(jid: string): Promise { 105 | try { 106 | return await this.getProfilePicture(jid) 107 | } catch (err) { 108 | return null 109 | } 110 | } 111 | 112 | async banAction(chat: string, users: string[], ban: boolean, M: WAMessage): Promise { 113 | for (const user of users) { 114 | const { notify, vname, name } = this.contacts[user] 115 | const username = notify || vname || name || user.split('@')[0] 116 | if (!this.config.admins.includes(user)) { 117 | const response = (await this.banUser(user, ban)) 118 | ? ban 119 | ? responses['banned-user'] 120 | : responses['unbanned-user'] 121 | : !ban 122 | ? responses['already-unbanned'] 123 | : responses['already-banned'] 124 | this.reply(chat, { body: response.replace('{U}', username) }, M) 125 | } 126 | } 127 | } 128 | 129 | clearCycle = async (time: string): Promise => { 130 | if (!validate(time)) 131 | return console.log( 132 | chalk.redBright('[CRON]'), 133 | chalk.blue(moment(Date.now() * 1000).format('DD/MM HH:mm:ss')), 134 | chalk.red('Invalid Cron String', time) 135 | ) 136 | console.log( 137 | chalk.blueBright('[CRON]'), 138 | chalk.blue(moment(Date.now() * 1000).format('DD/MM HH:mm:ss')), 139 | chalk.yellow('Cron Job for Clearing all chats has been scheduled for'), 140 | chalk.greenBright(time) 141 | ) 142 | schedule(time, async () => { 143 | console.log( 144 | chalk.blueBright('[CRON]'), 145 | chalk.blue(moment(Date.now() * 1000).format('DD/MM HH:mm:ss')), 146 | chalk.yellow('Clearing All Chats...') 147 | ) 148 | await this.clearAllChats() 149 | console.log( 150 | chalk.blueBright('[CRON]'), 151 | chalk.blue(moment(Date.now() * 1000).format('DD/MM HH:mm:ss')), 152 | chalk.yellow('Cleared All Chats') 153 | ) 154 | }) 155 | } 156 | 157 | clearAllChats = async (): Promise<{ status: 200 | 500 }> => { 158 | const chats = this.chats.all() 159 | this.setMaxListeners(25) 160 | try { 161 | for (const chat of chats) { 162 | await this.modifyChat(chat.jid, 'clear') 163 | } 164 | return { status: 200 } 165 | } catch (err) { 166 | return { status: 500 } 167 | } 168 | } 169 | 170 | getLinkPreview = async (link: string): Promise => 171 | Buffer.from((await this.generateLinkPreview(link)).jpegThumbnail) 172 | 173 | deleteQuotedMessage = async (M: WAMessage): Promise => { 174 | if (!M?.message?.extendedTextMessage?.contextInfo || !M.key.remoteJid) return responses['wrong-format'] 175 | await this.deleteMessage(M.key.remoteJid, { 176 | id: M.message.extendedTextMessage.contextInfo.stanzaId, 177 | remoteJid: M.key.remoteJid, 178 | fromMe: true 179 | }) 180 | return `Sucessfully Deleted Message` 181 | } 182 | 183 | getUserProfile = async (jid: string, userinfo: IUserInfo, admin = false): Promise => { 184 | const caption = `🍁 *Username: ${ 185 | userinfo.user.notify || userinfo.user.vname || userinfo.user.name || 'None' 186 | }*\n\n🍥 *About: ${(await this.getStatus(jid)).status || 'None'}*\n\n🎖️ *Admin: ${admin}*\n\n🎯 *Ban: ${ 187 | userinfo.data.ban || false 188 | }*` 189 | return { 190 | body: await Utils.download( 191 | (await this.getPfp(jid)) || 'https://img.wallpapersafari.com/tablet/1536/2048/19/44/evOxST.jpg' 192 | ), 193 | caption, 194 | type: MessageType.image 195 | } 196 | } 197 | } 198 | -------------------------------------------------------------------------------- /src/lib/group.ts: -------------------------------------------------------------------------------- 1 | import { GroupSettingChange, MessageType, WAGroupMetadata, WAGroupModification, WAMessage } from '@adiwajshing/baileys' 2 | import { Client } from '../Client' 3 | import Utils from '../Utils' 4 | import responses from './responses.json' 5 | import moment from 'moment-timezone' 6 | import { IGroup, IGroupInfo, IReply } from '../Typings' 7 | import { join } from 'path' 8 | import { readFile } from 'fs-extra' 9 | export class GroupEx { 10 | constructor(public client: Client) {} 11 | 12 | toggleEvent = async ( 13 | chat: string, 14 | contacts: string[], 15 | uia: boolean, 16 | xim: boolean, 17 | type: 'promote' | 'demote' | 'remove' 18 | ): Promise => { 19 | if (!uia) return { body: responses['user-lacks-permission'] } 20 | if (!xim) return { body: responses['no-permission'] } 21 | if (contacts.length === 0) return { body: responses['wrong-format'] } 22 | let mod: WAGroupModification = { status: 0 } 23 | switch (type) { 24 | case 'demote': 25 | mod = await this.client.groupDemoteAdmin(chat, contacts) 26 | break 27 | case 'promote': 28 | mod = await this.client.groupMakeAdmin(chat, contacts) 29 | break 30 | case 'remove': 31 | contacts.map(async (user) => await this.client.groupRemove(chat, [user])) 32 | } 33 | return { 34 | body: `Execution Successful\n\n${Utils.capitalize(type)}:\n${ 35 | !mod.participants 36 | ? contacts 37 | .map((user) => { 38 | const conatct = this.client.contacts[user] 39 | return conatct?.notify || conatct?.vname || conatct?.name || user.split('@')[0] 40 | }) 41 | .join('\n') 42 | : mod?.participants 43 | .map((user: { [k: string]: { code: number } }) => { 44 | const key = Object.keys(user)?.[0] 45 | if (!key || user[key].code < 200) return '' 46 | const conatct = this.client.contacts[key] 47 | return conatct?.notify || conatct?.vname || conatct?.name || key.split('@')[0] 48 | }) 49 | .join('\n') 50 | }` 51 | } 52 | } 53 | 54 | register = async ( 55 | admin: boolean, 56 | chat: IGroup, 57 | register: boolean, 58 | type: toggleableGroupActions 59 | ): Promise => { 60 | if (!admin) return { body: responses['user-lacks-permission'] } 61 | if (!Object.values(toggleableGroupActions).includes(type)) 62 | return { body: responses['invalid-group-action'].replace('{A}', type) } 63 | if (register && chat[type]) 64 | return { 65 | body: responses[register ? 'already-enabled' : 'not-enabled'].replace('{T}', Utils.capitalize(type)) 66 | } 67 | await this.client.GroupModel.updateOne({ jid: chat.jid }, { $set: { [type]: register } }) 68 | return { 69 | body: responses[register ? 'enable-successful' : 'disable-successful'].replace( 70 | '{T}', 71 | Utils.capitalize(type) 72 | ) 73 | } 74 | } 75 | 76 | join = async (text: string, mod: boolean, username = 'User'): Promise => { 77 | const regExec = Utils.urlMatch(text) 78 | if (!regExec) return { body: responses['no-url-provided'] } 79 | if (!mod) { 80 | if (process.env.ADMIN_GROUP_JID || this.client._config.admins[0]) { 81 | void (await this.client.reply(process.env.ADMIN_GROUP_JID || this.client._config.admins[0], { 82 | body: responses['join-request'].replace('{A}', username).replace('{L}', regExec[0]) 83 | })) 84 | return { body: responses['join-req-forwarded'] } 85 | } else return { body: responses['cannot-process-request'] } 86 | } else { 87 | try { 88 | const all = this.client.chats.all().map((chat) => chat.jid) 89 | const group = await this.client.acceptInvite(regExec[0].split('m/')[1]) 90 | if (group?.gid) { 91 | const metadata = await this.client.groupMetadata(group.gid) 92 | return { 93 | body: all.includes(group.gid) 94 | ? `Already in ${metadata.subject}` 95 | : `🎊 Sucessfully Joined!\n\n🎋 *Title:* ${metadata.subject}\n🏊 *Participants:* ${metadata.participants.length}\n📑 *Description:* ${metadata.desc}\n👑 *Created By:* ${metadata.owner}` 96 | } 97 | } 98 | return { body: responses['failed-to-join'] } 99 | } catch (err) { 100 | console.log(err) 101 | return { body: responses['failed-to-join'] } 102 | } 103 | } 104 | } 105 | 106 | simplifiedGroupInfo = async (info: IGroupInfo): Promise => { 107 | const { metadata, data } = info 108 | const [mod, safe, events, NSFW, icon] = [ 109 | data?.mod || false, 110 | data?.safe || false, 111 | data?.events || false, 112 | data?.nsfw || false, 113 | await this.client.getPfp(metadata.id) 114 | ] 115 | const owner = this.client.contacts[metadata.owner] 116 | return { 117 | body: icon ? await Utils.download(icon) : await readFile(join(this.client.assets, 'images', 'yui.jpg')), 118 | caption: `💮 *Title:* ${metadata.subject}\n\n👑 *Created By:* ${ 119 | owner?.notify || owner?.vname || owner?.name || metadata.owner.split('@')[0] 120 | }\n\n📅 *Created On:* ${moment(metadata.creation * 1000).format('DD/MM HH:mm:ss')}\n\n🔊 *Announce:* ${ 121 | metadata.announce || false 122 | }\n\n🍀 *Restricted:* ${metadata.restrict || metadata.restrict || false}\n\n🏊 *Participants:* ${ 123 | metadata.participants.length 124 | }\n\n🏅 *Admins:* ${ 125 | metadata.participants.filter((participant: { isAdmin: unknown }) => participant.isAdmin).length 126 | }\n\n🎯 *Moderation:* ${mod}\n\n🔮 *Events:* ${events}\n\n🌟 *Safe:* ${safe}\n\n🔞 *NSFW:* ${NSFW}\n\n〽 *Description:* \n${ 127 | metadata.desc 128 | }`, 129 | type: MessageType.image 130 | } 131 | } 132 | 133 | announce = async (metadata: WAGroupMetadata, admin: boolean, me: boolean, announce: boolean): Promise => { 134 | if (!admin) return { body: responses['user-lacks-permission'] } 135 | if (!me) return { body: responses['no-permission'] } 136 | if (!announce && !metadata.announce) return { body: `The group is already open` } 137 | if (announce && metadata.announce) return { body: `The group is already closed` } 138 | await this.client.groupSettingChange(metadata.id, GroupSettingChange.messageSend, announce) 139 | return { body: `The group is now ${announce ? 'Closed' : 'Opened'}` } 140 | } 141 | 142 | purge = async (metadata: WAGroupMetadata, sender: string, me: boolean): Promise => { 143 | if (metadata.owner !== sender && metadata.owner !== sender.replace('s.whatsapp.net', 'c.us')) 144 | return { body: responses['not-owner'] } 145 | if (!me) return { body: responses['no-permission'] } 146 | if (!this.purgeSet.has(metadata.id)) { 147 | this.addToPurge(metadata.id) 148 | return { body: responses.warnings.purge } 149 | } 150 | const participants = metadata.participants.map((user) => user.jid) 151 | for (const user of participants) { 152 | if (!(user === metadata.owner || user === this.client.user.jid)) 153 | await this.client.groupRemove(metadata.id, [user]) 154 | } 155 | return { body: 'Done!' } 156 | } 157 | 158 | purgeSet = new Set() 159 | 160 | addToPurge = async (id: string): Promise => { 161 | this.purgeSet.add(id) 162 | setTimeout(() => this.purgeSet.delete(id), 60000) 163 | } 164 | 165 | broadcast = async (text: string, M: WAMessage): Promise => { 166 | if (!text) return `The Broadcast Message can't be Empty` 167 | const chats = this.client.chats.all().filter((chat) => chat.jid.endsWith('g.us')) 168 | const img = await (M.message?.imageMessage 169 | ? this.client.downloadMediaMessage(M) 170 | : readFile(join(__dirname, '..', '..', 'assets', 'images', 'broadcast.png'))) 171 | const bc = `${text}\n\n*[${this.client._config.name} BROADCAST]*` 172 | const groups: string[] = [] 173 | for (const chat of chats) { 174 | if (!chat.read_only) { 175 | try { 176 | await this.client.sendMessage(chat.jid, img, MessageType.image, { caption: bc }) 177 | groups.push(chat.metadata?.subject || '') 178 | } catch (err) { 179 | console.log(err.msg) 180 | continue 181 | } 182 | } 183 | } 184 | return `📣 *Broadcast: ${text}*\n\n💌 *Sent to:*\n${groups.join('\n')}` 185 | } 186 | } 187 | 188 | export enum toggleableGroupActions { 189 | events = 'events', 190 | NSFW = 'nsfw', 191 | safe = 'safe', 192 | mod = 'mod' 193 | } 194 | -------------------------------------------------------------------------------- /src/Handler/Message.ts: -------------------------------------------------------------------------------- 1 | import { MessageType, Mimetype, proto, WAGroupMetadata, WAMessage, WA_MESSAGE_STUB_TYPE } from '@adiwajshing/baileys' 2 | import chalk from 'chalk' 3 | import { Client } from '../Client' 4 | import { 5 | createSticker, 6 | help, 7 | toggleableGroupActions, 8 | getWById, 9 | wSearch, 10 | ytSearch, 11 | getYTMediaFromUrl, 12 | lyrics, 13 | convertStickerToImage, 14 | convertStickerToVideo, 15 | getGifReply 16 | } from '../lib' 17 | import moment from 'moment-timezone' 18 | import responses from '../lib/responses.json' 19 | import Utils from '../Utils' 20 | import { IParsedArgs } from '../Typings' 21 | import { readFile } from 'fs-extra' 22 | import { join } from 'path' 23 | import { getRepoInfo, info } from '../lib/info' 24 | import { wallpaper } from '../lib/wallpaper' 25 | import { reddit } from '../lib/reddit' 26 | import { tmpdir } from 'os' 27 | export class Message { 28 | validTypes = [MessageType.text, MessageType.image, MessageType.video, MessageType.extendedText] 29 | constructor(private client: Client) {} 30 | 31 | handleGroupMessage = async (M: WAMessage): Promise => { 32 | const from = M.key.remoteJid 33 | if (!from) return 34 | const { message } = M.message?.ephemeralMessage || M 35 | if (!message) return 36 | const sender = M.participant 37 | 38 | const mod = this.client._config.admins.includes(sender) 39 | const group = await this.client.getGroupInfo(from) 40 | const { user, data: userData } = await this.client.getUser(sender) 41 | const [admin, iAdmin] = [group.admins.includes(sender), group.admins.includes(this.client.user.jid)] 42 | const username = user?.notify || user?.vname || user?.name || '' 43 | const { body, media } = this.getBase(M, message) 44 | 45 | if (group.data.mod && !admin && iAdmin && !(await this.moderate(M, body || '', group.metadata, username))) 46 | return void null 47 | if (group.data.safe && !admin && iAdmin && (await this.checkMessageandAct(M, username, group.metadata))) 48 | return void null 49 | if (!body) return 50 | const opt = this.parseArgs(body) 51 | if (!opt) return 52 | const { args, flags } = opt 53 | if (!args[0].startsWith(this.client._config.prefix)) return this.freeText(body, M) 54 | const command = args[0].slice(1).toLowerCase() 55 | if (!command) 56 | return void this.client.reply( 57 | from, 58 | { body: responses['no-command-after-prefix'].replace('{P}', this.client._config.prefix) }, 59 | M 60 | ) 61 | const slicedJoinedArgs = args 62 | .join(' ') 63 | .slice(command.length + this.client._config.prefix.length) 64 | .trim() 65 | 66 | const barSplit = slicedJoinedArgs.includes('|') ? slicedJoinedArgs.split('|') : [] 67 | 68 | const mentioned = 69 | message?.extendedTextMessage?.contextInfo?.mentionedJid && 70 | message.extendedTextMessage.contextInfo.mentionedJid.length > 0 71 | ? message.extendedTextMessage.contextInfo?.mentionedJid 72 | : message.extendedTextMessage?.contextInfo?.quotedMessage && 73 | message.extendedTextMessage.contextInfo.participant 74 | ? [message.extendedTextMessage.contextInfo.participant] 75 | : [] 76 | const tag = mentioned[0] || sender 77 | console.log( 78 | chalk.green('[EXEC]'), 79 | chalk.blue(moment(Number(M.messageTimestamp) * 1000).format('DD/MM HH:mm:ss')), 80 | chalk.blueBright(command), 81 | chalk.yellow('from'), 82 | chalk.white(username), 83 | chalk.yellow('in'), 84 | chalk.white(group.metadata.subject) 85 | ) 86 | if (userData.ban) return void this.client.reply(from, { body: responses['banned'] }, M) 87 | 88 | const ad = Math.floor(Math.random() * 5) + 1 89 | try { 90 | switch (command) { 91 | default: 92 | this.client.reply(from, { body: responses['invalid-command'] }, M) 93 | break 94 | case 'bc': 95 | if (!mod) return void null 96 | return void this.client.reply(from, { 97 | body: await this.client.group.broadcast(slicedJoinedArgs, media || M) 98 | }) 99 | case 'id': 100 | return void this.client.reply(from, { body: `GID: ${from}` }, M) 101 | case 'profile': 102 | return void this.client.reply( 103 | from, 104 | await this.client.getUserProfile( 105 | tag, 106 | tag === sender ? { user, data: userData } : await this.client.getUser(tag), 107 | group.admins.includes(tag) 108 | ), 109 | M 110 | ) 111 | case 'everyone': 112 | return void this.client.everyone(from, group.metadata, admin, flags.includes('--hide'), M) 113 | case 'group': 114 | return void this.client.reply(from, await this.client.group.simplifiedGroupInfo(group), M) 115 | case 'eval': 116 | if (mod) return void eval(slicedJoinedArgs) 117 | break 118 | case 'join': 119 | return void this.client.reply( 120 | from, 121 | from === process.env.ADMIN_GROUP_JID 122 | ? await this.client.group.join(slicedJoinedArgs, mod, username) 123 | : { body: responses['cannot-execute'] }, 124 | M 125 | ) 126 | case 'ban': 127 | case 'unban': 128 | if (!mod || mentioned.length === 0) return 129 | return this.client.banAction(from, mentioned, command === 'ban', M) 130 | case 'hi': 131 | this.client.reply(from, { body: `Hi! ${username}` }, M) 132 | break 133 | case 'promote': 134 | case 'demote': 135 | case 'remove': 136 | this.client.reply( 137 | from, 138 | await this.client.group.toggleEvent(from, mentioned, admin, iAdmin, command), 139 | M 140 | ) 141 | break 142 | case 'help': 143 | this.client.reply(from, { body: help(this.client, slicedJoinedArgs.toLowerCase().trim()) }, M) 144 | break 145 | case 'img': 146 | return void (await this.client.reply( 147 | from, 148 | !media || !M.message?.extendedTextMessage?.contextInfo?.quotedMessage?.stickerMessage 149 | ? { body: `Tag the sticker you want to convert` } 150 | : M.message?.extendedTextMessage?.contextInfo?.quotedMessage?.stickerMessage.isAnimated 151 | ? await convertStickerToVideo( 152 | await this.client.downloadAndSaveMediaMessage( 153 | media, 154 | `${tmpdir()}/${Math.random().toString(36)}` 155 | ) 156 | ) 157 | : await convertStickerToImage( 158 | await this.client.downloadAndSaveMediaMessage( 159 | media, 160 | `${tmpdir()}/${Math.random().toString(36)}` 161 | ) 162 | ), 163 | M 164 | )) 165 | case 'sticker': 166 | const sticker = 167 | !media || M.message?.extendedTextMessage?.contextInfo?.quotedMessage?.stickerMessage 168 | ? { body: responses['wrong-format-media'] } 169 | : await createSticker( 170 | await this.client.downloadMediaMessage(media), 171 | flags.includes('--strech'), 172 | barSplit[1], 173 | barSplit[2] 174 | ) 175 | const m = await this.client.reply(from, sticker, M) 176 | if (m && typeof m === 'object' && (m as WAMessage)?.message?.stickerMessage && ad === 5) 177 | return void this.client.reply(from, { body: responses['ads']['sticker'] }, m as WAMessage) 178 | break 179 | case 'wallpaper': 180 | return void this.client.reply(from, await wallpaper(slicedJoinedArgs), M) 181 | case 'anime': 182 | case 'manga': 183 | case 'character': 184 | this.client.reply(from, await wSearch(slicedJoinedArgs, this.client._config.prefix, command), M) 185 | break 186 | case 'aid': 187 | case 'mid': 188 | case 'chid': 189 | this.client.reply( 190 | from, 191 | await getWById( 192 | slicedJoinedArgs, 193 | command === 'aid' ? 'anime' : command === 'mid' ? 'manga' : 'character' 194 | ), 195 | M 196 | ) 197 | break 198 | case 'register': 199 | case 'unregister': 200 | return void this.client.reply( 201 | from, 202 | await this.client.group.register( 203 | admin, 204 | group.data, 205 | command === 'register', 206 | slicedJoinedArgs.toLowerCase().trim() as toggleableGroupActions 207 | ), 208 | M 209 | ) 210 | case 'yta': 211 | case 'ytv': 212 | return void this.client.reply( 213 | from, 214 | await getYTMediaFromUrl(slicedJoinedArgs.trim(), command === 'ytv' ? 'video' : 'audio'), 215 | M 216 | ) 217 | case 'yts': 218 | return void this.client.reply(from, { body: await ytSearch(slicedJoinedArgs.trim()) }, M) 219 | case 'gify': 220 | return void this.client.reply(from, await getGifReply(slicedJoinedArgs), M) 221 | case 'slap': 222 | case 'pat': 223 | case 'punch': 224 | return void this.client.reply( 225 | from, 226 | await getGifReply(command, [ 227 | username, 228 | this.client.contacts[tag].notify || 229 | this.client.contacts[tag].vname || 230 | this.client.contacts[tag].name || 231 | 'User' 232 | ]) 233 | ) 234 | case 'lyrics': 235 | return void this.client.reply(from, { body: await lyrics(slicedJoinedArgs) }, M) 236 | case 'info': 237 | return void this.client.reply(from, await info(), M) 238 | case 'commits': 239 | case 'issues': 240 | return void this.client.reply(from, await getRepoInfo(command), M) 241 | case 'open': 242 | case 'close': 243 | return void this.client.reply( 244 | from, 245 | await this.client.group.announce(group.metadata, admin, iAdmin, command === 'close') 246 | ) 247 | case 'purge': 248 | return void this.client.reply( 249 | from, 250 | await this.client.group.purge(group.metadata, sender, iAdmin), 251 | M 252 | ) 253 | case 'delete': 254 | return void this.client.reply( 255 | from, 256 | { body: admin ? await this.client.deleteQuotedMessage(M) : responses['user-lacks-permission'] }, 257 | M 258 | ) 259 | case 'subred': 260 | return void this.client.reply(from, await reddit(slicedJoinedArgs, !group.data.nsfw), M) 261 | } 262 | } catch (err) { 263 | console.log(err) 264 | return void this.client.reply( 265 | from, 266 | { 267 | body: await readFile(join(this.client.assets, 'images', 'Error-500.gif')), 268 | //eslint-disable-next-line @typescript-eslint/ban-ts-comment 269 | //@ts-ignore 270 | caption: !mod ? responses.error[500].regular : responses.error[500].mod.replace('{M}', err.message), 271 | type: MessageType.video, 272 | mime: Mimetype.gif 273 | }, 274 | M 275 | ) 276 | } 277 | } 278 | 279 | handleDirectMessage = async (M: WAMessage): Promise => { 280 | const from = M.key.remoteJid 281 | if (!from) return 282 | 283 | const { message } = M 284 | if (!message) return 285 | const { body } = this.getBase(M, message) 286 | if (!body) return 287 | const opt = this.parseArgs(body) 288 | if (!opt) return 289 | const { args } = opt 290 | 291 | const { user, data } = await this.client.getUser(from) 292 | if (data.ban) return 293 | const username = user?.notify || user?.vname || user?.name || '' 294 | const cmd = args[0].startsWith(this.client._config.prefix) 295 | console.log( 296 | chalk.green(!cmd ? '[CHAT]' : '[EXEC]'), 297 | chalk.blue(moment(Number(M.messageTimestamp) * 1000).format('DD/MM HH:mm:ss')), 298 | chalk.blueBright(args[0], `[${args.length}]`), 299 | chalk.yellow('from'), 300 | chalk.white(username) 301 | ) 302 | 303 | if (!cmd) 304 | return process.env.EIF 305 | ? void this.client.reply( 306 | from, 307 | { 308 | body: ( 309 | await Utils.fetch( 310 | `${process.env.EIF}/${encodeURI( 311 | `chatbot?message=${body}&bot=${this.client._config.name}&user=${from}` 312 | )}`, 313 | {} 314 | ) 315 | ).message 316 | }, 317 | M 318 | ) 319 | : void null 320 | 321 | const command = args[0].slice(1).toLowerCase() 322 | 323 | const mod = this.client._config.admins.includes(from) 324 | if (!command) return 325 | 326 | switch (command) { 327 | default: 328 | return void this.client.reply(from, { body: responses['direct-message-cmd'] }, M) 329 | case 'join': 330 | return void this.client.reply(from, await this.client.group.join(body, mod, username)) 331 | case 'eval': 332 | if (mod) return void eval(args.slice(1).join(' ').trim()) 333 | break 334 | } 335 | } 336 | 337 | validate = (Msg: WAMessage): { type: MessageType; chat: 'group' | 'dm' } | false => { 338 | const M = Msg.message?.ephemeralMessage || Msg 339 | if (!M.message) return false 340 | if (!!Msg.key.fromMe) return false 341 | if (Msg.key.remoteJid?.endsWith('broadcast')) return false 342 | const type = Object.keys(M.message)[0] 343 | if (!this.validTypes.includes(type as MessageType)) return false 344 | return { type: type as MessageType, chat: Msg.key.remoteJid?.endsWith('g.us') ? 'group' : 'dm' } 345 | } 346 | 347 | getBase = (M: WAMessage, message: proto.IMessage): { body: string | null | undefined; media: WAMessage | null } => { 348 | const body = message?.conversation 349 | ? message.conversation 350 | : message?.extendedTextMessage 351 | ? message.extendedTextMessage.text 352 | : message?.imageMessage 353 | ? message.imageMessage.caption 354 | : message?.videoMessage 355 | ? message.videoMessage.caption 356 | : null 357 | 358 | const media = 359 | message?.imageMessage || message?.videoMessage 360 | ? M 361 | : message?.extendedTextMessage?.contextInfo?.quotedMessage?.imageMessage || 362 | message?.extendedTextMessage?.contextInfo?.quotedMessage?.videoMessage || 363 | message?.extendedTextMessage?.contextInfo?.quotedMessage?.stickerMessage 364 | ? JSON.parse(JSON.stringify(M).replace('quotedM', 'm')).message.extendedTextMessage.contextInfo 365 | : null 366 | 367 | return { body, media } 368 | } 369 | 370 | parseArgs = (text: string): false | IParsedArgs => { 371 | const [args, flags]: string[][] = [[], []] 372 | if (!text) return false 373 | const baseArgs = text.split(' ') 374 | baseArgs.forEach((arg) => { 375 | if (arg?.startsWith('--')) flags.push(arg) 376 | args.push(arg) 377 | }) 378 | return { args, flags } 379 | } 380 | 381 | freeText = async (text: string, M: WAMessage): Promise => { 382 | const args = text.split(/ +/g) 383 | const from = M.key.remoteJid 384 | if (!from) return 385 | const { user, data: userData } = await this.client.getUser(M.participant) 386 | if (userData.ban) return 387 | const username = user?.notify || user?.vname || user?.name || '' 388 | const group = await this.client.getGroupInfo(from) 389 | const admin = group.admins.includes(user.jid) 390 | 391 | let txt = args[0].toLowerCase() 392 | let [log, body] = [false, ''] 393 | if (args.includes('@everyone') && admin) { 394 | if (admin) void this.client.everyone(from, group.metadata, true, false, M) 395 | log = true 396 | txt = '@everyone' 397 | } 398 | switch (txt) { 399 | case 'hey': 400 | body = 'Hi there!' 401 | log = true 402 | break 403 | case 'test': 404 | body = 'Well...' 405 | log = true 406 | break 407 | } 408 | if (log) { 409 | console.log( 410 | chalk.white('[TEXT]'), 411 | chalk.blue(moment(Number(M.messageTimestamp) * 1000).format('DD/MM HH:mm:ss')), 412 | chalk.blueBright(text), 413 | chalk.yellow('from'), 414 | chalk.white(username), 415 | chalk.yellow('in'), 416 | chalk.white(group.metadata.subject) 417 | ) 418 | if (body) this.client.reply(from, { body }, M) 419 | } 420 | } 421 | 422 | checkMessageandAct = async (M: WAMessage, username: string, metadata: WAGroupMetadata): Promise => { 423 | if (!M.message?.imageMessage) return false 424 | if (await this.client.ML.nsfw.check(await this.client.downloadMediaMessage(M))) { 425 | await this.client.reply(metadata.id, { body: responses['nsfw-detected'] }, M) 426 | await this.client.group.toggleEvent(metadata.id, [M.participant], true, true, 'remove') 427 | console.log( 428 | chalk.redBright('[NSFW]'), 429 | chalk.yellow(moment((M.messageTimestamp as number) * 1000).format('DD/MM HH:mm:ss')), 430 | 'By', 431 | chalk.red(username), 432 | 'in', 433 | chalk.red(metadata.subject) 434 | ) 435 | return true 436 | } 437 | return false 438 | } 439 | 440 | moderate = async (M: WAMessage, text: string, metadata: WAGroupMetadata, username: string): Promise => { 441 | if (this.checkForGroupLink(text)) { 442 | await this.client.reply(M.key.remoteJid as string, { body: responses['mod']['group-invite'] }, M) 443 | await this.client.groupRemove(M.key.remoteJid as string, [M.participant]) 444 | console.log( 445 | chalk.redBright('[MOD] GROUP LINK'), 446 | chalk.yellow(moment((M.messageTimestamp as number) * 1000).format('DD/MM HH:mm:ss')), 447 | 'By', 448 | chalk.red(username), 449 | 'in', 450 | chalk.red(metadata.subject) 451 | ) 452 | return false 453 | } 454 | return true 455 | } 456 | 457 | checkForGroupLink = (text: string): boolean => text.includes('chat.whatsapp.com') 458 | 459 | isMessageSafe = (M: WAMessage): boolean => { 460 | if (M.messageStubType === WA_MESSAGE_STUB_TYPE.OVERSIZED) return false 461 | return true 462 | } 463 | 464 | loopText = (inc: number): string => { 465 | let text = `\n` 466 | for (let i = 0; i < inc; i++) text += `\n` 467 | return text 468 | } 469 | } 470 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | --------------------------------------------------------------------------------