2021-08-25 23:51:33 +00:00
|
|
|
using PluralKit.Core;
|
|
|
|
|
2021-11-27 02:10:56 +00:00
|
|
|
namespace PluralKit.Bot;
|
|
|
|
|
|
|
|
public static class GroupMemberUtils
|
2021-08-25 23:51:33 +00:00
|
|
|
{
|
2021-11-27 02:10:56 +00:00
|
|
|
public static string GenerateResponse(Groups.AddRemoveOperation action, int memberCount, int groupCount,
|
|
|
|
int actionedOn, int notActionedOn)
|
2021-08-25 23:51:33 +00:00
|
|
|
{
|
2021-11-27 02:10:56 +00:00
|
|
|
var op = action;
|
|
|
|
|
|
|
|
var actionStr = action == Groups.AddRemoveOperation.Add ? "added to" : "removed from";
|
|
|
|
var containStr = action == Groups.AddRemoveOperation.Add ? "in" : "not in";
|
|
|
|
var emojiStr = actionedOn > 0 ? Emojis.Success : Emojis.Error;
|
|
|
|
|
|
|
|
var memberPlural = memberCount > 1;
|
|
|
|
var groupPlural = groupCount > 1;
|
|
|
|
|
|
|
|
// sanity checking: we can't add multiple groups to multiple members (at least for now)
|
|
|
|
if (memberPlural && groupPlural)
|
|
|
|
throw new ArgumentOutOfRangeException();
|
|
|
|
|
|
|
|
// sanity checking: we can't act/not act on a different number of entities than we have
|
|
|
|
if (memberPlural && actionedOn + notActionedOn != memberCount)
|
|
|
|
throw new ArgumentOutOfRangeException();
|
|
|
|
if (groupPlural && actionedOn + notActionedOn != groupCount)
|
|
|
|
throw new ArgumentOutOfRangeException();
|
|
|
|
|
|
|
|
// name generators
|
|
|
|
string MemberString(int count, bool capitalize = false)
|
|
|
|
=> capitalize
|
|
|
|
? count == 1 ? "Member" : "Members"
|
|
|
|
: count == 1
|
|
|
|
? "member"
|
|
|
|
: "members";
|
|
|
|
|
|
|
|
string GroupString(int count)
|
|
|
|
=> count == 1 ? "group" : "groups";
|
|
|
|
|
|
|
|
// string generators
|
|
|
|
|
|
|
|
string ResponseString()
|
2021-08-25 23:51:33 +00:00
|
|
|
{
|
2021-11-27 02:10:56 +00:00
|
|
|
if (actionedOn > 0 && notActionedOn > 0 && memberPlural)
|
|
|
|
return $"{actionedOn} {MemberString(actionedOn)} {actionStr} {GroupString(groupCount)}";
|
|
|
|
if (actionedOn > 0 && notActionedOn > 0 && groupPlural)
|
|
|
|
return $"{MemberString(memberCount, true)} {actionStr} {actionedOn} {GroupString(actionedOn)}";
|
|
|
|
if (notActionedOn == 0)
|
|
|
|
return $"{MemberString(memberCount, true)} {actionStr} {GroupString(groupCount)}";
|
|
|
|
if (actionedOn == 0)
|
|
|
|
return $"{MemberString(memberCount, true)} not {actionStr} {GroupString(groupCount)}";
|
|
|
|
|
|
|
|
throw new ArgumentOutOfRangeException();
|
2021-08-25 23:51:33 +00:00
|
|
|
}
|
2021-11-27 02:10:56 +00:00
|
|
|
|
|
|
|
string InfoMessage()
|
|
|
|
{
|
|
|
|
if (notActionedOn == 0) return "";
|
|
|
|
|
|
|
|
var msg = "";
|
|
|
|
if (actionedOn > 0 && memberPlural)
|
|
|
|
msg += $"{notActionedOn} {MemberString(notActionedOn)}";
|
|
|
|
else
|
|
|
|
msg += $"{MemberString(memberCount)}";
|
|
|
|
|
|
|
|
msg += $" already {containStr}";
|
|
|
|
|
|
|
|
if (actionedOn > 0 && groupPlural)
|
|
|
|
msg += $" {notActionedOn} {GroupString(notActionedOn)}";
|
|
|
|
else
|
|
|
|
msg += $" {GroupString(groupCount)}";
|
|
|
|
|
|
|
|
return $" ({msg})";
|
|
|
|
}
|
|
|
|
|
|
|
|
return $"{emojiStr} {ResponseString()}{InfoMessage()}.";
|
2021-08-25 23:51:33 +00:00
|
|
|
}
|
|
|
|
}
|