Beispiel #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;
                }
            }
        }
Beispiel #2
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```");
                    }
                }
            }
        }