public async Task AssignColorCommand(IUser user, IRole colorRole, [OverrideTypeReader(typeof(KiteTimeSpanReader))] TimeSpan timeToRemove = default(TimeSpan)) { var timeSpan = timeToRemove != default(TimeSpan) ? (TimeSpan?)timeToRemove : null; var assignTask = await RankService.AssignColorToUser(Context.Guild.Id, user.Id, colorRole.Id, timeSpan).ConfigureAwait(false); await ReplyAsync(assignTask? "OK" : "Couldn't remove rank").ConfigureAwait(false); }
public async Task RankCommand([Remainder] IRole role) { var availableColors = (await RankService.GetAvailableColors(Context.User as SocketGuildUser, Context.Guild).ConfigureAwait(false)).ToList(); if (RankService.GetRanksForGuild(Context.Guild.Id).SelectMany(x => x.Colors).Select(x => x.Id).Union(availableColors.Select(x => x.Id)).All(y => y != role.Id)) { await ReplyAsync("That role is not managed by this bot, try `?rank`").ConfigureAwait(false); return; } if (availableColors.Any(x => x.Id == role.Id)) { var user = (IGuildUser)Context.User; //Check for any rank, since users can get demoted and then use this command before they get their grade back, might not be nessesary in the future var currentRank = RankService.GetRanksForGuild(Context.Guild.Id) .SelectMany(x => x.Colors) .Union(availableColors) .FirstOrDefault(x => user.RoleIds.Any(y => y == x.Id)); if (currentRank != null) { if (currentRank.Id == role.Id) { await user.RemoveRoleAsync(role).ConfigureAwait(false); await ReplyAsync("Removed existing rank").ConfigureAwait(false); return; } await user.RemoveRoleAsync(Context.Guild.Roles.First(x => x.Id == currentRank.Id)).ConfigureAwait(false); } await user.AddRoleAsync(role).ConfigureAwait(false); await ReplyAsync($"Added {role.Name}").ConfigureAwait(false); } else { await ReplyAsync($"You don't have access to that, {Format.Italics("yet...")}").ConfigureAwait(false); } }
public async Task RanksCommand(IUser user, Debug showDebugInfo = Debug.Release) { await RankService.FlushQueue().ConfigureAwait(false); var embed = new EmbedBuilder(); var userRanks = await RankService.GetAwardedRoles(user as SocketGuildUser, Context.Guild).ConfigureAwait(false); if (userRanks.Any()) { var sb = new StringBuilder("You currently have these ranks:\n"); foreach (Json.Rank rank in userRanks) { sb.AppendLine( $"{Context.Guild.Roles.First(x => x.Id == rank.RoleId).Name} rewarded by {rank.RequiredTimeSpan.ToPrettyFormat()} in the server"); } embed.AddField(x => { x.Name = "Ranks"; x.IsInline = true; x.Value = sb.ToString(); }); } else { embed.AddField(x => { x.Name = "Ranks"; x.IsInline = true; x.Value = "You currently have no ranks"; }); } var(nextRole, timeSpan) = await RankService.GetNextRole(user as SocketGuildUser, Context.Guild).ConfigureAwait(false); if (nextRole != null) { embed.AddField(x => { x.Name = "Next Rank"; x.IsInline = true; x.Value = $"Your next rank is {nextRole.Name} in another {timeSpan.ToPrettyFormat()}"; }); } var assignedRoles = await RankService.GetAssignedRolesAsync(Context.Guild.Id, user.Id).ConfigureAwait(false); if (assignedRoles.Any()) { var sb = new StringBuilder(); foreach (var role in assignedRoles) { var name = Context.Guild.Roles.First(x => x.Id == role.roleId).Name; var expiry = role.expiry; sb.AppendLine(expiry == null ? $"{name}" : $"{name} expires in {(expiry - DateTimeOffset.UtcNow).Value.ToPrettyFormat()}"); } embed.AddField(x => { x.Name = "Assigned Roles"; x.IsInline = true; x.Value = sb.ToString(); }); } var guildColors = (await RankService.GetAvailableColors(user as SocketGuildUser, Context.Guild).ConfigureAwait(false)).ToList(); if (guildColors.Any()) { var roles = Context.Guild.Roles.Where(x => guildColors.Any(y => y.Id == x.Id)).OrderBy(x => x.Position); embed.AddField(e => { e.Name = "Colors"; e.IsInline = true; e.Value = $"You currently have these colors available:\n {string.Join(", ", roles.Select(x => x.Mention))}."; }); embed.WithColor(roles.Last().Color); } if (showDebugInfo == Debug.Debug) { string info = $"Last activity: {await RankService.GetUserLastActivity(user as SocketGuildUser, Context.Guild).ConfigureAwait(false)}\n" + $"Joindate used: {await RankService.GetUserJoinDate(user as SocketGuildUser, Context.Guild).ConfigureAwait(false)}"; embed.AddField(e => { e.Name = "Debug info"; e.IsInline = true; e.Value = info; }); } embed.WithAuthor(x => { var url = user.GetAvatarUrl(); if (url != null) { x.IconUrl = url; } x.Name = (user as SocketGuildUser)?.Nickname ?? user.Username; }); embed.WithFooter(x => x.Text = "Hit the 📱 reaction if on mobile."); var msg = await ReplyAsync("", false, embed).ConfigureAwait(false); try { ReactionCallbackBuilder rcb = new ReactionCallbackBuilder(); await rcb .WithClient(Context.Client) .WithPrecondition(x => x.Id == Context.User.Id) .WithReactions("📱", "❌") .AddCallback("📱", async func => { await msg.ModifyAsync(message => message.Content = string.Join(", ", Context.Guild.Roles.Where(x => guildColors.Any(y => y.Id == x.Id)) .OrderBy(x => x.Position) .Select(z => z.Mention))).ConfigureAwait(false); }) .AddCallback("❌", async func => { await msg.DeleteAsync().ConfigureAwait(false); }) .WithTimeout(120000) .ExecuteAsync(msg) .ConfigureAwait(false); } catch (Exception e) { Console.WriteLine(e); throw; } }
public async Task UnassignColorCommand(IUser user, IRole role) { var result = await RankService.UnassignColorFromUserAsync(user, role).ConfigureAwait(false); await ReplyAsync(result? "OK" : "Couldn't remove rank").ConfigureAwait(false); }