private async void ProcessPayload(string payload) { try { GitHubWebHookData ghdata = JsonConvert.DeserializeObject <GitHubWebHookData>(payload); if (ghdata.action == "released") { EmbedBuilder eb = null; eb = new EmbedBuilder { Color = new Color((uint)EmbedColor.SalmonPink) }; eb.WithAuthor("I've heard some great news!"); eb.WithThumbnailUrl(ghdata.repository.html_url + "/raw/master/thumbnail.png"); eb.WithTitle(ghdata.release.name); eb.WithUrl(ghdata.release.html_url); eb.WithDescription("There is a new version of Miharu Available!"); List <string> tags = new List <string>(); tags.Add("Miharu"); await DiscordAPIHelper.PublishNews(eb, _databaseManager, _discordSocketClient, tags.ToArray()); } } catch (Exception e) { Logger.LogError("Error processing GitHub release payload: " + e.Message); } }
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"); } }
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"); } }
private async void OnRSSUpdateAsync(object sender, RSSUpdateEventArgs e) { EmbedBuilder eb = new EmbedBuilder { Color = new Color((uint)EmbedColor.SalmonPink) }; eb.WithAuthor("I've heard some great news!"); eb.WithTitle(e.Update.Title.Text); eb.WithUrl(e.Update.Id); eb.WithFooter($"There is a new chapter available to read!"); int idIndex = e.Feed.Id.LastIndexOf("/") + 1; int id = -1; string imageUrl = null; if (int.TryParse(e.Feed.Id.Substring(idIndex), out id)) { imageUrl = $"https://mangadex.org/images/manga/{id}."; } if (imageUrl != null) { if (DoesImageExist(ref imageUrl)) { eb.WithImageUrl(imageUrl); } } await DiscordAPIHelper.PublishNews(eb, _databaseManager, _discordSocketClient, e.Feed.Tag); }
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 }
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"); } }
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); } }
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); } }
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); }
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); }
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); }
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"); } }
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); }
private async void ProcessPayload(string payload) { try { EmbedData embedData = JsonConvert.DeserializeObject <EmbedData>(payload); EmbedBuilder eb = null; eb = new EmbedBuilder { Color = new Color(embedData.Color ?? (uint)EmbedColor.SalmonPink) }; eb.Title = embedData.Title; eb.Description = embedData.Description; eb.Url = embedData.URL; eb.ImageUrl = embedData.IconURL; if (embedData.Author != null && embedData.Author != "") { eb.WithAuthor(embedData.Author, embedData.AuthorIconURL, embedData.AuthorURL); } if (embedData.Fields != null) { foreach (EmbedFieldData efdata in embedData.Fields) { if ((efdata.Name ?? "") != "" && (efdata.Value ?? "") != "") { eb.AddField(efdata.Name, efdata.Value, efdata.Inline); } } } if ((embedData.Footer ?? "") != "") { eb.WithFooter(embedData.Footer, embedData.FooterIcon); } List <string> tags = new List <string>(); foreach (string tag in embedData.Tags) { tags.Add(tag); } await DiscordAPIHelper.PublishNews(eb, _databaseManager, _discordSocketClient, tags.ToArray()); } catch (Exception e) { Logger.LogError("Error processing " + Prefix + " payload: " + e.Message); } }
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"); } }
private async Task UpdateSelfRoleMessage(RoleMenu rm, string list) { IUserMessage message = await GetSelfRoleMessage(rm); if (message != null) { EmbedBuilder embedBuilder = CreateEmbed(EmbedColor.SalmonPink); StringBuilder sb = new StringBuilder(); List <IEmote> reactions = new List <IEmote>(); foreach (string key in rm.SelfRoles.Keys) { sb.AppendLine($"{key} - {Context.Guild.GetRole(rm.SelfRoles[key]).Mention}\n"); reactions.Add(GetEmote(key)); } if (rm.SelfRoles.Keys.Count > 0) { string title = list ?? "Self Roles"; embedBuilder.AddField($"**{title}**", sb.ToString()); } else { embedBuilder.AddField($"**There are no roles in {list ?? "default"} self role menu**", "ごめんね"); } await message.ModifyAsync(x => x.Embed = embedBuilder.Build()); //Get the difference set of the message reactions set minus the final reactions set List <IEmote> toDelete = new List <IEmote>(message.Reactions.Keys.Except <IEmote>(reactions)); foreach (IEmote emote in toDelete) { await DiscordAPIHelper.DeleteAllReactionsWithEmote(message, emote); //Making this was :CoconaSweat: } //Get the difference set of the final reactions set minus the message reactions set List <IEmote> toAdd = new List <IEmote>(reactions.Except <IEmote>(message.Reactions.Keys)); await message.AddReactionsAsync(toAdd.ToArray()); //Just because of pride, if the Discord API improves in the future, leave this shit here. } }
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); }
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); }
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); }