Beispiel #1
0
        private async Task Greet(IMessageChannel channel, EventsSettings settings, SocketGuildUser user)
        {
            if (settings.GreetMessage != default)
            {
                await _communicator.SendMessage(channel, ReplacePlaceholders(settings.GreetMessage, user));
            }
            else if (settings.GreetEmbed != default)
            {
                var embed = new EmbedBuilder()
                            .WithTitle(ReplacePlaceholders(settings.GreetEmbed.Title, user))
                            .WithDescription(ReplacePlaceholders(settings.GreetEmbed.Body, user))
                            .WithThumbnailUrl(user.GetAvatarUrl(size: 512) ?? user.GetDefaultAvatarUrl());

                if (settings.GreetEmbed.Color.HasValue)
                {
                    embed.WithColor(Math.Min(settings.GreetEmbed.Color.Value, 0xfffffe)); // 0xfffffff is a special code for blank...
                }
                if (settings.GreetEmbed.Image != default)
                {
                    embed.WithImageUrl(settings.GreetEmbed.Image.AbsoluteUri);
                }

                if (!string.IsNullOrEmpty(settings.GreetEmbed.Footer))
                {
                    embed.WithFooter(ReplacePlaceholders(settings.GreetEmbed.Footer, user));
                }

                await _communicator.SendMessage(channel, embed.Build());
            }
            else
            {
                throw new InvalidOperationException("Inconsistent settings");
            }
        }
Beispiel #2
0
        public Task SaveSettings(ulong guildId, EventsSettings settings)
        {
            // Don't let clients change this!
            settings.Guild = guildId;

            return(SettingsService.SaveSettings(settings));
        }
Beispiel #3
0
        public async Task Update()
        {
            Log.Write("Updating Calendar", "Bot");

            foreach (SocketGuild guild in Program.DiscordClient.Guilds)
            {
                EventsSettings settings = await SettingsService.GetSettings <EventsSettings>(guild.Id);

                if (settings == null)
                {
                    continue;
                }

                if (settings.CalendarChannel == null)
                {
                    continue;
                }

                ulong channelId       = 0;
                ulong weekMessageID   = 0;
                ulong futureMessageID = 0;

                ulong.TryParse(settings.CalendarChannel, out channelId);
                ulong.TryParse(settings.CalendarWeekMessageId, out weekMessageID);
                ulong.TryParse(settings.CalendarFutureMessageId, out futureMessageID);

                if (channelId == 0)
                {
                    return;
                }

                weekMessageID = await this.Update(guild.Id, channelId, weekMessageID, "Events in the next week", 0, 7);

                futureMessageID = await this.Update(guild.Id, channelId, futureMessageID, "Events in the future", 7, 30);

                settings.CalendarWeekMessageId   = weekMessageID.ToString();
                settings.CalendarFutureMessageId = futureMessageID.ToString();
                await SettingsService.SaveSettings(settings);
            }
        }