mirror of
https://gitlab.com/Kwoth/nadekobot.git
synced 2025-09-11 01:38:27 -04:00
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:
@@ -9,6 +9,8 @@ public class FeedSub : DbEntity
|
|||||||
public ulong ChannelId { get; set; }
|
public ulong ChannelId { get; set; }
|
||||||
public string Url { get; set; }
|
public string Url { get; set; }
|
||||||
|
|
||||||
|
public string Message { get; set; }
|
||||||
|
|
||||||
public override int GetHashCode()
|
public override int GetHashCode()
|
||||||
=> Url.GetHashCode(StringComparison.InvariantCulture) ^ GuildConfigId.GetHashCode();
|
=> Url.GetHashCode(StringComparison.InvariantCulture) ^ GuildConfigId.GetHashCode();
|
||||||
|
|
||||||
|
3628
src/NadekoBot/Migrations/Mysql/20221122204432_feed-text.Designer.cs
generated
Normal file
3628
src/NadekoBot/Migrations/Mysql/20221122204432_feed-text.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load Diff
26
src/NadekoBot/Migrations/Mysql/20221122204432_feed-text.cs
Normal file
26
src/NadekoBot/Migrations/Mysql/20221122204432_feed-text.cs
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace NadekoBot.Migrations.Mysql
|
||||||
|
{
|
||||||
|
public partial class feedtext : Migration
|
||||||
|
{
|
||||||
|
protected override void Up(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.AddColumn<string>(
|
||||||
|
name: "message",
|
||||||
|
table: "feedsub",
|
||||||
|
type: "longtext",
|
||||||
|
nullable: true)
|
||||||
|
.Annotation("MySql:CharSet", "utf8mb4");
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void Down(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.DropColumn(
|
||||||
|
name: "message",
|
||||||
|
table: "feedsub");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -975,6 +975,10 @@ namespace NadekoBot.Migrations.Mysql
|
|||||||
.HasColumnType("int")
|
.HasColumnType("int")
|
||||||
.HasColumnName("guildconfigid");
|
.HasColumnName("guildconfigid");
|
||||||
|
|
||||||
|
b.Property<string>("Message")
|
||||||
|
.HasColumnType("longtext")
|
||||||
|
.HasColumnName("message");
|
||||||
|
|
||||||
b.Property<string>("Url")
|
b.Property<string>("Url")
|
||||||
.IsRequired()
|
.IsRequired()
|
||||||
.HasColumnType("varchar(255)")
|
.HasColumnType("varchar(255)")
|
||||||
|
3776
src/NadekoBot/Migrations/PostgreSql/20221122204423_feed-text.Designer.cs
generated
Normal file
3776
src/NadekoBot/Migrations/PostgreSql/20221122204423_feed-text.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,25 @@
|
|||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace NadekoBot.Migrations.PostgreSql
|
||||||
|
{
|
||||||
|
public partial class feedtext : Migration
|
||||||
|
{
|
||||||
|
protected override void Up(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.AddColumn<string>(
|
||||||
|
name: "message",
|
||||||
|
table: "feedsub",
|
||||||
|
type: "text",
|
||||||
|
nullable: true);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void Down(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.DropColumn(
|
||||||
|
name: "message",
|
||||||
|
table: "feedsub");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -1023,6 +1023,10 @@ namespace NadekoBot.Migrations.PostgreSql
|
|||||||
.HasColumnType("integer")
|
.HasColumnType("integer")
|
||||||
.HasColumnName("guildconfigid");
|
.HasColumnName("guildconfigid");
|
||||||
|
|
||||||
|
b.Property<string>("Message")
|
||||||
|
.HasColumnType("text")
|
||||||
|
.HasColumnName("message");
|
||||||
|
|
||||||
b.Property<string>("Url")
|
b.Property<string>("Url")
|
||||||
.IsRequired()
|
.IsRequired()
|
||||||
.HasColumnType("text")
|
.HasColumnType("text")
|
||||||
|
2910
src/NadekoBot/Migrations/Sqlite/20221122204324_feed-text.Designer.cs
generated
Normal file
2910
src/NadekoBot/Migrations/Sqlite/20221122204324_feed-text.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load Diff
25
src/NadekoBot/Migrations/Sqlite/20221122204324_feed-text.cs
Normal file
25
src/NadekoBot/Migrations/Sqlite/20221122204324_feed-text.cs
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace NadekoBot.Migrations
|
||||||
|
{
|
||||||
|
public partial class feedtext : Migration
|
||||||
|
{
|
||||||
|
protected override void Up(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.AddColumn<string>(
|
||||||
|
name: "Message",
|
||||||
|
table: "FeedSub",
|
||||||
|
type: "TEXT",
|
||||||
|
nullable: true);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void Down(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.DropColumn(
|
||||||
|
name: "Message",
|
||||||
|
table: "FeedSub");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -765,6 +765,9 @@ namespace NadekoBot.Migrations
|
|||||||
b.Property<int>("GuildConfigId")
|
b.Property<int>("GuildConfigId")
|
||||||
.HasColumnType("INTEGER");
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
|
b.Property<string>("Message")
|
||||||
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
b.Property<string>("Url")
|
b.Property<string>("Url")
|
||||||
.IsRequired()
|
.IsRequired()
|
||||||
.HasColumnType("TEXT");
|
.HasColumnType("TEXT");
|
||||||
|
@@ -16,7 +16,7 @@ public partial class Searches
|
|||||||
[Cmd]
|
[Cmd]
|
||||||
[RequireContext(ContextType.Guild)]
|
[RequireContext(ContextType.Guild)]
|
||||||
[UserPerm(GuildPerm.ManageMessages)]
|
[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);
|
var m = _ytChannelRegex.Match(url);
|
||||||
if (!m.Success)
|
if (!m.Success)
|
||||||
@@ -24,13 +24,13 @@ public partial class Searches
|
|||||||
|
|
||||||
var channelId = m.Groups["channelid"].Value;
|
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]
|
[Cmd]
|
||||||
[RequireContext(ContextType.Guild)]
|
[RequireContext(ContextType.Guild)]
|
||||||
[UserPerm(GuildPerm.ManageMessages)]
|
[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)
|
if (!Uri.TryCreate(url, UriKind.Absolute, out var uri)
|
||||||
|| (uri.Scheme != Uri.UriSchemeHttp && uri.Scheme != Uri.UriSchemeHttps))
|
|| (uri.Scheme != Uri.UriSchemeHttp && uri.Scheme != Uri.UriSchemeHttps))
|
||||||
@@ -51,7 +51,10 @@ public partial class Searches
|
|||||||
return;
|
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)
|
if (result == FeedAddResult.Success)
|
||||||
{
|
{
|
||||||
await ReplyConfirmLocalizedAsync(strs.feed_added);
|
await ReplyConfirmLocalizedAsync(strs.feed_added);
|
||||||
|
@@ -162,7 +162,6 @@ public class FeedsService : INService
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
embed.WithTitle(title.TrimTo(256));
|
embed.WithTitle(title.TrimTo(256));
|
||||||
|
|
||||||
var desc = feedItem.Description?.StripHtml();
|
var desc = feedItem.Description?.StripHtml();
|
||||||
@@ -171,15 +170,15 @@ public class FeedsService : INService
|
|||||||
|
|
||||||
//send the created embed to all subscribed channels
|
//send the created embed to all subscribed channels
|
||||||
var feedSendTasks = kvp.Value
|
var feedSendTasks = kvp.Value
|
||||||
.Where(x => x.GuildConfig is not null)
|
.Where(x => x.GuildConfig is not null)
|
||||||
.Select(x => _client.GetGuild(x.GuildConfig.GuildId)
|
.Select(x => _client.GetGuild(x.GuildConfig.GuildId)
|
||||||
?.GetTextChannel(x.ChannelId))
|
?.GetTextChannel(x.ChannelId)
|
||||||
.Where(x => x is not null)
|
?.EmbedAsync(embed, x.Message))
|
||||||
.Select(x => x.EmbedAsync(embed));
|
.Where(x => x is not null);
|
||||||
|
|
||||||
allSendTasks.Add(feedSendTasks.WhenAll());
|
allSendTasks.Add(feedSendTasks.WhenAll());
|
||||||
|
|
||||||
// as data retrieval was sucessful, reset error counter
|
// as data retrieval was successful, reset error counter
|
||||||
ClearErrors(rssUrl);
|
ClearErrors(rssUrl);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -207,7 +206,7 @@ public class FeedsService : INService
|
|||||||
.ToList();
|
.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));
|
ArgumentNullException.ThrowIfNull(rssFeed, nameof(rssFeed));
|
||||||
|
|
||||||
|
@@ -1991,13 +1991,22 @@ ytuploadnotif:
|
|||||||
desc: |-
|
desc: |-
|
||||||
Subscribe to a youtube channel's upload rss feed.
|
Subscribe to a youtube channel's upload rss feed.
|
||||||
Shortcut for `.feed https://www.youtube.com/feeds/videos.xml?channel_id=%3Cyoutube_channel_id`
|
Shortcut for `.feed https://www.youtube.com/feeds/videos.xml?channel_id=%3Cyoutube_channel_id`
|
||||||
|
You can optionally specify a message which will be posted with an update.
|
||||||
args:
|
args:
|
||||||
- "https://www.youtube.com/channel/UCSJ4gkVC6NrvII8umztf0Ow"
|
- "https://www.youtube.com/channel/UCSJ4gkVC6NrvII8umztf0Ow"
|
||||||
|
- "https://www.youtube.com/channel/UCSJ4gkVC6NrvII8umztf0Ow New video is posted"
|
||||||
feed:
|
feed:
|
||||||
desc: "Subscribes to a feed. Bot will post an update up to once every 10 seconds. You can have up to 10 feeds on one server. All feeds must have unique URLs. Set a channel as a second optional parameter to specify where to send the updates."
|
desc: |-
|
||||||
|
Subscribes to a feed.
|
||||||
|
Bot will post an update up to once every 10 seconds.
|
||||||
|
You can have up to 10 feeds on one server.
|
||||||
|
All feeds must have unique URLs.
|
||||||
|
Set a channel as a second optional parameter to specify where to send the updates.
|
||||||
|
You can optionally specify a message after the channel name which will be posted with an update.
|
||||||
args:
|
args:
|
||||||
- "https://blog.playstation.com/feed/"
|
- "https://blog.playstation.com/feed/"
|
||||||
- "https://blog.playstation.com/feed/ #updates"
|
- "https://blog.playstation.com/feed/ #updates"
|
||||||
|
- "https://blog.playstation.com/feed/ #updates New playstation rss feed post!"
|
||||||
feedremove:
|
feedremove:
|
||||||
desc: "Stops tracking a feed on the given index. Use `{0}feeds` command to see a list of feeds and their indexes."
|
desc: "Stops tracking a feed on the given index. Use `{0}feeds` command to see a list of feeds and their indexes."
|
||||||
args:
|
args:
|
||||||
|
Reference in New Issue
Block a user