diff --git a/src/Mewdeko.Coordinator/Mewdeko.Coordinator.csproj b/src/Mewdeko.Coordinator/Mewdeko.Coordinator.csproj index 20c11ce62..bc63122cc 100644 --- a/src/Mewdeko.Coordinator/Mewdeko.Coordinator.csproj +++ b/src/Mewdeko.Coordinator/Mewdeko.Coordinator.csproj @@ -10,19 +10,17 @@ - - - - - + + + all runtime; build; native; contentfiles; analyzers; buildtransitive - - - - - + + + + + diff --git a/src/Mewdeko.Database/Mewdeko.Database.csproj b/src/Mewdeko.Database/Mewdeko.Database.csproj index 925ee0323..21db58579 100644 --- a/src/Mewdeko.Database/Mewdeko.Database.csproj +++ b/src/Mewdeko.Database/Mewdeko.Database.csproj @@ -10,23 +10,23 @@ - - - - + + + + all runtime; build; native; contentfiles; analyzers; buildtransitive - - + + all runtime; build; native; contentfiles; analyzers; buildtransitive - - - - - + + + + + diff --git a/src/Mewdeko.Tests/BotStringsTests.cs b/src/Mewdeko.Tests/BotStringsTests.cs index dedc066c5..249c52bf2 100644 --- a/src/Mewdeko.Tests/BotStringsTests.cs +++ b/src/Mewdeko.Tests/BotStringsTests.cs @@ -38,7 +38,7 @@ where cmdStrings is null TestContext.Out.WriteLine($"{commandName} doesn't exist in commands.en-US.yml"); } - Assert.IsTrue(isSuccess); + Assert.That(isSuccess); } private static IEnumerable GetCommandMethodNames() @@ -69,7 +69,7 @@ public void AllCommandMethodsHaveNames() isSuccess = false; } - Assert.IsTrue(isSuccess); + Assert.That(isSuccess); } [Test] @@ -88,6 +88,6 @@ public void NoObsoleteAliases() isSuccess = false; } - Assert.IsTrue(isSuccess); + Assert.That(isSuccess); } } \ No newline at end of file diff --git a/src/Mewdeko.Tests/GroupGreetTests.cs b/src/Mewdeko.Tests/GroupGreetTests.cs deleted file mode 100644 index 61a75fb9d..000000000 --- a/src/Mewdeko.Tests/GroupGreetTests.cs +++ /dev/null @@ -1,74 +0,0 @@ -using System.Linq; -using System.Threading.Tasks; -using Mewdeko.Services.Common; -using NUnit.Framework; - -namespace Mewdeko.Tests; - -public class GroupGreetTests -{ - private GreetGrouper grouper; - - [SetUp] - public void Setup() - => grouper = new GreetGrouper(); - - [Test] - public void CreateTest() - { - var created = grouper.CreateOrAdd(0, 5); - - Assert.True(created); - } - - [Test] - public void CreateClearTest() - { - grouper.CreateOrAdd(0, 5); - grouper.ClearGroup(0, 5, out var items); - - Assert.AreEqual(0, items.Count()); - } - - [Test] - public void NotCreatedTest() - { - grouper.CreateOrAdd(0, 5); - var created = grouper.CreateOrAdd(0, 4); - - Assert.False(created); - } - - [Test] - public void ClearAddedTest() - { - grouper.CreateOrAdd(0, 5); - grouper.CreateOrAdd(0, 4); - grouper.ClearGroup(0, 5, out var items); - - var list = items.ToList(); - - Assert.AreEqual(1, list.Count, $"Count was {list.Count}"); - Assert.AreEqual(4, list[0]); - } - - [Test] - public async Task ClearManyTest() - { - grouper.CreateOrAdd(0, 5); - - // add 15 items - await Task.WhenAll(Enumerable.Range(10, 15) - .Select(x => Task.Run(() => grouper.CreateOrAdd(0, x)))).ConfigureAwait(false); - - // get 5 at most - grouper.ClearGroup(0, 5, out var items); - var list = items.ToList(); - Assert.AreEqual(5, list.Count, $"Count was {list.Count}"); - - // try to get 15, but there should be 10 left - grouper.ClearGroup(0, 15, out items); - list = items.ToList(); - Assert.AreEqual(10, list.Count, $"Count was {list.Count}"); - } -} \ No newline at end of file diff --git a/src/Mewdeko.Tests/IndexedCollectionTests.cs b/src/Mewdeko.Tests/IndexedCollectionTests.cs deleted file mode 100644 index d26f9bba0..000000000 --- a/src/Mewdeko.Tests/IndexedCollectionTests.cs +++ /dev/null @@ -1,218 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using Mewdeko.Database.Common; -using Mewdeko.Database.Models; -using NUnit.Framework; - -namespace Mewdeko.Tests; - -public class IndexedCollectionTests -{ - [Test] - public void AddTest() - { - var collection = GetCollectionSample(Enumerable.Empty()); - - // Add the items - for (var counter = 0; counter < 10; counter++) - collection.Add(new ShopEntry()); - - // Evaluate the items are ordered - CheckIndices(collection); - } - - [Test] - public void RemoveTest() - { - var collection = GetCollectionSample(); - - collection.Remove(collection[1]); - collection.Remove(collection[1]); - - // Evaluate the indices are ordered - CheckIndices(collection); - Assert.AreEqual(8, collection.Count); - } - - [Test] - public void RemoveAtTest() - { - var collection = GetCollectionSample(); - - // Remove items 5 and 7 - collection.RemoveAt(5); - collection.RemoveAt(6); - - // Evaluate if the items got removed - foreach (var item in collection) - Assert.IsFalse(item.Id == 5 || item.Id == 7, $"Item at index {item.Index} was not removed"); - - CheckIndices(collection); - - // RemoveAt out of range - Assert.Throws(() => collection.RemoveAt(999), $"No exception thrown when removing from index 999 in a collection of size {collection.Count}."); - Assert.Throws(() => collection.RemoveAt(-3), "No exception thrown when removing from negative index -3."); - } - - [Test] - public void ClearTest() - { - var collection = GetCollectionSample(); - collection.Clear(); - - Assert.IsTrue(collection.Count == 0, "Collection has not been cleared."); - // ReSharper disable once ReturnValueOfPureMethodIsNotUsed - _ = Assert.Throws(() => collection.Contains(collection[0]), "Collection has not been cleared."); - } - - [Test] - public void CopyToTest() - { - var collection = GetCollectionSample(); - var fullCopy = new ShopEntry[10]; - - collection.CopyTo(fullCopy, 0); - - // Evaluate copy - for (var index = 0; index < fullCopy.Length; index++) - Assert.AreEqual(index, fullCopy[index].Index); - - Assert.Throws(() => collection.CopyTo(new ShopEntry[10], 4)); - Assert.Throws(() => collection.CopyTo(new ShopEntry[6], 0)); - } - - [Test] - public void IndexOfTest() - { - var collection = GetCollectionSample(); - - Assert.AreEqual(4, collection.IndexOf(collection[4])); - Assert.AreEqual(0, collection.IndexOf(collection[0])); - Assert.AreEqual(7, collection.IndexOf(collection[7])); - Assert.AreEqual(9, collection.IndexOf(collection[9])); - } - - [Test] - public void InsertTest() - { - var collection = GetCollectionSample(); - - // Insert items at indices 5 and 7 - collection.Insert(5, new ShopEntry - { - Id = 555 - }); - collection.Insert(7, new ShopEntry - { - Id = 777 - }); - - Assert.AreEqual(12, collection.Count); - Assert.AreEqual(555, collection[5].Id); - Assert.AreEqual(777, collection[7].Id); - - CheckIndices(collection); - - // Insert out of range - Assert.Throws(() => collection.Insert(999, new ShopEntry - { - Id = 999 - }), $"No exception thrown when inserting at index 999 in a collection of size {collection.Count}."); - Assert.Throws(() => collection.Insert(-3, new ShopEntry - { - Id = -3 - }), "No exception thrown when inserting at negative index -3."); - } - - [Test] - public void ContainsTest() - { - var subCol = new[] - { - new ShopEntry - { - Id = 111 - }, - new ShopEntry - { - Id = 222 - }, - new ShopEntry - { - Id = 333 - } - }; - - var collection = GetCollectionSample( - Enumerable.Range(0, 10) - .Select(x => new ShopEntry - { - Id = x - }) - .Concat(subCol) - ); - - collection.Remove(subCol[1]); - CheckIndices(collection); - - Assert.IsTrue(collection.Contains(subCol[0])); - Assert.IsFalse(collection.Contains(subCol[1])); - Assert.IsTrue(collection.Contains(subCol[2])); - } - - [Test] - public void EnumeratorTest() - { - var collection = GetCollectionSample(); - using var enumerator = collection.GetEnumerator(); - - foreach (var item in collection) - { - enumerator.MoveNext(); - Assert.AreEqual(item, enumerator.Current); - } - } - - [Test] - public void IndexTest() - { - var collection = GetCollectionSample(); - - collection[4] = new ShopEntry - { - Id = 444 - }; - collection[7] = new ShopEntry - { - Id = 777 - }; - CheckIndices(collection); - - Assert.AreEqual(444, collection[4].Id); - Assert.AreEqual(777, collection[7].Id); - } - - /// - /// Checks whether all indices of the items are properly ordered. - /// - /// An indexed, reference type. - /// The indexed collection to be checked. - private static void CheckIndices(IndexedCollection collection) where T : class, IIndexed - { - for (var index = 0; index < collection.Count; index++) - Assert.AreEqual(index, collection[index].Index); - } - - /// - /// Gets an from the specified or a collection with 10 shop entries if none is provided. - /// - /// An indexed, database entity type. - /// A sample collection to be added as an indexed collection. - /// An indexed collection of . - private static IndexedCollection GetCollectionSample(IEnumerable sample = default) where T : DbEntity, IIndexed, new() - => new(sample ?? Enumerable.Range(0, 10).Select(x => new T - { - Id = x - })); -} \ No newline at end of file diff --git a/src/Mewdeko.Tests/Mewdeko.Tests.csproj b/src/Mewdeko.Tests/Mewdeko.Tests.csproj index cf66946f0..983ac36c7 100644 --- a/src/Mewdeko.Tests/Mewdeko.Tests.csproj +++ b/src/Mewdeko.Tests/Mewdeko.Tests.csproj @@ -8,12 +8,10 @@ - - - - - - + + + + diff --git a/src/Mewdeko.Tests/PubSubTests.cs b/src/Mewdeko.Tests/PubSubTests.cs deleted file mode 100644 index cc3ba649c..000000000 --- a/src/Mewdeko.Tests/PubSubTests.cs +++ /dev/null @@ -1,135 +0,0 @@ -using System.Threading.Tasks; -using Mewdeko.Common.PubSub; -using NUnit.Framework; -using NUnit.Framework.Internal; - -namespace Mewdeko.Tests; - -public class PubSubTests -{ - [Test] - public async Task Test_EventPubSub_PubSub() - { - TypedKey key = "test_key"; - var expected = new Randomizer().Next(); - var pubsub = new EventPubSub(); - await pubsub.Sub(key, data => - { - Assert.AreEqual(expected, data); - Assert.Pass(); - return default; - }).ConfigureAwait(false); - await pubsub.Pub(key, expected).ConfigureAwait(false); - Assert.Fail("Event not registered"); - } - - [Test] - public async Task Test_EventPubSub_MeaninglessUnsub() - { - TypedKey key = "test_key"; - var expected = new Randomizer().Next(); - var pubsub = new EventPubSub(); - await pubsub.Sub(key, data => - { - Assert.AreEqual(expected, data); - Assert.Pass(); - return default; - }).ConfigureAwait(false); - await pubsub.Unsub(key, _ => default).ConfigureAwait(false); - await pubsub.Pub(key, expected).ConfigureAwait(false); - Assert.Fail("Event not registered"); - } - - [Test] - public async Task Test_EventPubSub_MeaninglessUnsubThatLooksTheSame() - { - TypedKey key = "test_key"; - var expected = new Randomizer().Next(); - var pubsub = new EventPubSub(); - await pubsub.Sub(key, data => - { - Assert.AreEqual(expected, data); - Assert.Pass(); - return default; - }).ConfigureAwait(false); - await pubsub.Unsub(key, data => - { - Assert.AreEqual(expected, data); - Assert.Pass(); - return default; - }).ConfigureAwait(false); - await pubsub.Pub(key, expected).ConfigureAwait(false); - Assert.Fail("Event not registered"); - } - - [Test] - public async Task Test_EventPubSub_MeaningfullUnsub() - { - TypedKey key = "test_key"; - var pubsub = new EventPubSub(); - - ValueTask Action(int data) - { - Assert.Fail("Event is raised when it shouldn't be"); - return default; - } - - await pubsub.Sub(key, Action).ConfigureAwait(false); - await pubsub.Unsub(key, Action).ConfigureAwait(false); - await pubsub.Pub(key, 0).ConfigureAwait(false); - Assert.Pass(); - } - - [Test] - public async Task Test_EventPubSub_ObjectData() - { - TypedKey key = "test_key"; - var pubsub = new EventPubSub(); - - var localData = new byte[1]; - - ValueTask Action(byte[] data) - { - Assert.AreEqual(localData, data); - Assert.Pass(); - return default; - } - - await pubsub.Sub(key, Action).ConfigureAwait(false); - await pubsub.Pub(key, localData).ConfigureAwait(false); - - Assert.Fail("Event not raised"); - } - - [Test] - public async Task Test_EventPubSub_MultiSubUnsub() - { - TypedKey key = "test_key"; - var pubsub = new EventPubSub(); - - var localData = new object(); - var successCounter = 0; - - ValueTask Action1(object data) - { - Assert.AreEqual(localData, data); - successCounter += 10; - return default; - } - - ValueTask Action2(object data) - { - Assert.AreEqual(localData, data); - successCounter++; - return default; - } - - await pubsub.Sub(key, Action1).ConfigureAwait(false); // + 10 \ - await pubsub.Sub(key, Action2).ConfigureAwait(false); // + 1 - + = 12 - await pubsub.Sub(key, Action2).ConfigureAwait(false); // + 1 / - await pubsub.Unsub(key, Action2).ConfigureAwait(false); // - 1/ - await pubsub.Pub(key, localData).ConfigureAwait(false); - - Assert.AreEqual(successCounter, 11, "Not all events are raised."); - } -} \ No newline at end of file diff --git a/src/Mewdeko.Tests/Random.cs b/src/Mewdeko.Tests/Random.cs deleted file mode 100644 index 722e6627a..000000000 --- a/src/Mewdeko.Tests/Random.cs +++ /dev/null @@ -1,22 +0,0 @@ -using System; -using System.Text; -using Mewdeko.Common.Yml; -using NUnit.Framework; - -namespace Mewdeko.Tests; - -public class RandomTests -{ - [SetUp] - public void Setup() - => Console.OutputEncoding = Encoding.UTF8; - - [Test] - public void Utf8CodepointsToEmoji() - { - const string point = @"0001F338"; - var hopefullyEmoji = YamlHelper.UnescapeUnicodeCodePoint(point); - - Assert.AreEqual("🌸", hopefullyEmoji, hopefullyEmoji); - } -} \ No newline at end of file diff --git a/src/Mewdeko.Votes/Mewdeko.Votes.csproj b/src/Mewdeko.Votes/Mewdeko.Votes.csproj index 32ae3df82..9d995eb5d 100644 --- a/src/Mewdeko.Votes/Mewdeko.Votes.csproj +++ b/src/Mewdeko.Votes/Mewdeko.Votes.csproj @@ -8,9 +8,9 @@ - - - + + + diff --git a/src/Mewdeko/Mewdeko.csproj b/src/Mewdeko/Mewdeko.csproj index 434cf1e96..7c2a732bb 100644 --- a/src/Mewdeko/Mewdeko.csproj +++ b/src/Mewdeko/Mewdeko.csproj @@ -31,90 +31,90 @@ - - - - - + + + + + - - - + + + - + - + - + - - - + + + all runtime; build; native; contentfiles; analyzers; buildtransitive - + - - - - + + + + all runtime; build; native; contentfiles; analyzers; buildtransitive - - + + all runtime; build; native; contentfiles; analyzers; buildtransitive - - - - - - - - - + + + + + + + + + - - + + - + - - - + + + - - - - + + + + - + - - - + + + diff --git a/src/Mewdeko/Modules/Giveaways/SlashGiveaways.cs b/src/Mewdeko/Modules/Giveaways/SlashGiveaways.cs index 576be9fe8..8f926fc3a 100644 --- a/src/Mewdeko/Modules/Giveaways/SlashGiveaways.cs +++ b/src/Mewdeko/Modules/Giveaways/SlashGiveaways.cs @@ -3,7 +3,6 @@ using Fergun.Interactive.Pagination; using Mewdeko.Common.Attributes.InteractionCommands; using Mewdeko.Modules.Giveaways.Services; -using SkiaSharp; namespace Mewdeko.Modules.Giveaways; @@ -11,6 +10,34 @@ namespace Mewdeko.Modules.Giveaways; public class SlashGiveaways(DbService db, InteractiveService interactiveService, GuildSettingsService guildSettings) : MewdekoSlashModuleBase { + [SlashCommand("emote", "Set the giveaway emote!"), SlashUserPerm(GuildPermission.ManageMessages), CheckPermissions] + public async Task GEmote(string maybeEmote) + { + await DeferAsync().ConfigureAwait(false); + var emote = maybeEmote.ToIEmote(); + if (emote.Name == null) + { + await ctx.Interaction.SendErrorFollowupAsync("That emote is invalid!").ConfigureAwait(false); + return; + } + + try + { + var message = await ctx.Interaction.SendConfirmFollowupAsync("Checking emote...").ConfigureAwait(false); + await message.AddReactionAsync(emote).ConfigureAwait(false); + } + catch + { + await ctx.Interaction.SendErrorFollowupAsync( + "I'm unable to use that emote for giveaways! Most likely because I'm not in a server with it.").ConfigureAwait(false); + return; + } + + await Service.SetGiveawayEmote(ctx.Guild, emote.ToString()).ConfigureAwait(false); + await ctx.Interaction.SendConfirmFollowupAsync( + $"Giveaway emote set to {emote}! Just keep in mind this doesn't update until the next giveaway.").ConfigureAwait(false); + } + [SlashCommand("banner", "Allows you to set a banner for giveaways!"), SlashUserPerm(GuildPermission.ManageMessages)] public async Task GBanner(string banner) { @@ -29,55 +56,37 @@ public async Task GBanner(string banner) await ctx.Interaction.SendConfirmAsync("Giveaway banner set!").ConfigureAwait(false); } - [SlashCommand("winembedcolor", "Allows you to set the win embed color!"), - SlashUserPerm(GuildPermission.ManageMessages)] + [SlashCommand("winembedcolor", "Allows you to set the win embed color!"), SlashUserPerm(GuildPermission.ManageMessages)] public async Task GWinEmbedColor(string color) { - var colorVal = StringExtensions.GetHexFromColorName(color); - if (color.StartsWith("#")) - { - if (SKColor.TryParse(color, out _)) - colorVal = color; - } - - if (colorVal is not null) + if (SixLabors.ImageSharp.Color.TryParse(color, out _)) { var gc = await guildSettings.GetGuildConfig(Context.Guild.Id); - gc.GiveawayEmbedColor = colorVal; + gc.GiveawayWinEmbedColor = color; await guildSettings.UpdateGuildConfig(Context.Guild.Id, gc); await ctx.Interaction.SendConfirmAsync( - $"Giveaway win embed color set! Just keep in mind this doesn't update until the next giveaway.") - .ConfigureAwait(false); + $"Giveaway win embed color set! Just keep in mind this doesn't update until the next giveaway.").ConfigureAwait(false); } else { - await ctx.Interaction.SendErrorAsync("That's not a valid color! Please use hex.").ConfigureAwait(false); + await ctx.Interaction.SendErrorAsync("That's not a valid color!").ConfigureAwait(false); } } - [SlashCommand("embedcolor", "Allows you to set the regular embed color!"), - SlashUserPerm(GuildPermission.ManageMessages)] + [SlashCommand("embedcolor", "Allows you to set the regular embed color!"), SlashUserPerm(GuildPermission.ManageMessages)] public async Task GEmbedColor(string color) { - var colorVal = StringExtensions.GetHexFromColorName(color); - if (color.StartsWith("#")) - { - if (SKColor.TryParse(color, out _)) - colorVal = color; - } - - if (colorVal is not null) + if (SixLabors.ImageSharp.Color.TryParse(color, out _)) { var gc = await guildSettings.GetGuildConfig(Context.Guild.Id); - gc.GiveawayEmbedColor = colorVal; + gc.GiveawayEmbedColor = color; await guildSettings.UpdateGuildConfig(Context.Guild.Id, gc); await ctx.Interaction.SendConfirmAsync( - $"Giveaway embed color set! Just keep in mind this doesn't update until the next giveaway.") - .ConfigureAwait(false); + $"Giveaway embed color set! Just keep in mind this doesn't update until the next giveaway.").ConfigureAwait(false); } else { - await ctx.Interaction.SendErrorAsync("That's not a valid color! Please use hex.").ConfigureAwait(false); + await ctx.Interaction.SendErrorAsync("That's not a valid color!").ConfigureAwait(false); } } @@ -85,41 +94,10 @@ await ctx.Interaction.SendConfirmAsync( public async Task GDm() { var gc = await guildSettings.GetGuildConfig(Context.Guild.Id); - gc.DmOnGiveawayWin = gc.DmOnGiveawayWin == 0 ? 1 : 0; + gc.DmOnGiveawayWin = gc.DmOnGiveawayWin == 1 ? 0 : 1; await guildSettings.UpdateGuildConfig(Context.Guild.Id, gc); await ctx.Interaction.SendConfirmAsync( - $"Giveaway DMs set to {gc.DmOnGiveawayWin == 1}! Just keep in mind this doesn't update until the next giveaway.") - .ConfigureAwait(false); - } - - [SlashCommand("emote", "Set the giveaway emote!"), SlashUserPerm(GuildPermission.ManageMessages), CheckPermissions] - public async Task GEmote(string maybeEmote) - { - await DeferAsync().ConfigureAwait(false); - var emote = maybeEmote.ToIEmote(); - if (emote.Name == null) - { - await ctx.Interaction.SendErrorFollowupAsync("That emote is invalid!").ConfigureAwait(false); - return; - } - - try - { - var message = await ctx.Interaction.SendConfirmFollowupAsync("Checking emote...").ConfigureAwait(false); - await message.AddReactionAsync(emote).ConfigureAwait(false); - } - catch - { - await ctx.Interaction.SendErrorFollowupAsync( - "I'm unable to use that emote for giveaways! Most likely because I'm not in a server with it.") - .ConfigureAwait(false); - return; - } - - await Service.SetGiveawayEmote(ctx.Guild, emote.ToString()).ConfigureAwait(false); - await ctx.Interaction.SendConfirmFollowupAsync( - $"Giveaway emote set to {emote}! Just keep in mind this doesn't update until the next giveaway.") - .ConfigureAwait(false); + $"Giveaway DMs set to {gc.DmOnGiveawayWin}! Just keep in mind this doesn't update until the next giveaway.").ConfigureAwait(false); } [SlashCommand("reroll", "Rerolls a giveaway!"), SlashUserPerm(GuildPermission.ManageMessages), CheckPermissions] @@ -130,8 +108,7 @@ public async Task GReroll(ulong messageid) .GiveawaysForGuild(ctx.Guild.Id).ToList().Find(x => x.MessageId == messageid); if (gway is null) { - await ctx.Interaction.SendErrorAsync("No Giveaway with that message ID exists! Please try again!") - .ConfigureAwait(false); + await ctx.Interaction.SendErrorAsync("No Giveaway with that message ID exists! Please try again!").ConfigureAwait(false); return; } @@ -179,8 +156,9 @@ public async Task GStats() } [SlashCommand("start", "Start a giveaway!"), SlashUserPerm(GuildPermission.ManageMessages), CheckPermissions] - public async Task GStart(ITextChannel chan, TimeSpan time, int winners, string what) + public async Task GStart(ITextChannel chan, TimeSpan time, int winners, string what, IRole pingRole = null, IAttachment attachment = null, IUser host = null) { + host ??= ctx.User; await ctx.Interaction.DeferAsync().ConfigureAwait(false); var emote = (await Service.GetGiveawayEmote(ctx.Guild.Id)).ToIEmote(); try @@ -191,8 +169,7 @@ public async Task GStart(ITextChannel chan, TimeSpan time, int winners, string w catch { await ctx.Interaction.SendErrorFollowupAsync( - "I'm unable to use that emote for giveaways! Most likely because I'm not in a server with it.") - .ConfigureAwait(false); + "I'm unable to use that emote for giveaways! Most likely because I'm not in a server with it.").ConfigureAwait(false); return; } @@ -200,8 +177,7 @@ await ctx.Interaction.SendErrorFollowupAsync( var perms = user.GetPermissions(chan); if (!perms.Has(ChannelPermission.AddReactions)) { - await ctx.Interaction.SendErrorFollowupAsync("I cannot add reactions in that channel!") - .ConfigureAwait(false); + await ctx.Interaction.SendErrorFollowupAsync("I cannot add reactions in that channel!").ConfigureAwait(false); return; } @@ -211,8 +187,8 @@ await ctx.Interaction.SendErrorFollowupAsync("I cannot add reactions in that cha return; } - await Service.GiveawaysInternal(chan, time, what, winners, ctx.User.Id, ctx.Guild.Id, - ctx.Channel as ITextChannel, ctx.Guild).ConfigureAwait(false); + await Service.GiveawaysInternal(chan, time, what, winners, host.Id, ctx.Guild.Id, + ctx.Channel as ITextChannel, ctx.Guild, banner: attachment?.Url, pingROle: pingRole).ConfigureAwait(false); } [SlashCommand("list", "View current giveaways!"), SlashUserPerm(GuildPermission.ManageMessages), CheckPermissions] @@ -243,8 +219,7 @@ async Task PageFactory(int page) return new PageBuilder().WithOkColor().WithTitle($"{gways.Count()} Active Giveaways") .WithDescription(string.Join("\n\n", await gways.Skip(page * 5).Take(5).Select(async x => - $"{x.MessageId}\nPrize: {x.Item}\nWinners: {x.Winners}\nLink: {await GetJumpUrl(x.ChannelId, x.MessageId).ConfigureAwait(false)}") - .GetResults() + $"{x.MessageId}\nPrize: {x.Item}\nWinners: {x.Winners}\nLink: {await GetJumpUrl(x.ChannelId, x.MessageId).ConfigureAwait(false)}").GetResults() .ConfigureAwait(false))); } } @@ -256,8 +231,7 @@ private async Task GetJumpUrl(ulong channelId, ulong messageId) return message.GetJumpUrl(); } - [SlashCommand("end", "End a giveaway!"), RequireContext(ContextType.Guild), - SlashUserPerm(GuildPermission.ManageMessages), CheckPermissions] + [SlashCommand("end", "End a giveaway!"), RequireContext(ContextType.Guild), SlashUserPerm(GuildPermission.ManageMessages), CheckPermissions] public async Task GEnd(ulong messageid) { await using var uow = db.GetDbContext(); @@ -265,15 +239,13 @@ public async Task GEnd(ulong messageid) .GiveawaysForGuild(ctx.Guild.Id).ToList().Find(x => x.MessageId == messageid); if (gway is null) { - await ctx.Channel.SendErrorAsync("No Giveaway with that message ID exists! Please try again!") - .ConfigureAwait(false); + await ctx.Channel.SendErrorAsync("No Giveaway with that message ID exists! Please try again!").ConfigureAwait(false); } if (gway.Ended == 1) { await ctx.Channel.SendErrorAsync( - $"This giveaway has already ended! Plase use `{await guildSettings.GetPrefix(ctx.Guild)}greroll {messageid}` to reroll!") - .ConfigureAwait(false); + $"This giveaway has already ended! Plase use `{await guildSettings.GetPrefix(ctx.Guild)}greroll {messageid}` to reroll!").ConfigureAwait(false); } else { diff --git a/src/Mewdeko/Services/IGoogleApiService.cs b/src/Mewdeko/Services/IGoogleApiService.cs index 7ee8635bf..b588b0809 100644 --- a/src/Mewdeko/Services/IGoogleApiService.cs +++ b/src/Mewdeko/Services/IGoogleApiService.cs @@ -9,5 +9,4 @@ public interface IGoogleApiService : INService Task GetVideoLinksByKeywordAsync(string keywords); Task ShortenUrl(string url); - Task GetVideoLinksByVideoId(string id, int max); } \ No newline at end of file diff --git a/src/Mewdeko/Services/Impl/GoogleApiService.cs b/src/Mewdeko/Services/Impl/GoogleApiService.cs index 0e44c4170..2951dd8d3 100644 --- a/src/Mewdeko/Services/Impl/GoogleApiService.cs +++ b/src/Mewdeko/Services/Impl/GoogleApiService.cs @@ -440,20 +440,6 @@ public async Task GetVideoLinksByKeywordAsync(string keywords) return (await query.ExecuteAsync().ConfigureAwait(false)).Items.ToArray(); } - public async Task GetVideoLinksByVideoId(string keywords, int max) - { - await Task.Yield(); - if (string.IsNullOrWhiteSpace(keywords)) - throw new ArgumentNullException(nameof(keywords)); - - var query = yt.Search.List("snippet"); - query.MaxResults = max; - query.Type = "video"; - query.RelatedToVideoId = keywords; - query.SafeSearch = SearchResource.ListRequest.SafeSearchEnum.Strict; - - return (await query.ExecuteAsync().ConfigureAwait(false)).Items.ToArray(); - } public async Task ShortenUrl(string url)