Esempio n. 1
0
            internal bool AddGuild(JsonGuild jsonGuild, GuildSettings?settings = null, Dictionary <ulong, ChannelSettings>?channelSettings = null)
            {
                var guild = new Guild(jsonGuild, settings, _client);

                if (_guildMap.TryAdd(guild.Id, guild))
                {
                    foreach (var jsonChannel in jsonGuild.Channels)
                    {
                        ChannelSettings?thisChannelSettings = null;
                        channelSettings?.TryGetValue(jsonChannel.Id, out thisChannelSettings);

                        var channel = _client.Channels.AddChannel(jsonChannel, guild.Id, thisChannelSettings);
                        if (channel is not null)
                        {
                            guild.AddChannel(jsonChannel.Id);
                        }
                    }

                    foreach (var member in jsonGuild.Members)
                    {
                        _client.Members.AddGuildMember(guild.Id, member);
                    }

                    foreach (var voiceState in jsonGuild.VoiceStates)
                    {
                        _client.Voice.UpdateVoiceState(voiceState);
                    }

                    return(true);
                }

                return(false);
            }
Esempio n. 2
0
        internal void UpdateFromRestGuild(JsonGuild restGuild)
        {
            Guard.IsEqualTo(Id, restGuild.Id, nameof(Id));

            Name         = restGuild.Name;
            AFKChannelId = restGuild.AFKChannelId ?? AFKChannelId;
            AFKTimeout   = restGuild.AFKTimeout ?? AFKTimeout;
            DefaultMessageNotifications = restGuild.DefaultMessageNotifications;
            MfaLevel                 = restGuild.MfaLevel;
            VerificationLevel        = restGuild.VerificationLevel;
            ExplicitContentFilter    = restGuild.ExplicitContentFilter;
            NsfwLevel                = restGuild.NsfwLevel;
            PremiumSubscriptionCount = restGuild.PremiumSubscriptionCount ?? 0;
            IconId                 = restGuild.Icon;
            SplashId               = restGuild.Splash;
            DiscoverySplashId      = restGuild.Splash;
            WidgetChannelId        = restGuild.WidgetChannelId;
            SystemChannelId        = restGuild.SystemChannelId;
            RulesChannelId         = restGuild.RulesChannelId;
            PublicUpdatesChannelId = restGuild.PublicUpdatesChannelId;
            IsWidgetEnabled        = restGuild.IsWidgetEnabled ?? false;
            OwnerId                = restGuild.OwnerId;
            VoiceRegionId          = restGuild.Region;

            Available = true;
        }
Esempio n. 3
0
            internal bool UpdateGuild(JsonGuild jsonGuild)
            {
                if (!_guildMap.TryGetValue(jsonGuild.Id, out Guild guild))
                {
                    return(false);
                }

                guild.UpdateFromRestGuild(jsonGuild);
                return(true);
            }
Esempio n. 4
0
 public Diswords(DiswordsClient client, IGuildUser creator, JsonGuild guild, ITextChannel channel,
                 bool createdNewChannel, int previousSlowModeInterval, JsonLanguage language)
 {
     Creator                   = creator ?? throw new ArgumentNullException(nameof(creator));
     Channel                   = channel ?? throw new ArgumentNullException(nameof(channel));
     Language                  = language ?? throw new ArgumentNullException(nameof(language));
     Locale                    = ILocale.Find(Language.ShortName);
     Guild                     = guild;
     _newChannelCreated        = createdNewChannel;
     _previousSlowModeInterval = previousSlowModeInterval;
     _client                   = client;
     _lastSender               = null !;
 }
Esempio n. 5
0
        /// <summary>
        ///     Load every guild and language into memory. (Lists)
        ///     <para>
        ///         <bold>There are two types of lists: static and private.</bold>
        ///     </para>
        ///     <remarks>This method loads guilds and languages into <bold>static</bold> lists.</remarks>
        ///     <para>See <see cref="LoadPrivateResources" /> for loading guilds and languages into <bold>private</bold> lists.</para>
        /// </summary>
        private async Task LoadResources()
        {
            Console.WriteLine("Diswords: Loading static resources..");
            StaticGuilds.Clear();
            StaticLanguages.Clear();
            foreach (var guild in Directory.EnumerateFiles(
                         $"{Config.RootDirectory}{Path.DirectorySeparatorChar}{Config.GuildsDirectoryName}",
                         "*.json", SearchOption.AllDirectories))
            {
                if (!guild.EndsWith(".json"))
                {
                    continue;
                }
                var id = Path.GetFileNameWithoutExtension(guild);
                Console.WriteLine($"Diswords: Loading guild {id}..");
                try
                {
                    StaticGuilds.Add(await JsonGuild.FromJsonFile(guild));
                }
                catch (Exception e)
                {
                    Console.WriteLine($"Diswords: Failed to load guild {id}:\n{e}");
                    throw;
                }
            }

            foreach (var language in Directory.EnumerateFiles(
                         $"{Config.RootDirectory}{Path.DirectorySeparatorChar}{Config.LanguagesDirectoryName}",
                         "*.json", SearchOption.AllDirectories))
            {
                if (!language.EndsWith(".json"))
                {
                    continue;
                }
                var languageName = Path.GetFileNameWithoutExtension(language);
                Console.WriteLine($"Diswords: Loading language {languageName}..");
                try
                {
                    StaticLanguages.Add(await JsonLanguage.FromJsonFile(language));
                }
                catch (Exception e)
                {
                    Console.WriteLine($"Diswords: Failed to load guild {languageName}:\n{e}");
                    throw;
                }
            }
        }
Esempio n. 6
0
        /// <summary>
        /// Initializes new instance of the <see cref="Guild"/> class.
        /// </summary>
        internal Guild(JsonGuild restGuild, GuildSettings?settings, QuarrelClient context)
            : base(context)
        {
            Id   = restGuild.Id;
            Name = restGuild.Name;

            AFKChannelId = restGuild.AFKChannelId;
            AFKTimeout   = restGuild.AFKTimeout;

            DefaultMessageNotifications = restGuild.DefaultMessageNotifications;
            MfaLevel              = restGuild.MfaLevel;
            VerificationLevel     = restGuild.VerificationLevel;
            ExplicitContentFilter = restGuild.ExplicitContentFilter;
            NsfwLevel             = restGuild.NsfwLevel;

            OwnerId = restGuild.OwnerId;

            PremiumSubscriptionCount = restGuild.PremiumSubscriptionCount ?? 0;
            IconId            = restGuild.Icon;
            SplashId          = restGuild.Splash;
            DiscoverySplashId = restGuild.DiscoverySplash;

            WidgetChannelId        = restGuild.WidgetChannelId;
            SystemChannelId        = restGuild.SystemChannelId;
            RulesChannelId         = restGuild.RulesChannelId;
            PublicUpdatesChannelId = restGuild.PublicUpdatesChannelId;
            VoiceRegionId          = restGuild.Region;

            IsWidgetEnabled = restGuild.IsWidgetEnabled ?? false;
            Available       = true;

            Muted = settings?.Muted ?? false;

            _channelIds = new HashSet <ulong>();
            _roles      = new Dictionary <ulong, Role>();

            foreach (var role in restGuild.Roles)
            {
                _roles.Add(role.Id, new Role(role, context));
            }
        }
Esempio n. 7
0
        /// <summary>
        /// Method for creating the config file for the guild.
        /// </summary>
        /// <param name="guild">The Joined Guild.</param>
        private async Task JoinedGuild(SocketGuild guild, string language)
        {
            try
            {
                var jsonGuild = new JsonGuild(language, Config.DefaultPrefix, guild.Id);
                var path      =
                    $"{Config.RootDirectory}{Path.DirectorySeparatorChar}{Config.GuildsDirectoryName}{(Config.GuildsDirectoryName == "" ? "" : Path.DirectorySeparatorChar.ToString())}{Client.CurrentUser.Id}";
                if (!Directory.Exists(path))
                {
                    Directory.CreateDirectory(path);
                }
                await File.WriteAllTextAsync(
                    $"{Config.RootDirectory}{Path.DirectorySeparatorChar}{Config.GuildsDirectoryName}{(Config.GuildsDirectoryName == "" ? "" : Path.DirectorySeparatorChar.ToString())}{Client.CurrentUser.Id}{Path.DirectorySeparatorChar}{guild.Id}.json",
                    jsonGuild.ToJson());

                Guilds.Add(jsonGuild);
            }
            catch (Exception e)
            {
                Console.WriteLine($"Diswords: {e}");
                throw;
            }
        }