async Task DeliverRoleAsync(ulong userId, RoleReward reward) { if (reward.Duration is null) { if (await DB.RoleInventory.HasAnyAsync(userId, reward.RoleId)) { return; } await DB.RoleInventory.AddAsync(userId, reward.RoleId, "Reward"); return; } var dbRole = await DB.Roles.GetAsync(reward.RoleId); if (dbRole is null) { RiftBot.Log.Error($"No such role ID in database: {reward.RoleId.ToString()}"); return; } await roleService.AddTempRoleAsync(userId, dbRole.RoleId, reward.Duration.Value, nameof(RoleReward)); }
public async Task MuteAsync(IUser target, string reason, string time, IUser moderator) { (var passed, var sgTarget) = await ValidateAsync(target, reason, moderator); if (!passed) { return; } if (RiftBot.IsAdmin(sgTarget) || await RiftBot.IsModeratorAsync(sgTarget)) { await messageService.SendMessageAsync("mod-friendly-fire", Settings.ChannelId.Commands, new FormatData(moderator.Id)); return; } if (!int.TryParse(time.Remove(time.Length - 1), out var timeInt)) { await messageService.SendMessageAsync("mod-wrong-time-format", Settings.ChannelId.Commands, new FormatData(moderator.Id)); return; } TimeSpan ts; var timeMod = time.Last(); switch (timeMod) { case 's': ts = TimeSpan.FromSeconds(timeInt); break; case 'm': ts = TimeSpan.FromMinutes(timeInt); break; case 'h': ts = TimeSpan.FromHours(timeInt); break; case 'd': ts = TimeSpan.FromDays(timeInt); break; default: await messageService.SendMessageAsync("mod-wrong-time-format", Settings.ChannelId.Commands, new FormatData(moderator.Id)); return; } var muted = await DB.Roles.GetAsync(40); await roleService.AddTempRoleAsync(sgTarget.Id, muted.RoleId, ts, $"Muted by {moderator}|{moderator.Id.ToString()} with reason: {reason}"); await DB.ModerationLogs.AddAsync(sgTarget.Id, moderator.Id, "Mute", reason, DateTime.UtcNow, ts); (var oldToxicity, var newToxicity) = await GetNewToxicityAsync(sgTarget.Id, ToxicitySource.Mute); await DB.Toxicity.UpdatePercentAsync(sgTarget.Id, newToxicity.Percent); if (newToxicity.Level > oldToxicity.Level) { await messageService.SendMessageAsync("mod-toxicity-increased", Settings.ChannelId.Chat, new FormatData(sgTarget.Id)); } var data = new FormatData(sgTarget.Id) { Moderation = new ModerationData { TargetId = sgTarget.Id, ModeratorId = moderator.Id, Reason = reason, Duration = ts } }; await messageService.SendMessageAsync("mod-mute-success", Settings.ChannelId.Chat, data); }