Skip to content

Commit

Permalink
prep work
Browse files Browse the repository at this point in the history
  • Loading branch information
th0mk committed Mar 27, 2024
1 parent 88625b6 commit c097b22
Show file tree
Hide file tree
Showing 15 changed files with 5,032 additions and 22 deletions.
7 changes: 4 additions & 3 deletions src/FMBot.Bot/Builders/ImportBuilders.cs
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,10 @@ public async Task<ResponseModel> GetAppleMusicImportInstructions(ContextModel co
description.AppendLine("2. Sign in to your account");
description.AppendLine("3. Click on **Request a copy of your data**");
description.AppendLine("4. Select **Apple Media Services Information**");
description.AppendLine("5. Press **Continue**");
description.AppendLine("5. Press **Complete request**");
description.AppendLine("7. Wait up to 7 days for Apple to deliver your files");
description.AppendLine("5. De-select the other options");
description.AppendLine("6. Press **Continue**");
description.AppendLine("7. Press **Complete request**");
description.AppendLine("8. Wait up to 7 days for Apple to deliver your files");

description.AppendLine("### Importing your data into .fmbot");
description.AppendLine("1. Download the file Apple provided");
Expand Down
10 changes: 9 additions & 1 deletion src/FMBot.Bot/Builders/UserBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,15 @@ public async Task<ResponseModel> FeaturedAsync(ContextModel context)
return response;
}

response.Embed.WithThumbnailUrl(this._timer.CurrentFeatured.ImageUrl);
if (this._timer.CurrentFeatured.FullSizeImage == null)
{
response.Embed.WithThumbnailUrl(this._timer.CurrentFeatured.ImageUrl);
}
else
{
response.Embed.WithImageUrl(this._timer.CurrentFeatured.FullSizeImage);
}

response.Embed.AddField("Featured:", this._timer.CurrentFeatured.Description);

if (context.DiscordGuild != null && guildUsers.Any() && this._timer.CurrentFeatured.UserId.HasValue && this._timer.CurrentFeatured.UserId.Value != 0)
Expand Down
21 changes: 21 additions & 0 deletions src/FMBot.Bot/Handlers/CommandHandler.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Linq;
using System.Security.Cryptography;
using System.Threading.Tasks;
using Discord;
using Discord.Commands;
Expand Down Expand Up @@ -324,6 +325,26 @@ private async Task ExecuteCommand(SocketUserMessage msg, ShardedCommandContext c
return;
}

var aprilFirst = new DateTime(2024, 4, 1);
var randomNumber = RandomNumberGenerator.GetInt32(1, 30);
if (DateTime.Today == aprilFirst && randomNumber == 1)
{
var randomResponse = RandomNumberGenerator.GetInt32(1, 6);
var response = randomResponse switch

Check warning on line 333 in src/FMBot.Bot/Handlers/CommandHandler.cs

View workflow job for this annotation

GitHub Actions / build

The switch expression does not handle all possible values of its input type (it is not exhaustive). For example, the pattern '0' is not covered.

Check warning on line 333 in src/FMBot.Bot/Handlers/CommandHandler.cs

View workflow job for this annotation

GitHub Actions / build

The switch expression does not handle all possible values of its input type (it is not exhaustive). For example, the pattern '0' is not covered.
{
1 => "😴 Zzz... Scrobble? Oh, right, music stats! I was dreaming of vinyl records in the cloud.",
2 => "😴 Oh sorry, I was sleeping.. I guess I'll get to work.",
3 => "😴 Oh hey, good morning, just woke up. I wasn't sleep scrobbling, was I? Let's get to work.",
4 => "😴 Sorry, I dozed off while listening to #3 from Aphex Twin. I'll get to work now.",
5 => "😴 Help! Oh sorry, I was having a nightmare where someone stole my Daft Punk crown. I'll get to work now.."
};

await context.Channel.SendMessageAsync(response);
await Task.Delay(RandomNumberGenerator.GetInt32(1000, 1400));
await context.Channel.TriggerTypingAsync();
await Task.Delay(RandomNumberGenerator.GetInt32(1000, 1400));
}

var result = await this._commands.ExecuteAsync(context, argPos, this._provider);

if (result.IsSuccess)
Expand Down
2 changes: 1 addition & 1 deletion src/FMBot.Bot/Services/GenericEmbedService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public static void UsernameNotSetErrorResponse(this EmbedBuilder embed, string p
$"Please use the {loginCommand} command. The bot will then send you a link so you can connect your Last.fm account.");

embed.WithUrl($"{Constants.DocsUrl}/commands/");

embed.WithColor(DiscordConstants.WarningColorOrange);
}

Expand Down
21 changes: 18 additions & 3 deletions src/FMBot.Bot/Services/Guild/WebhookService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public async Task<Webhook> CreateWebhook(ICommandContext context, int guildId)
}

await using var db = await this._contextFactory.CreateDbContextAsync();

await db.Webhooks.AddAsync(webhook);
await db.SaveChangesAsync();

Expand Down Expand Up @@ -174,7 +174,15 @@ public async Task SendFeaturedPreview(FeaturedLog featured, string webhook)
public async Task PostFeatured(FeaturedLog featuredLog, DiscordShardedClient client)
{
var builder = new EmbedBuilder();
builder.WithThumbnailUrl(featuredLog.ImageUrl);
if (featuredLog.FullSizeImage == null)
{
builder.WithThumbnailUrl(featuredLog.ImageUrl);
}
else
{
builder.WithImageUrl(featuredLog.FullSizeImage);
}

builder.AddField("Featured:", featuredLog.Description);

if (this._botSettings.Bot.BaseServerId != 0 && this._botSettings.Bot.FeaturedChannelId != 0)
Expand Down Expand Up @@ -218,7 +226,14 @@ public async Task PostFeatured(FeaturedLog featuredLog, DiscordShardedClient cli

if (message != null)
{
await this._guildService.AddGuildReactionsAsync(message, guild);
if (featuredLog.Reactions != null && featuredLog.Reactions.Any())
{
await GuildService.AddReactionsAsync(message, featuredLog.Reactions);
}
else
{
await this._guildService.AddGuildReactionsAsync(message, guild);
}
}
}
}
Expand Down
6 changes: 6 additions & 0 deletions src/FMBot.Bot/Services/TimerService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,12 @@ public async Task UpdateStatus()

try
{
if (this.CurrentFeatured.Status != null)
{
await this._client.SetCustomStatusAsync(this.CurrentFeatured.Status);
return;
}

if (this._client?.Guilds?.Count == null)
{
Log.Information($"Client guild count is null, cancelling {nameof(UpdateStatus)}");
Expand Down
22 changes: 16 additions & 6 deletions src/FMBot.Bot/SlashCommands/UserSlashCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public class UserSlashCommands : InteractionModuleBase
private readonly IPrefixService _prefixService;
private readonly AdminService _adminService;
private readonly ImportBuilders _importBuilders;
private readonly TimerService _timerService;

private readonly BotSettings _botSettings;

Expand All @@ -65,7 +66,8 @@ public UserSlashCommands(UserService userService,
ImportService importService,
IPrefixService prefixService,
AdminService adminService,
ImportBuilders importBuilders)
ImportBuilders importBuilders,
TimerService timerService)
{
this._userService = userService;
this._dataSourceFactory = dataSourceFactory;
Expand All @@ -81,6 +83,7 @@ public UserSlashCommands(UserService userService,
this._prefixService = prefixService;
this._adminService = adminService;
this._importBuilders = importBuilders;
this._timerService = timerService;
this._botSettings = botSettings.Value;
}

Expand Down Expand Up @@ -868,13 +871,20 @@ public async Task FeaturedAsync()
PublicProperties.UsedCommandsResponseMessageId.TryAdd(this.Context.Interaction.Id, message.Id);
PublicProperties.UsedCommandsResponseContextId.TryAdd(message.Id, this.Context.Interaction.Id);

if (contextUser.EmoteReactions != null && contextUser.EmoteReactions.Any() && SupporterService.IsSupporter(contextUser.UserType))
if (this._timerService.CurrentFeatured?.Reactions != null && this._timerService.CurrentFeatured.Reactions.Any())
{
await GuildService.AddReactionsAsync(message, contextUser.EmoteReactions);
await GuildService.AddReactionsAsync(message, this._timerService.CurrentFeatured.Reactions);
}
else if (this.Context.Guild != null)
else
{
await this._guildService.AddGuildReactionsAsync(message, this.Context.Guild, response.Text == "in-server");
if (contextUser.EmoteReactions != null && contextUser.EmoteReactions.Any() && SupporterService.IsSupporter(contextUser.UserType))
{
await GuildService.AddReactionsAsync(message, contextUser.EmoteReactions);
}
else if (this.Context.Guild != null)
{
await this._guildService.AddGuildReactionsAsync(message, this.Context.Guild, response.Text == "in-server");
}
}
}
}
Expand Down Expand Up @@ -1128,7 +1138,7 @@ public async Task ImportManage()
{
var contextUser = await this._userService.GetUserSettingsAsync(this.Context.User);
await DeferAsync(true);

try
{
var response = await this._userBuilder.ImportMode(new ContextModel(this.Context, contextUser), contextUser.UserId);
Expand Down
21 changes: 15 additions & 6 deletions src/FMBot.Bot/TextCommands/UserCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public class UserCommands : BaseCommandModule
private readonly UserBuilder _userBuilder;
private readonly ArtistsService _artistsService;
private readonly OpenAiService _openAiService;

private readonly TimerService _timerService;

private InteractiveService Interactivity { get; }

Expand All @@ -55,7 +55,8 @@ public UserCommands(
UserBuilder userBuilder,
InteractiveService interactivity,
ArtistsService artistsService,
OpenAiService openAiService) : base(botSettings)
OpenAiService openAiService,
TimerService timerService) : base(botSettings)
{
this._guildService = guildService;
this._indexService = indexService;
Expand All @@ -67,6 +68,7 @@ public UserCommands(
this.Interactivity = interactivity;
this._artistsService = artistsService;
this._openAiService = openAiService;
this._timerService = timerService;
}

[Command("settings", RunMode = RunMode.Async)]
Expand Down Expand Up @@ -381,13 +383,20 @@ public async Task FeaturedAsync([Remainder] string options = null)
PublicProperties.UsedCommandsResponseMessageId.TryAdd(this.Context.Message.Id, message.Id);
PublicProperties.UsedCommandsResponseContextId.TryAdd(message.Id, this.Context.Message.Id);

if (contextUser?.EmoteReactions != null && contextUser.EmoteReactions.Any() && SupporterService.IsSupporter(contextUser.UserType))
if (this._timerService.CurrentFeatured?.Reactions != null && this._timerService.CurrentFeatured.Reactions.Any())
{
await GuildService.AddReactionsAsync(message, contextUser.EmoteReactions);
await GuildService.AddReactionsAsync(message, this._timerService.CurrentFeatured.Reactions);
}
else if (this.Context.Guild != null)
else
{
await this._guildService.AddGuildReactionsAsync(message, this.Context.Guild, response.Text == "in-server");
if (contextUser.EmoteReactions != null && contextUser.EmoteReactions.Any() && SupporterService.IsSupporter(contextUser.UserType))
{
await GuildService.AddReactionsAsync(message, contextUser.EmoteReactions);
}
else if (this.Context.Guild != null)
{
await this._guildService.AddGuildReactionsAsync(message, this.Context.Guild, response.Text == "in-server");
}
}
}

Expand Down
6 changes: 6 additions & 0 deletions src/FMBot.Persistence.Domain/Models/FeaturedLog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,11 @@ public class FeaturedLog

public bool SupporterDay { get; set; }

public string FullSizeImage { get; set; }

public string Status { get; set; }

public string[] Reactions { get; set; }

public User User { get; set; }
}
2 changes: 1 addition & 1 deletion src/FMBot.Persistence.EntityFrameWork/FMBotDbContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
optionsBuilder.UseNpgsql(this._configuration["Database:ConnectionString"]);

// Uncomment below connection string when creating migrations, and also comment out the above iconfiguration stuff
//optionsBuilder.UseNpgsql("Host=localhost;Port=5435;Username=postgres;Password=password;Database=fmbot;Command Timeout=60;Timeout=60;Persist Security Info=True");
//optionsBuilder.UseNpgsql("Host=localhost;Port=5435;Username=postgres;Password=password;Database=fmbot-restore-2;Command Timeout=60;Timeout=60;Persist Security Info=True");

optionsBuilder.UseSnakeCaseNamingConvention();
}
Expand Down
Loading

0 comments on commit c097b22

Please sign in to comment.