Exemplo n.º 1
0
Arquivo: Web.cs Projeto: ta1H3n/Namiko
        public async Task Unsubscribe(string name)
        {
            await Context.Channel.TriggerTypingAsync();

            var subs = SpecialChannelDb.GetChannelsByGuild(Context.Guild.Id, Model.ChannelType.Reddit);
            var olds = subs.Where(x => x.Args.Split(",")[0].Equals(name, StringComparison.OrdinalIgnoreCase));

            if (!olds.Any())
            {
                await Context.Channel.SendMessageAsync($"Subreddit **{name}** not found. Try `{Program.GetPrefix(Context)}sublist` for a list of your subreddits.");
            }
            foreach (var old in olds)
            {
                await SpecialChannelDb.Delete(old);

                await Context.Channel.SendMessageAsync($"Unsubscribed from **{name}**. Were their posts not good enough?");
            }
        }
Exemplo n.º 2
0
        public static EmbedBuilder SubListEmbed(ulong guildId)
        {
            var eb   = new EmbedBuilder();
            var subs = SpecialChannelDb.GetChannelsByGuild(guildId, Model.ChannelType.Reddit);

            string desc = "";
            int    i    = 1;

            foreach (var sub in subs)
            {
                string[] args = sub.Args.Split(",");
                desc += $"{i++}. *{args[0]}* - **{args[1]}** upvotes\n";
            }

            eb.WithDescription(desc == "" ? "-" : desc);
            eb.WithAuthor("Subreddits subscribed in this server");
            eb.WithColor(BasicUtil.RandomColor());
            eb.WithFooter($"Type `{Program.GetPrefix(guildId)}unsub [name]` to unsubscribe.");
            return(eb);
        }
Exemplo n.º 3
0
Arquivo: Web.cs Projeto: 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());
        }