Ejemplo n.º 1
0
        public async Task PartnerEvent()
        {
            var configs = Database.Query <PartnerConfig>();
            var sorted  = configs
                          .Where(x => x.Enabled)
                          .Select(x => new GroupedConfig
            {
                Guild  = Client.GetGuild(x.GuildId),
                Config = x
            })
                          .Where(x => x.Guild != null)
                          .ToList();
            var randomised = sorted.OrderBy(x => Random.Next()).ToList();

            foreach (var group in randomised)
            {
                var embedToSend = await group.Config.GetEmbedAsync(group.Guild);

                if (!embedToSend.Item1)
                {
                    continue;
                }

                var receiver = sorted.FirstOrDefault(x => x.Config.GuildId != group.Config.GuildId);
                if (receiver == null)
                {
                    return;
                }
                sorted.Remove(receiver);

                var receiverChannel = receiver.Guild.GetTextChannel(receiver.Config.ReceiverChannelId);
                if (receiverChannel == null)
                {
                    continue;
                }

                ChannelPermissions?perms = receiver.Guild?.CurrentUser?.GetPermissions(receiverChannel);
                if (perms.HasValue && !perms.Value.SendMessages)
                {
                    continue;
                }

                try
                {
                    await receiverChannel.SendMessageAsync("", false, embedToSend.Item2.Build());

                    group.Config.ServerCount++;
                    group.Config.UserCount += receiver.Guild.MemberCount;
                    Database.Store(group.Config, PartnerConfig.DocumentName(group.Config.GuildId));
                }
                catch
                {
                    //
                }
            }
        }
Ejemplo n.º 2
0
        public PartnerConfig GetOrCreatePartnerConfig(ulong guildId)
        {
            var config = Database.Load <PartnerConfig>(PartnerConfig.DocumentName(guildId));

            if (config == null)
            {
                config = new PartnerConfig(guildId);
                Database.Store(config, PartnerConfig.DocumentName(guildId));
            }

            return(config);
        }
Ejemplo n.º 3
0
 public void SavePartnerConfig(PartnerConfig config)
 {
     Database.Store(config, PartnerConfig.DocumentName(config.GuildId));
 }