Пример #1
0
        public async Task CreateRoleSyncAsync(SocketRole socketRole, string productId, ulong?watchMessageId = null)
        {
            var result = await _gumroad.GetProductAsync(_config["gumroad:token"], productId);

            if (!result.IsSuccess)
            {
                await ReplyAsync("Sorry, I couldn't find any products matching that ID.");

                return;
            }

            var product = new RexoProduct
            {
                Id              = result.Product.Id,
                Name            = result.Product.Name,
                PreviewImageUrl = result.Product.PreviewUrl,
                ShortUrl        = result.Product.ShortUrl,
                GuildId         = Context.Guild.Id,
                RoleId          = socketRole.Id,
                WatchMessageId  = watchMessageId
            };

            _db.Products.Add(product);
            _db.SaveChanges();

            await ReplyAsync($"Successfully added `{product.Name}` to the syncing service!");
        }
Пример #2
0
 public Task SetSyncMessageAsync(RexoProduct product, ulong msgId)
 {
     product.WatchMessageId = msgId;
     _db.Update(product);
     _db.SaveChanges();
     return(Task.CompletedTask);
 }
Пример #3
0
 public RexoProduct RemoveProduct(RexoProduct product, ulong msgId)
 {
     if (_syncedProducts.TryRemove(msgId, out RexoProduct result))
     {
         return(result);
     }
     return(null);
 }
Пример #4
0
 public void AddProduct(RexoProduct product)
 {
     if (product.WatchMessageId == null)
     {
         return;
     }
     _syncedProducts.TryAdd(product.WatchMessageId.Value, product);
 }
Пример #5
0
        public async Task CreateSyncMessageAsync(RexoProduct product, SocketTextChannel channel, [Remainder] string message = null)
        {
            var role = Context.Guild.GetRole(product.RoleId);

            var embed = new EmbedBuilder()
                        .WithTitle(product.Name)
                        .WithThumbnailUrl(product.PreviewImageUrl)
                        .WithUrl(product.ShortUrl)
                        .WithDescription(message != null ? message : $"If you would like to sync your Gumroad purchase for this product to Discord for the {role.Mention} role, add a reaction to this message!");

            var msg = await channel.SendMessageAsync(embed : embed.Build());

            await msg.AddReactionAsync(new Emoji("👍"));

            await SetSyncMessageAsync(product, msg.Id);
        }
Пример #6
0
        public async Task RemoveRoleSyncAsync(RexoProduct product)
        {
            await ReplyAsync($"Are you sure you want to remove `{product.Name}` from the sycning service? Reply yes/no");

            var response = await _responsive.WaitForMessageAsync((msg) =>
            {
                return(msg.Content.ToLower() == "yes");
            });

            if (response == null)
            {
                return;
            }

            _db.Remove(product);
            _db.SaveChanges();

            await ReplyAsync($"Successfully removed `{product.Name}` from the syncing service!");
        }
Пример #7
0
 public async Task LinkAsync([Remainder] RexoProduct product)
 {
     await _linking.LinkUserAsync(Context.User.Id, product);
 }