Exemplo n.º 1
0
 private void ThrowIfMissingListPermission(UserInfo userInfo, CustomList list)
 {
     if (!list.IsAllowedToList(userInfo))
     {
         throw GetListPermissionException(ListErrorMessage.Permission.NoPermission_list, list.Name);
     }
 }
 private static void CheckPermissionList(ulong userId, CustomList list)
 {
     if (!list.IsAllowedToList(userId))
     {
         throw GetListManagerException(ListErrorMessage.Permission.NoPermission_list, list.Name);
     }
 }
 private void CheckPermissionList(UserInfo userInfo, CustomList list)
 {
     if (!list.IsAllowedToList(userInfo))
     {
         throw GetListManagerException(ListErrorMessage.Permission.NoPermission_list, list.Name);
     }
 }
Exemplo n.º 4
0
        private ListOutput GetAll(UserInfo userInfo, ListPermission outputPermission)
        {
            if (Lists.Count == 0)
            {
                throw GetListManagerException(ListErrorMessage.General.NoLists);
            }

            Func <int, int, int> GetLonger = (i1, i2) => { return(i1 > i2 ? i1 : i2); };

            var tableValuesList = new Dictionary <String, String>();

            for (int i = 0; i < Lists.Count; i++)
            {
                CustomList l = Lists[i];
                if (l.IsAllowedToList(userInfo))
                {
                    tableValuesList.Add(l.Name, $"{l.Count()} {GetNounPlural("item", l.Count())}");
                }
            }
            var maxItemLength = 0;
            var tableValues   = new string[tableValuesList.Count, 2];

            for (int i = 0; i < tableValues.GetLength(0); i++)
            {
                var keyPair = tableValuesList.ElementAt(i);
                tableValues[i, 0] = keyPair.Key;
                tableValues[i, 1] = keyPair.Value;
                maxItemLength     = GetLonger(maxItemLength, keyPair.Key.Length);
                maxItemLength     = GetLonger(maxItemLength, keyPair.Value.Length);
            }

            var header = new[] { "List name", "Item count" };

            foreach (string s in header)
            {
                maxItemLength = GetLonger(maxItemLength, s.Length);
            }
            var    tableSettings = new MessageFormater.TableSettings("All lists", header, -(maxItemLength), true);
            string output        = MessageFormater.CreateTable(tableSettings, tableValues);
            var    count         = 0;

            for (int i = 0; i < output.Length; i++)
            {
                if (output[i] == '\n')
                {
                    if (count == 8)
                    {
                        output = output.Insert(i, LineIndicator);
                        break;
                    }
                    else
                    {
                        count++;
                    }
                }
            }

            var returnValue = GetListOutput(output, outputPermission);

            returnValue.listenForReactions = true;
            return(returnValue);
        }