Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: tuhinpal/WhatsBot
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: main
Choose a base ref
...
head repository: sdip15fa/WhatsBot
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: main
Choose a head ref
Checking mergeability… Don’t worry, you can still create the pull request.
Loading
Showing with 15,108 additions and 3,435 deletions.
  1. +9 −0 .dockerignore
  2. +23 −0 .eslintrc.json
  3. +2 −2 .github/workflows/publish-docker.yml
  4. +5 −1 .gitignore
  5. +59 −0 .gitlab-ci.yml
  6. +1 −0 .husky/.gitignore
  7. +19 −0 .husky/pre-commit
  8. +1 −0 .prettierrc.json
  9. +26 −13 Dockerfile
  10. +4 −0 README.md
  11. +13 −0 cf-worker/.editorconfig
  12. +6 −0 cf-worker/.prettierrc
  13. +17 −0 cf-worker/package.json
  14. +45 −0 cf-worker/src/auth.ts
  15. +35 −0 cf-worker/src/exceptions.ts
  16. +133 −0 cf-worker/src/index.ts
  17. +5 −0 cf-worker/src/types.ts
  18. +7 −0 cf-worker/wrangler.toml.template
  19. +643 −0 cf-worker/yarn.lock
  20. +19 −13 commands/{afk.js → afk.ts}
  21. +13 −5 commands/{allow.js → allow.ts}
  22. +47 −0 commands/autoreply.ts
  23. +8 −2 commands/{awake.js → awake.ts}
  24. +144 −0 commands/blacklist.ts
  25. +14 −5 commands/{block.js → block.ts}
  26. +34 −0 commands/calc.ts
  27. +0 −49 commands/carbon.js
  28. +77 −0 commands/carbon.ts
  29. +33 −0 commands/chatlist.ts
  30. +213 −0 commands/chess.ts
  31. +239 −0 commands/chm.ts
  32. +25 −0 commands/cleargpt.ts
  33. +79 −0 commands/count.ts
  34. +0 −65 commands/courier.js
  35. +77 −0 commands/courier.ts
  36. +194 −0 commands/covid.ts
  37. +0 −52 commands/crypto.js
  38. +67 −0 commands/crypto.ts
  39. +34 −0 commands/delete.ts
  40. +20 −0 commands/dice.ts
  41. +88 −0 commands/dict.ts
  42. +0 −47 commands/directlink.js
  43. +60 −0 commands/directlink.ts
  44. +32 −0 commands/disable.ts
  45. +0 −30 commands/dldsong.js
  46. +46 −0 commands/dldsong.ts
  47. +140 −0 commands/dse.ts
  48. +71 −0 commands/eight_ball.ts
  49. +32 −0 commands/enable.ts
  50. +20 −0 commands/flip.ts
  51. +107 −0 commands/gemini.ts
  52. +63 −0 commands/gif.ts
  53. +0 −71 commands/git.js
  54. +102 −0 commands/git.ts
  55. +93 −0 commands/gpt.ts
  56. +448 −0 commands/hangman.ts
  57. +0 −41 commands/help.js
  58. +58 −0 commands/help.ts
  59. +9 −0 commands/hm.ts
  60. +31 −21 commands/{imdb.js → imdb.ts}
  61. +140 −0 commands/index.ts
  62. +70 −0 commands/joke.ts
  63. +128 −0 commands/llama.ts
  64. +43 −0 commands/media.ts
  65. +86 −0 commands/metar.ts
  66. +12 −6 commands/{mute.js → mute.ts}
  67. +38 −0 commands/nato.ts
  68. +46 −0 commands/nick.ts
  69. +12 −5 commands/{nopm.js → nopm.ts}
  70. +0 −44 commands/ocr.js
  71. +62 −0 commands/ocr.ts
  72. +29 −0 commands/pick.ts
  73. +0 −12 commands/ping.js
  74. +19 −0 commands/ping.ts
  75. +0 −39 commands/qr.js
  76. +47 −0 commands/qr.ts
  77. +51 −0 commands/ratelimit.ts
  78. +82 −0 commands/schedule.ts
  79. +82 −0 commands/sd.ts
  80. +0 −51 commands/shorten.js
  81. +88 −0 commands/shorten.ts
  82. +0 −26 commands/song.js
  83. +34 −0 commands/song.ts
  84. +0 −56 commands/spam.js
  85. +68 −0 commands/spam.ts
  86. +30 −16 commands/{start.js → start.ts}
  87. +0 −22 commands/sticker.js
  88. +53 −0 commands/sticker.ts
  89. +248 −0 commands/story.ts
  90. +41 −0 commands/suicide.ts
  91. +0 −25 commands/term.js
  92. +30 −0 commands/term.ts
  93. +55 −0 commands/time.ts
  94. +0 −95 commands/tr.js
  95. +104 −0 commands/tr.ts
  96. +65 −0 commands/transcribe.ts
  97. +243 −0 commands/ttt.ts
  98. +16 −11 commands/{ud.js → ud.ts}
  99. +0 −17 commands/unmute.js
  100. +26 −0 commands/unmute.ts
  101. +32 −0 commands/unschedule.ts
  102. +0 −60 commands/verifyemail.js
  103. +0 −77 commands/watch.js
  104. +24 −0 commands/weakness.ts
  105. +18 −13 commands/{weather.js → weather.ts}
  106. +77 −0 commands/wf.ts
  107. +0 −65 commands/yt.js
  108. +87 −0 commands/yt.ts
  109. +0 −62 commands/ytmusic.js
  110. +22 −12 config.js → config.ts
  111. +0 −13 db/index.js
  112. +11 −0 db/index.ts
  113. +61 −0 docker/docker-compose.yml
  114. +22 −3 example.env
  115. +0 −13 examples/command_template.js
  116. +14 −0 examples/command_template.ts
  117. +6 −12 helpers/{afkWrapper.js → afkWrapper.ts}
  118. +91 −0 helpers/agenda.ts
  119. +7 −0 helpers/axios.ts
  120. +38 −0 helpers/count.ts
  121. +33 −0 helpers/date.ts
  122. +63 −0 helpers/dict.ts
  123. +232 −0 helpers/dsechin.ts
  124. +0 −17 helpers/formatNum.js
  125. +18 −0 helpers/formatNum.ts
  126. +22 −0 helpers/getName.ts
  127. +30 −43 helpers/{pmpermit.js → pmpermit.ts}
  128. +4 −4 helpers/{processImage.js → processImage.ts}
  129. +0 −98 helpers/song.js
  130. +113 −0 helpers/song.ts
  131. +55 −0 helpers/suicide-wordlist.ts
  132. +11 −0 helpers/timeToWord.ts
  133. +71 −0 helpers/togif.ts
  134. +5 −5 helpers/{tr_languages.js → tr_languages.ts}
  135. +73 −0 helpers/weakness.ts
  136. +4 −2 logger/{index.js → index.ts}
  137. +0 −160 main.js
  138. +692 −0 main.ts
  139. +10 −0 models/count.ts
  140. +17 −0 models/covid.ts
  141. +7 −0 models/media.ts
  142. +9 −0 models/nickname.ts
  143. +11 −0 models/story.ts
  144. +0 −1,790 package-lock.json
  145. +70 −16 package.json
  146. +10 −6 session/{genToken.js → genToken.ts}
  147. +8 −6 session/{genTokenWithDownload.js → genTokenWithDownload.ts}
  148. +0 −101 session/manage.js
  149. +94 −0 session/manage.ts
  150. +0 −15 startProcess.js
  151. +16 −0 startProcess.ts
  152. +21 −0 tsconfig.json
  153. +12 −0 types/command.ts
  154. +33 −0 types/metar.d.ts
  155. +10 −0 types/mime-to-extensions.d.ts
  156. +3 −0 types/nato-pad.d.ts
  157. +8 −0 types/pmpermit.ts
  158. +3 −0 types/scalc.d.ts
  159. +89 −0 types/weather-js.d.ts
  160. +85 −0 types/wolfram.d.ts
  161. +6,818 −0 yarn.lock
9 changes: 9 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/node_modules/
/dist/
/.lh/
/.wwebjs_auth/
/session.secure
/.env
/Dockerfile
/docker
/.dockerignore
23 changes: 23 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"env": {
"browser": true,
"es2021": true
},
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended"
],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": "latest",
"sourceType": "module"
},
"plugins": [
"@typescript-eslint"
],
"rules": {
"no-empty": 0,
"no-empty-function": 0,
"@typescript-eslint/no-empty-function": 0
}
}
4 changes: 2 additions & 2 deletions .github/workflows/publish-docker.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Publish Docker Image 'jeeetpaul/whatsbot'
name: Publish Docker Image 'wcyat/whatsbot'

on:
push:
@@ -20,5 +20,5 @@ jobs:
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
repository: jeeetpaul/whatsbot
repository: wcyat/whatsbot
tag_with_ref: true
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -21,4 +21,8 @@ session.zip
session.txt
session-output/*
session-output
session.secure
session.secure
/.lh/
/dist/
/docker/data
/docker/wtstodis-data
59 changes: 59 additions & 0 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# This file is a template, and might need editing before it works on your project.
# To contribute improvements to CI/CD templates, please follow the Development guide at:
# https://docs.gitlab.com/ee/development/cicd/templates.html
# This specific template is located at:
# https://gitlab.com/gitlab-org/gitlab/-/blob/master/lib/gitlab/ci/templates/Docker.gitlab-ci.yml

# Build a Docker image with CI/CD and push to the GitLab registry.
# Docker-in-Docker documentation: https://docs.gitlab.com/ee/ci/docker/using_docker_build.html
#
# This template uses one generic job with conditional builds
# for the default branch and all other (MR) branches.

docker-build:
# Use the official docker image.
image: docker:latest
stage: build
services:
- docker:dind
before_script:
- docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY
# Default branch leaves tag empty (= latest tag)
# All other branches are tagged with the escaped branch name (commit ref slug)
script:
- |
if [[ "$CI_COMMIT_BRANCH" == "$CI_DEFAULT_BRANCH" ]]; then
tag=""
echo "Running on default branch '$CI_DEFAULT_BRANCH': tag = 'latest'"
else
tag=":$CI_COMMIT_REF_SLUG"
echo "Running on branch '$CI_COMMIT_BRANCH': tag = $tag"
fi
- docker build --pull -t "$CI_REGISTRY_IMAGE${tag}" -t "$CI_REGISTRY_IMAGE:$CI_COMMIT_SHORT_SHA" .
- docker push "$CI_REGISTRY_IMAGE${tag}"
- docker push "$CI_REGISTRY_IMAGE:$CI_COMMIT_SHORT_SHA"
# Run this job in a branch where a Dockerfile exists
rules:
- if: $UPDATE
when: never
- if: $CI_COMMIT_BRANCH
exists:
- Dockerfile

update-dependencies:
image: node:18
before_script:
- apt update && apt install -y git python3 build-essential
- git config --global user.email "bot@wcyat.me"
- git config --global user.name "wcyat bot"
- git remote set-url origin https://root:$gitlab_token@$CI_SERVER_HOST/$CI_PROJECT_PATH
- git fetch origin
- git checkout main
- git reset --hard origin/main
script:
- yarn
- yarn add https://github.com/pedroslopez/whatsapp-web.js
- git commit -a -m "Update whatsapp-web.js" || exit 0
- git push origin main
rules:
- if: $UPDATE
1 change: 1 addition & 0 deletions .husky/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
_
19 changes: 19 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

fileList=$(git diff --diff-filter=d --cached --name-only | tr '\n' ' ' | xargs)
lintFileList=$(echo $fileList | tr ' ' '\n' | grep -E '\.(ts|js)$' | tr '\n' ' ' | xargs)

# test for errors
if [ "$fileList" != "" ];
then
yarn test;
fi;

# lint
if [ "$lintFileList" != "" ];
then
yarn eslint --fix $lintFileList || echo "WARNING: eslint failed to run";
yarn prettier --write $lintFileList || echo "WARNING: prettier failed to run";
git add $lintFileList;
fi;
1 change: 1 addition & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
39 changes: 26 additions & 13 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,17 +1,30 @@
FROM node:alpine
FROM ghcr.io/puppeteer/puppeteer:latest as build

# prepare
RUN apk add --no-cache \
chromium \
ca-certificates \
ffmpeg
USER root

# skip installing chrome
ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true \
PUPPETEER_EXECUTABLE_PATH=/usr/bin/chromium-browser
WORKDIR /app

COPY ./package.json ./yarn.lock ./

RUN yarn install

COPY . ./

RUN yarn build

FROM ghcr.io/puppeteer/puppeteer:latest

WORKDIR /app
COPY . /app
RUN npm install
CMD ["npm", "start"]
EXPOSE 8080

USER root

RUN apt-get update && apt-get install -y ffmpeg stockfish && rm -rf /var/lib/{apt,dpkg,cache,log}/

COPY ./package.json ./yarn.lock ./
RUN yarn install --production

COPY --from=build /app/dist ./

VOLUME ["/app/data"]

CMD ["node", "startProcess.js"]
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# Whatsbot

This is a feature-rich heavily-modified Whatsbot fork.

<!-- <h1 align="center">
<a href="https://github.com/tuhinpal/WhatsBot"><img src="https://telegra.ph/file/96ccad5945c18944c5f15.png" alt="whatsbot" width="290"></a>
<br>
13 changes: 13 additions & 0 deletions cf-worker/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# http://editorconfig.org
root = true

[*]
indent_style = tab
tab_width = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.yml]
indent_style = space
6 changes: 6 additions & 0 deletions cf-worker/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"printWidth": 140,
"singleQuote": true,
"semi": true,
"useTabs": true
}
17 changes: 17 additions & 0 deletions cf-worker/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"name": "whatsbot-worker",
"version": "0.0.0",
"private": true,
"type": "module",
"scripts": {
"deploy": "wrangler deploy",
"dev": "wrangler dev",
"start": "wrangler dev"
},
"devDependencies": {
"wrangler": "^3.0.0"
},
"dependencies": {
"@cloudflare/ai": "^1.1.0"
}
}
45 changes: 45 additions & 0 deletions cf-worker/src/auth.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { BadRequestException, UnauthorizedException } from './exceptions.js';
import { Env } from './types.js';

export function basicAuthentication(request: Request) {
const Authorization = request.headers.get('Authorization');

const [scheme, encoded] = Authorization?.split(' ') || ['', ''];

// The Authorization header must start with Basic, followed by a space.
if (!encoded || scheme !== 'Basic') {
throw new BadRequestException('Malformed authorization header.');
}

// Decodes the base64 value and performs unicode normalization.
// @see https://datatracker.ietf.org/doc/html/rfc7613#section-3.3.2 (and #section-4.2.2)
// @see https://dev.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String/normalize
const buffer = Uint8Array.from(atob(encoded), (character) => character.charCodeAt(0));
const decoded = new TextDecoder().decode(buffer).normalize();

// The username & password are split by the first colon.
//=> example: "username:password"
const index = decoded.indexOf(':');

// The user & password are split by the first colon and MUST NOT contain control characters.
// @see https://tools.ietf.org/html/rfc5234#appendix-B.1 (=> "CTL = %x00-1F / %x7F")
// eslint-disable-next-line no-control-regex
if (index === -1 || /[\0-\x1F\x7F]/.test(decoded)) {
throw new BadRequestException('Invalid authorization value.');
}

return {
user: decoded.substring(0, index),
pass: decoded.substring(index + 1),
};
}

export function verifyCredentials(user: string, pass: string, env: Env) {
if (env.AUTH_USER !== user) {
throw new UnauthorizedException('Invalid credentials.');
}

if (env.AUTH_PASSWORD !== pass) {
throw new UnauthorizedException('Invalid credentials.');
}
}
35 changes: 35 additions & 0 deletions cf-worker/src/exceptions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
export class UnauthorizedException {
status: number;
statusText: string;
reason: string;

constructor(reason: string) {
this.status = 401;
this.statusText = 'Unauthorized';
this.reason = reason;
}
}

export class BadRequestException {
status: number;
statusText: string;
reason: string;

constructor(reason: string) {
this.status = 400;
this.statusText = 'Bad Request';
this.reason = reason;
}
}

export class FailedException {
status: number;
statusText: string;
reason: string;

constructor(reason: string) {
this.status = 500;
this.statusText = 'Internal Server Error';
this.reason = reason;
}
}
Loading