Skip to content

Commit

Permalink
- anti-remix support
Browse files Browse the repository at this point in the history
  • Loading branch information
Pannoniae committed Nov 1, 2023
1 parent 3ebb88e commit 8c78640
Show file tree
Hide file tree
Showing 12 changed files with 179 additions and 89 deletions.
4 changes: 2 additions & 2 deletions CommandHandlers/ChatHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ namespace EconomyBot.CommandHandlers;

public class ChatHandler {
public static async Task test2(DiscordGuild guild) {
var messages = await guild.GetChannel(916804452193824809).GetMessagesAsync(1000);
foreach (var message in messages.Reverse()) {
var messages = await guild.GetChannel(916804452193824809).GetMessagesAsync(1000).ToListAsync();
foreach (var message in messages.Reverse<DiscordMessage>()) {
await Console.Out.WriteLineAsync($"({message.Timestamp}) {message.Author}:{message.Content}");
}
}
Expand Down
34 changes: 28 additions & 6 deletions CommandHandlers/ChatModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ namespace EconomyBot;
[ModuleLifespan(ModuleLifespan.Singleton)]
public class ChatModule : BaseCommandModule {

public const ulong ZEROX = 1091089609234059316;

private MusicService Music { get; set; }

/// <summary>
Expand All @@ -32,15 +34,19 @@ static IEnumerable<string> ChunksUpTo(string str, int maxChunkSize) {
[Command]
[RequirePermissions(Permissions.ManageMessages)]
public async Task purge(CommandContext ctx, int amt) {
IReadOnlyList<DiscordMessage> messages;
var messages = new List<DiscordMessage>();
// ReSharper disable once ConditionIsAlwaysTrueOrFalseAccordingToNullableAPIContract
// the library is stupid
if (ctx.Message.Reference != null) {
await Console.Out.WriteLineAsync("Purging from given message!");
messages = await ctx.Channel.GetMessagesBeforeAsync(ctx.Message.Reference.Message.Id, amt);
await foreach (var message in ctx.Channel.GetMessagesBeforeAsync(ctx.Message.Reference.Message.Id, amt)) {
messages.Add(message);
}
}
else {
messages = await ctx.Channel.GetMessagesAsync(amt);
await foreach (var message in ctx.Channel.GetMessagesAsync(amt)) {
messages.Add(message);
}
}

if (ctx.Channel.Id != Program.LOG) {
Expand Down Expand Up @@ -75,15 +81,15 @@ public async Task roll(CommandContext ctx, int sides) {

[Command]
public async Task save(CommandContext ctx) {
var names = (await ctx.Guild.GetAllMembersAsync()).Select(member => member.ToString());
var names = await ctx.Guild.GetAllMembersAsync().Select(member => member.ToString()).ToListAsync();
await File.WriteAllLinesAsync(Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "/names.txt",
names);
}

[Command("bishop")]
public async Task saveBishop(CommandContext ctx) {
var messages = (await ctx.Channel.GetMessagesAsync(2000)).Where(msg => msg.Author.Id == 540265036141297676)
.Select(msg => msg.Content);
var messages = await ctx.Channel.GetMessagesAsync(2000).Where(msg => msg.Author.Id == 540265036141297676)
.Select(msg => msg.Content).ToListAsync();
await File.WriteAllLinesAsync(Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "/bishop.txt",
messages);
}
Expand Down Expand Up @@ -118,4 +124,20 @@ public async Task squish(CommandContext ctx, DiscordMember member) {
new DiscordEmbedBuilder().WithImageUrl(
cat)), cat, "Giant cat");
}

[Command("0x")]
public async Task love0x(CommandContext ctx) {
var zerox = "https://tenor.com/view/girl-anime-kiss-anime-i-love-you-girl-kiss-gif-14375355";
await ctx.RespondAsync(new DiscordMessageBuilder()
.WithContent($"{(await ctx.Guild.GetMemberAsync(ZEROX)).Mention} is amazing and I love them so much!"));
await ctx.Channel.SendMessageAsync(zerox);
}

[Command("panno")]
public async Task lovepanno(CommandContext ctx) {
var panno = "https://tenor.com/view/hug-gif-25588769";
await ctx.RespondAsync(new DiscordMessageBuilder()
.WithContent($"Pannoniae is a 12/10 human being that deserves love and appreciation <3"));
await ctx.Channel.SendMessageAsync(panno);
}
}
2 changes: 1 addition & 1 deletion CommandHandlers/ChatModuleSlash.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public class ChatModuleSlash : ApplicationCommandModule {

[SlashCommand("purge", "")]
public async Task purge(InteractionContext ctx, [Option("amt", "Amount")] long amt) {
var messages = await ctx.Channel.GetMessagesAsync((int)amt);
var messages = await ctx.Channel.GetMessagesAsync((int)amt).ToListAsync();
var message = string.Join("\n", messages.Select(m => $"{m.Timestamp} {m.Author}: {m.Content}"));
await ctx.Guild.GetChannel(Program.LOG).SendMessageAsync(message);
await ctx.Channel.DeleteMessagesAsync(messages);
Expand Down
10 changes: 10 additions & 0 deletions CommandHandlers/MusicModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,16 @@ public async Task PlayJazzAsync(CommandContext ctx) {
await GuildMusic.queue.PlayAsync();
await common.respond(ctx, "Started playing jazz.");
}

[Command("live"), Description("Live music! :3"), Aliases("l"), Priority(1)]
public async Task PlayLiveAsync(CommandContext ctx) {
// yeet the bot in
GuildMusic.queue.addToQueue("_fatslive");
await GuildMusic.queue.seedQueue();
await startPlayer(ctx);
await GuildMusic.queue.PlayAsync();
await common.respond(ctx, "Started playing jazz.");
}

[Command("analyse"), Description("Analyse the frequency of artists."), Aliases("an")]
public async Task AnalyseAsync(CommandContext ctx) {
Expand Down
21 changes: 14 additions & 7 deletions EconomyBot.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@
<PackageReference Include="Catalyst.ConceptNet.English" Version="1.0.31050" />
<PackageReference Include="Catalyst.Models.English" Version="1.0.30952" />
<PackageReference Include="DetectLanguage" Version="1.0.0" />
<PackageReference Include="DSharpPlus" Version="5.0.0-nightly-01690" />
<PackageReference Include="DSharpPlus.CommandsNext" Version="5.0.0-nightly-01690" />
<PackageReference Include="DSharpPlus.Interactivity" Version="5.0.0-nightly-01690" />
<PackageReference Include="DSharpPlus.Lavalink" Version="5.0.0-nightly-01690" />
<PackageReference Include="DSharpPlus.SlashCommands" Version="5.0.0-nightly-01690" />
<PackageReference Include="DSharpPlus.VoiceNext" Version="5.0.0-nightly-01690" />
<PackageReference Include="DSharpPlus" Version="5.0.0-nightly-01839" />
<PackageReference Include="DSharpPlus.CommandsNext" Version="5.0.0-nightly-01839" />
<PackageReference Include="DSharpPlus.Interactivity" Version="5.0.0-nightly-01839" />
<PackageReference Include="DSharpPlus.Lavalink" Version="5.0.0-nightly-01839" />
<PackageReference Include="DSharpPlus.SlashCommands" Version="5.0.0-nightly-01839" />
<PackageReference Include="DSharpPlus.VoiceNext" Version="5.0.0-nightly-01839" />
<PackageReference Include="FuzzierSharp" Version="3.0.1" />
<PackageReference Include="JetBrains.Annotations" Version="2023.3.0-eap1" />
<PackageReference Include="LanguageExt.Core" Version="4.4.3" />
Expand All @@ -38,10 +38,13 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="SpotifyAPI.Web" Version="7.0.0" />
<PackageReference Include="System.Linq.Async" Version="6.0.1" />
<PackageReference Include="System.Linq.Parallel" Version="4.3.0" />
</ItemGroup>


<ItemGroup>
<Content Include="bin\Debug\net8.0\runtimes\linux-x64\native\libe_sqlite3.so" />
<Content Include="lua\**">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
Expand All @@ -52,18 +55,22 @@
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Launch.ps1">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Lavalink.jar">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="application.yml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="launch.sh">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>


<ItemGroup>
<Folder Include="bin\Debug\net8.0\runtimes\linux-x64\native\" />
<Folder Include="lua\" />
</ItemGroup>

Expand Down
19 changes: 10 additions & 9 deletions EconomyBot.sln.DotSettings.user
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:String x:Key="/Default/Environment/AssemblyExplorer/XmlDocument/@EntryValue">&lt;AssemblyExplorer&gt;&#xD;
&lt;Assembly Path="D:\dev\cs\EconomyBot\bin\Debug\net6.0\EconomyBot.dll" /&gt;&#xD;
&lt;Assembly Path="D:\dev\cs\EconomyBot\bin\Debug\net6.0\Newtonsoft.Json.dll" /&gt;&#xD;
&lt;Assembly Path="C:\Program Files\dotnet\packs\Microsoft.NETCore.App.Ref\6.0.10\ref\net6.0\System.Collections.NonGeneric.dll" /&gt;&#xD;
&lt;Assembly Path="C:\Users\prisz\.nuget\packages\boorusharp\3.5.5\lib\netstandard2.0\BooruSharp.dll" /&gt;&#xD;
&lt;Assembly Path="C:\Users\prisz\.nuget\packages\dsharpplus.slashcommands\4.3.0\lib\netstandard2.0\DSharpPlus.SlashCommands.dll" /&gt;&#xD;
&lt;Assembly Path="C:\Users\prisz\.nuget\packages\microsoft.extensions.dependencyinjection\5.0.1\lib\net5.0\Microsoft.Extensions.DependencyInjection.dll" /&gt;&#xD;
&lt;Assembly Path="C:\Users\prisz\.nuget\packages\microsoft.extensions.dependencyinjection.abstractions\5.0.0\lib\netstandard2.0\Microsoft.Extensions.DependencyInjection.Abstractions.dll" /&gt;&#xD;
&lt;Assembly Path="C:\Users\prisz\.nuget\packages\dsharpplus.interactivity\4.3.0\lib\netstandard2.0\DSharpPlus.Interactivity.dll" /&gt;&#xD;
<s:String x:Key="/Default/Environment/AssemblyExplorer/XmlDocument/@EntryValue">&lt;AssemblyExplorer&gt;
&lt;Assembly Path="D:\dev\cs\EconomyBot\bin\Debug\net6.0\EconomyBot.dll" /&gt;
&lt;Assembly Path="D:\dev\cs\EconomyBot\bin\Debug\net6.0\Newtonsoft.Json.dll" /&gt;
&lt;Assembly Path="C:\Program Files\dotnet\packs\Microsoft.NETCore.App.Ref\6.0.10\ref\net6.0\System.Collections.NonGeneric.dll" /&gt;
&lt;Assembly Path="C:\Users\prisz\.nuget\packages\boorusharp\3.5.5\lib\netstandard2.0\BooruSharp.dll" /&gt;
&lt;Assembly Path="C:\Users\prisz\.nuget\packages\dsharpplus.slashcommands\4.3.0\lib\netstandard2.0\DSharpPlus.SlashCommands.dll" /&gt;
&lt;Assembly Path="C:\Users\prisz\.nuget\packages\microsoft.extensions.dependencyinjection\5.0.1\lib\net5.0\Microsoft.Extensions.DependencyInjection.dll" /&gt;
&lt;Assembly Path="C:\Users\prisz\.nuget\packages\microsoft.extensions.dependencyinjection.abstractions\5.0.0\lib\netstandard2.0\Microsoft.Extensions.DependencyInjection.Abstractions.dll" /&gt;
&lt;Assembly Path="C:\Users\prisz\.nuget\packages\dsharpplus.interactivity\4.3.0\lib\netstandard2.0\DSharpPlus.Interactivity.dll" /&gt;
&lt;Assembly Path="/home/pannoniae/.nuget/packages/boorusharp/4.0.0-beta/lib/net5.0/BooruSharp.dll" /&gt;
&lt;/AssemblyExplorer&gt;</s:String>
<s:Boolean x:Key="/Default/ResxEditorPersonal/Initialized/@EntryValue">True</s:Boolean></wpf:ResourceDictionary>
61 changes: 33 additions & 28 deletions Music/GuildMusicData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,26 +43,28 @@ public sealed class GuildMusicData {
public static string rootPath;

public static readonly Dictionary<string, Artist> artistMappings = new() {
{ "_fats", new Artist("Fats Waller", 1.5) },
{ "ella mae morse", new Artist("Ella Mae Morse", 1.2) },
{ "slim gaillard", new Artist("Slim Gaillard", 1.0) },
{ "louis jordan", new Artist("Louis Jordan", 1.0) },
{ "caravan palace", new Artist("Caravan Palace", 1.0, 2) },
{ "tape five", new Artist("Tape Five", 1.0) },
{ "caro emerald", new Artist("Caro Emerald", 1.0) },
{ "chuck berry", new Artist("Chuck Berry", 1.0, 0.25) }, // most of this is trash
{ "jamie berry", new Artist("Jamie Berry", 0.8) },
{ "sim gretina", new Artist("Sim Gretina", 0.8, 0) }, // too much earrape
{ "freshly squeezed", new Artist("Freshly Squeezed Music", 0.8, 0.5, 0.5, 0.3) },
{ "puppini sisters", new Artist("Puppini Sisters", 1.0) },
{ "11 acorn lane", new Artist("11 Acorn Lane", 1.0) },
{ "electric swing circus", new Artist("Electric Swing Circus", 1.0) },
{ "the speakeasies swing band", new Artist("The Speakeasies Swing Band", 1.0) },
{ "donald lambert", new Artist("Donald Lambert", 1.5) },
{ "newport", new Artist("Newport Jazz Festival", 1.5) }, // 1960 Newport Jazz Festival, full recording
{ "hot sardines", new Artist("The Hot Sardines", 1.0) },
{ "the wolfe tones", new Artist("The Wolfe Tones", 0.8, 0.25) },
{ "the dubliners", new Artist("The Dubliners", 0.8, 0.25) }
{ "_fats", new Artist("Fats Waller", "Fats Waller", 1.5) },
{ "_fatslive", new Artist("Fats Waller Live", "Fats Waller/Fats Waller Live", 1.5) },
{ "ella mae morse", new Artist("Ella Mae Morse", "Ella Mae Morse", 1.2) },
{ "slim gaillard", new Artist("Slim Gaillard", "Slim Gaillard", 1.0) },
{ "louis jordan", new Artist("Louis Jordan", "Louis Jordan", 1.0) },
{ "caravan palace", new Artist("Caravan Palace", "Caravan Palace", 1.0, 2) },
{ "tape five", new Artist("Tape Five", "Tape Five", 1.0) },
{ "caro emerald", new Artist("Caro Emerald", "Caro Emerald", 1.0) },
{ "chuck berry", new Artist("Chuck Berry", "Chuck Berry", 1.0, 0.25) }, // most of this is trash
{ "jamie berry", new Artist("Jamie Berry", "Jamie Berry", 0.8) },
{ "sim gretina", new Artist("Sim Gretina", "Sim Gretina", 0.8, 0) }, // too much earrape
{ "freshly squeezed", new Artist("Freshly Squeezed Music", "Freshly Squeezed Music", 0.8, 0.25, 0.5, 0.3) },
{ "puppini sisters", new Artist("Puppini Sisters", "Puppini Sisters", 1.0) },
{ "11 acorn lane", new Artist("11 Acorn Lane", "11 Acorn Lane", 1.0) },
{ "electric swing circus", new Artist("Electric Swing Circus", "Electric Swing Circus", 1.0) },
{ "the speakeasies swing band", new Artist("The Speakeasies Swing Band", "The Speakeasies Swing Band", 1.0) },
{ "donald lambert", new Artist("Donald Lambert", "Donald Lambert", 1.5) }, {
"newport", new Artist("Newport Jazz Festival", "Newport Jazz Festival", 1.5)
}, // 1960 Newport Jazz Festival, full recording
{ "hot sardines", new Artist("The Hot Sardines", "The Hot Sardines", 1.0) },
{ "the wolfe tones", new Artist("The Wolfe Tones", "The Wolfe Tones", 0.8, 0.25) },
{ "the dubliners", new Artist("The Dubliners", "The Dubliners", 0.8, 0.25) }
};

public static readonly Dictionary<string, double> artistWeights = new();
Expand All @@ -82,7 +84,6 @@ public sealed class GuildMusicData {
/// <param name="lavalink">Lavalink service.</param>
/// <param name="node">The Lavalink node this guild is connected to.</param>
public GuildMusicData(DiscordGuild guild, LavalinkExtension lavalink, LavalinkNodeConnection node) {

// setup paths by OS
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) {
rootPath = "/snd/music";
Expand All @@ -93,7 +94,7 @@ public GuildMusicData(DiscordGuild guild, LavalinkExtension lavalink, LavalinkNo
else {
throw new NotSupportedException("OS not supported, specify paths for the music.");
}

Node = node;
Guild = guild;
Lavalink = lavalink;
Expand All @@ -102,7 +103,8 @@ public GuildMusicData(DiscordGuild guild, LavalinkExtension lavalink, LavalinkNo
foreach (var artist in artistMappings) {
// get the count of files at the directory
int fCount = Directory
.GetFiles(getPath(artist.Value.path), "*", new EnumerationOptions { RecurseSubdirectories = true, MatchCasing = MatchCasing.CaseInsensitive })
.GetFiles(getPath(artist.Value.path), "*",
new EnumerationOptions { RecurseSubdirectories = true, MatchCasing = MatchCasing.CaseInsensitive })
.Length;
artistWeights[artist.Key] = fCount * artist.Value.weight;
}
Expand All @@ -112,7 +114,7 @@ public GuildMusicData(DiscordGuild guild, LavalinkExtension lavalink, LavalinkNo
logger.info("Initialised artist weights.");
}

public string getPath(string path) {
public static string getPath(string path) {
return Path.Combine(rootPath, path);
}

Expand All @@ -139,7 +141,7 @@ public async Task PauseAsync() {
await Player.PauseAsync();
}

/// <summary>
/// <summary>summary
/// Resumes the playback.
/// </summary>
public async Task ResumeAsync() {
Expand Down Expand Up @@ -334,15 +336,18 @@ public void toggleEQ() {
/// <summary>
/// Stores artist information which is used for song selection.
/// </summary>
/// <param name="name">The artist's name.</param>
/// <param name="path">The path of the music files for the artist.</param>
/// <param name="volume">The volume modifier for the artist.</param>
/// <param name="weight">The rarity multiplier for the artist in the random selection.</param>
/// <param name="repeatPenalty">If the queue already contains the artist, the chance of selecting the artist again will be multiplied by the value.</param>
/// <param name="historyRepeatPenalty">If the history already contains the artist, the chance of selecting the artist again will be multiplied by the value.</param>
/// <param name="doubleRepeatPenalty">If the previous track is the same artist, the chance of selecting the artist again will be multiplied by the value.</param>
public record Artist(string path,
public record Artist(
string name,
string path,
double volume,
double weight = 1.0,
double repeatPenalty = 1.0,
double historyRepeatPenalty = 1.0,
double doubleRepeatPenalty = 1.0);

public record Track(LavalinkTrack track, string? artist);
Expand Down
Loading

0 comments on commit 8c78640

Please sign in to comment.