예제 #1
0
        public async Task ConfigureServerAsync()
        {
            ulong configChannelId;
            ulong reminderChannelId;

            // config channel
            await ReplyAndDeleteAsync($"Tag the channel you want **configuration** messages sent to (for example, {MentionUtils.MentionChannel(Context.Channel.Id)}).", false, null, TimeSpan.FromMinutes(1));

            var response = await NextMessageAsync(true, true, TimeSpan.FromSeconds(30));

            if (response != null)
            {
                if (response.MentionedChannels.FirstOrDefault() != null)
                {
                    configChannelId = MentionUtils.ParseChannel(response.Content);
                }
                else
                {
                    await ReplyAsync("You didn't correctly tag a channel. Follow the instructions, dingus.");

                    return;
                }
            }
            else
            {
                await ReplyAsync("I didn't get a response in time. Try again.");

                return;
            }


            // reminder channel
            await ReplyAndDeleteAsync($"Tag the channel you want **reminders & the schedule** sent to (for example, {MentionUtils.MentionChannel(Context.Channel.Id)}).", false, null, TimeSpan.FromMinutes(1));

            response = await NextMessageAsync(true, true, TimeSpan.FromSeconds(30));

            if (response != null)
            {
                if (response.MentionedChannels.FirstOrDefault() != null)
                {
                    reminderChannelId = MentionUtils.ParseChannel(response.Content);
                }
                else
                {
                    await ReplyAsync("You didn't correctly tag a channel. Follow the instructions, dingus.");

                    return;
                }
            }
            else
            {
                await ReplyAsync("I didn't get a response in time. Try again.");

                return;
            }

            // build our new server object
            var newServer = new DbDiscordServer()
            {
                ConfigChannelId   = configChannelId.ToString(),
                ReminderChannelId = reminderChannelId.ToString(),
                ServerId          = Context.Guild.Id.ToString(),
                ServerName        = Context.Guild.Name,
                RemindersEnabled  = true
            };

            // add this server's data to the database
            await DatabaseServers.AddServerInfo(newServer);

            // initialize this server
            RaidEventsService.SetServerDiscordObjects(newServer);

            // update the ServerList with the new server
            DbDiscordServers.ServerList.Add(newServer);

            // set up google api authentication
            await AuthAsync();
        }
        public override async Task <bool> HandleTextMessage(SocketMessage message)
        {
            // Get the guild
            SocketGuild guild = (message.Channel as SocketGuildChannel).Guild;

            // Parse the channel ID
            ulong channelId;

            try
            {
                channelId = MentionUtils.ParseChannel(message.Content);
            }
            catch (ArgumentException)
            {
                await DiscordUtil.SendErrorMessageByLocalizedDescription(guild, this.Channel, "discord.setup.enter_channel.bad_channel");

                return(false);
            }

            // Get the channel
            SocketChannel foundChannel = DiscordBot.GetChannel(channelId);

            // Check if it exists
            if (foundChannel == null)
            {
                await DiscordUtil.SendErrorMessageByLocalizedDescription(guild, this.Channel, "discord.setup.enter_channel.bad_channel");

                return(false);
            }

            // Check this channel's guild
            SocketGuildChannel socketGuildChannel = foundChannel as SocketGuildChannel;

            // Check that this exists and that it is in the user's guild
            if (socketGuildChannel == null || socketGuildChannel.Guild.Id != SetupFlow.Guild.Id)
            {
                await DiscordUtil.SendErrorMessageByLocalizedDescription(guild, this.Channel, "discord.setup.enter_channel.bad_channel");

                return(false);
            }

            // Get the text channel
            SocketTextChannel socketTextChannel = foundChannel as SocketTextChannel;

            // Check if this is a text channel
            if (socketTextChannel == null)
            {
                await DiscordUtil.SendErrorMessageByLocalizedDescription(guild, this.Channel, "discord.setup.enter_channel.bad_channel");

                return(false);
            }

            // Check if this already exists as settings
            if (SetupFlow.GuildSettings.ChannelSettings.Where(p => p.Key == channelId).Count() != 0)
            {
                await DiscordUtil.SendErrorMessageByLocalizedDescription(guild, this.Channel, "discord.setup.enter_channel.already_exists");

                return(false);
            }

            // Get all required permissions
            List <ChannelPermission> requiredPermissions = new ChannelPermissions(Configuration.LoadedConfiguration.DiscordConfig.Permissions).ToList();

            // Get current permissions for this channel
            ChannelPermissions channelPermissions = guild.CurrentUser.GetPermissions(socketTextChannel);

            // Get a list of permissions that the bot does not have
            IEnumerable <ChannelPermission> missingPermissions = requiredPermissions.Where(x => !channelPermissions.Has(x));

            // Check if we are missing any
            if (missingPermissions.Count() > 0)
            {
                // Try to get the default language
                Language language = DiscordUtil.GetDefaultLanguage(guild);

                // Create the description string for the error message
                string description = Localizer.Localize("discord.setup.enter_channel.missing_permissions", language) + "\n\n";

                // Append the permissions
                foreach (ChannelPermission permission in missingPermissions)
                {
                    description += permission.ToString() + "\n";
                }

                // Create an embed
                await DiscordUtil.SendErrorMessageByDescription(guild, this.Channel, description);

                return(false);
            }

            // Set the new message flag
            SetupFlow.ShouldSendNewMessage = true;

            if (SetupFlow.ChannelSettings == null)
            {
                // Create a DynamicSettingsData instance
                SetupFlow.ChannelSettings = new DynamicSettingsData();

                // Set the ID
                SetupFlow.TargetChannelId = channelId;

                // Proceed to language selection
                await SetupFlow.SetPage((int)SetupFlowPage.SelectLanguage);
            }
            else
            {
                // Move the data
                SetupFlow.GuildSettings.ChannelSettings.TryRemove(SetupFlow.TargetChannelId, out DynamicSettingsData data);
                SetupFlow.GuildSettings.ChannelSettings.TryAdd(channelId, data);

                // Set a pre-prompt
                SetupFlow.ModeSelectPrePromptLocalizable = "discord.setup.mode_select.pre_prompt.edits_saved";

                // Change to mode select
                await SetupFlow.SetPage((int)SetupFlowPage.ModeSelect);
            }

            return(false);
        }