Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
8 changes: 4 additions & 4 deletions .github/workflows/integrate.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
ci_to_main:
runs-on: ubuntu-latest
container:
image: 'ubuntu:24.04'
image: 'ubuntu:26.04'
steps:
- name: Update apt and install required packages
run: |
Expand All @@ -34,13 +34,13 @@ jobs:
sudo rm -f /etc/ssl/certs/ca-bundle.crt
sudo apt reinstall --yes ca-certificates
sudo update-ca-certificates
curl -fsSL https://pgp.mongodb.com/server-6.0.asc | \
sudo gpg -o /usr/share/keyrings/mongodb-server-6.0.gpg \
curl -fsSL https://pgp.mongodb.com/server-8.0.asc | \
sudo gpg -o /usr/share/keyrings/mongodb-server-8.0.gpg \
--dearmor

- name: Install MongoDB
run: |
echo "deb [ arch=amd64,arm64 signed-by=/usr/share/keyrings/mongodb-server-6.0.gpg ] https://repo.mongodb.org/apt/ubuntu jammy/mongodb-org/6.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-6.0.list
echo "deb [ arch=amd64,arm64 signed-by=/usr/share/keyrings/mongodb-server-8.0.gpg ] https://repo.mongodb.org/apt/ubuntu noble/mongodb-org/8.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-8.0.list
sudo apt-get update
sudo apt-get install -y mongodb-org
- name: Check Mongo version
Expand Down
13 changes: 8 additions & 5 deletions bot/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -682,7 +682,7 @@ const cancelOrder = async (
if (order.hash) await cancelHoldInvoice({ hash: order.hash });

order.status = 'CANCELED';
order.canceled_by = user._id;
order.canceled_by = user._id.toString();
await order.save();
OrderEvents.orderUpdated(order);
// we sent a private message to the user
Expand Down Expand Up @@ -739,7 +739,10 @@ const cancelOrder = async (
if (counterPartyUser == null)
throw new Error('counterPartyUser was not found');

const updateOrder = await setCooperativeCancelFlag(order._id, initiator);
const updateOrder = await setCooperativeCancelFlag(
order._id.toString(),
initiator,
);

// If the call returns null, the flag was already set (or order is missing),
// so we treat it as a duplicate request.
Expand All @@ -761,12 +764,12 @@ const cancelOrder = async (
if (updateOrder.hash) await cancelHoldInvoice({ hash: updateOrder.hash });

updateOrder.status = 'CANCELED';
updateOrder.canceled_by = String(user._id);
updateOrder.canceled_by = user._id.toString();
await updateOrder.save();

let seller = initiatorUser;
let i18nCtxSeller = ctx.i18n;
if (order.seller_id == counterPartyUser._id) {
if (order.seller_id === counterPartyUser._id.toString()) {
seller = counterPartyUser;
i18nCtxSeller = i18nCtxCP;
}
Expand Down Expand Up @@ -861,7 +864,7 @@ const release = async (
const order = await validateReleaseOrder(ctx, user, orderId);
if (!order) return;
// We look for a dispute for this order
const dispute = await Dispute.findOne({ order_id: order._id });
const dispute = await Dispute.findOne({ order_id: order._id.toString() });

if (dispute) {
dispute.status = 'RELEASED';
Expand Down
8 changes: 4 additions & 4 deletions bot/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ const invoicePaymentRequestMessage = async (
parse_mode: 'Markdown',
});

await ctx.telegram.sendMessage(user.tg_id, order._id, {
await ctx.telegram.sendMessage(user.tg_id, order._id.toString(), {
reply_markup: {
inline_keyboard: [
[
Expand Down Expand Up @@ -443,7 +443,7 @@ const beginTakeBuyMessage = async (
},
]);

await bot.telegram.sendMessage(seller.tg_id, order._id, {
await bot.telegram.sendMessage(seller.tg_id, order._id.toString(), {
reply_markup: {
inline_keyboard: [
[
Expand Down Expand Up @@ -543,7 +543,7 @@ const onGoingTakeBuyMessage = async (
days: ageInDays,
}),
);
await bot.telegram.sendMessage(buyer.tg_id, order._id, {
await bot.telegram.sendMessage(buyer.tg_id, order._id.toString(), {
reply_markup: {
inline_keyboard: [
[{ text: i18nBuyer.t('continue'), callback_data: 'addInvoiceBtn' }],
Expand Down Expand Up @@ -575,7 +575,7 @@ const beginTakeSellMessage = async (
ctx.i18n.t('you_took_someone_order', { expirationTime }),
{ parse_mode: 'MarkdownV2' },
);
await bot.telegram.sendMessage(buyer.tg_id, order._id, {
await bot.telegram.sendMessage(buyer.tg_id, order._id.toString(), {
reply_markup: {
inline_keyboard: [
[
Expand Down
6 changes: 3 additions & 3 deletions bot/modules/block/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import { Telegraf } from 'telegraf';
import { CommunityContext } from '../community/communityContext';
import { logger } from '../../../logger';

const commands = require('./commands');
const messages = require('./messages');
const { userMiddleware } = require('../../middleware/user');
import * as commands from './commands';
import * as messages from './messages';
import { userMiddleware } from '../../middleware/user';

export const configure = (bot: Telegraf<CommunityContext>) => {
bot.command('block', userMiddleware, async ctx => {
Expand Down
14 changes: 8 additions & 6 deletions bot/modules/community/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { MainContext } from '../../start';
import { CommunityContext } from './communityContext';
import { Telegraf } from 'telegraf';

async function getOrderCountByCommunity(): Promise<number[]> {
async function getOrderCountByCommunity(): Promise<Record<string, number>> {
const data = await Order.aggregate([
{ $group: { _id: '$community_id', total: { $count: {} } } },
]);
Expand Down Expand Up @@ -57,7 +57,7 @@ export const setComm = async (ctx: MainContext) => {
return await ctx.reply(ctx.i18n.t('community_not_found'));
}

user.default_community_id = community._id;
user.default_community_id = community._id.toString();
await user.save();

await ctx.reply(ctx.i18n.t('operation_successful'));
Expand Down Expand Up @@ -89,7 +89,9 @@ export const myComms = async (ctx: MainContext) => {
try {
const { user } = ctx;

const communities = await Community.find({ creator_id: user._id });
const communities = await Community.find({
creator_id: user._id.toString(),
});

if (!communities.length)
return await ctx.reply(ctx.i18n.t('you_dont_have_communities'));
Expand Down Expand Up @@ -146,7 +148,7 @@ export const updateCommunity = async (
if (!(await validateObjectId(ctx, id))) return;
const community = await Community.findOne({
_id: id,
creator_id: user._id,
creator_id: user._id.toString(),
});

if (!community) {
Expand Down Expand Up @@ -221,7 +223,7 @@ export const deleteCommunity = async (ctx: CommunityContext) => {
if (!(await validateObjectId(ctx, id))) return;
const community = await Community.findOne({
_id: id,
creator_id: ctx.user._id,
creator_id: ctx.user._id.toString(),
});

if (!community) {
Expand All @@ -244,7 +246,7 @@ export const changeVisibility = async (ctx: CommunityContext) => {
if (!(await validateObjectId(ctx, id))) return;
const community = await Community.findOne({
_id: id,
creator_id: ctx.user._id,
creator_id: ctx.user._id.toString(),
});

if (!community) {
Expand Down
2 changes: 1 addition & 1 deletion bot/modules/community/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ export const earningsMessage = async (ctx: MainContext) => {
// We check if there is a payment scheduled for this community
const isScheduled = await PendingPayment.findOne({
community_id: communityId,
attempts: { $lt: process.env.PAYMENT_ATTEMPTS },
attempts: { $lt: Number(process.env.PAYMENT_ATTEMPTS) },
paid: false,
});
if (isScheduled)
Expand Down
12 changes: 6 additions & 6 deletions bot/modules/community/scenes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -394,9 +394,9 @@ const createCommunitySteps = {
const user = await User.findOne({ username });
if (user) {
solvers.push({
id: user._id,
id: user._id.toString(),
username: user.username,
} as IUsernameId);
} as unknown as IUsernameId);
}
}
} else {
Expand Down Expand Up @@ -745,9 +745,9 @@ export const updateSolversCommunityWizard = new Scenes.WizardScene(
if (user == null) throw new Error('user not found');
if (user) {
solvers.push({
id: user._id,
id: user._id.toString(),
username: user.username,
} as IUsernameId);
} as unknown as IUsernameId);
botUsers.push(username);
} else {
notBotUsers.push(username);
Expand Down Expand Up @@ -945,8 +945,8 @@ export const addEarningsInvoiceWizard = new Scenes.WizardScene(
return await ctx.reply(ctx.i18n.t('invoice_with_incorrect_amount'));

const isScheduled = await PendingPayment.findOne({
community_id: community._id,
attempts: { $lt: process.env.PAYMENT_ATTEMPTS },
community_id: community._id.toString(),
attempts: { $lt: Number(process.env.PAYMENT_ATTEMPTS) },
paid: false,
is_invoice_expired: false,
});
Expand Down
10 changes: 8 additions & 2 deletions bot/modules/dispute/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,16 @@ export const takeDispute = async (ctx: MainContext): Promise<void> => {
if (seller === null) throw new Error('seller not found');
const initiator = order.buyer_dispute ? 'buyer' : 'seller';
const buyerDisputes = await Dispute.countDocuments({
$or: [{ buyer_id: buyer._id }, { seller_id: buyer._id }],
$or: [
{ buyer_id: buyer._id.toString() },
{ seller_id: buyer._id.toString() },
],
});
const sellerDisputes = await Dispute.countDocuments({
$or: [{ buyer_id: seller._id }, { seller_id: seller._id }],
$or: [
{ buyer_id: seller._id.toString() },
{ seller_id: seller._id.toString() },
],
});

dispute.solver_id = solver.id;
Expand Down
18 changes: 12 additions & 6 deletions bot/modules/dispute/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export const handleDispute = async (ctx: MainContext, orderId: string) => {
const seller = await User.findOne({ _id: order.seller_id });
if (seller === null) throw new Error('seller was not found');
let initiator: 'seller' | 'buyer' = 'seller';
if (user._id == order.buyer_id) initiator = 'buyer';
if (user._id.toString() == order.buyer_id) initiator = 'buyer';

order.previous_dispute_status = order.status;
if (initiator === 'seller') order.seller_dispute = true;
Expand All @@ -53,11 +53,17 @@ export const handleDispute = async (ctx: MainContext, orderId: string) => {
// If a user disputes is equal to MAX_DISPUTES, we ban the user
const buyerDisputes =
(await Dispute.countDocuments({
$or: [{ buyer_id: buyer._id }, { seller_id: buyer._id }],
$or: [
{ buyer_id: buyer._id.toString() },
{ seller_id: buyer._id.toString() },
],
})) + 1;
const sellerDisputes =
(await Dispute.countDocuments({
$or: [{ buyer_id: seller._id }, { seller_id: seller._id }],
$or: [
{ buyer_id: seller._id.toString() },
{ seller_id: seller._id.toString() },
],
})) + 1;
const maxDisputes = Number(process.env.MAX_DISPUTES);
// if MAX_DISPUTES is not specified or can't be parsed as number, following
Expand Down Expand Up @@ -164,13 +170,13 @@ const deleteDispute = async (ctx: MainContext) => {

// We check if this dispute is from a community we validate that
// the solver is running this command
if (dispute && dispute.solver_id != admin._id) {
if (dispute && dispute.solver_id != admin._id.toString()) {
return await globalMessages.notAuthorized(ctx);
}
}

if (user._id == dispute.buyer_id) dispute.buyer_id = null;
if (user._id == dispute.seller_id) dispute.seller_id = null;
if (user._id.toString() == dispute.buyer_id) dispute.buyer_id = null;
if (user._id.toString() == dispute.seller_id) dispute.seller_id = null;
await dispute.save();

await ctx.reply(ctx.i18n.t('operation_successful'));
Expand Down
2 changes: 1 addition & 1 deletion bot/modules/orders/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ async function enterWizard(

const isMaxPending = async (user: UserDocument) => {
const pendingOrders = await Order.countDocuments({
creator_id: user._id,
creator_id: user._id.toString(),
status: 'PENDING',
});
const maxPendingOrders = process.env.MAX_PENDING_ORDERS;
Expand Down
4 changes: 2 additions & 2 deletions bot/modules/orders/takeOrder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export const takebuy = async (
const { randomImage } = generateRandomImage(user._id.toString());

order.status = 'WAITING_PAYMENT';
order.seller_id = user._id;
order.seller_id = user._id.toString();
order.taken_at = new Date(Date.now());

order.random_image = randomImage;
Expand Down Expand Up @@ -129,7 +129,7 @@ export const takesell = async (
return await messages.bannedUserErrorMessage(ctx, user);
if (!(await validateTakeSellOrder(ctx, bot, user, order))) return;
order.status = 'WAITING_BUYER_INVOICE';
order.buyer_id = user._id;
order.buyer_id = user._id.toString();
order.taken_at = new Date(Date.now());

await order.save();
Expand Down
12 changes: 9 additions & 3 deletions bot/ordersActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,10 @@ const getOrder = async (

const where = {
_id: orderId,
$or: [{ seller_id: user._id }, { buyer_id: user._id }],
$or: [
{ seller_id: user._id.toString() },
{ buyer_id: user._id.toString() },
],
};

const order = await Order.findOne(where).exec();
Expand All @@ -318,7 +321,10 @@ const getOrders = async (user: UserDocument, status?: string) => {
const where: any = {
$and: [
{
$or: [{ buyer_id: user._id }, { seller_id: user._id }],
$or: [
{ buyer_id: user._id.toString() },
{ seller_id: user._id.toString() },
],
},
],
};
Expand Down Expand Up @@ -365,7 +371,7 @@ const getNewRangeOrderPayload = async (order: IOrder) => {
paymentMethod: order.payment_method,
status: 'PENDING',
priceMargin: order.price_margin,
range_parent_id: order._id,
range_parent_id: order._id.toString(),
tgChatId: order.tg_chat_id,
tgOrderMessage: order.tg_order_message,
community_id: order.community_id,
Expand Down
4 changes: 2 additions & 2 deletions bot/scenes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,8 @@ const addInvoicePHIWizard = new Scenes.WizardScene(
return await messages.incorrectAmountInvoiceMessage(ctx);

const isScheduled = await PendingPayment.findOne({
order_id: order._id,
attempts: { $lt: process.env.PAYMENT_ATTEMPTS },
order_id: order._id.toString(),
attempts: { $lt: Number(process.env.PAYMENT_ATTEMPTS) },
is_invoice_expired: false,
});
// We check if the payment is on flight
Expand Down
Loading