Skip to content

Commit

Permalink
Merge branch 'dev' into feature/server-features
Browse files Browse the repository at this point in the history
  • Loading branch information
th0mk committed May 29, 2023
2 parents b391534 + 4ddfa34 commit e7269fa
Show file tree
Hide file tree
Showing 11 changed files with 44 additions and 35 deletions.
2 changes: 1 addition & 1 deletion src/FMBot.Bot/Builders/AlbumBuilders.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1160,7 +1160,7 @@ public class AlbumBuilders
}
else
{
albumPageString.Append($"{counter}. ");
albumPageString.Append($"{counter}\\. ");
albumPageString.AppendLine(name);
}

Expand Down
2 changes: 1 addition & 1 deletion src/FMBot.Bot/Builders/ArtistBuilders.cs
Original file line number Diff line number Diff line change
Expand Up @@ -618,7 +618,7 @@ public class ArtistBuilders
}
else
{
artistPageString.Append($"{counter}. ");
artistPageString.Append($"{counter}\\. ");
artistPageString.AppendLine(name);
}

Expand Down
2 changes: 1 addition & 1 deletion src/FMBot.Bot/Builders/DiscogsBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ public async Task<ResponseModel> DiscogsLoginAsync(ContextModel context)
$"**[{artist.ArtistName}]({artist.ArtistUrl})** ({artist.UserReleasesInCollection} {StringExtensions.GetReleasesString(artist.UserReleasesInCollection)})";

// TODO for those who know how to deal with this: honor Billboard :)
artistPageString.Append($"{counter}. ");
artistPageString.Append($"{counter}\\. ");
artistPageString.AppendLine(name);

counter++;
Expand Down
2 changes: 1 addition & 1 deletion src/FMBot.Bot/Builders/GenreBuilders.cs
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ public async Task<ResponseModel> GetGuildGenres(ContextModel context, Guild guil
}
else
{
genrePageString.Append($"{counter}. ");
genrePageString.Append($"{counter}\\. ");
genrePageString.AppendLine(name);
}

Expand Down
4 changes: 2 additions & 2 deletions src/FMBot.Bot/Builders/StaticBuilders.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ public StaticBuilders(SupporterService supporterService)
embedDescription.AppendLine("This means that this is a Last.fm issue and **not an .fmbot issue**. __We can't fix it for you__, but we can give you some tips that worked for others.");
embedDescription.AppendLine();
embedDescription.AppendLine("Some things you can try that usually work:");
embedDescription.AppendLine(" - Restarting your Spotify application");
embedDescription.AppendLine(" - Disconnecting and **reconnecting Spotify in [your Last.fm settings](https://www.last.fm/settings/applications)**");
embedDescription.AppendLine("- Restarting your Spotify application");
embedDescription.AppendLine("- Disconnecting and **reconnecting Spotify in [your Last.fm settings](https://www.last.fm/settings/applications)**");
embedDescription.AppendLine();
embedDescription.AppendLine("If the two options above don't work, check out **[the complete guide for this issue on the Last.fm support forums](https://support.last.fm/t/spotify-has-stopped-scrobbling-what-can-i-do/3184)**.");

Expand Down
2 changes: 1 addition & 1 deletion src/FMBot.Bot/Builders/TrackBuilders.cs
Original file line number Diff line number Diff line change
Expand Up @@ -897,7 +897,7 @@ private async Task<string> GetAlbumCoverUrl(ContextModel context, TrackSearch tr
}
else
{
trackPageString.Append($"{counter}. ");
trackPageString.Append($"{counter}\\. ");
trackPageString.AppendLine(name);
}

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 @@ -192,7 +192,7 @@ public static void HelpResponse(this EmbedBuilder embed, CommandInfo commandInfo
var optionsString = new StringBuilder();
foreach (var option in options.Options)
{
optionsString.AppendLine($" - {option}");
optionsString.AppendLine($"- {option}");
}

embed.AddField("Options", optionsString.ToString());
Expand Down
4 changes: 2 additions & 2 deletions src/FMBot.Bot/Services/Guild/WebhookService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ public async Task SendFeaturedPreview(FeaturedLog featured, string webhook)
await using var db = await this._contextFactory.CreateDbContextAsync();
var user = await db.Users.FindAsync(featured.UserId.Value);

Log.Information("Featured: Checking is username is offensive");

var possiblyOffensive = await this._openAiService.CheckIfUsernameOffensive(user?.UserNameLastFM);

if (possiblyOffensive)
Expand All @@ -151,8 +153,6 @@ public async Task SendFeaturedPreview(FeaturedLog featured, string webhook)
embed.WithColor(DiscordConstants.WarningColorOrange);
}
}



var webhookClient = new DiscordWebhookClient(webhook);
await webhookClient.SendMessageAsync(embeds: new[] { embed.Build() });
Expand Down
47 changes: 28 additions & 19 deletions src/FMBot.Bot/Services/OpenAiService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using FMBot.Persistence.Domain.Models;
using FMBot.Persistence.EntityFrameWork;
using Microsoft.EntityFrameworkCore;
using Serilog;

namespace FMBot.Bot.Services;

Expand Down Expand Up @@ -104,33 +105,41 @@ public async Task<int> GetCommandUsesLeft(User user)

public async Task<bool> CheckIfUsernameOffensive(string username)
{
var request = new HttpRequestMessage(HttpMethod.Post, "https://api.openai.com/v1/chat/completions");
request.Headers.Add("Authorization", $"Bearer {this._botSettings.OpenAi.Key}");

var content = new OpenAiRequest
try
{
Model = Model,
Messages = new List<RequestMessage>
var request = new HttpRequestMessage(HttpMethod.Post, "https://api.openai.com/v1/chat/completions");
request.Headers.Add("Authorization", $"Bearer {this._botSettings.OpenAi.Key}");

var content = new OpenAiRequest
{
new()
Model = Model,
Messages = new List<RequestMessage>
{
Role = "system",
Content = $"Is the username '{username}' offensive? Only reply with 'true' or 'false'."
new()
{
Role = "system",
Content = $"Is the username '{username}' offensive? Only reply with 'true' or 'false'."
}
}
}
};
};

var requestContent = JsonSerializer.Serialize(content);
var requestContent = JsonSerializer.Serialize(content);

request.Content = new StringContent(requestContent, null, "application/json");
var response = await this._httpClient.SendAsync(request);
Statistics.OpenAiCalls.Inc();
request.Content = new StringContent(requestContent, null, "application/json");
var response = await this._httpClient.SendAsync(request);
Statistics.OpenAiCalls.Inc();

var responseContent = await response.Content.ReadAsStringAsync();
var responseContent = await response.Content.ReadAsStringAsync();

var responseModel = JsonSerializer.Deserialize<OpenAiResponse>(responseContent);
var responseModel = JsonSerializer.Deserialize<OpenAiResponse>(responseContent);

var output = responseModel.Choices.FirstOrDefault()?.ChoiceMessage?.Content;
return output != null && output.ToLower().Contains("true");
var output = responseModel.Choices.FirstOrDefault()?.ChoiceMessage?.Content;
return output != null && output.ToLower().Contains("true");
}
catch (Exception e)
{
Log.Error(e, "Feature: Error in OpenAI call");
return false;
}
}
}
2 changes: 1 addition & 1 deletion src/FMBot.Bot/Services/TimerService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ public class TimerService
}
},
null,
TimeSpan.FromSeconds(this._botSettings.Bot.BotWarmupTimeInSeconds),
TimeSpan.FromSeconds(this._botSettings.Bot.BotWarmupTimeInSeconds + 15),
TimeSpan.FromHours(12));

this._checkNewSupporterTimer = new Timer(async _ =>
Expand Down
10 changes: 5 additions & 5 deletions src/FMBot.Bot/TextCommands/StaticCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -588,8 +588,8 @@ private async Task SetGeneralHelpEmbed(string prefix)
description.AppendLine();

description.AppendLine($"**Commands**");
description.AppendLine($" - View all commands on [our website](https://fmbot.xyz/commands/)");
description.AppendLine($" - Or use the dropdown below this message to pick a category");
description.AppendLine($"- View all commands on [our website](https://fmbot.xyz/commands/)");
description.AppendLine($"- Or use the dropdown below this message to pick a category");


if (prefix != this._botSettings.Bot.Prefix)
Expand Down Expand Up @@ -770,7 +770,7 @@ public async Task FullHelpAsync()
}
}

var moduleSummary = string.IsNullOrEmpty(module.Summary) ? "" : $" - {module.Summary}";
var moduleSummary = string.IsNullOrEmpty(module.Summary) ? "" : $"- {module.Summary}";

if (!string.IsNullOrEmpty(module.Name) && !string.IsNullOrEmpty(moduleCommands))
{
Expand Down Expand Up @@ -821,7 +821,7 @@ public async Task ServerHelpAsync()
}
}

var moduleSummary = string.IsNullOrEmpty(module.Summary) ? "" : $" - {module.Summary}";
var moduleSummary = string.IsNullOrEmpty(module.Summary) ? "" : $"- {module.Summary}";

if (!string.IsNullOrEmpty(module.Name) && !string.IsNullOrEmpty(moduleCommands))
{
Expand Down Expand Up @@ -870,7 +870,7 @@ public async Task StaffHelpAsync()
}
}

var moduleSummary = string.IsNullOrEmpty(module.Summary) ? "" : $" - {module.Summary}";
var moduleSummary = string.IsNullOrEmpty(module.Summary) ? "" : $"- {module.Summary}";

if (!string.IsNullOrEmpty(module.Name) && !string.IsNullOrEmpty(moduleCommands))
{
Expand Down

0 comments on commit e7269fa

Please sign in to comment.