Skip to content

Commit

Permalink
owo events
Browse files Browse the repository at this point in the history
  • Loading branch information
ChristopherBThai committed Jun 24, 2024
1 parent 9a4f09a commit 32a7596
Show file tree
Hide file tree
Showing 3 changed files with 171 additions and 10 deletions.
18 changes: 18 additions & 0 deletions src/commands/commandList/admin/testEvent.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
* OwO Bot for Discord
* Copyright (C) 2024 Christopher Thai
* This software is licensed under Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International
* For more information, see README.md and LICENSE
*/

const CommandInterface = require('../../CommandInterface.js');

module.exports = new CommandInterface({
alias: ['testevent', 'te'],

owner: true,

execute: async function () {
this.event.getAllItems.bind(this)(this.args[0]);
},
});
124 changes: 124 additions & 0 deletions src/data/event.json
Original file line number Diff line number Diff line change
Expand Up @@ -580,5 +580,129 @@
"textEmoji": "🦧"
}
]
},
"2024_june": {
"start": "2024-06-24T00:00:00",
"end": "2024-07-02T00:00:00",
"type": "june",
"chance": 0.05,
"rewards": [
{
"type": "cowoncy",
"min": 1000,
"max": 5000,
"chance": 3,
"text": "OWO! Sharky thinks you are friend and gave you **?count? ?emoji? Cowoncies**!",
"textEmoji": "🦈"
},
{
"type": "ws",
"min": 300,
"max": 1000,
"chance": 3,
"text": "Aww~ you played with the dolphins. You receive **?count? ?emoji? Weapon Shards** for the entertainment!",
"textEmoji": "🐬"
},
{
"type": "lb",
"min": 1,
"max": 3,
"chance": 3,
"text": "Oh ho! You went swimming and fought with lobsty. You surprisingly won and gained **?count? ?emoji? ?plural?**!",
"textEmoji": "🦞"
},
{
"type": "wc",
"min": 1,
"max": 3,
"chance": 3,
"text": "UWU~ do you know milk contains calcium that strengthens your bones? You received **?count? ?emoji? Weapon ?plural?** for reading and knowing!",
"textEmoji": "🥛"
},
{
"type": "flb",
"count": 1,
"chance": 1,
"text": "Do you know Boba can be done not only with milk but also soymilk? You have gotten **?count? ?emoji? Fabled ?plural?** for your OWO treat!",
"textEmoji": "🧋"
},
{
"type": "cookie",
"count": 1,
"chance": 1,
"text": "Do you add milk into your coffee? Here's a **?emoji? ?plural?** for considering!",
"textEmoji": ""
},
{
"type": "sgem",
"count": 1,
"chance": 3,
"text": "OwO what's this! A rainbow peeking out of the clouds!? W-wait it just dropped a **?emoji? ?rank? ?type? Gem**!",
"textEmoji": "<:hrainbow:1254595698113118270>"
}
]
},
"2024_july": {
"start": "2024-07-02T00:00:01",
"end": "2024-07-10T00:00:00",
"type": "july",
"chance": 0.05,
"rewards": [
{
"type": "cowoncy",
"min": 1000,
"max": 5000,
"chance": 3,
"text": "Remember to stay cool~ you received **?count? ?emoji? Cowoncies** for keeping cool!",
"textEmoji": "🧊"
},
{
"type": "ws",
"min": 300,
"max": 1000,
"chance": 3,
"text": "Whose up for a soft serve and **?count? ?emoji? Weapon Shards** to chill off the day? Owo does~",
"textEmoji": "🍦"
},
{
"type": "lb",
"min": 1,
"max": 3,
"chance": 3,
"text": "UwU? Have you tried to eat snow as ice cream? You receive **?count? ?emoji? ?plural?** for thinking about it",
"textEmoji": "❄️"
},
{
"type": "wc",
"min": 1,
"max": 3,
"chance": 3,
"text": "UWU~ do you know milk contains calcium that strengthens your bones? You received for reading and knowing!",
"text": "Fireworks are a fantastic way to celebrate! You can celebrate by having **?count? ?emoji? Weapon ?plural?**!",
"textEmoji": "🎆"
},
{
"type": "flb",
"count": 1,
"chance": 1,
"text": "While it may not be the festival of snakes, we still appreciate our serpent friends. Here is a **?count? ?emoji? Fabled ?plural?** to remember them!",
"textEmoji": "🐍"
},
{
"type": "cookie",
"count": 1,
"chance": 1,
"text": "Do you add milk into your coffee? Here's a for considering!",
"text": "Not all snakes are scary! Some only grow to weigh less than 1 gram! To compensate here is a **?emoji? ?plural?**!",
"textEmoji": "🐍"
},
{
"type": "sgem",
"count": 1,
"chance": 3,
"text": "HIIII! i've nevew seen a boww of snakes befowe wow! Quick take these wewawds: **?emoji? ?rank? ?type? Gem** (;ω;)",
"textEmoji": "🐍"
}
]
}
}
39 changes: 29 additions & 10 deletions src/utils/eventUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,17 +68,17 @@ exports.useItem = async function (item) {
this.send(text);
};

exports.getEventItem = async function () {
const event = getCurrentActive();
const getEventItem = (exports.getEventItem = async function ({ overrideEvent, overrideItem } = {}) {
const event = getCurrentActive(overrideEvent);
if (!event) return;
const random = Math.random();
if (random >= event.chance) {
if (!overrideEvent && random >= event.chance) {
return;
}
// Cache if user is done today
let today = new Date();
today = today.toLocaleDateString();
if (this.msg.author.eventItemDone) {
if (!overrideEvent && this.msg.author.eventItemDone) {
const date = this.msg.author.eventItemDone;
if (date === today) {
return;
Expand All @@ -96,7 +96,7 @@ exports.getEventItem = async function () {
claimed = (result[0]?.claim_count || 0) + 1;

const reset = this.dateUtil.afterMidnight(result[0]?.claim_reset);
if (result[0] && result[0]?.claim_count >= eventMax && !reset.after) {
if (!overrideEvent && result[0] && result[0]?.claim_count >= eventMax && !reset.after) {
this.msg.author.eventItemDone = today;
con.rollback();
return;
Expand All @@ -113,7 +113,8 @@ exports.getEventItem = async function () {
const { rewardSql, rewardTxt, rewardEmoji } = await getEventRewards.bind(this)(
this.msg.author,
con,
event
event,
overrideItem
);
if (rewardSql) {
await con.query(rewardSql);
Expand All @@ -126,6 +127,17 @@ exports.getEventItem = async function () {
con.rollback();
return;
}
});

exports.getAllItems = async function (overrideEvent) {
const event = events[overrideEvent];
if (!event) {
this.errorMsg(', no event');
return;
}
for (let overrideItem in event.rewards) {
await getEventItem.bind(this)({ overrideEvent, overrideItem });
}
};

exports.isValentines = function () {
Expand All @@ -149,13 +161,19 @@ function setActiveEvents() {
for (const key in events) {
const event = events[key];
if (Date.now() < event.end) {
event.id = key;
activeEvents[key] = event;
}
}
console.log('Active Events: ' + JSON.stringify(activeEvents, null, 2));
console.log('Upcoming/Active: ' + Object.keys(activeEvents));
const current = getCurrentActive();
console.log('Current: ' + current?.id);
}

function getCurrentActive() {
function getCurrentActive(override) {
if (override) {
return events[override];
}
let resetActive = false;
for (const key in activeEvents) {
if (isEventActive(activeEvents[key])) {
Expand Down Expand Up @@ -204,13 +222,14 @@ async function parseReward(reward, con) {
return rewardUtil.getReward(this.msg.author.id, uid, con, reward.type, reward.id, reward.count);
}

async function getEventRewards(user, con, event) {
async function getEventRewards(user, con, event, override) {
const id = user.id;
const uid = await this.global.getUserUid(user);
if (!event.rewardTotal) {
event.rewardTotal = event.rewards.reduce((acc, curr) => acc + curr.chance, 0);
}
const reward = this.global.selectRandom(event.rewards, event.rewardTotal);
const reward =
event.rewards[override] || this.global.selectRandom(event.rewards, event.rewardTotal);

let count = reward.count;
if (reward.min && reward.max) {
Expand Down

0 comments on commit 32a7596

Please sign in to comment.