2021-08-25 23:51:33 +00:00
|
|
|
using System;
|
|
|
|
|
|
|
|
using PluralKit.Core;
|
|
|
|
|
|
|
|
namespace PluralKit.Bot
|
|
|
|
{
|
2021-10-31 05:11:10 +00:00
|
|
|
public static class GroupMemberUtils
|
2021-08-25 23:51:33 +00:00
|
|
|
{
|
|
|
|
public static string GenerateResponse(Groups.AddRemoveOperation action, int memberCount, int groupCount, int actionedOn, int notActionedOn)
|
|
|
|
{
|
2021-08-27 23:18:59 +00:00
|
|
|
var op = action;
|
2021-08-25 23:51:33 +00:00
|
|
|
|
2021-08-27 23:18:59 +00:00
|
|
|
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;
|
2021-08-25 23:51:33 +00:00
|
|
|
|
2021-08-27 23:18:59 +00:00
|
|
|
var memberPlural = memberCount > 1;
|
|
|
|
var groupPlural = groupCount > 1;
|
2021-08-27 15:03:47 +00:00
|
|
|
|
2021-08-27 23:18:59 +00:00
|
|
|
// sanity checking: we can't add multiple groups to multiple members (at least for now)
|
|
|
|
if (memberPlural && groupPlural)
|
|
|
|
throw new ArgumentOutOfRangeException();
|
2021-08-25 23:51:33 +00:00
|
|
|
|
2021-08-27 23:18:59 +00:00
|
|
|
// 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();
|
2021-08-27 15:03:47 +00:00
|
|
|
|
2021-08-25 23:51:33 +00:00
|
|
|
// name generators
|
2021-08-27 23:18:59 +00:00
|
|
|
string MemberString(int count, bool capitalize = false)
|
2021-08-25 23:51:33 +00:00
|
|
|
=> capitalize
|
|
|
|
? (count == 1 ? "Member" : "Members")
|
|
|
|
: (count == 1 ? "member" : "members");
|
2021-08-27 15:03:47 +00:00
|
|
|
|
2021-08-27 23:18:59 +00:00
|
|
|
string GroupString(int count)
|
2021-08-25 23:51:33 +00:00
|
|
|
=> count == 1 ? "group" : "groups";
|
|
|
|
|
|
|
|
// string generators
|
2021-08-27 15:03:47 +00:00
|
|
|
|
2021-08-27 23:18:59 +00:00
|
|
|
string ResponseString()
|
2021-08-25 23:51:33 +00:00
|
|
|
{
|
2021-08-27 23:18:59 +00:00
|
|
|
if (actionedOn > 0 && notActionedOn > 0 && memberPlural)
|
|
|
|
return $"{actionedOn} {MemberString(actionedOn)} {actionStr} {GroupString(groupCount)}";
|
|
|
|
if (actionedOn > 0 && notActionedOn > 0 && groupPlural)
|
|
|
|
return $"{MemberString(memberCount, capitalize: true)} {actionStr} {actionedOn} {GroupString(actionedOn)}";
|
|
|
|
if (notActionedOn == 0)
|
|
|
|
return $"{MemberString(memberCount, capitalize: true)} {actionStr} {GroupString(groupCount)}";
|
|
|
|
if (actionedOn == 0)
|
|
|
|
return $"{MemberString(memberCount, capitalize: true)} not {actionStr} {GroupString(groupCount)}";
|
2021-08-25 23:51:33 +00:00
|
|
|
|
|
|
|
throw new ArgumentOutOfRangeException();
|
|
|
|
}
|
|
|
|
|
2021-08-27 23:18:59 +00:00
|
|
|
string InfoMessage()
|
2021-08-25 23:51:33 +00:00
|
|
|
{
|
2021-08-27 23:18:59 +00:00
|
|
|
if (notActionedOn == 0) return $"";
|
2021-08-25 23:51:33 +00:00
|
|
|
|
|
|
|
var msg = "";
|
2021-08-27 23:18:59 +00:00
|
|
|
if (actionedOn > 0 && memberPlural)
|
|
|
|
msg += $"{notActionedOn} {MemberString(notActionedOn)}";
|
2021-08-25 23:51:33 +00:00
|
|
|
else
|
2021-08-27 23:18:59 +00:00
|
|
|
msg += $"{MemberString(memberCount)}";
|
2021-08-25 23:51:33 +00:00
|
|
|
|
2021-08-27 23:18:59 +00:00
|
|
|
msg += $" already {containStr}";
|
2021-08-25 23:51:33 +00:00
|
|
|
|
2021-08-27 23:18:59 +00:00
|
|
|
if (actionedOn > 0 && groupPlural)
|
|
|
|
msg += $" {notActionedOn} {GroupString(notActionedOn)}";
|
2021-08-25 23:51:33 +00:00
|
|
|
else
|
2021-08-27 23:18:59 +00:00
|
|
|
msg += $" {GroupString(groupCount)}";
|
2021-08-25 23:51:33 +00:00
|
|
|
|
|
|
|
return $" ({msg})";
|
|
|
|
}
|
2021-08-27 15:03:47 +00:00
|
|
|
|
2021-08-27 23:18:59 +00:00
|
|
|
return $"{emojiStr} {ResponseString()}{InfoMessage()}.";
|
2021-08-25 23:51:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|