public async Task UpdateCooldowns(CooldownObject data) { Fields field = new Fields(); field.AddField("Daily", data.Daily); field.AddField("Bless", data.Bless); field.AddField("Pluck", data.Pluck); field.AddField("Vote", data.Vote); field.AddField("Work", data.Work); field.AddField("Thievery", data.Thievery); await Base.UpdateRecord(table, field, data.RecordId); }
public async Task <CooldownObject> GetCooldowns(ulong id) { CooldownObject cooldowns = new CooldownObject(); var records = await Base.ListRecords(table, filterByFormula : "{userId} = " + id); foreach (var record in records.Records) { cooldowns.Bless = Convert.ToInt64(record.GetField("Bless")); cooldowns.Daily = Convert.ToInt64(record.GetField("Daily")); cooldowns.Vote = Convert.ToInt64(record.GetField("Vote")); cooldowns.RecordId = record.Id; cooldowns.Id = id; } Console.WriteLine(cooldowns.Daily); return(cooldowns); }
public async Task DailyCommand() { int amount = 1000; if (await cooldown.CheckIfRecordExist(Context.User.Id)) { CooldownObject userCooldowns = await cooldown.GetCooldowns(Context.User.Id); Console.WriteLine(userCooldowns.Daily); if (Convert.ToInt64(DateTime.Now.Millisecond) <= userCooldowns.Daily) { var time = userCooldowns.Daily - Convert.ToInt64(DateTime.Now.Millisecond); Console.WriteLine(time); await Context.Channel.SendMessageAsync($"Sorry, but you are still on a cooldown for this command. Please wait another `{(new DateTime(time).Hour == 1 ? $"{new DateTime(time).Minute} minutes" : $"{new DateTime(time).Hour} hours")}`"); return; } } if (!await UserDb.CheckIfRecordExist(Context.User.Id)) { await UserDb.CreateUserProfile(new UserObject() { Id = Context.User.Id, Balance = amount }); } else { UserObject user = await UserDb.GetUserProfile(Context.User.Id); user.Balance = user.Balance + amount; await UserDb.UpdateUserProfile(user); } var embed = new EmbedBuilder() { Color = new Color(0xffb6c1), Title = $"{Context.User.Username}'s Daily Reward!!!", Description = $"{Context.User.Username} got {amount} <a:FLflower2:678622764080431114> flowers as their daily reward!" }; CooldownObject _userCooldowns = await cooldown.GetCooldowns(Context.User.Id); _userCooldowns.Daily = _userCooldowns.Daily + 86400000; // 86400000 milliseconds = 1 day await cooldown.UpdateCooldowns(_userCooldowns); await Context.Channel.SendMessageAsync(embed : embed.Build()); }