You can now specify an optional custom message in .feed and .yun which will be posted along with an update

This commit is contained in:
Kwoth
2022-11-22 21:08:42 +00:00
parent 3c23b58088
commit 9f96edbb46
13 changed files with 10429 additions and 15 deletions

View File

@@ -16,7 +16,7 @@ public partial class Searches
[Cmd]
[RequireContext(ContextType.Guild)]
[UserPerm(GuildPerm.ManageMessages)]
public Task YtUploadNotif(string url, [Leftover] ITextChannel channel = null)
public Task YtUploadNotif(string url, ITextChannel channel = null, [Leftover] string message = null)
{
var m = _ytChannelRegex.Match(url);
if (!m.Success)
@@ -24,19 +24,19 @@ public partial class Searches
var channelId = m.Groups["channelid"].Value;
return Feed("https://www.youtube.com/feeds/videos.xml?channel_id=" + channelId, channel);
return Feed("https://www.youtube.com/feeds/videos.xml?channel_id=" + channelId, channel, message);
}
[Cmd]
[RequireContext(ContextType.Guild)]
[UserPerm(GuildPerm.ManageMessages)]
public async Task Feed(string url, [Leftover] ITextChannel channel = null)
public async Task Feed(string url, ITextChannel channel = null, [Leftover] string message = null)
{
if (!Uri.TryCreate(url, UriKind.Absolute, out var uri)
|| (uri.Scheme != Uri.UriSchemeHttp && uri.Scheme != Uri.UriSchemeHttps))
{
await ReplyErrorLocalizedAsync(strs.feed_invalid_url);
return;
return;
}
channel ??= (ITextChannel)ctx.Channel;
@@ -51,7 +51,10 @@ public partial class Searches
return;
}
var result = _service.AddFeed(ctx.Guild.Id, channel.Id, url);
if (ctx.User is not IGuildUser gu || !gu.GuildPermissions.Administrator)
message = message?.SanitizeMentions(true);
var result = _service.AddFeed(ctx.Guild.Id, channel.Id, url, message);
if (result == FeedAddResult.Success)
{
await ReplyConfirmLocalizedAsync(strs.feed_added);

View File

@@ -162,7 +162,6 @@ public class FeedsService : INService
}
}
embed.WithTitle(title.TrimTo(256));
var desc = feedItem.Description?.StripHtml();
@@ -171,15 +170,15 @@ public class FeedsService : INService
//send the created embed to all subscribed channels
var feedSendTasks = kvp.Value
.Where(x => x.GuildConfig is not null)
.Select(x => _client.GetGuild(x.GuildConfig.GuildId)
?.GetTextChannel(x.ChannelId))
.Where(x => x is not null)
.Select(x => x.EmbedAsync(embed));
.Where(x => x.GuildConfig is not null)
.Select(x => _client.GetGuild(x.GuildConfig.GuildId)
?.GetTextChannel(x.ChannelId)
?.EmbedAsync(embed, x.Message))
.Where(x => x is not null);
allSendTasks.Add(feedSendTasks.WhenAll());
// as data retrieval was sucessful, reset error counter
// as data retrieval was successful, reset error counter
ClearErrors(rssUrl);
}
}
@@ -207,7 +206,7 @@ public class FeedsService : INService
.ToList();
}
public FeedAddResult AddFeed(ulong guildId, ulong channelId, string rssFeed)
public FeedAddResult AddFeed(ulong guildId, ulong channelId, string rssFeed, string message)
{
ArgumentNullException.ThrowIfNull(rssFeed, nameof(rssFeed));