Exemplo n.º 1
0
 public async Task BaseCommand(string url, string tag)
 {
     if (url.StartsWith("https://mangadex.org/rss/"))
     {
         RSSFeed feed = new RSSFeed {
             Id = url, Tag = tag
         };
         if (!Context.Database.Exists <RSSFeed>(feed))
         {
             Context.Database.Save <RSSFeed>(feed);
             EmbedBuilder eb = CreateEmbed(EmbedColor.SalmonPink);
             eb.WithAuthor("Added RSS feed.");
             eb.WithDescription("RSS feeds are only polled every 60 seconds, be patient if no news appears immediately.");
             await ReplyAsync(string.Empty, eb.Build(), false, false);
         }
         else
         {
             await DiscordAPIHelper.ReplyWithError(Context.Message,
                                                   "I'm already subscribed to that RSS feed.",
                                                   Context.HttpServerManager.GetIp + "/images/error.png");
         }
     }
     else
     {
         await DiscordAPIHelper.ReplyWithError(Context.Message,
                                               "That's not a valid RSS feed URL.",
                                               Context.HttpServerManager.GetIp + "/images/error.png");
     }
 }
Exemplo n.º 2
0
            public async Task BaseCommand()
            {
                GuildConfig  gc    = Context.GuildConfig;
                SocketGuild  guild = Context.Guild;
                EmbedBuilder eb    = CreateEmbed(EmbedColor.SalmonPink);

                eb.WithAuthor($"List of news roles.");

                bool atLeastOneRole = false;

                if (gc.AllNewsRole.HasValue)
                {
                    SocketRole role = guild.GetRole(gc.AllNewsRole.Value);
                    eb.AddField("All News", role.Mention, true);
                    atLeastOneRole = true;
                }
                foreach (string tag in gc.NewsRoles.Keys)
                {
                    SocketRole role = guild.GetRole(gc.NewsRoles[tag]);
                    eb.AddField("Tag: " + tag, role.Mention, true);
                    atLeastOneRole = true;
                }

                if (atLeastOneRole)
                {
                    await ReplyAsync(string.Empty, eb.Build(), false, true);
                }
                else
                {
                    await DiscordAPIHelper.ReplyWithError(Context.Message,
                                                          "No roles assigned to tags.",
                                                          Context.HttpServerManager.GetIp + "/images/error.png");
                }
            }
Exemplo n.º 3
0
        private async Task InternalSelfRoleList(RoleMenu rm, string list = null)
        {
            if (rm.SelfRoles.Count == 0)
            {
                await DiscordAPIHelper.ReplyWithError(Context.Message,
                                                      $"Guild has no self assignable roles in {list ?? "default"} menu.",
                                                      Context.HttpServerManager.GetIp + "/images/error.png");

                return;
            }

            if (rm.Channel.HasValue && rm.Message.HasValue)
            {
                if ((Context.Guild.GetChannel(rm.Channel.Value) is SocketTextChannel channel &&
                     await channel.GetMessageAsync(rm.Message.Value) is IUserMessage prevMessage))
                {
                    await prevMessage.DeleteAsync();
                }
            }


            EmbedBuilder embedBuilder = CreateEmbed(EmbedColor.SalmonPink);


            StringBuilder sb = new StringBuilder();

            foreach (string key in rm.SelfRoles.Keys)
            {
                sb.AppendLine($"{key} - {Context.Guild.GetRole(rm.SelfRoles[key]).Mention}\n");
            }

            string title = list ?? "Self Roles";

            embedBuilder.AddField($"**{title}**", sb.ToString());
            IUserMessage message = await ReplyAsync(string.Empty, embedBuilder.Build());



            foreach (var em in rm.SelfRoles.Keys)
            {
                try {
                    IEmote emote = GetEmote(em);
                    await message.AddReactionAsync(emote);
                }
                catch (Exception ex) {
                    Logger.LogException(ex);
                    throw ex;
                }
            }


            rm.Channel = message.Channel.Id;
            rm.Message = message.Id;
            Context.Database.Save(Context.GuildConfig);      // Save manually rather than sending another message
            await Context.Message.DeleteAsync();             //It will look more clean if we delete the command message
        }
Exemplo n.º 4
0
 public async Task SelfRoleRemoveAsync(string em, string list)
 {
     if (Context.GuildConfig.SelfRoleMenus.ContainsKey(list))
     {
         await InternalSelfRoleRemove(em, Context.GuildConfig.SelfRoleMenus[list], list);
     }
     else
     {
         await DiscordAPIHelper.ReplyWithError(Context.Message,
                                               $"There is no {list} selfrole menu.",
                                               Context.HttpServerManager.GetIp + "/images/error.png");
     }
 }
Exemplo n.º 5
0
 public async Task SelfRoleListDeleteAsync(string list)
 {
     if (!Context.GuildConfig.SelfRoleMenus.ContainsKey(list))
     {
         await DiscordAPIHelper.ReplyWithError(Context.Message,
                                               $"There is no selfrole menu for {list}.",
                                               Context.HttpServerManager.GetIp + "/images/error.png");
     }
     else
     {
         Context.GuildConfig.SelfRoleMenus.Remove(list);
         await ReplyAsync($"Deleted self role menu for {list}", updateGuild : true);
     }
 }
Exemplo n.º 6
0
 public async Task SelfRoleListCreateAsync(string list)
 {
     if (Context.GuildConfig.SelfRoleMenus.ContainsKey(list))
     {
         await DiscordAPIHelper.ReplyWithError(Context.Message,
                                               $"There is already a {list} selfrole menu.",
                                               Context.HttpServerManager.GetIp + "/images/error.png");
     }
     else
     {
         Context.GuildConfig.SelfRoleMenus.Add(list, new RoleMenu());
         await ReplyAsync($"Created {list} self role menu.", updateGuild : true);
     }
 }
Exemplo n.º 7
0
        public async Task RemoveUserAgent(string agent)
        {
            if (!Context.Config.UserAgents.Contains(agent))
            {
                await DiscordAPIHelper.ReplyWithError(Context.Message,
                                                      "This user agent has not been added.",
                                                      Context.HttpServerManager.GetIp + "/images/error.png");

                return;
            }

            Context.Config.UserAgents.Remove(agent);
            await ReplyAsync($"Removed user agent `{agent}`. Restarting HTTP server...", updateConfig : true);

            Context.HttpServerManager.ChangeAgents(Context.Config.UserAgents);
        }
Exemplo n.º 8
0
        public async Task AddUserAgent(string agent)
        {
            if (Context.Config.UserAgents.Contains(agent))
            {
                await DiscordAPIHelper.ReplyWithError(Context.Message,
                                                      "This user agent has already been added.",
                                                      Context.HttpServerManager.GetIp + "/images/error.png");

                return;
            }

            Context.Config.UserAgents.Add(agent);
            await ReplyAsync($"Added user agent `{agent}`.", updateConfig : true);

            Context.HttpServerManager.ChangeAgents(Context.Config.UserAgents);
        }
Exemplo n.º 9
0
        private async Task InternalSelfRoleRemove(string em, RoleMenu rm, string list = null)
        {
            IEmote emote = GetEmote(em);

            if (!rm.SelfRoles.ContainsKey(emote.ToString()))
            {
                await DiscordAPIHelper.ReplyWithError(Context.Message,
                                                      $"There is not a role assigned to {emote.ToString()} in {list ?? "default"} menu.",
                                                      Context.HttpServerManager.GetIp + "/images/error.png");

                return;
            }

            rm.SelfRoles.Remove(emote.ToString());
            await UpdateSelfRoleMessage(rm, list);
            await ReplyAsync($"Removed self role assigned to {emote.ToString()} in {list ?? "default"} menu.", updateGuild : true);
        }
Exemplo n.º 10
0
        public async Task ListUserAgent()
        {
            if (Context.Config.UserAgents.Count == 0)
            {
                await DiscordAPIHelper.ReplyWithError(Context.Message,
                                                      "No user agents have been added",
                                                      Context.HttpServerManager.GetIp + "/images/error.png");

                return;
            }

            var embed = CreateEmbed(EmbedColor.Purple)
                        .WithTitle("HTTP User Agents")
                        .WithDescription(Context.Config.UserAgents.Aggregate("", (current, agent) => current + $"{agent}\n"))
                        .Build();

            await ReplyAsync(string.Empty, embed);
        }
Exemplo n.º 11
0
        public async Task BaseCommand()
        {
            if (Context.GuildConfig.NewsChannel.HasValue)
            {
                SocketTextChannel channel = Context.Guild.GetTextChannel(Context.GuildConfig.NewsChannel.Value);
                EmbedBuilder      eb      = CreateEmbed(EmbedColor.SalmonPink);
                eb.WithAuthor("News channel:");
                eb.WithDescription(channel.Mention);

                await ReplyAsync(string.Empty, eb.Build(), false, false);
            }
            else
            {
                await DiscordAPIHelper.ReplyWithError(Context.Message,
                                                      "No news channel set.",
                                                      Context.HttpServerManager.GetIp + "/images/error.png");
            }
        }
Exemplo n.º 12
0
        public async Task BaseCommand(string url)
        {
            RSSFeed feed = new RSSFeed {
                Id = url
            };

            if (Context.Database.Exists <RSSFeed>(feed))
            {
                Context.Database.Remove <RSSFeed>(feed);
                EmbedBuilder eb = CreateEmbed(EmbedColor.SalmonPink);
                eb.WithAuthor("Removed RSS feed.");
                await ReplyAsync(string.Empty, eb.Build(), false, false);
            }
            else
            {
                await DiscordAPIHelper.ReplyWithError(Context.Message,
                                                      "I'm not subscribed to that RSS feed.",
                                                      Context.HttpServerManager.GetIp + "/images/error.png");
            }
        }
Exemplo n.º 13
0
                public async Task BaseCommand(string tag)
                {
                    EmbedBuilder eb = null;

                    if (Context.GuildConfig.NewsRoles.ContainsKey(tag))
                    {
                        SocketRole role = Context.Guild.GetRole(Context.GuildConfig.NewsRoles[tag]);
                        Context.GuildConfig.NewsRoles.Remove(tag);
                        eb = CreateEmbed(EmbedColor.SalmonPink);
                        eb.WithAuthor($"News role removed!");
                        eb.WithDescription($"I will no longer ping {role.Mention} for news with {tag} tag.");
                    }
                    else
                    {
                        await DiscordAPIHelper.ReplyWithError(Context.Message,
                                                              "There is no role linked to that tag.",
                                                              Context.HttpServerManager.GetIp + "/images/error.png");
                    }

                    await ReplyAsync(string.Empty, eb.Build(), false, true);
                }
Exemplo n.º 14
0
                public async Task BaseCommand()
                {
                    EmbedBuilder eb = null;

                    if (Context.GuildConfig.AllNewsRole.HasValue)
                    {
                        SocketRole role = Context.Guild.GetRole(Context.GuildConfig.AllNewsRole.Value);
                        Context.GuildConfig.AllNewsRole = null;
                        eb = CreateEmbed(EmbedColor.SalmonPink);
                        eb.WithAuthor($"News role removed!");
                        eb.WithDescription($"I will no longer ping {role.Mention} for all news.");
                    }
                    else
                    {
                        await DiscordAPIHelper.ReplyWithError(Context.Message,
                                                              "There is no role for all news.",
                                                              Context.HttpServerManager.GetIp + "/images/error.png");

                        return;
                    }

                    await ReplyAsync(string.Empty, eb.Build(), false, true);
                }
Exemplo n.º 15
0
        public async Task BaseCommand()
        {
            EmbedBuilder eb = null;

            RSSFeed[] feeds = Context.Database.GetAll <RSSFeed>("https://mangadex.org/rss/");
            if (feeds == null || feeds.Length == 0)
            {
                await DiscordAPIHelper.ReplyWithError(Context.Message,
                                                      "No available RSS Feeds.",
                                                      Context.HttpServerManager.GetIp + "/images/error.png");

                return;
            }
            else
            {
                eb = CreateEmbed(EmbedColor.SalmonPink);
                eb.WithAuthor("List of available RSS Feeds");
                foreach (RSSFeed feed in feeds)
                {
                    eb.AddField("Tag: " + feed.Tag, feed.Id);
                }
            }
            await ReplyAsync(string.Empty, eb.Build(), false, false);
        }