public async Task ShowLeaderboard() { var builder = new StringBuilder(); builder.Append("```\n"); var serverProfiles = Profiles.GetOrCreate(Context.Guild.Id); var profileValues = new ElectionProfile[serverProfiles.Count]; serverProfiles.Values.CopyTo(profileValues, 0); Array.Sort(profileValues, (x, y) => y.WasVotedBy.Count - x.WasVotedBy.Count); foreach (var profile in profileValues) { if (profile.WasVotedBy.Count < 1) { continue; } var user = Context.Guild.GetUser(profile.UserId); if (user == null) { continue; } var name = KrispyNickname.NickName(user.Nickname); builder.Append(name.PadRight(20) + " | " + profile.WasVotedBy.Count.ToString().PadLeft(4) + "\n"); } builder.Append("```"); await ReplyAsync(builder.ToString()); }
public static void GenNamesStatic(SocketGuild guild) { var serverNames = Names.GetOrCreate(guild.Id); serverNames.Clear(); foreach (var user in guild.Users) { if (user.IsBot || user.Nickname == null || !user.Nickname.Contains('|')) { continue; } var first = KrispyNickname.FirstName(user.Nickname).ToLower(); var nick = KrispyNickname.NickName(user.Nickname).ToLower(); if (serverNames.ContainsKey(first)) { serverNames[first] = NullVoter; } else { serverNames[first] = user.Id; } if (serverNames.ContainsKey(nick)) { serverNames[nick] = NullVoter; } else { serverNames[nick] = user.Id; } } }
public async Task ForceProfile(SocketUser user) { var guildUser = (IGuildUser)user; var profile = Profiles.GetOrCreate(Context.Guild.Id).GetOrCreate(user.Id); var desc = new StringBuilder(); desc.Append("Voted For:\n"); foreach (var voted in profile.VotedFor) { if (voted == NullVoter) { continue; } var voteUser = Context.Guild.GetUser(voted); if (voteUser == null) { continue; } var nick = KrispyNickname.NickName(voteUser.Nickname); desc.Append("\t" + nick + "\n"); } desc.Append("Was Voted By:\n"); foreach (var voter in profile.WasVotedBy) { var nick = voter == NullVoter ? "Krispy Bot" : KrispyNickname.NickName(Context.Guild.GetUser(voter).Nickname); desc.Append("\t" + nick + "\n"); } var embed = new EmbedBuilder() .WithTitle(guildUser.Nickname + "'s profile") .WithDescription(desc.ToString()) .WithCurrentTimestamp() .WithImageUrl("https://cdn.discordapp.com/avatars/" + user.Id + "/" + user.AvatarId + ".png") .WithColor(Color.Red) .Build(); await ReplyAsync("", false, embed); }