コード例 #1
0
        public static void Handle(MessageEventArgs e)
        {
            try
            {
                ServerData S = ServerData.Servers[e.Server.Id];
                if (S.Trivia.ContainsKey(e.Channel.Id) && S.Trivia[e.Channel.Id].Try(e))
                {
                    return;
                }

                List <Command> Cmds = S.GetCommands(e.Channel.Id);

                string Raw = e.Message.RawText;

                if (e.Message.Text.StartsWith("{") && e.Message.Text.EndsWith("}") && Db.HasPermission(e.User.Id, "anime"))
                {
                    Search.AnimeInfo(Raw.TrimStart('{').TrimEnd('}'), e);
                }
                else if (e.Message.Text.StartsWith("<") && !e.Message.Text.StartsWith("<@") && e.Message.Text.EndsWith(">") && Db.HasPermission(e.User.Id, "manga"))
                {
                    Search.MangaInfo(Raw.TrimStart('<').TrimEnd('>'), e);
                }

                string Key;
                string Lower;
                foreach (Command Cmd in Cmds)
                {
                    string Prefix = CmdPrefix;
                    Lower = Raw.ToLower();

                    if (Cmd.Prefix != Command.PrefixType.None)
                    {
                        if (Db.HasPermission(e.User.Id, Cmd.Keys[0]))
                        {
                            if (Cmd.Prefix == Command.PrefixType.Mention)
                            {
                                Prefix = Bot.Mention + " ";
                            }

                            foreach (string CmdKey in Cmd.Keys)
                            {
                                Key = Prefix + CmdKey;

                                if (Lower.StartsWith(Key) && (Raw.Length == Key.Length || Raw.Substring(Key.Length, 1) == " " || Raw.Substring(Key.Length, 1) == "." || Raw.Substring(Key.Length, 1) == "?"))
                                {
                                    Cmd.Handler(Raw.Substring(Key.Length).TrimStart(' '), e);
                                    Executed++;
                                    return;
                                }
                            }
                        }
                    }
                    else if (Lower.Contains(Cmd.Keys[0]))
                    {
                        Executed++;
                        Cmd.Handler(Raw, e);
                        return;
                    }
                }

                if (Raw.StartsWith(Bot.Mention) && Raw.EndsWith("?") && Db.HasPermission(e.User.Id, "ask") && Cmds.Any(x => x.Keys.Contains("ask")))
                {
                    Search.Ask(Raw, e);
                }
            }
            catch (Exception Ex)
            {
                $"CommandExeption: {Ex}".Log();
            }
        }