Example #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));
            }
        }
 public GlobalGuildAccount GetById(ulong id)
 {
     return(serverAccounts.GetOrAdd(id, (key) =>
     {
         var newAccount = new GlobalGuildAccount(id);
         _jsonDataStorage.StoreObject(newAccount, Path.Combine(Constants.ServerAccountsFolder, $"{id}.json"), useIndentations: true);
         return newAccount;
     }));
 }
Example #3
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);
            }
        }