コード例 #1
0
        public Embed SubscribeToBlog(ulong userId, string blogname)
        {
            var blogs = _jsonDataStorage.RestoreObject <List <BlogItem> >(blogFile);

            var blog = blogs.FirstOrDefault(k => k.Name == blogname);

            if (blog != null)
            {
                if (!blog.Subscribers.Contains(userId))
                {
                    blog.Subscribers.Add(userId);

                    _jsonDataStorage.StoreObject(blogs, blogFile, Formatting.Indented);

                    return(EmbedHandler.CreateEmbed("Blog", "You now follow this blog", EmbedHandler.EmbedMessageType.Success));
                }
                else
                {
                    return(EmbedHandler.CreateEmbed("Blog :x:", "You already follow this blog", EmbedHandler.EmbedMessageType.Info));
                }
            }
            else
            {
                return(EmbedHandler.CreateEmbed("Blog :x:", $"There is no Blog with the name {blogname}", EmbedHandler.EmbedMessageType.Error));
            }
        }
コード例 #2
0
        public async Task Create(string name)
        {
            await Context.Message.DeleteAsync();

            var blogs = jsonDataStorage.RestoreObject <List <BlogItem> >(blogFile) ?? new List <BlogItem>();

            if (blogs.FirstOrDefault(k => k.Name == name) == null)
            {
                var newBlog = new BlogItem
                {
                    BlogId      = Guid.NewGuid(),
                    Author      = Context.User.Id,
                    Name        = name,
                    Subscribers = new List <ulong>()
                };

                blogs.Add(newBlog);

                jsonDataStorage.StoreObject(blogs, blogFile, Formatting.Indented);

                var embed = EmbedHandler.CreateEmbed("Blog", $"Your blog {name} was created.", EmbedHandler.EmbedMessageType.Success);
                await Context.Channel.SendMessageAsync("", false, embed);
            }
            else
            {
                var embed = EmbedHandler.CreateEmbed("Blog :x:", $"There is already a Blog with the name {name}", EmbedHandler.EmbedMessageType.Error);
                await Context.Channel.SendMessageAsync("", false, embed);
            }
        }
コード例 #3
0
        public GlobalGuildAccounts(JsonDataStorage jsonDataStorage)
        {
            _jsonDataStorage = jsonDataStorage;
            var info  = System.IO.Directory.CreateDirectory(Path.Combine(Constants.ResourceFolder, Constants.ServerAccountsFolder));
            var files = info.GetFiles("*.json");

            if (files.Length > 0)
            {
                foreach (var file in files)
                {
                    var server = jsonDataStorage.RestoreObject <GlobalGuildAccount>(Path.Combine(file.Directory.Name, file.Name));
                    serverAccounts.TryAdd(server.Id, server);
                }
            }
            else
            {
                serverAccounts = new ConcurrentDictionary <ulong, GlobalGuildAccount>();
            }
        }
コード例 #4
0
        public GlobalUserAccounts(JsonDataStorage jsonDataStorage)
        {
            _jsonDataStorage = jsonDataStorage;
            _directoryInfo   = Directory.CreateDirectory(_directoryPath);
            var files = _directoryInfo.GetFiles("*.json");

            if (files.Length > 0)
            {
                foreach (var file in files)
                {
                    var user = jsonDataStorage.RestoreObject <GlobalUserAccount>(Path.Combine(file.Directory.Name, file.Name));
                    userAccounts.TryAdd(user.Id, user);
                }
            }
            else
            {
                userAccounts = new ConcurrentDictionary <ulong, GlobalUserAccount>();
            }
        }