Ejemplo n.º 1
0
        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;
                }
            }
        }
Ejemplo n.º 2
0
        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());
        }
Ejemplo n.º 3
0
        private async Task CheckMessage(SocketMessage msg)
        {
            if (!(msg is SocketUserMessage userMsg))
            {
                return;
            }

            await KrispyCommands.MonitorMessages(msg);

            int  mentionPos = 0, charPos = 0;
            bool passMention = false, passChar = false;

            if (userMsg.HasMentionPrefix(Client.CurrentUser, ref mentionPos))
            {
                passMention = true;
            }
            else if (userMsg.HasCharPrefix('$', ref charPos))
            {
                passChar = true;
            }

            if (passMention || passChar)
            {
                var pos = passMention ? mentionPos : charPos;
                if (await KrispyCommands.Fun(Client, msg, pos))
                {
                    return;
                }
                var context = new SocketCommandContext(Client, userMsg);
                var result  = await Commands.ExecuteAsync(context, pos, Services);

                if (!result.IsSuccess)
                {
                    if (result.Error == CommandError.UnknownCommand)
                    {
                        var chosenLine = KrispyGenerator.PickLine(KrispyLines.Unknown);
                        if (chosenLine.Contains("{0}"))
                        {
                            chosenLine =
                                string.Format(chosenLine, KrispyNickname.FirstName(((IGuildUser)msg.Author).Nickname));
                        }
                        await context.Channel.SendMessageAsync(chosenLine);
                    }
                    else
                    {
                        await context.Channel.SendMessageAsync(
                            "Hehehe... We've hit an error!\n```\n" + result.ErrorReason + "\n```");
                    }
                }
            }
        }
Ejemplo n.º 4
0
        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);
        }