/// <summary> /// Generates a partner message based off the input server /// </summary> /// <param name="guildObj"> /// The guild obj. /// </param> /// <param name="guild"> /// The guild. /// </param> /// <returns> /// The <see cref="EmbedBuilder" />. /// </returns> public EmbedBuilder GenerateMessage(PartnerService.PartnerInfo guildObj, SocketGuild guild) { var image = guildObj.Message.ImageUrl; if (image != null) { if (!Uri.IsWellFormedUriString(image, UriKind.Absolute)) { image = null; guildObj.Message.ImageUrl = null; guildObj.Save(); } } try { var embed = new EmbedBuilder(); embed.Title = guild.Name; embed.Description = guildObj.Message.Content; embed.ImageUrl = image; embed.Color = new Color(guildObj.Message.Color.R, guildObj.Message.Color.G, guildObj.Message.Color.B); if (guildObj.Message.Invite == null) { guildObj.Message.Invite = guild.GetTextChannel(guildObj.Settings.ChannelId)?.CreateInviteAsync(null).Result?.Url; guildObj.Save(); } var invites = guild.GetInvitesAsync().Result; if (invites != null) { if (!invites.Select(x => x.Url).Contains(guildObj.Message.Invite)) { guildObj.Message.Invite = guild.GetTextChannel(guildObj.Settings.ChannelId)?.CreateInviteAsync(null).Result?.Url; guildObj.Save(); } } embed.AddField("Invite", $"{guildObj.Message.Invite ?? "N/A"}"); embed.ThumbnailUrl = guildObj.Message.UseThumb ? guild.IconUrl : null; embed.Footer = new EmbedFooterBuilder { Text = $"{(guildObj.Message.UserCount ? $"Users: {guild.MemberCount} | " : string.Empty)}Get PassiveBOT: {_HomeService.CurrentHomeModel.HomeInvite}", IconUrl = guild.IconUrl }; return(embed); } catch (Exception e) { LogHandler.LogMessage($"Partner Embed Build Error for {guild.Name} [{guild.Id}]\n" + $"{e}"); return(new EmbedBuilder { Description = $"Partner Embed Build Error for {guild.Name} [{guild.Id}]\n" + $"{e.Message}" }); } }
public Task BanPartnerAsync(ulong guildId) { PartnerService.PartnerInfo match = PartnerService.GetPartnerInfo(guildId, true); if (match == null) { return(SimpleEmbedAsync("Partner not found")); } match.Settings.Banned = true; match.Settings.Enabled = false; PartnerService.OverWrite(match); return(SimpleEmbedAsync("Partner has been banned")); }
/// <summary> /// Logs a partner update /// </summary> /// <param name="client"> /// The client. /// </param> /// <param name="partnerGuild"> /// The partner guild. /// </param> /// <param name="fieldInfo"> /// The field info. /// </param> /// <returns> /// The <see cref="Task" />. /// </returns> public async Task PartnerLogAsync(DiscordShardedClient client, PartnerService.PartnerInfo partnerGuild, EmbedFieldBuilder fieldInfo) { var home = _HomeService.CurrentHomeModel; if (home.Logging.LogPartnerChanges) { if (client.GetChannel(home.Logging.PartnerLogChannel) is SocketTextChannel logChannel) { var emb = GenerateMessage(partnerGuild, client.GetGuild(partnerGuild.GuildId)); emb.AddField(fieldInfo); await logChannel.SendMessageAsync(string.Empty, false, emb.Build()); } } }