public override async Task <PreconditionResult> CheckPermissionsAsync(ICommandContext context, CommandInfo command, IServiceProvider services) { var role = await DB.Roles.GetAsync(173); if (IonicHelper.HasRolesAny(Settings.App.MainGuildId, context.User.Id, role.RoleId) || RiftBot.IsAdmin(context.User)) { return(PreconditionResult.FromSuccess()); } return(PreconditionResult.FromError(RiftBot.CommandDenyMessage)); }
async Task GiveRewardsForLevelAsync(ulong userId, uint fromLevel, uint toLevel) { if (!IonicHelper.GetGuildUserById(Settings.App.MainGuildId, userId, out var sgUser)) { return; } var reward = new ItemReward(); for (var level = fromLevel + 1; level <= toLevel; level++) { if (level == 100u) { reward.AddCapsules(1u).AddCoins(2_000u); } else if (level == 50u) { reward.AddSpheres(1u).AddCoins(2_000u); } else if (level % 25u == 0u) { reward.AddSpheres(1u).AddCoins(2_000u); } else if (level % 10u == 0u) { reward.AddTokens(2u).AddCoins(2_000u); } else if (level % 5u == 0u) { reward.AddTickets(1u).AddCoins(2_000u); } else { reward.AddChests(1u).AddCoins(2_000u); } var nitroBooster = await DB.Roles.GetAsync(91); if (IonicHelper.HasRolesAny(sgUser, nitroBooster.RoleId)) { reward.AddChests(2u); } var rankGold = await DB.Roles.GetAsync(3); if (IonicHelper.HasRolesAny(sgUser, rankGold.RoleId)) { reward.AddCoins(250u); } var rankPlatinum = await DB.Roles.GetAsync(11); if (IonicHelper.HasRolesAny(sgUser, rankPlatinum.RoleId)) { reward.AddCoins(500u); } var rankDiamond = await DB.Roles.GetAsync(8); if (IonicHelper.HasRolesAny(sgUser, rankDiamond.RoleId)) { reward.AddCoins(750u); } var rankMaster = await DB.Roles.GetAsync(79); if (IonicHelper.HasRolesAny(sgUser, rankMaster.RoleId)) { reward.AddCoins(1000u); } var rankGrandmaster = await DB.Roles.GetAsync(71); if (IonicHelper.HasRolesAny(sgUser, rankGrandmaster.RoleId)) { reward.AddCoins(1250u); } var rankChallenger = await DB.Roles.GetAsync(23); if (IonicHelper.HasRolesAny(sgUser, rankChallenger.RoleId)) { reward.AddCoins(1500u); } } await rewardService.DeliverToAsync(userId, reward); await messageService.SendMessageAsync("levelup", Settings.ChannelId.Chat, new FormatData(userId) { Reward = reward }); }
public async Task UpdateInventoryRoleAsync(ulong userId, int id, bool add) { if (!await DB.RoleInventory.HasAnyAsync(userId, id)) { await messageService.SendMessageAsync("roleinventory-wrongnumber", Settings.ChannelId.Commands, new FormatData(userId)); return; } var dbUser = await DB.Users.GetAsync(userId); if (dbUser is null || !IonicHelper.GetGuildUserById(Settings.App.MainGuildId, userId, out var sgUser)) { await messageService.SendMessageAsync(MessageService.UserNotFound, Settings.ChannelId.Commands); return; } var role = await DB.Roles.GetAsync(id); if (role is null) { await messageService.SendMessageAsync(MessageService.RoleNotFound, Settings.ChannelId.Commands); await RiftBot.SendMessageToAdmins($"User <@{userId.ToString()}> failed to set role ID {id.ToString()}."); return; } if (!IonicHelper.GetRole(Settings.App.MainGuildId, role.RoleId, out var guildRole)) { await messageService.SendMessageAsync(MessageService.RoleNotFound, Settings.ChannelId.Commands); return; } var hasRole = IonicHelper.HasRolesAny(Settings.App.MainGuildId, userId, role.RoleId); if (add) { if (hasRole) { await messageService.SendMessageAsync("roleinventory-hasrole", Settings.ChannelId.Commands, new FormatData(userId)); return; } await sgUser.AddRoleAsync(guildRole); } else { if (!hasRole) { await messageService.SendMessageAsync("roleinventory-norole", Settings.ChannelId.Commands, new FormatData(userId)); return; } await sgUser.RemoveRoleAsync(guildRole); } }
async Task <IonicMessage> GiftAsync(SocketGuildUser fromSgUser, SocketGuildUser toSgUser) { var senderId = fromSgUser.Id; var receiverId = toSgUser.Id; if (toSgUser.IsBot) { RiftBot.Log.Debug("[Gift] Target is bot."); return(await messageService.GetMessageAsync("gift-target-bot", new FormatData(senderId))); } if (fromSgUser.Id == toSgUser.Id) { RiftBot.Log.Debug("[Gift] Ouch, self-gift."); return(await messageService.GetMessageAsync("gift-target-self", new FormatData(senderId))); } (var canGift, var remainingTime) = await CanGift(senderId); if (!canGift) { return(await messageService.GetMessageAsync("gift-cooldown", new FormatData(senderId) { Gift = new GiftData { Cooldown = remainingTime } })); } var dbInventory = await DB.Inventory.GetAsync(senderId); if (dbInventory.Coins < Settings.Economy.GiftPrice) { return(await messageService.GetMessageAsync("gift-nocoins", new FormatData(senderId) { Gift = new GiftData { NecessaryCoins = Settings.Economy.GiftPrice - dbInventory.Coins } })); } await DB.Inventory.RemoveAsync(senderId, new InventoryData { Coins = Settings.Economy.GiftPrice }); var giftItem = new GiftReward(); await rewardService.DeliverToAsync(receiverId, giftItem); GiftSent?.Invoke(null, new GiftSentEventArgs(senderId, receiverId)); GiftReceived?.Invoke(null, new GiftReceivedEventArgs(senderId, fromSgUser.Id)); if (toSgUser.Id == 178443743026872321ul) { GiftedFounder?.Invoke(null, new GiftedFounderEventArgs(receiverId, senderId)); } var developers = await DB.Roles.GetAsync(44); if (IonicHelper.HasRolesAny(toSgUser, developers.RoleId)) { GiftedDeveloper?.Invoke(null, new GiftedDeveloperEventArgs(senderId, receiverId)); } if (await RiftBot.IsModeratorAsync(toSgUser)) { GiftedModerator?.Invoke(null, new GiftedModeratorEventArgs(senderId, receiverId)); } if (!(await DB.Streamers.GetAsync(receiverId) is null)) { GiftedStreamer?.Invoke(null, new GiftedStreamerEventArgs(senderId, receiverId)); } RiftBot.Log.Debug("[Gift] Success."); await DB.Cooldowns.SetLastGiftTimeAsync(senderId, DateTime.UtcNow); await DB.Statistics.AddAsync(senderId, new StatisticData { GiftsSent = 1u }); await DB.Statistics.AddAsync(receiverId, new StatisticData { GiftsReceived = 1u }); return(await messageService.GetMessageAsync("gift-success", new FormatData(senderId) { Gift = new GiftData { TargetId = receiverId }, Reward = giftItem })); }