mirror of
https://github.com/Myxelium/Lunaris2.0.git
synced 2026-04-17 03:35:53 +00:00
Add Spotify support
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using Discord;
|
||||
using Discord.WebSocket;
|
||||
using Lunaris2.Notification;
|
||||
using MediatR;
|
||||
@@ -19,13 +21,41 @@ public class MessageReceivedHandler : INotificationHandler<MessageReceivedNotifi
|
||||
public async Task Handle(MessageReceivedNotification notification, CancellationToken cancellationToken)
|
||||
{
|
||||
await BotMentioned(notification, cancellationToken);
|
||||
await Statistics(notification, cancellationToken);
|
||||
}
|
||||
|
||||
private async Task Statistics(MessageReceivedNotification notification, CancellationToken cancellationToken)
|
||||
{
|
||||
if (notification.Message.Content.Contains("!LunarisStats"))
|
||||
{
|
||||
var servers = _client.Guilds.Select(guild => guild.Name);
|
||||
var channels = _client.Guilds
|
||||
.SelectMany(guild => guild.VoiceChannels)
|
||||
.Where(channel => channel.Users.Any(user => user.IsBot));
|
||||
|
||||
var table = new StringBuilder();
|
||||
var serverColumnWidth = 25; // Width for server column
|
||||
var channelColumnWidth = 25; // Width for channel column
|
||||
table.AppendLine($"{"Servers".PadRight(serverColumnWidth - 1)}|{"Channels".PadRight(channelColumnWidth - 1)}");
|
||||
table.AppendLine($"{new string('-', serverColumnWidth - 1)}|{new string('-', channelColumnWidth - 1)}");
|
||||
foreach (var (server, channel) in servers.Zip(channels))
|
||||
{
|
||||
table.AppendLine($"{server.PadRight(serverColumnWidth - 1)}|{channel.Name.PadRight(channelColumnWidth - 1)}");
|
||||
}
|
||||
|
||||
var embed = new EmbedBuilder()
|
||||
.WithTitle("Lunaris Statistics")
|
||||
.WithDescription(table.ToString())
|
||||
.Build();
|
||||
|
||||
await notification.Message.Channel.SendMessageAsync(embed: embed);
|
||||
}
|
||||
}
|
||||
|
||||
private async Task BotMentioned(MessageReceivedNotification notification, CancellationToken cancellationToken)
|
||||
{
|
||||
if (notification.Message.MentionedUsers.Any(user => user.Id == _client.CurrentUser.Id))
|
||||
{
|
||||
// The bot was mentioned
|
||||
const string pattern = "<.*?>";
|
||||
const string replacement = "";
|
||||
var regex = new Regex(pattern);
|
||||
|
||||
Reference in New Issue
Block a user