From ccbac03289a6dc1290b2db6c4312d78eecc66771 Mon Sep 17 00:00:00 2001 From: Christopher Thai Date: Wed, 27 May 2020 21:51:44 -0700 Subject: [PATCH] patreon --- index.js | 2 +- src/commands/commandList/patreon/alastor.js | 122 ++++++++++++++----- src/commands/commandList/patreon/lollipop.js | 82 +++++++++++++ src/commands/commandList/patreon/teddy.js | 82 +++++++++++++ src/commands/commandList/utils/feedback.js | 1 - src/commands/commandList/utils/math.js | 1 - src/owo.js | 2 +- 7 files changed, 260 insertions(+), 32 deletions(-) create mode 100644 src/commands/commandList/patreon/lollipop.js create mode 100644 src/commands/commandList/patreon/teddy.js diff --git a/index.js b/index.js index 59ea89e0..2643f64b 100644 --- a/index.js +++ b/index.js @@ -6,7 +6,7 @@ */ // Grab tokens and secret files -const debug = false; +const debug = true; if(!debug) var tracer = require('dd-trace').init() if(debug) var auth = require('../tokens/scuttester-auth.json'); else var auth = require('../tokens/owo-auth.json'); diff --git a/src/commands/commandList/patreon/alastor.js b/src/commands/commandList/patreon/alastor.js index a724cbde..becdfc8b 100644 --- a/src/commands/commandList/patreon/alastor.js +++ b/src/commands/commandList/patreon/alastor.js @@ -10,6 +10,8 @@ const CommandInterface = require('../../CommandInterface.js'); const dateUtil = require('../../../utils/dateUtil.js'); const gif1 = "https://cdn.discordapp.com/attachments/626155987904102402/673253558577004555/image0.gif"; const gif2 = "https://cdn.discordapp.com/attachments/626155987904102402/673253769907142679/image0.gif"; +const gif3 = "https://cdn.discordapp.com/attachments/626155987904102402/696858611627851787/image0.gif"; +const gif4 = "https://cdn.discordapp.com/attachments/626155987904102402/696858882680684604/image0.gif"; const table = "alastor"; module.exports = new CommandInterface({ @@ -33,39 +35,103 @@ module.exports = new CommandInterface({ six:400, execute: async function(p){ - const lasttime = await p.redis.hget("cd_"+p.msg.author.id,table); - const afterMid = dateUtil.afterMidnight(lasttime); - - let streak = 1; - let title = p.msg.author.username+"'s Alastor"; - if (afterMid.after) { - await p.redis.hset("cd_"+p.msg.author.id,table,afterMid.now); - if (afterMid.withinDay || !lasttime) { - streak = await p.redis.hincrby(p.msg.author.id,table); - title = p.msg.author.username+" fed Alastor!"; - } else { - await p.redis.hset(p.msg.author.id,table,1); - title = p.msg.author.username+", Alastor has stopped broadcasting"; + if (p.args[0] === "feed") { + const lastCrown = await p.redis.hget("cd_"+p.msg.author.id,table+"_crown"); + if (!lastCrown) + await p.redis.hset("cd_"+p.msg.author.id,table+"_crown",new Date()); + else if (new Date() - new Date(lastCrown) > 345600000) { + displayCrown(p); + return; } + feed(p); + } else if (p.args[0] === "crown") { + giveCrown(p); } else { - streak = await p.redis.hget(p.msg.author.id,table); + display(p); } + } +}) - const embed = { - "author": { - "name": title, - "icon_url": p.msg.author.avatarURL - }, - "color":p.config.embed_color, - "image": { - "url": afterMid.after ? gif1 : gif2 - }, - "footer": { - "text": `STREAK: ${streak} | Resets in: ${afterMid.hours}H ${afterMid.minutes}M ${afterMid.seconds}S` - } +async function giveCrown(p) { + let lastCrown = await p.redis.hget("cd_"+p.msg.author.id,table+"_crown"); + lastCrown = lastCrown ? new Date(lastCrown) : new Date(); + if (new Date() - lastCrown < 345600000) { + p.errorMsg(", Alastor doesn't need a crown"); + return; + } + + let result = await p.redis.incr("crown",p.msg.author.id,-1); + // Error checking + if(result==null||result<0){ + if(result<0) p.redis.incr("crown",p.msg.author.id,1); + p.errorMsg(", you do not have any crowns! >:c",3000); + return; + } + + await p.redis.hset("cd_"+p.msg.author.id,table+"_crown",new Date()); + display(p, "That seems to have done the trick, he seems content. He will allow you to claim the daily streak.. maybe.", gif4); +} + +async function displayCrown(p) { + display(p, "Alastor is ready to battle. Try calming him down with a gift, quickly! Try the crown!", gif3); +} + +async function feed(p) { + const lasttime = await p.redis.hget("cd_"+p.msg.author.id,table); + const afterMid = dateUtil.afterMidnight(lasttime); + + let streak = 1; + let title = p.msg.author.username+"'s Alastor"; + if (afterMid.after) { + await p.redis.hset("cd_"+p.msg.author.id,table,afterMid.now); + if (afterMid.withinDay || !lasttime) { + streak = await p.redis.hincrby(p.msg.author.id,table); + title = p.msg.author.username+" fed Alastor!"; + } else { + await p.redis.hset(p.msg.author.id,table,1); + title = p.msg.author.username+", Alastor has stopped broadcasting"; } + } else { + streak = await p.redis.hget(p.msg.author.id,table); + } - p.send({embed}); + const embed = { + "author": { + "name": title, + "icon_url": p.msg.author.avatarURL + }, + "color":p.config.embed_color, + "image": { + "url": afterMid.after ? gif1 : gif2 + }, + "footer": { + "text": `STREAK: ${streak} | Resets in: ${afterMid.hours}H ${afterMid.minutes}M ${afterMid.seconds}S` + } } -}) + p.send({embed}); +} + +async function display(p, title, gif) { + const lasttime = await p.redis.hget("cd_"+p.msg.author.id,table); + const afterMid = dateUtil.afterMidnight(lasttime); + const streak = await p.redis.hget(p.msg.author.id,table); + if (!title) title = p.msg.author.username+"'s Alastor"; + if (!gif) gif = gif2 + + const embed = { + "author": { + "name": title, + "icon_url": p.msg.author.avatarURL + }, + "color":p.config.embed_color, + "image": { + "url": gif + }, + "footer": { + "text": `STREAK: ${streak} | Resets in: ${afterMid.hours}H ${afterMid.minutes}M ${afterMid.seconds}S` + } + } + + p.send({embed}); +} diff --git a/src/commands/commandList/patreon/lollipop.js b/src/commands/commandList/patreon/lollipop.js new file mode 100644 index 00000000..080960d6 --- /dev/null +++ b/src/commands/commandList/patreon/lollipop.js @@ -0,0 +1,82 @@ +/* + * OwO Bot for Discord + * Copyright (C) 2019 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'); + +const emoji = ""; +const owner = "370709798020448257"; +const data = "lollipop"; +const plural = "lollipops"; + +module.exports = new CommandInterface({ + + alias:["lollipop"], + + args:"{@user}", + + desc:"Give a lollipop to someone! You can only gain one if you receive it! This command was created by SleepyPanda", + + example:[], + + related:[], + + permissions:["sendMessages"], + + group:["patreon"], + + cooldown:30000, + half:80, + six:400, + bot:true, + + execute: async function(p){ + if(p.args.length==0){ + display(p); + p.setCooldown(5); + }else{ + let user = p.getMention(p.args[0]); + if(!user){ + user = await p.fetch.getMember(p.msg.channel.guild,p.args[0]); + if(!user){ + p.errorMsg(", Invalid syntax! Please tag a user!",3000); + p.setCooldown(5); + return; + } + } + if(user.id==p.msg.author.id){ + p.errorMsg(", You cannot give it yourself!!",3000); + p.setCooldown(5); + return; + } + give(p,user); + } + } +}); + +async function display(p){ + let count = await p.redis.hget("data_"+p.msg.author.id, data); + if(!count) count = 0; + + p.replyMsg(emoji, ", you currently have "+count+" "+plural+"!"); +} + +async function give(p,user){ + if(p.msg.author.id!=owner){ + let result = await p.redis.hincrby("data_"+p.msg.author.id, data, -1); + + // Error checking + if(result==null||result<0){ + if(result<0) p.redis.hincrby("data_"+p.msg.author.id, data, 1); + p.errorMsg(", you do not have any "+plural+" to give! >:c",3000); + p.setCooldown(5); + return; + } + } + + await p.redis.hincrby("data_"+user.id, data, 2); + p.send(`${emoji} **| ${user.username}**, ${p.msg.author.username} gave you 2 ${plural}!`); +} diff --git a/src/commands/commandList/patreon/teddy.js b/src/commands/commandList/patreon/teddy.js new file mode 100644 index 00000000..7be4d443 --- /dev/null +++ b/src/commands/commandList/patreon/teddy.js @@ -0,0 +1,82 @@ +/* + * OwO Bot for Discord + * Copyright (C) 2019 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'); + +const emoji = "<:teddy:714218781022617710>"; +const owner = "625340848556474369"; +const data = "teddy"; +const plural = "teddy bears"; + +module.exports = new CommandInterface({ + + alias:["teddy"], + + args:"{@user}", + + desc:"Give a teddy bear to someone! You can only gain one if you receive it! This command was created by {ᗩTᒪ} StellaBear", + + example:[], + + related:[], + + permissions:["sendMessages"], + + group:["patreon"], + + cooldown:30000, + half:80, + six:400, + bot:true, + + execute: async function(p){ + if(p.args.length==0){ + display(p); + p.setCooldown(5); + }else{ + let user = p.getMention(p.args[0]); + if(!user){ + user = await p.fetch.getMember(p.msg.channel.guild,p.args[0]); + if(!user){ + p.errorMsg(", Invalid syntax! Please tag a user!",3000); + p.setCooldown(5); + return; + } + } + if(user.id==p.msg.author.id){ + p.errorMsg(", You cannot give it yourself!!",3000); + p.setCooldown(5); + return; + } + give(p,user); + } + } +}); + +async function display(p){ + let count = await p.redis.hget("data_"+p.msg.author.id, data); + if(!count) count = 0; + + p.replyMsg(emoji, ", you currently have "+count+" "+plural+"!"); +} + +async function give(p,user){ + if(p.msg.author.id!=owner){ + let result = await p.redis.hincrby("data_"+p.msg.author.id, data, -1); + + // Error checking + if(result==null||result<0){ + if(result<0) p.redis.hincrby("data_"+p.msg.author.id, data, 1); + p.errorMsg(", you do not have any "+plural+" to give! >:c",3000); + p.setCooldown(5); + return; + } + } + + await p.redis.hincrby("data_"+user.id, data, 2); + p.send(`${emoji} **| ${user.username}**, ${p.msg.author.username} thinks you're bear-y special and sent you 2 teddies! *hugs*`); +} diff --git a/src/commands/commandList/utils/feedback.js b/src/commands/commandList/utils/feedback.js index d477b52b..86fab7c8 100644 --- a/src/commands/commandList/utils/feedback.js +++ b/src/commands/commandList/utils/feedback.js @@ -34,7 +34,6 @@ module.exports = new CommandInterface({ cooldown:600000, half:15, six:30, - bot:true, execute: async function(p){ let message = p.args.join(" "); diff --git a/src/commands/commandList/utils/math.js b/src/commands/commandList/utils/math.js index aec67d12..06c96113 100644 --- a/src/commands/commandList/utils/math.js +++ b/src/commands/commandList/utils/math.js @@ -31,7 +31,6 @@ module.exports = new CommandInterface({ cooldown:5000, half:100, six:500, - bot:true, execute: function(p){ // quick and dirty fix for function calls and tags diff --git a/src/owo.js b/src/owo.js index 6560f7b8..886cf82a 100644 --- a/src/owo.js +++ b/src/owo.js @@ -18,7 +18,7 @@ const dbl = new DBL(auth.dbl); class OwO extends Base{ constructor(bot){ super(bot); - this.debug = false; + this.debug = true; this.auth = auth; this.dbl = dbl;