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

Issue 543 error displaying username with underscore #586

Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
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
18 changes: 16 additions & 2 deletions bot/modules/dispute/messages.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
const { getDisputeChannel, getDetailedOrder } = require('../../../util');
const { logger } = require('../../../logger');

const escapeMarkdown = function(text) {
const characterToEscape = '_';
const regex = new RegExp(characterToEscape, 'g');

return text.replace(regex, '\\_');
};

exports.beginDispute = async (ctx, initiator, order, buyer, seller) => {
try {
let initiatorUser = buyer;
Expand Down Expand Up @@ -87,11 +94,18 @@ exports.disputeData = async (
}

const detailedOrder = getDetailedOrder(ctx.i18n, order, buyer, seller);

// Fix Issue 543: Escape underscores in usernames
const escapedInitiatorUsername = escapeMarkdown(initiatorUser.username);
const escapedCounterPartyUsername = escapeMarkdown(counterPartyUser.username);

await ctx.telegram.sendMessage(
solver.tg_id,
ctx.i18n.t('dispute_started_channel', {
initiatorUser,
counterPartyUser,
initiatorUser: { ...initiatorUser, username: escapedInitiatorUsername },
initiatorTgId: initiatorUser.tg_id,
counterPartyUser: { ...counterPartyUser, username: escapedCounterPartyUsername },
counterPartyUserTgId: counterPartyUser.tg_id,
buyer,
seller,
buyerDisputes,
Expand Down
4 changes: 2 additions & 2 deletions locales/en.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,8 @@ order_detail: |
seller: seller
buyer: buyer
dispute_started_channel: |
User ${type} @${initiatorUser.username}
has started a dispute with @${counterPartyUser.username} for the order
User ${type} @${initiatorUser.username} TG ID: ${initiatorTgId}
has started a dispute with @${counterPartyUser.username} TG ID: ${counterPartyUserTgId} for the order

${detailedOrder}

Expand Down
4 changes: 2 additions & 2 deletions locales/es.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,8 @@ order_detail: |
seller: vendedor
buyer: comprador
dispute_started_channel: |
El ${type} @${initiatorUser.username}
ha iniciado una disputa con @${counterPartyUser.username} en la orden:
El ${type} @${initiatorUser.username} TG ID: ${initiatorTgId}
ha iniciado una disputa con @${counterPartyUser.username} TG ID: ${counterPartyUserTgId} en la orden:

${detailedOrder}

Expand Down
Loading
Loading