コード例 #1
0
ファイル: Program.cs プロジェクト: filthfiend/Fifthbot
        private async Task Client_MessageReceived(SocketMessage MessageParam)
        {
            var Message = MessageParam as SocketUserMessage;

            SocketGuild userGuild = null;
            SocketUser  user      = null;

            if (Message.Channel.GetType() == typeof(SocketDMChannel))
            {
                userGuild = Client.Guilds.Where(x => x.Users.Any(y => Message.Author.Id == y.Id)).FirstOrDefault();
                user      = userGuild?.Users.Where(x => x.Id == Message.Author.Id).FirstOrDefault();
            }
            else
            {
                userGuild = (Message.Channel as SocketGuildChannel)?.Guild;
                user      = Message.Author;
            }



            var Context = new SocketCommandContext(Client, Message, userGuild, user);

            if (Context.Message == null || Context.Message.Content == "")
            {
                return;
            }
            if (Context.User.IsBot)
            {
                return;
            }

            HelperMethods.LoadSettings();
            int ArgPos = 0;

            if (!(Message.HasStringPrefix(Setting.prefix, ref ArgPos) || Message.HasMentionPrefix(Client.CurrentUser, ref ArgPos)))
            {
                var guildUser = Context.User as SocketGuildUser;

                if (!(

                        guildUser.GuildPermissions.Administrator ||
                        guildUser.Roles.Any(x => x.Name == "Seven Deadly Sins") ||
                        guildUser.Roles.Any(x => x.Name == "Tester")

                        ))
                {
                    return;
                }

                // to AddKinkData
                if (Vars.activeCommands.Where(x => x.ActorID == Context.User.Id && x.CommandName == "addkink" && x.ChannelID == Context.Channel.Id).Count() > 0)
                {
                    UtilMethods kinkToAdd = new UtilMethods();

                    Console.WriteLine(" we're entering AddKinkData ");
                    await kinkToAdd.AddKinkData(Context);
                }

                // to AddGroupData
                if (Vars.activeCommands.Where(x => x.ActorID == Context.User.Id && x.CommandName == "addgroup" && x.ChannelID == Context.Channel.Id).Count() > 0)
                {
                    UtilMethods groupToAdd = new UtilMethods();

                    Console.WriteLine(" we're entering AddGroupData ");
                    await groupToAdd.AddGroupData(Context);
                }

                // to EditKinkData
                if (Vars.activeCommands.Where(x => x.ActorID == Context.User.Id && x.CommandName == "editkink" && x.ChannelID == Context.Channel.Id).Count() > 0)
                {
                    UtilMethods kinkToEdit = new UtilMethods();

                    Console.WriteLine(" we're entering EditKinkData ");
                    await kinkToEdit.EditKinkData(Context);
                }

                // to EditGroupData
                if (Vars.activeCommands.Where(x => x.ActorID == Context.User.Id && x.CommandName == "editgroup" && x.ChannelID == Context.Channel.Id).Count() > 0)
                {
                    UtilMethods groupToEdit = new UtilMethods();

                    Console.WriteLine(" we're entering EditGroupData ");
                    await groupToEdit.EditGroupData(Context);
                }

                // to GroupMenuCreator
                if (
                    Vars.menuBuilder.IsActive &&
                    Vars.menuBuilder.ChannelID == Context.Channel.Id &&
                    Vars.menuBuilder.UserID == Context.User.Id
                    )
                {
                    MenuCreateMethods menuToCreate = new MenuCreateMethods();

                    Console.WriteLine(" we're entering GroupMenuCreator ");
                    await menuToCreate.GroupMenuCreator(Context);
                }


                /*
                 * if (!(Vars.usersAddingKinks.Where(x => x == Context.User.Id).Count() > 0) )
                 * {
                 *  return;
                 * }
                 *
                 * UtilMethods kinkToAdd = new UtilMethods();
                 *
                 * await kinkToAdd.AddKinkData(Context);
                 */


                return;
            }


            var Result = await Commands.ExecuteAsync(Context, ArgPos, null);

            if (!Result.IsSuccess)
            {
                Console.WriteLine($"{DateTime.Now} at Commands] Something went wrong executing a command. Text: {Context.Message.Content} | Error: {Result.ErrorReason}");
            }
        }