2023-09-24 13:08:35 +00:00
|
|
|
import { Chat, User } from "grammy_types";
|
2023-09-22 02:59:22 +00:00
|
|
|
|
2023-09-24 12:05:28 +00:00
|
|
|
export function formatUserChat(
|
2023-09-24 13:08:35 +00:00
|
|
|
ctx: { from?: User; chat?: Chat; sdInstanceId?: string },
|
2023-09-24 12:05:28 +00:00
|
|
|
) {
|
2023-09-22 02:59:22 +00:00
|
|
|
const msg: string[] = [];
|
|
|
|
if (ctx.from) {
|
|
|
|
msg.push(ctx.from.first_name);
|
|
|
|
if (ctx.from.last_name) msg.push(ctx.from.last_name);
|
|
|
|
if (ctx.from.username) msg.push(`(@${ctx.from.username})`);
|
|
|
|
if (ctx.from.language_code) msg.push(`(${ctx.from.language_code.toUpperCase()})`);
|
|
|
|
}
|
|
|
|
if (ctx.chat) {
|
|
|
|
if (
|
|
|
|
ctx.chat.type === "group" ||
|
|
|
|
ctx.chat.type === "supergroup" ||
|
|
|
|
ctx.chat.type === "channel"
|
|
|
|
) {
|
|
|
|
msg.push("in");
|
|
|
|
msg.push(ctx.chat.title);
|
|
|
|
if (
|
|
|
|
(ctx.chat.type === "supergroup" || ctx.chat.type === "channel") &&
|
|
|
|
ctx.chat.username
|
|
|
|
) {
|
|
|
|
msg.push(`(@${ctx.chat.username})`);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-09-24 12:05:28 +00:00
|
|
|
if (ctx.sdInstanceId) {
|
|
|
|
msg.push(`using ${ctx.sdInstanceId}`);
|
|
|
|
}
|
2023-09-22 02:59:22 +00:00
|
|
|
return msg.join(" ");
|
|
|
|
}
|