mirror of
https://gitlab.com/Kwoth/nadekobot.git
synced 2025-09-11 01:38:27 -04:00
Clarified .feedadd errors
This commit is contained in:
@@ -32,10 +32,13 @@ public partial class Searches
|
|||||||
[UserPerm(GuildPerm.ManageMessages)]
|
[UserPerm(GuildPerm.ManageMessages)]
|
||||||
public async Task Feed(string url, [Leftover] ITextChannel channel = null)
|
public async Task Feed(string url, [Leftover] ITextChannel channel = null)
|
||||||
{
|
{
|
||||||
var success = 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))
|
||||||
if (success)
|
|
||||||
{
|
{
|
||||||
|
await ReplyErrorLocalizedAsync(strs.feed_invalid_url);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
channel ??= (ITextChannel)ctx.Channel;
|
channel ??= (ITextChannel)ctx.Channel;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -44,21 +47,28 @@ public partial class Searches
|
|||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Log.Information(ex, "Unable to get feeds from that url");
|
Log.Information(ex, "Unable to get feeds from that url");
|
||||||
success = false;
|
await ReplyErrorLocalizedAsync(strs.feed_cant_parse);
|
||||||
}
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (success)
|
var result = _service.AddFeed(ctx.Guild.Id, channel.Id, url);
|
||||||
{
|
if (result == FeedAddResult.Success)
|
||||||
success = _service.AddFeed(ctx.Guild.Id, channel.Id, url);
|
|
||||||
if (success)
|
|
||||||
{
|
{
|
||||||
await ReplyConfirmLocalizedAsync(strs.feed_added);
|
await ReplyConfirmLocalizedAsync(strs.feed_added);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (result == FeedAddResult.Duplicate)
|
||||||
|
{
|
||||||
|
await ReplyErrorLocalizedAsync(strs.feed_duplicate);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
await ReplyConfirmLocalizedAsync(strs.feed_not_valid);
|
if (result == FeedAddResult.LimitReached)
|
||||||
|
{
|
||||||
|
await ReplyErrorLocalizedAsync(strs.feed_limit_reached);
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[Cmd]
|
[Cmd]
|
||||||
|
@@ -207,7 +207,7 @@ public class FeedsService : INService
|
|||||||
.ToList();
|
.ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool AddFeed(ulong guildId, ulong channelId, string rssFeed)
|
public FeedAddResult AddFeed(ulong guildId, ulong channelId, string rssFeed)
|
||||||
{
|
{
|
||||||
ArgumentNullException.ThrowIfNull(rssFeed, nameof(rssFeed));
|
ArgumentNullException.ThrowIfNull(rssFeed, nameof(rssFeed));
|
||||||
|
|
||||||
@@ -221,9 +221,9 @@ public class FeedsService : INService
|
|||||||
var gc = uow.GuildConfigsForId(guildId, set => set.Include(x => x.FeedSubs));
|
var gc = uow.GuildConfigsForId(guildId, set => set.Include(x => x.FeedSubs));
|
||||||
|
|
||||||
if (gc.FeedSubs.Any(x => x.Url.ToLower() == fs.Url.ToLower()))
|
if (gc.FeedSubs.Any(x => x.Url.ToLower() == fs.Url.ToLower()))
|
||||||
return false;
|
return FeedAddResult.Duplicate;
|
||||||
if (gc.FeedSubs.Count >= 10)
|
if (gc.FeedSubs.Count >= 10)
|
||||||
return false;
|
return FeedAddResult.LimitReached;
|
||||||
|
|
||||||
gc.FeedSubs.Add(fs);
|
gc.FeedSubs.Add(fs);
|
||||||
uow.SaveChanges();
|
uow.SaveChanges();
|
||||||
@@ -242,7 +242,7 @@ public class FeedsService : INService
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return FeedAddResult.Success;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool RemoveFeed(ulong guildId, int index)
|
public bool RemoveFeed(ulong guildId, int index)
|
||||||
@@ -271,3 +271,11 @@ public class FeedsService : INService
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public enum FeedAddResult
|
||||||
|
{
|
||||||
|
Success,
|
||||||
|
LimitReached,
|
||||||
|
Invalid,
|
||||||
|
Duplicate,
|
||||||
|
}
|
@@ -885,7 +885,10 @@
|
|||||||
"started": "Started. Reposting every {0}s.",
|
"started": "Started. Reposting every {0}s.",
|
||||||
"stopped": "Stopped reposting.",
|
"stopped": "Stopped reposting.",
|
||||||
"feed_added": "Feed added.",
|
"feed_added": "Feed added.",
|
||||||
"feed_not_valid": "Invalid link, or you're already following that feed on this server, or you've reached maximum number of feeds allowed.",
|
"feed_limit_reached": "You've reached the maximum number of feeds allowed per server.",
|
||||||
|
"feed_duplicate": "You're already following that feed on this server.",
|
||||||
|
"feed_cant_parse": "Unable to access or parse that feed url's contents.",
|
||||||
|
"feed_invalid_url": "Invalid feed url. It must be an absolute http or https url.",
|
||||||
"feed_out_of_range": "Index out of range.",
|
"feed_out_of_range": "Index out of range.",
|
||||||
"feed_removed": "Feed removed.",
|
"feed_removed": "Feed removed.",
|
||||||
"feed_no_feed": "You haven't subscribed to any feeds on this server.",
|
"feed_no_feed": "You haven't subscribed to any feeds on this server.",
|
||||||
|
Reference in New Issue
Block a user