Skip to content

Commit

Permalink
feat: 現在每日轉蛋要多寫入星數
Browse files Browse the repository at this point in the history
- 錯誤修正
- 文案補全
- 刪除用不到的資料表
  • Loading branch information
hanshinoai committed Sep 12, 2024
1 parent 314e050 commit dae934b
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 60 deletions.
3 changes: 2 additions & 1 deletion app/locales/zh_tw.json
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,8 @@
"rank_max": "已達到最高星數",
"rank_up_manual": "請輸入 `#升星 {角色名稱}` 來提昇角色星數\n_小提示:將開頭符號 `#` 改為 `!` 可以跳過確認步驟_",
"full_rank_up_manual": "請輸入 `#升滿星 {角色名稱}` 可一次將角色升滿星\n_小提示:將開頭符號 `#` 改為 `!` 可以跳過確認步驟_",
"full_rank_up_confirm": "確定要花費 *{{ cost }}* 將 *{{ name }}* 升滿星嗎?\n請改輸入 `!升滿星 {{ name }}`\n手機用戶可直接點擊上面按鈕"
"full_rank_up_confirm": "確定要花費 *{{ cost }}* 將 *{{ name }}* 升滿星嗎?\n請改輸入 `!升滿星 {{ name }}`\n手機用戶可直接點擊上面按鈕",
"full_rank_up_success": "成功將 *{{ name }}* 升滿星"
}
},
"advancement": {
Expand Down
15 changes: 15 additions & 0 deletions app/migrations/20240912090806_drop_gacha_signin_table.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/**
* @param { import("knex").Knex } knex
* @returns { Promise<void> }
*/
exports.up = function (knex) {
return knex.schema.dropTable("GachaSignin");
};

/**
* @param { import("knex").Knex } knex
* @returns { Promise<void> }
*/
exports.down = function (knex) {
return;
};
4 changes: 2 additions & 2 deletions app/src/controller/princess/character.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ async function fullRankup(context, props) {
return context.replyText(i18n.__("message.character.multiple_found"));
}

const [character] = findResult || filterResult;
const character = findResult || filterResult[0];
if (character.attributes.find(attr => attr.key === "star").value === 5) {
return context.replyText(i18n.__("message.character.rank_max"));
}
Expand Down Expand Up @@ -129,7 +129,7 @@ async function rankup(context, props) {
return context.replyText(i18n.__("message.character.multiple_found"));
}

const [character] = findResult || filterResult;
const character = findResult || filterResult[0];
if (character.attributes.find(attr => attr.key === "star").value === 5) {
return context.replyText(i18n.__("message.character.rank_max"));
}
Expand Down
10 changes: 8 additions & 2 deletions app/src/controller/princess/gacha.js
Original file line number Diff line number Diff line change
Expand Up @@ -366,10 +366,16 @@ async function gacha(context, { match, pickup, ensure = false, europe = false })
if (dailyResult.newCharacters.length > 0) {
queries.push(
inventory.knex.insert(
newItemIds.map(itemId => ({
dailyResult.newCharacters.map(character => ({
userId,
itemId,
itemId: character.id,
itemAmount: 1,
attributes: JSON.stringify([
{
key: "star",
value: parseInt(character.star),
},
]),
note: i18n.__("message.gacha.new_character_note"),
}))
)
Expand Down
55 changes: 0 additions & 55 deletions app/src/model/princess/gacha/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,61 +71,6 @@ exports.deleteData = id => {
return mysql.from("GachaPool").where({ id }).del();
};

/**
* 當日轉蛋紀錄
* @param {String} userId
* @returns {object|undefined}
*/
exports.getSignin = async userId => {
var memoryKey = `GachaSignin_${userId}`;
var isSignin = await redis.get(memoryKey);

if (isSignin !== null) return isSignin;

[isSignin] = await mysql
.select("ID")
.from("GachaSignin")
.where({ userId, signinDate: getTodayDate() });

let ID = isSignin ? isSignin.ID : 1;
redis.set(memoryKey, ID, {
EX: 10 * 60,
});

return isSignin;
};

exports.allSignin = async options => {
let query = mysql.from("GachaSignin").select("*");

if (get(options, "filter.userId")) {
query = query.where({ userId: options.filter.userId });
}

if (get(options, "filter.signinAt.start")) {
query = query.where("signinDate", ">=", options.filter.signinAt.start);
}

if (get(options, "filter.signinAt.end")) {
query = query.where("signinDate", "<=", options.filter.signinAt.end);
}

return await query;
};

/**
* 轉蛋紀錄
* @param {String} userId
* @param {String} record
*/
exports.touchSingin = (userId, record = "") => {
var memoryKey = `GachaSignin_${userId}`;
redis.set(memoryKey, 1, {
EX: 10 * 60,
});
return mysql.insert({ userId, signinDate: getTodayDate(), record }).into("GachaSignin").then();
};

/**
* 獲取所有公主角色
* @return {Promise<Array>}
Expand Down

0 comments on commit dae934b

Please sign in to comment.