Skip to content

Commit

Permalink
Merge pull request #442 from hanshino/fix/quote
Browse files Browse the repository at this point in the history
Revert history
  • Loading branch information
hanshino authored Sep 26, 2023
2 parents ad4bc6b + 9edfb27 commit 3ea97e3
Show file tree
Hide file tree
Showing 39 changed files with 235 additions and 285 deletions.
50 changes: 0 additions & 50 deletions app/src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -369,56 +369,6 @@ function Nothing(context) {

async function App(context) {
traffic.recordPeople(context);

context.quoteReply = function (...args) {
if (!context.event.isText) {
return context.reply(...args);
}

const { quoteToken } = context.event.message;
const [text] = args;
let replyObject = {};

const textType = typeof text;

if (textType === "string") {
replyObject = [
{
type: "text",
text,
quoteToken,
},
];
} else if (Array.isArray(text)) {
replyObject = text.map((t, index) => {
let reply;
if (typeof t === "string") {
reply = {
type: "text",
text: t,
};
} else if (typeof t === "object") {
reply = {
...t,
};
}

if (index === 0) {
reply.quoteToken = quoteToken;
}

return reply;
});
} else if (textType === "object") {
replyObject = {
...text,
quoteToken,
};
}

return context.reply(replyObject);
};

return chain([
setProfile, // 設置各式用戶資料
statistics, // 數據蒐集
Expand Down
24 changes: 12 additions & 12 deletions app/src/controller/application/AdvancementController.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ async function list(context) {
const data = await advModel.findUserAdvancementsByPlatformId(userId);

if (data.length === 0) {
return context.quoteReply(i18n.__("message.advancement.no_data"));
return context.replyText(i18n.__("message.advancement.no_data"));
}

const rows = data.map(item => {
Expand Down Expand Up @@ -62,7 +62,7 @@ async function adminList(context) {
let page = 1;

if (args.help || args.h) {
return context.quoteReply(i18n.__("message.advancement.list_usage"));
return context.replyText(i18n.__("message.advancement.list_usage"));
}

if (args.page) {
Expand Down Expand Up @@ -109,7 +109,7 @@ async function adminList(context) {
config
);

return context.quoteReply(messages);
return context.replyText(messages);
}

/**
Expand All @@ -120,7 +120,7 @@ async function adminAdd(context) {
const args = minimist(context.event.message.text.split(" "));

if (args.help || args.h) {
return context.quoteReply(i18n.__("message.advancement.add_usage"));
return context.replyText(i18n.__("message.advancement.add_usage"));
}

const ajv = new Ajv();
Expand Down Expand Up @@ -165,15 +165,15 @@ async function adminAdd(context) {
const valid = validate(attributes);
if (!valid) {
DefaultLogger.warn("管理員新增成就錯誤", validate.errors);
return context.quoteReply(i18n.__("message.advancement.add_invalid_bad_request"));
return context.replyText(i18n.__("message.advancement.add_invalid_bad_request"));
}

const result = await advModel.create(attributes);

if (result) {
return context.quoteReply(i18n.__("message.advancement.add_success", { name: attributes.name }));
return context.replyText(i18n.__("message.advancement.add_success", { name: attributes.name }));
} else {
return context.quoteReply(i18n.__("message.advancement.add_fail"));
return context.replyText(i18n.__("message.advancement.add_fail"));
}
}

Expand All @@ -183,30 +183,30 @@ async function adminAttach(context) {
const mentionees = get(mention, "mentionees", []);

if (args.help || args.h) {
return context.quoteReply(i18n.__("message.advancement.attach_usage"));
return context.replyText(i18n.__("message.advancement.attach_usage"));
}

const advId = get(args, "_.2", null);
if (!isNumber(advId)) {
return context.quoteReply(i18n.__("message.advancement.attach_usage"));
return context.replyText(i18n.__("message.advancement.attach_usage"));
}

if (mentionees.length === 0) {
return context.quoteReply(i18n.__("message.advancement.attach_no_mention"));
return context.replyText(i18n.__("message.advancement.attach_no_mention"));
}

const userIds = mentionees.map(item => item.userId);
const result = await advModel.attachManyByPlatformId(advId, userIds);

if (result) {
const { name } = await advModel.find(advId);
return context.quoteReply(
return context.replyText(
i18n.__("message.advancement.attach_success", {
players: userIds.length,
name,
})
);
} else {
return context.quoteReply(i18n.__("message.advancement.attach_fail"));
return context.replyText(i18n.__("message.advancement.attach_fail"));
}
}
4 changes: 2 additions & 2 deletions app/src/controller/application/AdvertisementController.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ async function addAdvertisement(context) {
const strMessage = match ? match[0] : "";

if (!strMessage) {
await context.quoteReply(i18n.__("message.advertisement.add_usage"));
await context.replyText(i18n.__("message.advertisement.add_usage"));
return;
}

Expand All @@ -40,7 +40,7 @@ async function addAdvertisement(context) {

const ad = await adModel.findLatestByTitle(title);

await context.quoteReply(
await context.replyText(
i18n.__("message.advertisement.add_success", {
title: ad.title,
id: ad.id,
Expand Down
4 changes: 2 additions & 2 deletions app/src/controller/application/AliasController.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ async function alias(context) {
const restStr = message.replace(get(args, "_.0"), "").trim();

if (get(args, "_").length === 1) {
await context.quoteReply(i18n.__("message.alias.add_usage"));
await context.replyText(i18n.__("message.alias.add_usage"));
return;
}

const [newAlias, command] = trim(restStr, '"').split("=");

await setAlias(newAlias, command);

return context.quoteReply(`${newAlias} 已經設定成 ${command}`);
return context.replyText(`${newAlias} 已經設定成 ${command}`);
}

async function setAlias(newAlias, command) {
Expand Down
6 changes: 3 additions & 3 deletions app/src/controller/application/BullshitController.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ exports.router = [
];

async function bullshitManual(context) {
await context.quoteReply(i18n.__("message.bullshit.manual"));
await context.replyText(i18n.__("message.bullshit.manual"));
}

/**
Expand Down Expand Up @@ -44,7 +44,7 @@ async function bullshitGenerator(context, props) {

const data = get(result, "data");
if (!data) {
await context.quoteReply(
await context.replyText(
i18n.__("message.bullshit.failed", {
userId: get(context, "event.source.userId"),
})
Expand All @@ -59,5 +59,5 @@ async function bullshitGenerator(context, props) {
.trim()
.replace(/<br>/g, "\n");

await context.quoteReply(bullshit);
await context.replyText(bullshit);
}
14 changes: 7 additions & 7 deletions app/src/controller/application/ChatLevelController.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ exports.showStatus = async (context, props) => {
pictureUrl = pictureUrl || "https://i.imgur.com/NMl4z2u.png";

if (!userId || !displayName) {
context.quoteReply("獲取失敗,無法辨識用戶");
context.replyText("獲取失敗,無法辨識用戶");
throw "userId or displayName is empty";
}

Expand Down Expand Up @@ -209,7 +209,7 @@ exports.showStatus = async (context, props) => {

const isSelf = context.event.source.userId === userId;
if (!level && isSelf) {
context.quoteReply("尚未有任何數據,經驗開始累積後即可投胎!");
context.replyText("尚未有任何數據,經驗開始累積後即可投胎!");
}
} catch (e) {
DefaultLogger.error(e);
Expand Down Expand Up @@ -313,7 +313,7 @@ async function getQuestInfo(userId) {
exports.showFriendStatus = async context => {
const { mention, text } = context.event.message;
if (!mention) {
return context.quoteReply("請tag想要查詢的夥伴們!");
return context.replyText("請tag想要查詢的夥伴們!");
}
let users = mention.mentionees.map(d => ({
...d,
Expand All @@ -330,10 +330,10 @@ exports.showFriendStatus = async context => {
);

if (messages.length === 0) {
context.quoteReply("查詢失敗!");
context.replyText("查詢失敗!");
} else {
messages = [">>>查詢結果<<<", ...messages];
context.quoteReply(messages.join("\n"));
context.replyText(messages.join("\n"));
}
};

Expand All @@ -348,7 +348,7 @@ exports.setEXP = (context, { match }) => {
console.log(userId, exp, "修改經驗");
ChatLevelModel.setExperience(userId, exp).then(result => {
let msg = result ? "修改成功" : "修改失敗";
context.quoteReply(msg, { sender: { name: "管理員指令" } });
context.replyText(msg, { sender: { name: "管理員指令" } });
});
};

Expand All @@ -363,7 +363,7 @@ exports.setEXPRate = (context, { match }) => {
console.log(expRate, "修改經驗倍率");
ChatLevelModel.setExperienceRate(expRate).then(result => {
let msg = result ? "修改成功" : "修改失敗";
context.quoteReply(msg, { sender: { name: "管理員指令" } });
context.replyText(msg, { sender: { name: "管理員指令" } });
});
};

Expand Down
22 changes: 11 additions & 11 deletions app/src/controller/application/CouponController.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ async function adminAdd(context) {
const args = minimist(context.event.text.split(" "));

if (args.h || args.help) {
return context.quoteReply(i18n.__("message.coupon.admin_add_usage"));
return context.replyText(i18n.__("message.coupon.admin_add_usage"));
}

const [code, startAt, endAt, reward] = [
Expand All @@ -39,7 +39,7 @@ async function adminAdd(context) {
DefaultLogger.warn(
`[CouponController.addCoupon] Validation failed: ${JSON.stringify(validate.errors)}`
);
return context.quoteReply(i18n.__("message.coupon.admin_add_invalid_param"));
return context.replyText(i18n.__("message.coupon.admin_add_invalid_param"));
}

try {
Expand All @@ -53,10 +53,10 @@ async function adminAdd(context) {
end_at: moment(endAt).toDate(),
});

return context.quoteReply(i18n.__("message.coupon.admin_add_success", { id, code }));
return context.replyText(i18n.__("message.coupon.admin_add_success", { id, code }));
} catch (e) {
DefaultLogger.error(e);
return context.quoteReply(i18n.__("message.coupon.admin_add_failed"));
return context.replyText(i18n.__("message.coupon.admin_add_failed"));
}
}

Expand All @@ -69,24 +69,24 @@ async function userUse(context, props) {
const { userId } = context.event.source;

if (!userId) {
return context.quoteReply(i18n.__("message.user_unreconized"));
return context.replyText(i18n.__("message.user_unreconized"));
}

const coupon = await couponCode.findByCode(code);

if (!coupon) {
return context.quoteReply(i18n.__("message.coupon.not_found", { code }));
return context.replyText(i18n.__("message.coupon.not_found", { code }));
}

const [startAt, endAt] = [moment(coupon.start_at), moment(coupon.end_at)];
const now = moment();

if (now.isBefore(startAt)) {
return context.quoteReply(i18n.__("message.coupon.not_yet_available", { code }));
return context.replyText(i18n.__("message.coupon.not_yet_available", { code }));
}

if (now.isAfter(endAt)) {
return context.quoteReply(i18n.__("message.coupon.expired", { code }));
return context.replyText(i18n.__("message.coupon.expired", { code }));
}

const records = await couponUsedHistory.all({
Expand All @@ -103,7 +103,7 @@ async function userUse(context, props) {
});

if (records.length > 0) {
return context.quoteReply(i18n.__("message.coupon.already_used", { code }));
return context.replyText(i18n.__("message.coupon.already_used", { code }));
}

try {
Expand All @@ -114,15 +114,15 @@ async function userUse(context, props) {
coupon_code_id: coupon.id,
});

return context.quoteReply(
return context.replyText(
i18n.__("message.coupon.success", {
code,
reward: getRewardMessage(coupon.reward),
})
);
} catch (e) {
DefaultLogger.error(e);
return context.quoteReply(
return context.replyText(
i18n.__("message.coupon.failed", {
userId,
code,
Expand Down
Loading

0 comments on commit 3ea97e3

Please sign in to comment.