Catalogger.NET/Catalogger.Backend/Bot/DiscordUtils.cs

72 lines
2.4 KiB
C#
Raw Permalink Normal View History

// Copyright (C) 2021-present sam (starshines.gay)
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published
// by the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
2024-08-13 13:08:50 +02:00
using System.Drawing;
using Remora.Discord.API;
using Remora.Discord.API.Abstractions.Objects;
2024-10-14 00:26:17 +02:00
using Remora.Discord.API.Objects;
using Remora.Discord.Pagination;
using Remora.Rest.Core;
2024-08-13 13:08:50 +02:00
namespace Catalogger.Backend.Bot;
public static class DiscordUtils
{
public static readonly Snowflake PkUserId = DiscordSnowflake.New(466378653216014359);
2024-08-16 17:04:24 +02:00
2024-08-13 13:08:50 +02:00
public static readonly Color Red = Color.FromArgb(231, 76, 60);
2024-08-13 16:48:54 +02:00
public static readonly Color Purple = Color.FromArgb(155, 89, 182);
public static readonly Color Green = Color.FromArgb(46, 204, 113);
2024-08-20 14:11:08 +02:00
public static readonly Color Blue = Color.FromArgb(52, 152, 219);
public static readonly Color Orange = Color.FromArgb(230, 126, 34);
2024-10-14 00:26:17 +02:00
public static List<Embed> PaginateFields(
IEnumerable<IEmbedField> fields,
Optional<string> title = default,
string description = "",
uint fieldsPerPage = 6
) =>
PageFactory.FromFields(
fields,
fieldsPerPage,
description,
new Embed(Title: title, Colour: Purple)
);
2024-10-29 00:06:39 +01:00
public static List<Embed> PaginateStrings(
IEnumerable<string> strings,
Optional<string> title = default,
int stringsPerPage = 20
)
{
var pages = strings.ToArray().Split(stringsPerPage);
return pages
.Select(p => new Embed(
Title: title,
Colour: Purple,
Description: string.Join("\n", p.Select((row, i) => $"{i + 1}. {row}"))
))
.ToList();
}
private static IEnumerable<IEnumerable<T>> Split<T>(this T[] arr, int size)
{
for (var i = 0; i < arr.Length / size + 1; i++)
{
yield return arr.Skip(i * size).Take(size);
}
}
2024-10-09 17:35:11 +02:00
}