Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added support for scheduling events (specials) and announcements in the database #240

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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
6 changes: 3 additions & 3 deletions src/commands/commandList/economy/daily.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ function finalizeText (p, uid, { streak, gain, extra }, boxRewards, marriageRewa
let sql = "";

if (showAnnouncement) {
sql += `SELECT * FROM announcement ORDER BY aid DESC LIMIT 1;`;
sql += `INSERT INTO user_announcement (uid, aid) VALUES (${uid}, (SELECT aid FROM announcement ORDER BY aid DESC LIMIT 1)) ON DUPLICATE KEY UPDATE aid = (SELECT aid FROM announcement ORDER BY aid DESC LIMIT 1);`
sql += `SELECT * FROM announcement WHERE adate <= NOW() ORDER BY aid DESC LIMIT 1;`;
sql += `INSERT INTO user_announcement (uid, aid) VALUES (${uid}, (SELECT aid FROM announcement WHERE adate <= NOW() ORDER BY aid DESC LIMIT 1)) ON DUPLICATE KEY UPDATE aid = (SELECT aid FROM announcement WHERE adate <= NOW() ORDER BY aid DESC LIMIT 1);`
}

let text = `${moneyEmoji} **| ${p.msg.author.username}**, Here is your daily **<:cowoncy:416043450337853441> ${gain} Cowoncy**!`;
Expand Down Expand Up @@ -163,7 +163,7 @@ async function getUserInfo (p, uid) {
WHERE
uid = ${uid}
AND (
aid = (SELECT aid FROM announcement ORDER BY aid DESC limit 1)
aid = (SELECT aid FROM announcement WHERE adate <= NOW() ORDER BY aid DESC limit 1)
OR disabled = 1
);`
sql += `SELECT
Expand Down
2 changes: 1 addition & 1 deletion src/commands/commandList/utils/announcement.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ module.exports = new CommandInterface({
});

async function announcement(p){
let sql = "SELECT * FROM announcement ORDER BY aid DESC LIMIT 1";
let sql = "SELECT * FROM announcement WHERE adate <= NOW() ORDER BY aid DESC LIMIT 1";
let result = await p.query(sql);
if(!result[0])
p.send("**📮 |** There are no announcements!",3000);
Expand Down
23 changes: 12 additions & 11 deletions src/commands/commandList/zoo/animalUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,22 @@ setTimeout(() => {
enableDistortedTier = false;
}, 21600000);

const specialRates = animals.specialRates;
let specialPercent = 0;
if (specialRates && specialRates.length) {
for (let i in specialRates) {
specialPercent += specialRates[i].rate
}
}

/**
* Picks a random animal from secret json file
*/
exports.randAnimal = function({patreon, gem, lucky, huntbot, manual} = {}){
exports.randAnimal = function({patreon, gem, lucky, huntbot, manual, specials} = {}){
let rand = Math.random();
let result = [];

/* Calculate special */
let specialPercent = 0;
if (specials && specials.length) {
for (let i in specials) {
specialPercent += specials[i].rate
}
}

/* Calculate percentage */
let patreonPercent = animals.cpatreon[0]+animals.patreon[0];
if(!patreon) patreonPercent = 0;
Expand Down Expand Up @@ -58,12 +59,12 @@ exports.randAnimal = function({patreon, gem, lucky, huntbot, manual} = {}){
}else if(specialPercent&&rand<specialPercent+patreonPercent){
let tempRate = patreonPercent;
let found = false;
for (let i in specialRates) {
tempRate += specialRates[i].rate;
for (let i in specials) {
tempRate += specials[i].rate;
if (!found && rand<=tempRate){
found = true;
result.push("**special** "+animals.ranks.special);
result.push(specialRates[i].animal);
result.push(specials[i].animal);
result.push("special");
result.push(500);
}
Expand Down
15 changes: 13 additions & 2 deletions src/commands/commandList/zoo/autohunt.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ async function claim(p,msg,con,query,bot){

let sql = "SELECT IF(patreonAnimal = 1 OR (TIMESTAMPDIFF(MONTH,patreonTimer,NOW())<patreonMonths),1,0) as patreon FROM user LEFT JOIN patreons ON user.uid = patreons.uid WHERE user.id = "+msg.author.id+";";
sql += "UPDATE autohunt SET huntmin = 0,huntcount=0,essence = essence +"+totalGain+",total = total + "+totalGain+" WHERE id = "+msg.author.id+" AND huntmin > 0;";
sql += "SELECT config FROM `events` WHERE eventtype = 'SPECIAL' AND NOW() >= starttime AND NOW() <= endtime;"
let result = await p.query(sql);

if(result[1].changedRows<=0){
Expand All @@ -71,8 +72,17 @@ async function claim(p,msg,con,query,bot){

//Check if patreon
let patreon = false;
if(result[0][0]&&result[0][0].patreon==1)
if (result[0][0]&&result[0][0].patreon==1) {
patreon = true;
}

// Parse specials
let specials = [];
if (result[2]) {
for (let i = 0; i < result[2].length; i++) {
specials.push(...JSON.parse(result[2][i].config));
}
}

sql = "";
//Get total exp
Expand All @@ -97,7 +107,8 @@ async function claim(p,msg,con,query,bot){
for(let i=0;i<query.huntcount;i++){
let animal = animalUtil.randAnimal({
patreon: patreon,
huntbot: radar.stat/100
huntbot: radar.stat/100,
specials: specials
});
if(total[animal[1]]){
total[animal[1]].count++;
Expand Down
21 changes: 17 additions & 4 deletions src/commands/commandList/zoo/catch.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ module.exports = new CommandInterface({
ORDER BY pet_team_animal.pos ASC;`;
sql += "SELECT *,TIMESTAMPDIFF(HOUR,claim,NOW()) as time FROM lootbox WHERE id = "+msg.author.id+";";
sql += "SELECT uid,activecount,gname,type FROM user NATURAL JOIN user_gem NATURAL JOIN gem WHERE id = "+msg.author.id+" AND activecount > 0;";
sql += "SELECT config FROM `events` WHERE eventtype = 'SPECIAL' AND NOW() >= starttime AND NOW() <= endtime;"
let result = await p.query(sql);
if(result[0][0]==undefined||result[0][0].money<animals.rollprice){
p.errorMsg(", You don't have enough cowoncy!",3000);
Expand Down Expand Up @@ -126,11 +127,20 @@ function getAnimals(p,result,gems,uid){
let patreon = (result[0][0].patreon==1);
let patreonGem = (gems["Patreon"])?true:false;

/* Parse specials */
let specials = [];
if (result[4]) {
for (let i = 0; i < result[4].length; i++) {
console.log(`${result[4][i].config}`);
specials.push(...JSON.parse(result[4][i].config));
}
}

/* If no gems */
let gemLength = Object.keys(gems).length;
let animal;
if (gemLength==0) {
animal = [animalUtil.randAnimal({ patreon: patreon, manual: true })];
animal = [animalUtil.randAnimal({ patreon: patreon, manual: true, specials: specials })];

/* If gems... */
} else {
Expand All @@ -144,13 +154,15 @@ function getAnimals(p,result,gems,uid){
patreon: (patreon||patreonGem),
gem: true,
lucky: gems["Lucky"],
manual: true
manual: true,
specials: specials
})];
if (gems["Patreon"]) animal.push(animalUtil.randAnimal({
patreon: true,
gem: true,
lucky: gems["Lucky"],
manual: true
manual: true,
specials: specials
}));

/* Get the rest of the animals */
Expand All @@ -159,7 +171,8 @@ function getAnimals(p,result,gems,uid){
patreon: patreon,
gem: true,
lucky: gems["Lucky"],
manual: true
manual: true,
specials: specials
}));
}
}
Expand Down