Repository navigation
Expand file tree
/
Copy pathUtilities.cs
More file actions
63 lines (53 loc) · 2.24 KB
/
Copy pathUtilities.cs
File metadata and controls
63 lines (53 loc) · 2.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
using DSharpPlus;
using DSharpPlus.CommandsNext;
using DSharpPlus.Entities;
using DSharpPlus.SlashCommands;
using System;
using System.Linq;
using System.Threading.Tasks;
namespace YumeChan.Essentials
{
public static class Utilities
{
public static DiscordEmoji GreenCheckEmoji { get; } = DiscordEmoji.FromUnicode("\u2705");
public static DiscordEmoji GreenCrossEmoji { get; } = DiscordEmoji.FromUnicode("\u274e");
public static DiscordChannel FindUserCurrentVoiceChannel(CommandContext context) =>
(from channel in context.Guild.Channels?.Values
where channel.Type is ChannelType.Voice
where channel.Users.Contains(context.Member)
select channel).FirstOrDefault();
public static DiscordEmoji FindEmote(CommandContext context, string emoteName)
{
return context.Guild.Emojis?.Values.FirstOrDefault(x => x.Name.IndexOf(emoteName, StringComparison.OrdinalIgnoreCase) != -1);
}
public static async Task MarkCommandAsCompleted(CommandContext context) => await context.Message.CreateReactionAsync(GreenCheckEmoji);
public static async Task MarkCommandAsCompleted(InteractionContext context) => await context.FollowUpAsync(new()
{
Content = $"{GreenCheckEmoji} Done!",
IsEphemeral = true
});
public static async Task MarkCommandAsFailed(CommandContext context) => await context.Message.CreateReactionAsync(GreenCrossEmoji);
public static string BuildChannelLink(ChannelLinkTypes type, DiscordChannel channel)
{
string linkType = type switch
{
ChannelLinkTypes.Discord => "discord",
ChannelLinkTypes.Https => "https",
_ => throw new Exception()
};
return $"{linkType}://discordapp.com/channels/{channel.GuildId}/{channel.Id}";
}
public enum ChannelLinkTypes
{
Discord = 0,
Https = 1
}
public static DiscordEmbedBuilder WithAuthor(this DiscordEmbedBuilder embed, DiscordUser user)
{
return embed.WithAuthor(user.GetFullUsername(), null, user.GetAvatarUrl(ImageFormat.Auto, 128));
}
public static string GetFullUsername(this DiscordUser user) => $"{user.Username}#{user.Discriminator}";
public static Task<DiscordMessage> FollowUpAsync(this BaseContext ctx, string content, bool isEphemeral = false)
=> ctx.FollowUpAsync(new() { Content = content, IsEphemeral = isEphemeral });
}
}