Skip to content

Commit

Permalink
Merge pull request #118 from bostrot/parsing_fix
Browse files Browse the repository at this point in the history
Parsing fix
  • Loading branch information
bostrot authored Sep 20, 2022
2 parents 68b123f + 4464a81 commit e173c06
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 20 deletions.
3 changes: 0 additions & 3 deletions .eslintrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,3 @@ parserOptions:
plugins:
- "@typescript-eslint"
- "prettier"
rules: {
linebreak-style: ["error", "windows"]
}
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ WORKDIR /bot
COPY ./src /bot/src
COPY ./package.json /bot/package.json
COPY ./package-lock.json /bot/package-lock.json
COPY ./tsconfig.json /bot/tsconfig.json

RUN apk update
RUN apk add wget python3 build-base
Expand Down
2 changes: 1 addition & 1 deletion config/config-sample.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ owner_id: 'YOUR_TELEGRAM_ID'
spam_time: 5 * 60 * 1000 # time (in MS) in which user may send 5 messages
spam_cant_msg: 5

parse_mode: 'MarkdownV2' # DO NOT CHANGE!
parse_mode: 'Markdown' # Experimental. Do not change unless you know what you are doing. Options: Markdown/MarkdownV2/HTML

allow_private: false # Allow / disallow option for staff to chat privately
direct_reply: false # Set this to true to just forward staff users to a user chat when allow_private
Expand Down
3 changes: 1 addition & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
version: '3'
services:
supportbot:
#build: .
image: "bostrot/telegram-support-bot:4.0.0"
build: .
restart: unless-stopped
volumes:
- ${PWD}/config:/bot/config
Expand Down
9 changes: 7 additions & 2 deletions src/files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ function fileHandler(type: string, bot: TelegramAddon, ctx: Context) {
);
}
// replying to non-ticket
if (userid === null || userid === undefined) {
if (userid == null) {
return;
}
}
Expand All @@ -77,7 +77,12 @@ function fileHandler(type: string, bot: TelegramAddon, ctx: Context) {
// }
// if admin
if (ctx.session.admin && userInfo === undefined) {
msgId = userid[1];
// null check here
if (userid != null) {
msgId = userid[1];
} else {
return;
}
}
db.getOpen(
msgId,
Expand Down
26 changes: 14 additions & 12 deletions src/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,18 @@ import {Context} from './interfaces';

// strict escape
const strictEscape = function(str: string | any[]) {
let newStr = '';
const chars = ['[', ']', '(', ')', '_', '*', '~', '`'];
for (let i = 0; i < str.length; i++) {
// escape special characters
if (chars.includes(str[i])) {
newStr += '\\' + str[i];
} else {
newStr += str[i];
}
}
return newStr;
// let newStr = '';
// const chars = ['[', ']', '(', ')', '_', '*', '~', '`'];
// for (let i = 0; i < str.length; i++) {
// // escape special characters
// if (chars.includes(str[i])) {
// newStr += '\\' + str[i];
// } else {
// newStr += str[i];
// }
// }
// return newStr;
return str.toString();
};

// escape special characters
Expand All @@ -26,7 +27,7 @@ const escapeText = function(str: string | string[]) {
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;')
.replace(/"/g, '&quot;');
} else {
} else if (cache.config.parse_mode == 'MarkdownV2') {
// '[', ']', '(', ')', are skipped as they are usally for urls
// '_', '*', '~', '`', are used for actualy markdown
const chars = ['>', '#', '+', '-', '=', '|', '{', '}', '.', '!'];
Expand All @@ -48,6 +49,7 @@ const escapeText = function(str: string | string[]) {
}
return newStr;
}
return str.toString();
};

// handle messages to web socket
Expand Down
1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"sourceMap": true,
"moduleResolution": "node",
"esModuleInterop": true,
"strictNullChecks" : false,
},
"include": [
"./src/**/**/*"
Expand Down

0 comments on commit e173c06

Please sign in to comment.