.clubtransfer added, transfer ownership of your club
This commit is contained in:
@ -26,6 +26,19 @@ namespace NadekoBot.Modules.Xp
|
||||
_client = client;
|
||||
}
|
||||
|
||||
[NadekoCommand, Usage, Description, Aliases]
|
||||
public async Task ClubTransfer([Remainder]IUser newOwner)
|
||||
{
|
||||
var club = _service.TransferClub(Context.User, newOwner);
|
||||
|
||||
if(club != null)
|
||||
await ReplyConfirmLocalized("club_transfered",
|
||||
Format.Bold(club.Name),
|
||||
Format.Bold(newOwner.ToString())).ConfigureAwait(false);
|
||||
else
|
||||
await ReplyErrorLocalized("club_transfer_failed").ConfigureAwait(false);
|
||||
}
|
||||
|
||||
[NadekoCommand, Usage, Description, Aliases]
|
||||
public async Task ClubAdmin([Remainder]IUser toAdmin)
|
||||
{
|
||||
|
@ -51,6 +51,27 @@ namespace NadekoBot.Modules.Xp.Services
|
||||
return true;
|
||||
}
|
||||
|
||||
public ClubInfo TransferClub(IUser from, IUser newOwner)
|
||||
{
|
||||
ClubInfo club;
|
||||
using (var uow = _db.UnitOfWork)
|
||||
{
|
||||
club = uow.Clubs.GetByOwner(from.Id);
|
||||
var newOwnerUser = uow.DiscordUsers.GetOrCreate(newOwner);
|
||||
|
||||
if (club == null ||
|
||||
club.Owner.UserId != from.Id ||
|
||||
!club.Users.Contains(newOwnerUser))
|
||||
return null;
|
||||
|
||||
club.Owner.IsClubAdmin = true; // old owner will stay as admin
|
||||
newOwnerUser.IsClubAdmin = true;
|
||||
club.Owner = newOwnerUser;
|
||||
uow.Complete();
|
||||
}
|
||||
return club;
|
||||
}
|
||||
|
||||
public bool ToggleAdmin(IUser owner, IUser toAdmin)
|
||||
{
|
||||
bool newState;
|
||||
@ -58,14 +79,14 @@ namespace NadekoBot.Modules.Xp.Services
|
||||
{
|
||||
var club = uow.Clubs.GetByOwner(owner.Id);
|
||||
var adminUser = uow.DiscordUsers.GetOrCreate(toAdmin);
|
||||
|
||||
if (club.OwnerId == adminUser.Id)
|
||||
return true;
|
||||
|
||||
|
||||
if (club == null || club.Owner.UserId != owner.Id ||
|
||||
!club.Users.Contains(adminUser))
|
||||
throw new InvalidOperationException();
|
||||
|
||||
if (club.OwnerId == adminUser.Id)
|
||||
return true;
|
||||
|
||||
newState = adminUser.IsClubAdmin = !adminUser.IsClubAdmin;
|
||||
uow.Complete();
|
||||
}
|
||||
|
Reference in New Issue
Block a user