Esempio n. 1
0
File: Web.cs Progetto: ta1H3n/Namiko
        public async Task Subreddit(string name, int upvotes)
        {
            var subs  = SpecialChannelDb.GetChannelsByGuild(Context.Guild.Id, Model.ChannelType.Reddit);
            int limit = 1;

            if (PremiumDb.IsPremium(Context.Guild.Id, ProType.Guild))
            {
                limit = 5;
            }
            if (PremiumDb.IsPremium(Context.Guild.Id, ProType.GuildPlus))
            {
                limit = 10;
            }

            if (subs.Count() >= limit)
            {
                await Context.Channel.SendMessageAsync($"Limit {limit} subscription per guild. Upgrade server to increase the limit! `{Program.GetPrefix(Context)}Pro`", embed : WebUtil.SubListEmbed(Context.Guild.Id).Build());

                return;
            }

            if (upvotes < 100)
            {
                await Context.Channel.SendMessageAsync("Upvote minimum must be at least 100.");

                return;
            }

            await Context.Channel.TriggerTypingAsync();

            Subreddit sub = null;

            try
            {
                sub = await RedditAPI.GetSubreddit(name);
            } catch
            {
                await Context.Channel.SendMessageAsync($"Subreddit **{name}** not found.");

                return;
            }
            if (sub.Subscribers < 20000)
            {
                await Context.Channel.SendMessageAsync("The Subreddit must have at least **20,000** subscribers.\n" +
                                                       $"**{sub.Name}** has **{sub.Subscribers?.ToString("n0")}**.");

                return;
            }
            try
            {
                if (sub.Over18.Value && !((SocketTextChannel)Context.Channel).IsNsfw)
                {
                    await Context.Channel.SendMessageAsync($"**{sub.Name}** is a NSFW subreddit. This channel must be marked as NSFW.");

                    return;
                }
            } catch { }

            var old = subs.FirstOrDefault(x => x.ChannelId == Context.Channel.Id && x.Args.Split(",")[0].Equals(sub.Name));

            if (old != null)
            {
                await SpecialChannelDb.Delete(old);
            }

            await SpecialChannelDb.AddChannel(Context.Channel.Id, Model.ChannelType.Reddit, Context.Guild.Id, sub.Name + "," + upvotes);

            await Context.Channel.SendMessageAsync(embed : WebUtil.SubredditSubscribedEmbed(sub, upvotes).Build());
        }