コード例 #1
0
        /// <summary>
        /// Start this module.
        /// </summary>
        private async Task InitializeChannel()
        {
            SocketTextChannel channel = null;
            var guild = _server.DiscordHandler;

            // - Check if exists the bot channel
            var channels = guild.Channels.Where(x => x.Name == _config["channel:name"]);

            // - If channel not exists
            if (channels.Count() <= 0)
            {
                var c = await guild.CreateTextChannelAsync(_config["channel:name"]);

                channel = guild.GetChannel(c.Id) as SocketTextChannel;
            }
            else
            {
                channel = channels.FirstOrDefault() as SocketTextChannel;
            }

            // - Gets all channel messages
            var asyncMessages = await channel.GetMessagesAsync().Flatten();

            // - Assign a message for each drawable
            foreach (var drawable in Drawables.OrderBy(x => x.Key).Select(x => x.Value))
            {
                // - Get the message for this drawable
                var messages = asyncMessages.Where(x => x.Embeds.First().Author.Value.Name == drawable.Name);

                var message = messages.Any() ? messages.First() : null;

                // - If message not exists make it!
                if (message == null)
                {
                    message = await channel.SendMessageAsync("", false, drawable.Render());
                }

                drawable.Message = message as RestUserMessage;

                await drawable.Update();
            }
        }
コード例 #2
0
        public void AddRenderer(IDrawable drawable)
        {
            Drawables.Add(drawable);

            Drawables = Drawables.OrderBy(x => (int)(x.DrawOrder)).ToList();
        }