Skip to content

Commit

Permalink
Remove the nl to br parser and changed the message sending structure.
Browse files Browse the repository at this point in the history
  • Loading branch information
mleandrojr committed Aug 1, 2024
1 parent 725c8f0 commit 7f4efb4
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 11 deletions.
1 change: 0 additions & 1 deletion src/action/Greetings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ export default class Greetings extends Action {
}

text = text.replace("{userid}", this.context.newChatMember!.getId());
text = text.replace(/\n/g, "<br>");
text = text.replace(
"{username}",
this.context.newChatMember?.getFirstName() || this.context.newChatMember?.getUsername()
Expand Down
3 changes: 1 addition & 2 deletions src/command/Rules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,7 @@ export default class Rules extends Command {
return this.context.chat.sendMessage(Lang.get("rulesNotFound"));
}

const text = result[0].rules.replace(/\n/g, "<br>");
return this.context.chat.sendMessage(text, { parseMode: "HTML" });
return this.context.chat.sendMessage(result[0].rules, { parseMode: "HTML" });
}

/**
Expand Down
29 changes: 21 additions & 8 deletions src/library/telegram/context/Chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -430,10 +430,16 @@ export default class Chat {
sendMessage.setOptions(options);
}

return sendMessage.post()
.then((response) => response.json())
.then((json) => new Message(json.result))
.catch((error) => console.error(error));
try {

const response = await sendMessage.post();
return await response.json();

} catch (error: any) {
Log.save(error.message);
}

return Promise.resolve();
}

/**
Expand All @@ -457,9 +463,16 @@ export default class Chat {
sendChatAction.setThreadId(this.context.messageThreadId);
}

return sendChatAction.post()
.then((response) => response.json())
.then((json) => new Message(json.result))
.catch((error) => console.error(error));
try {

const response = await sendChatAction.post();
console.log(response);
return await response.json();

} catch (error: any) {
Log.save(error.message);
}

return Promise.resolve();
}
}

0 comments on commit 7f4efb4

Please sign in to comment.