Merge branch 'v4' into v5

This commit is contained in:
Kwoth
2023-10-23 17:58:19 +00:00
11 changed files with 67 additions and 12 deletions

View File

@@ -5,16 +5,12 @@
<LangVersion>latest</LangVersion>
<IncludeBuildOutput>false</IncludeBuildOutput>
<IsRoslynComponent>true</IsRoslynComponent>
<EnforceExtendedAnalyzerRules>true</EnforceExtendedAnalyzerRules>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<RootNamespace>NadekoBot.Generators</RootNamespace>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.4.0" PrivateAssets="all" />
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="3.3.4" PrivateAssets="all" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.2" PrivateAssets="all" GeneratePathProperty="true" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" PrivateAssets="all" GeneratePathProperty="true" />
</ItemGroup>
<PropertyGroup>

View File

@@ -65,7 +65,10 @@ public partial class Administration
_localization.SetGuildCulture(ctx.Guild, ci);
}
await ReplyConfirmLocalizedAsync(strs.lang_set(Format.Bold(ci.ToString()), Format.Bold(ci.NativeName)));
var nativeName = ci.NativeName;
if (ci.Name == "ts-TS")
nativeName = _supportedLocales[ci.Name];
await ReplyConfirmLocalizedAsync(strs.lang_set(Format.Bold(ci.ToString()), Format.Bold(nativeName)));
}
catch (Exception)
{

View File

@@ -283,6 +283,24 @@ public partial class Xp
else if (result == ClubAcceptResult.NotOwnerOrAdmin)
await ReplyErrorLocalizedAsync(strs.club_admin_perms);
}
[Cmd]
[Priority(1)]
public Task ClubReject(IUser user)
=> ClubReject(user.ToString());
[Cmd]
[Priority(0)]
public async Task ClubReject([Leftover] string userName)
{
var result = _service.RejectApplication(ctx.User.Id, userName, out var discordUser);
if (result == ClubDenyResult.Rejected)
await ReplyConfirmLocalizedAsync(strs.club_rejected(Format.Bold(discordUser.ToString())));
else if(result == ClubDenyResult.NoSuchApplicant)
await ReplyErrorLocalizedAsync(strs.club_accept_invalid_applicant);
else if(result == ClubDenyResult.NotOwnerOrAdmin)
await ReplyErrorLocalizedAsync(strs.club_admin_perms);
}
[Cmd]
public async Task ClubLeave()

View File

@@ -19,7 +19,6 @@ public class ClubService : INService, IClubService
_httpFactory = httpFactory;
}
public async Task<ClubCreateResult> CreateClubAsync(IUser user, string clubName)
{
if (!CheckClubName(clubName))
@@ -143,7 +142,7 @@ public class ClubService : INService, IClubService
//user banned or a member of a club, or already applied,
// or doesn't min minumum level requirement, can't apply
if (du.Club is not null)
if (du.ClubId is not null)
return ClubApplyResult.AlreadyInAClub;
if (club.Bans.Any(x => x.UserId == du.Id))
@@ -189,6 +188,26 @@ public class ClubService : INService, IClubService
uow.SaveChanges();
return ClubAcceptResult.Accepted;
}
public ClubDenyResult RejectApplication(ulong clubOwnerUserId, string userName, out DiscordUser discordUser)
{
discordUser = null;
using var uow = _db.GetDbContext();
var club = uow.Clubs.GetByOwnerOrAdmin(clubOwnerUserId);
if (club is null)
return ClubDenyResult.NotOwnerOrAdmin;
var applicant =
club.Applicants.FirstOrDefault(x => x.User.ToString().ToUpperInvariant() == userName.ToUpperInvariant());
if (applicant is null)
return ClubDenyResult.NoSuchApplicant;
club.Applicants.Remove(applicant);
discordUser = applicant.User;
uow.SaveChanges();
return ClubDenyResult.Rejected;
}
public ClubInfo GetClubWithBansAndApplications(ulong ownerUserId)
{

View File

@@ -13,6 +13,7 @@ public interface IClubService
bool GetClubByName(string clubName, out ClubInfo club);
ClubApplyResult ApplyToClub(IUser user, ClubInfo club);
ClubAcceptResult AcceptApplication(ulong clubOwnerUserId, string userName, out DiscordUser discordUser);
ClubDenyResult RejectApplication(ulong clubOwnerUserId, string userName, out DiscordUser discordUser);
ClubInfo? GetClubWithBansAndApplications(ulong ownerUserId);
ClubLeaveResult LeaveClub(IUser user);
bool SetDescription(ulong userId, string? desc);

View File

@@ -5,4 +5,11 @@ public enum ClubAcceptResult
Accepted,
NotOwnerOrAdmin,
NoSuchApplicant,
}
public enum ClubDenyResult
{
Rejected,
NoSuchApplicant,
NotOwnerOrAdmin
}

View File

@@ -29,7 +29,7 @@
<PackageReference Include="CommandLineParser" Version="2.9.1" />
<PackageReference Include="CoreCLR-NCalc" Version="2.2.110" />
<PackageReference Include="Google.Apis.Urlshortener.v1" Version="1.41.1.138" />
<PackageReference Include="Google.Apis.YouTube.v3" Version="1.60.0.2945" />
<PackageReference Include="Google.Apis.YouTube.v3" Version="1.62.1.3205" />
<PackageReference Include="Google.Apis.Customsearch.v1" Version="1.49.0.2084" />
<PackageReference Include="Google.Protobuf" Version="3.22.1" />
<PackageReference Include="Grpc.Net.ClientFactory" Version="2.52.0" />

View File

@@ -57,7 +57,7 @@ public sealed partial class GoogleApiService : IGoogleApiService, INService
return (await query.ExecuteAsync()).Items.Select(i => i.Id.PlaylistId);
}
public async Task<IEnumerable<string>> GetRelatedVideosAsync(string id, int count = 1, string user = null)
public async Task<IEnumerable<string>> GetRelatedVideosAsync(string id, int count = 2, string user = null)
{
if (string.IsNullOrWhiteSpace(id))
throw new ArgumentNullException(nameof(id));
@@ -67,10 +67,14 @@ public sealed partial class GoogleApiService : IGoogleApiService, INService
var query = _yt.Search.List("snippet");
query.MaxResults = count;
query.RelatedToVideoId = id;
query.Q = id;
// query.RelatedToVideoId = id;
query.Type = "video";
query.QuotaUser = user;
return (await query.ExecuteAsync()).Items.Select(i => "https://www.youtube.com/watch?v=" + i.Id.VideoId);
// bad workaround as there's no replacement for related video querying right now.
// Query youtube with the id of the video, take a second video in the results
// skip the first one as that's probably the same video.
return (await query.ExecuteAsync()).Items.Select(i => "https://www.youtube.com/watch?v=" + i.Id.VideoId).Skip(1);
}
public async Task<IEnumerable<string>> GetVideoLinksByKeywordAsync(string keywords, int count = 1)

View File

@@ -1116,6 +1116,8 @@ clubapply:
- clubapply
clubaccept:
- clubaccept
clubreject:
- clubreject
clubleave:
- clubleave
clubdisband:

View File

@@ -1929,6 +1929,10 @@ clubaccept:
desc: "Accept a user who applied to your club."
args:
- "user#1337"
clubreject:
desc: "Reject a user who applied to your club."
args:
- "user#1337"
clubleave:
desc: "Leaves the club you're currently in."
args:

View File

@@ -847,6 +847,7 @@
"club_not_exists": "That club doesn't exist.",
"club_applied": "You've applied for membership in {0} club.",
"club_accepted": "Accepted user {0} to the club.",
"club_rejected": "The application by {0} has been rejected.",
"club_accept_invalid_applicant": "That user has not applied to your club.",
"club_left": "You've left the club.",
"club_not_in_a_club": "You are not in a club.",