Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

websocket implementation #6

Open
wants to merge 115 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
115 commits
Select commit Hold shift + click to select a range
bae60cf
first working version
ender-null Apr 7, 2024
f2294c4
delete bindings
ender-null Apr 7, 2024
11ce92a
upload to docker pull requests
ender-null Apr 7, 2024
d910068
update workflow
ender-null Apr 7, 2024
bcba11b
fix tag
ender-null Apr 7, 2024
78a2856
fix tag
ender-null Apr 7, 2024
6b9f386
fix port
ender-null Apr 7, 2024
77865c8
update format
ender-null Apr 8, 2024
34838dc
implement ping
ender-null Apr 8, 2024
933410c
remove sigkill
ender-null Apr 8, 2024
a44060b
deploy to wired
ender-null Apr 8, 2024
9b55385
update ssh action
ender-null Apr 8, 2024
7b7aef5
add commands
ender-null Apr 8, 2024
64dbbc0
fix build
ender-null Apr 8, 2024
7c871e2
fix bugfixes with locales
ender-null Apr 8, 2024
6680121
fix platform
ender-null Apr 10, 2024
20d27f2
bugfixes and debug
ender-null Apr 10, 2024
a40316c
add voice url for debug
ender-null Apr 10, 2024
a725459
fix null getAdmins
ender-null Apr 11, 2024
0ec3e47
add broadcast
ender-null Apr 11, 2024
3f6f89d
fix build
ender-null Apr 11, 2024
8badfc8
bugfixes for wow
ender-null Apr 12, 2024
1d16f07
fix format
ender-null Apr 12, 2024
d3fecd9
fix wow image
ender-null Apr 12, 2024
e743c2a
lol plugin fixes
ender-null Apr 12, 2024
757fb2a
add chatgpt plugin
ender-null Apr 12, 2024
473ae8f
add debug loggers
ender-null Apr 12, 2024
86b8144
fix debug
ender-null Apr 12, 2024
6695a4e
refactor commands
ender-null Apr 12, 2024
90cf754
add missing chatgpt plugin
ender-null Apr 12, 2024
5f9c1be
add logger for chatgpt
ender-null Apr 12, 2024
7e919ee
fix debug logs
ender-null Apr 12, 2024
e17fc81
remove logger
ender-null Apr 12, 2024
c2ee1b5
add tts to chatgpt
ender-null Apr 14, 2024
0ccdd85
fix file sending
ender-null Apr 14, 2024
f3dbd25
bugfixes
ender-null Apr 14, 2024
b611281
refactor chatgpt and voice plugins
ender-null Apr 14, 2024
b779c89
fix voice file encoding
ender-null Apr 14, 2024
0c00469
handle restart and add ping
ender-null Apr 15, 2024
93e763e
migrate to mongodb
ender-null Apr 16, 2024
634bec5
fix imports
ender-null Apr 16, 2024
6bc99cb
fix translation loading
ender-null Apr 16, 2024
1c6b731
fix poles, improve html to markdown and improve logger
ender-null Apr 16, 2024
ffe9627
don't show trailer when not available
ender-null Apr 16, 2024
887130d
fix text split
ender-null Apr 16, 2024
9cda732
small format change
ender-null Apr 16, 2024
65bf38a
fix wow format
ender-null Apr 16, 2024
ee84ce6
update docker-publish.yml
ender-null Apr 19, 2024
0de5e35
change port
ender-null Apr 22, 2024
82851a3
Merge branch 'feature/websocket' of https://github.com/ender-null/pol…
ender-null Apr 22, 2024
9953af4
fix polerank
ender-null May 5, 2024
8781c28
remove crypto plugin
ender-null May 5, 2024
229af84
fix twitter media forwarder
ender-null May 5, 2024
7c5b60b
add album art for last.fm
ender-null May 5, 2024
6fb6da1
change format
ender-null May 5, 2024
e9803da
fix getFullName
ender-null May 6, 2024
01f2db9
check if target exists on broadcast
ender-null May 6, 2024
2dc8121
broadcast refactor
ender-null May 6, 2024
0ae93a4
broadcast changes
ender-null May 6, 2024
e767f1a
don't show wow character media when not available
ender-null May 6, 2024
5fc7388
use correct config
ender-null May 6, 2024
7433632
refactor and add quotes
ender-null May 7, 2024
934535d
Merge branch 'feature/websocket' of https://github.com/ender-null/pol…
ender-null May 7, 2024
6ae0130
fix build
ender-null May 7, 2024
4129137
upgrade dependencies
ender-null May 7, 2024
455dd33
use debian base
ender-null May 7, 2024
c62ccbb
use node:slim
ender-null May 7, 2024
2123843
fix node-fetch version
ender-null May 7, 2024
66b68e8
remove title from urban dictionary
ender-null May 7, 2024
9c6caae
fix quote markdown
ender-null May 7, 2024
ec6db8c
fix html to markdown replacements
ender-null May 7, 2024
cea672c
format
ender-null May 7, 2024
d5005a4
add typings
ender-null May 7, 2024
10b23d2
fix markdown replacement
ender-null May 7, 2024
2279648
text refactor for urban dictionary
ender-null May 7, 2024
a2f3898
add redirect functionality
ender-null May 7, 2024
ab99389
fix redirect
ender-null May 7, 2024
249f6f9
fix redirect
ender-null May 7, 2024
df7a590
change exec and logger
ender-null May 8, 2024
6790be8
refactor lol plugin
ender-null May 11, 2024
1559f9c
fix build
ender-null May 11, 2024
971be28
fix region
ender-null May 11, 2024
730ab2a
add back regions
ender-null May 11, 2024
77e6e4e
fix riot api call params
ender-null May 11, 2024
26a7add
fix lol and wow plugins
ender-null May 11, 2024
210ef9c
fix gif plugin
ender-null May 11, 2024
54b6b62
small changes
ender-null May 22, 2024
bdd2837
add spica plugin
ender-null May 22, 2024
4156aed
wait for websocket to be ready
ender-null May 22, 2024
b1c656e
add loggers to spica
ender-null May 22, 2024
2bb9e59
add debug info
ender-null May 22, 2024
f11653c
use native websocket
ender-null May 22, 2024
9ca258f
refactor
ender-null May 22, 2024
5276c66
fix imports
ender-null May 22, 2024
516ec3f
fix lol region
ender-null May 22, 2024
7b4dfca
update chatgpt to gpt-4o
ender-null May 22, 2024
5857e40
add setCommands
ender-null May 22, 2024
07ce712
add parameter types
ender-null May 22, 2024
e45fa87
fix getUsername
ender-null May 23, 2024
d59460a
refactor
ender-null May 23, 2024
276a235
refactor help
ender-null May 23, 2024
4d88375
help refactor
ender-null May 23, 2024
270e22b
refactor
ender-null May 24, 2024
a5cc7e8
help and bus format
ender-null May 24, 2024
bfafad0
refactor and some bugfixes
ender-null May 25, 2024
3112c27
update dependencies
ender-null May 29, 2024
fa7bfe5
update dependencies
ender-null May 29, 2024
f052b31
fix build
ender-null May 29, 2024
a2de396
add attachment filename
ender-null Jun 4, 2024
18c485a
refactor attachment
ender-null Jun 4, 2024
ac755d5
improve attachments
ender-null Jun 4, 2024
74db511
refactor attachments
ender-null Jun 4, 2024
d8ce737
format
lunadesangre555 Jun 6, 2024
6f34ea6
update dependencies
lunadesangre555 Jun 12, 2024
e5400ef
add coffee plugin
lunadesangre555 Jun 14, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions .github/workflows/docker-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ on:
push:
branches:
- main
- 'feature/**'
# Publish semver tags as releases.
tags: ['v*.*.*']
pull_request:
Expand Down Expand Up @@ -115,6 +116,7 @@ jobs:
# against the sigstore community Fulcio instance.
run: echo "${TAGS}" | xargs -I {} cosign sign --yes {}@${DIGEST}
deploy:
if: ${{ github.event_name != 'pull_request' }}
runs-on: ubuntu-latest
needs: build
steps:
Expand All @@ -127,7 +129,7 @@ jobs:
CONTAINER_NAME="${REPO#$OWNER}"
CONTAINER_NAME="${CONTAINER_NAME#/}"

TAG=$(echo "${{github.sha}}" | cut -c1-8)
TAG=$(echo "${{github.sha}}" | cut -c1-7)
TAG="sha-$TAG"
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')

Expand All @@ -144,14 +146,15 @@ jobs:
export-env: true
env:
OP_SERVICE_ACCOUNT_TOKEN: ${{ secrets.OP_SERVICE_ACCOUNT_TOKEN }}
HOST: op://end.works/end.works/URL
PORT: op://end.works/end.works/port
USERNAME: op://end.works/end.works/username
HOST: op://end.works/wired/URL
PORT: op://end.works/wired/port
USERNAME: op://end.works/wired/username
KEY: op://end.works/SSH Key/private key
FINGERPRINT: op://end.works/SSH Key/fingerprint
MONGODB_URI: op://end.works/Polaris Config/mongodb uri

- name: Run container on host
uses: appleboy/ssh-action@v0.1.10
uses: appleboy/ssh-action@v1.0.3
with:
host: ${{ env.HOST }}
port: ${{ env.PORT }}
Expand All @@ -161,7 +164,7 @@ jobs:
docker pull ghcr.io/${{ github.repository }}:${{ env.TAG }}
docker stop ${{ env.CONTAINER_NAME }}
docker rm ${{ env.CONTAINER_NAME }}
docker run -v $PWD/logs:/usr/src/app/logs -v $PWD/docs/data:/usr/src/app/data -v $PWD/docs/firebase.json:/usr/src/app/firebase.json -p 1984:1984/tcp -ti -d --restart unless-stopped --name ${{ env.CONTAINER_NAME }} ghcr.io/${{ github.repository }}:${{ env.TAG }}
docker run -e MONGODB_URI=${{ env.MONGODB_URI }} -v $PWD/logs:/usr/src/app/logs -p 8040:8080 -e TZ=Europe/Madrid -ti -d --restart unless-stopped --name ${{ env.CONTAINER_NAME }} ghcr.io/${{ github.repository }}:${{ env.TAG }}

- name: Generate summary
id: generate-summary
Expand Down
1 change: 1 addition & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
yarn run format
13 changes: 11 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
FROM ghcr.io/ender-null/polaris-base:latest-debian as builder
FROM node:slim as builder

RUN npm install yarn@latest -g --force

RUN mkdir -p /usr/src/app

Expand All @@ -13,7 +15,7 @@ COPY . .

RUN yarn run build

FROM ghcr.io/ender-null/polaris-base:latest-debian as release
FROM node:slim as release

LABEL org.opencontainers.image.source https://github.com/ender-null/polaris

Expand All @@ -23,4 +25,11 @@ COPY --from=builder /usr/src/app/node_modules ./node_modules
COPY --from=builder /usr/src/app/build ./build
COPY --from=builder /usr/src/app/package.json ./

RUN apt-get update
RUN apt-get upgrade -y
RUN apt-get install -y ffmpeg opus-tools cron
RUN npm install yarn@latest -g --force
RUN crontab -l -u root | echo "*/15 * * * * find /tmp -type f -delete" | crontab -u root -
ENV TZ=Europe/Madrid

CMD ["yarn", "start"]
48 changes: 22 additions & 26 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "polaris",
"version": "0.10.1",
"version": "1.0.0",
"description": "A multi platform TypeScript bot using plugins!",
"license": "AGPL-3.0",
"author": {
Expand All @@ -21,16 +21,16 @@
"typedoc": "typedoc",
"build": "tsc -p tsconfig.release.json",
"build:watch": "tsc -w -p tsconfig.release.json",
"start": "NODE_OPTIONS=\"--max_old_space_size=4096\" UV_THREADPOOL_SIZE=128 node build/src/main.js",
"start:dev": "ENV=\"dev\" node build/src/main.js",
"start": "node build/src/main.js",
"test": "echo \"No tests yet\" && exit 0",
"lint": "eslint . --ext .ts",
"lint:fix": "eslint . --ext .ts --fix",
"format": "prettier --write src"
"format": "prettier --write src",
"prepare": "husky"
},
"husky": {
"hooks": {
"pre-commit": "npm run lint"
"pre-commit": "yarn run format"
}
},
"type": "commonjs",
Expand All @@ -39,51 +39,47 @@
},
"dependencies": {
"cheerio": "^1.0.0-rc.12",
"discord.js": "^14.14.1",
"firebase": "^10.10.0",
"crypto": "^1.0.1",
"form-data": "^4.0.0",
"html-to-text": "^9.0.5",
"matrix-bot-sdk": "^0.7.1",
"mime-types": "^2.1.35",
"mongodb": "^6.7.0",
"node-cron": "^3.0.3",
"node-fetch": "^2",
"prebuilt-tdlib": "^0.1008026.0",
"node-fetch": "^2.7.0",
"openai": "^4.51.0",
"string-format": "^2.0.0",
"tdl": "v7.4.1",
"tdl-tdlib-addon": "^1.2.2",
"tmp": "^0.2.3",
"winston": "^3.13.0",
"winston-daily-rotate-file": "^5.0.0"
"winston-daily-rotate-file": "^5.0.0",
"ws": "^8.17.0"
},
"devDependencies": {
"@types/mime-types": "^2.1.4",
"@types/node": "^20.12.2",
"@types/node": "^20.14.2",
"@types/node-fetch": "^3.0.3",
"@types/tmp": "^0.2.6",
"@typescript-eslint/eslint-plugin": "^7.4.0",
"@typescript-eslint/parser": "^7.4.0",
"eslint": "^8.57.0",
"@types/ws": "^8.5.10",
"@typescript-eslint/eslint-plugin": "^7.13.0",
"@typescript-eslint/parser": "^7.13.0",
"eslint": "^9.4.0",
"eslint-config-prettier": "^9.1.0",
"eslint-config-standard": "^17.1.0",
"eslint-config-standard-with-typescript": "^21.0.1",
"eslint-plugin-ava": "^14.0.0",
"eslint-plugin-ava": "^15.0.1",
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-prettier": "^5.1.3",
"eslint-plugin-promise": "^6.1.1",
"fluture": "^14.0.0",
"eslint-plugin-promise": "^6.2.0",
"husky": "^9.0.11",
"prettier": "^3.2.5",
"tdlib-types": "td-1.8.14",
"typedoc": "^0.25.12",
"typescript": "^5.4.3"
"pinst": "^3.0.0",
"prettier": "^3.3.2",
"typedoc": "^0.25.13",
"typescript": "^5.4.5"
},
"keywords": [
"polaris",
"polaris js",
"polaris.js",
"telegram",
"telegram bot api",
"bot",
"botapi",
"bot framework"
Expand Down
148 changes: 148 additions & 0 deletions src/actions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
import { Bot } from './bot';
import { ConversationInfo, Message, User } from './types';

export class Actions {
bot: Bot;

constructor(bot: Bot) {
this.bot = bot;
}

async getMessage(chatId: string | number, messageId: string | number, ignoreReply?: boolean): Promise<Message> {
this.bot.sendCommand('getMessage', {
chatId,
messageId,
ignoreReply,
});
return null;
}
async deleteMessage(chatId: string | number, messageId: string | number): Promise<boolean> {
this.bot.sendCommand('deleteMessage', {
chatId,
messageId,
});
return null;
}
async getFile(fileId: string | number, link?: boolean): Promise<string> {
this.bot.sendCommand('getFile', {
fileId,
link,
});
return null;
}
async createInviteLink(
conversationId: string | number,
name?: string,
createsJoinRequest?: boolean,
expirationDate?: number,
memberLimit?: number,
): Promise<string> {
this.bot.sendCommand('createInviteLink', {
conversationId,
name,
createsJoinRequest,
expirationDate,
memberLimit,
});
return null;
}
async checkInviteLink(inviteLink: string | number): Promise<boolean> {
this.bot.sendCommand('checkInviteLink', {
inviteLink,
});
return null;
}
async joinByInviteLink(inviteLink: string | number): Promise<boolean> {
this.bot.sendCommand('joinByInviteLink', {
inviteLink,
});
return null;
}
async inviteConversationMember(conversationId: string | number, userId: string | number): Promise<boolean> {
this.bot.sendCommand('inviteConversationMember', {
conversationId,
userId,
});
return null;
}
async promoteConversationMember(conversationId: string | number, userId: string | number): Promise<boolean> {
this.bot.sendCommand('promoteConversationMember', {
conversationId,
userId,
});
return null;
}
async kickConversationMember(conversationId: string | number, userId: string | number): Promise<boolean> {
this.bot.sendCommand('kickConversationMember', {
conversationId,
userId,
});
return null;
}
async leaveConversation(conversationId: string | number): Promise<boolean> {
this.bot.sendCommand('leaveConversation', {
conversationId,
});
return null;
}
async banConversationMember(conversationId: string | number, userId: string | number): Promise<boolean> {
this.bot.sendCommand('banConversationMember', {
conversationId,
userId,
});
return null;
}
async unbanConversationMember(conversationId: string | number, userId: string | number): Promise<boolean> {
this.bot.sendCommand('unbanConversationMember', {
conversationId,
userId,
});
return null;
}
async renameConversation(conversationId: string | number, title: string): Promise<boolean> {
this.bot.sendCommand('renameConversation', {
conversationId,
title,
});
return null;
}
async changeConversationDescription(conversationId: string | number, description: string): Promise<boolean> {
this.bot.sendCommand('changeConversationDescription', {
conversationId,
description,
});
return null;
}
async changeConversationPhoto(conversationId: string | number, photo: string): Promise<boolean> {
this.bot.sendCommand('changeConversationPhoto', {
conversationId,
photo,
});
return null;
}
async createCall(conversationId: string | number, isVideo: boolean): Promise<boolean> {
this.bot.sendCommand('createCall', {
conversationId,
isVideo,
});
return null;
}
async conversationInfo(conversationId: string | number): Promise<ConversationInfo> {
this.bot.sendCommand('conversationInfo', {
conversationId,
});
return null;
}
async getChatAdministrators(conversationId: string | number): Promise<User[]> {
this.bot.sendCommand('getChatAdministrators', {
conversationId,
});
return null;
}
async setCommands(commands: any[]): Promise<boolean> {
this.bot.sendCommand('setCommands', {
commands,
});
return null;
}
}
60 changes: 0 additions & 60 deletions src/bindings.ts

This file was deleted.

Loading