diff --git a/src/NadekoBot/DataStructures/AsyncLazy.cs b/src/NadekoBot/Common/AsyncLazy.cs similarity index 100% rename from src/NadekoBot/DataStructures/AsyncLazy.cs rename to src/NadekoBot/Common/AsyncLazy.cs diff --git a/src/NadekoBot/DataStructures/CREmbed.cs b/src/NadekoBot/Common/CREmbed.cs similarity index 100% rename from src/NadekoBot/DataStructures/CREmbed.cs rename to src/NadekoBot/Common/CREmbed.cs diff --git a/src/NadekoBot/DataStructures/ConcurrentHashSet.cs b/src/NadekoBot/Common/ConcurrentHashSet.cs similarity index 100% rename from src/NadekoBot/DataStructures/ConcurrentHashSet.cs rename to src/NadekoBot/Common/ConcurrentHashSet.cs diff --git a/src/NadekoBot/DataStructures/DisposableImutableList.cs b/src/NadekoBot/Common/DisposableImutableList.cs similarity index 100% rename from src/NadekoBot/DataStructures/DisposableImutableList.cs rename to src/NadekoBot/Common/DisposableImutableList.cs diff --git a/src/NadekoBot/DataStructures/IndexedCollection.cs b/src/NadekoBot/Common/IndexedCollection.cs similarity index 100% rename from src/NadekoBot/DataStructures/IndexedCollection.cs rename to src/NadekoBot/Common/IndexedCollection.cs diff --git a/src/NadekoBot/DataStructures/ModuleBehaviors/IEarlyBlocker.cs b/src/NadekoBot/Common/ModuleBehaviors/IEarlyBlocker.cs similarity index 100% rename from src/NadekoBot/DataStructures/ModuleBehaviors/IEarlyBlocker.cs rename to src/NadekoBot/Common/ModuleBehaviors/IEarlyBlocker.cs diff --git a/src/NadekoBot/DataStructures/ModuleBehaviors/IEarlyBlockingExecutor.cs b/src/NadekoBot/Common/ModuleBehaviors/IEarlyBlockingExecutor.cs similarity index 100% rename from src/NadekoBot/DataStructures/ModuleBehaviors/IEarlyBlockingExecutor.cs rename to src/NadekoBot/Common/ModuleBehaviors/IEarlyBlockingExecutor.cs diff --git a/src/NadekoBot/DataStructures/ModuleBehaviors/IEarlyExecutor.cs b/src/NadekoBot/Common/ModuleBehaviors/IEarlyExecutor.cs similarity index 100% rename from src/NadekoBot/DataStructures/ModuleBehaviors/IEarlyExecutor.cs rename to src/NadekoBot/Common/ModuleBehaviors/IEarlyExecutor.cs diff --git a/src/NadekoBot/DataStructures/ModuleBehaviors/IINputTransformer.cs b/src/NadekoBot/Common/ModuleBehaviors/IINputTransformer.cs similarity index 100% rename from src/NadekoBot/DataStructures/ModuleBehaviors/IINputTransformer.cs rename to src/NadekoBot/Common/ModuleBehaviors/IINputTransformer.cs diff --git a/src/NadekoBot/DataStructures/ModuleBehaviors/ILateBlocker.cs b/src/NadekoBot/Common/ModuleBehaviors/ILateBlocker.cs similarity index 100% rename from src/NadekoBot/DataStructures/ModuleBehaviors/ILateBlocker.cs rename to src/NadekoBot/Common/ModuleBehaviors/ILateBlocker.cs diff --git a/src/NadekoBot/DataStructures/ModuleBehaviors/ILateBlockingExecutor.cs b/src/NadekoBot/Common/ModuleBehaviors/ILateBlockingExecutor.cs similarity index 100% rename from src/NadekoBot/DataStructures/ModuleBehaviors/ILateBlockingExecutor.cs rename to src/NadekoBot/Common/ModuleBehaviors/ILateBlockingExecutor.cs diff --git a/src/NadekoBot/DataStructures/ModuleBehaviors/ILateExecutor.cs b/src/NadekoBot/Common/ModuleBehaviors/ILateExecutor.cs similarity index 100% rename from src/NadekoBot/DataStructures/ModuleBehaviors/ILateExecutor.cs rename to src/NadekoBot/Common/ModuleBehaviors/ILateExecutor.cs diff --git a/src/NadekoBot/DataStructures/NadekoRandom.cs b/src/NadekoBot/Common/NadekoRandom.cs similarity index 100% rename from src/NadekoBot/DataStructures/NadekoRandom.cs rename to src/NadekoBot/Common/NadekoRandom.cs diff --git a/src/NadekoBot/DataStructures/NoPublicBotPrecondition.cs b/src/NadekoBot/Common/NoPublicBotPrecondition.cs similarity index 100% rename from src/NadekoBot/DataStructures/NoPublicBotPrecondition.cs rename to src/NadekoBot/Common/NoPublicBotPrecondition.cs diff --git a/src/NadekoBot/DataStructures/PermissionAction.cs b/src/NadekoBot/Common/PermissionAction.cs similarity index 100% rename from src/NadekoBot/DataStructures/PermissionAction.cs rename to src/NadekoBot/Common/PermissionAction.cs diff --git a/src/NadekoBot/DataStructures/PlatformHelper.cs b/src/NadekoBot/Common/PlatformHelper.cs similarity index 100% rename from src/NadekoBot/DataStructures/PlatformHelper.cs rename to src/NadekoBot/Common/PlatformHelper.cs diff --git a/src/NadekoBot/DataStructures/PoopyRingBuffer.cs b/src/NadekoBot/Common/PoopyRingBuffer.cs similarity index 100% rename from src/NadekoBot/DataStructures/PoopyRingBuffer.cs rename to src/NadekoBot/Common/PoopyRingBuffer.cs diff --git a/src/NadekoBot/DataStructures/Replacements/ReplacementBuilder.cs b/src/NadekoBot/Common/Replacements/ReplacementBuilder.cs similarity index 99% rename from src/NadekoBot/DataStructures/Replacements/ReplacementBuilder.cs rename to src/NadekoBot/Common/Replacements/ReplacementBuilder.cs index 0dc367a6..0be7516d 100644 --- a/src/NadekoBot/DataStructures/Replacements/ReplacementBuilder.cs +++ b/src/NadekoBot/Common/Replacements/ReplacementBuilder.cs @@ -2,9 +2,9 @@ using Discord.Commands; using Discord.WebSocket; using NadekoBot.Extensions; +using NadekoBot.Modules.Music.Services; using NadekoBot.Services; using NadekoBot.Services.Administration; -using NadekoBot.Services.Music; using System; using System.Collections.Concurrent; using System.Linq; diff --git a/src/NadekoBot/DataStructures/Replacements/Replacer.cs b/src/NadekoBot/Common/Replacements/Replacer.cs similarity index 100% rename from src/NadekoBot/DataStructures/Replacements/Replacer.cs rename to src/NadekoBot/Common/Replacements/Replacer.cs diff --git a/src/NadekoBot/DataStructures/SearchImageCacher.cs b/src/NadekoBot/Common/SearchImageCacher.cs similarity index 100% rename from src/NadekoBot/DataStructures/SearchImageCacher.cs rename to src/NadekoBot/Common/SearchImageCacher.cs diff --git a/src/NadekoBot/DataStructures/Shard0Precondition.cs b/src/NadekoBot/Common/Shard0Precondition.cs similarity index 100% rename from src/NadekoBot/DataStructures/Shard0Precondition.cs rename to src/NadekoBot/Common/Shard0Precondition.cs diff --git a/src/NadekoBot/DataStructures/ShardCom/IShardComMessage.cs b/src/NadekoBot/Common/ShardCom/IShardComMessage.cs similarity index 100% rename from src/NadekoBot/DataStructures/ShardCom/IShardComMessage.cs rename to src/NadekoBot/Common/ShardCom/IShardComMessage.cs diff --git a/src/NadekoBot/DataStructures/ShardCom/ShardComClient.cs b/src/NadekoBot/Common/ShardCom/ShardComClient.cs similarity index 100% rename from src/NadekoBot/DataStructures/ShardCom/ShardComClient.cs rename to src/NadekoBot/Common/ShardCom/ShardComClient.cs diff --git a/src/NadekoBot/DataStructures/ShardCom/ShardComServer.cs b/src/NadekoBot/Common/ShardCom/ShardComServer.cs similarity index 100% rename from src/NadekoBot/DataStructures/ShardCom/ShardComServer.cs rename to src/NadekoBot/Common/ShardCom/ShardComServer.cs diff --git a/src/NadekoBot/DataStructures/SyncPrecondition.cs b/src/NadekoBot/Common/SyncPrecondition.cs similarity index 100% rename from src/NadekoBot/DataStructures/SyncPrecondition.cs rename to src/NadekoBot/Common/SyncPrecondition.cs diff --git a/src/NadekoBot/DataStructures/TypeReaders/BotCommandTypeReader.cs b/src/NadekoBot/Common/TypeReaders/BotCommandTypeReader.cs similarity index 98% rename from src/NadekoBot/DataStructures/TypeReaders/BotCommandTypeReader.cs rename to src/NadekoBot/Common/TypeReaders/BotCommandTypeReader.cs index d3e7b2c3..84c45c1f 100644 --- a/src/NadekoBot/DataStructures/TypeReaders/BotCommandTypeReader.cs +++ b/src/NadekoBot/Common/TypeReaders/BotCommandTypeReader.cs @@ -1,6 +1,6 @@ using Discord.Commands; +using NadekoBot.Modules.CustomReactions.Services; using NadekoBot.Services; -using NadekoBot.Services.CustomReactions; using System; using System.Linq; using System.Threading.Tasks; diff --git a/src/NadekoBot/DataStructures/TypeReaders/GuildDateTimeTypeReader.cs b/src/NadekoBot/Common/TypeReaders/GuildDateTimeTypeReader.cs similarity index 100% rename from src/NadekoBot/DataStructures/TypeReaders/GuildDateTimeTypeReader.cs rename to src/NadekoBot/Common/TypeReaders/GuildDateTimeTypeReader.cs diff --git a/src/NadekoBot/DataStructures/TypeReaders/GuildTypeReader.cs b/src/NadekoBot/Common/TypeReaders/GuildTypeReader.cs similarity index 100% rename from src/NadekoBot/DataStructures/TypeReaders/GuildTypeReader.cs rename to src/NadekoBot/Common/TypeReaders/GuildTypeReader.cs diff --git a/src/NadekoBot/DataStructures/TypeReaders/ModuleTypeReader.cs b/src/NadekoBot/Common/TypeReaders/ModuleTypeReader.cs similarity index 100% rename from src/NadekoBot/DataStructures/TypeReaders/ModuleTypeReader.cs rename to src/NadekoBot/Common/TypeReaders/ModuleTypeReader.cs diff --git a/src/NadekoBot/DataStructures/TypeReaders/PermissionActionTypeReader.cs b/src/NadekoBot/Common/TypeReaders/PermissionActionTypeReader.cs similarity index 100% rename from src/NadekoBot/DataStructures/TypeReaders/PermissionActionTypeReader.cs rename to src/NadekoBot/Common/TypeReaders/PermissionActionTypeReader.cs diff --git a/src/NadekoBot/Modules/Administration/Commands/SelfCommands.cs b/src/NadekoBot/Modules/Administration/Commands/SelfCommands.cs index 4e348f62..f669542c 100644 --- a/src/NadekoBot/Modules/Administration/Commands/SelfCommands.cs +++ b/src/NadekoBot/Modules/Administration/Commands/SelfCommands.cs @@ -14,7 +14,7 @@ using NadekoBot.Services.Database.Models; using Microsoft.EntityFrameworkCore; using NadekoBot.Services.Administration; using System.Diagnostics; -using NadekoBot.Services.Music; +using NadekoBot.Modules.Music.Services; namespace NadekoBot.Modules.Administration { diff --git a/src/NadekoBot/Modules/CustomReactions/CustomReactions.cs b/src/NadekoBot/Modules/CustomReactions/CustomReactions.cs index da99f55d..e4aa6e3c 100644 --- a/src/NadekoBot/Modules/CustomReactions/CustomReactions.cs +++ b/src/NadekoBot/Modules/CustomReactions/CustomReactions.cs @@ -8,7 +8,7 @@ using Discord; using NadekoBot.Extensions; using Discord.WebSocket; using System; -using NadekoBot.Services.CustomReactions; +using NadekoBot.Modules.CustomReactions.Services; namespace NadekoBot.Modules.CustomReactions { diff --git a/src/NadekoBot/Services/CustomReactions/Extensions.cs b/src/NadekoBot/Modules/CustomReactions/Extensions/Extensions.cs similarity index 96% rename from src/NadekoBot/Services/CustomReactions/Extensions.cs rename to src/NadekoBot/Modules/CustomReactions/Extensions/Extensions.cs index 351ac6d2..3e87ca37 100644 --- a/src/NadekoBot/Services/CustomReactions/Extensions.cs +++ b/src/NadekoBot/Modules/CustomReactions/Extensions/Extensions.cs @@ -5,6 +5,8 @@ using Discord.WebSocket; using NadekoBot.DataStructures; using NadekoBot.DataStructures.Replacements; using NadekoBot.Extensions; +using NadekoBot.Modules.CustomReactions.Services; +using NadekoBot.Services; using NadekoBot.Services.Database.Models; using System; using System.Collections.Generic; @@ -12,7 +14,7 @@ using System.Linq; using System.Text.RegularExpressions; using System.Threading.Tasks; -namespace NadekoBot.Services.CustomReactions +namespace NadekoBot.Modules.CustomReactions.Extensions { public static class Extensions { diff --git a/src/NadekoBot/Services/CustomReactions/CustomReactionsService.cs b/src/NadekoBot/Modules/CustomReactions/Services/CustomReactionsService.cs similarity index 97% rename from src/NadekoBot/Services/CustomReactions/CustomReactionsService.cs rename to src/NadekoBot/Modules/CustomReactions/Services/CustomReactionsService.cs index 2e068cde..b87d4145 100644 --- a/src/NadekoBot/Services/CustomReactions/CustomReactionsService.cs +++ b/src/NadekoBot/Modules/CustomReactions/Services/CustomReactionsService.cs @@ -4,15 +4,16 @@ using NadekoBot.DataStructures.ModuleBehaviors; using NadekoBot.Services.Database.Models; using NLog; using System.Collections.Concurrent; -using System.Diagnostics; using System.Linq; using System; using System.Threading.Tasks; using NadekoBot.Services.Permissions; using NadekoBot.Extensions; using NadekoBot.Services.Database; +using NadekoBot.Services; +using NadekoBot.Modules.CustomReactions.Extensions; -namespace NadekoBot.Services.CustomReactions +namespace NadekoBot.Modules.CustomReactions.Services { public class CustomReactionsService : IEarlyBlockingExecutor, INService { diff --git a/src/NadekoBot/Modules/Gambling/Commands/Lucky7Commands.cs b/src/NadekoBot/Modules/Gambling/Commands/Lucky7Commands.cs deleted file mode 100644 index 725fe7c0..00000000 --- a/src/NadekoBot/Modules/Gambling/Commands/Lucky7Commands.cs +++ /dev/null @@ -1,185 +0,0 @@ -namespace NadekoBot.Modules.Gambling -{ - //public partial class Gambling - //{ - // [Group] - // public class Lucky7Commands : NadekoSubmodule - // { - // [NadekoCommand, Usage, Description, Aliases] - // [RequireContext(ContextType.Guild)] - // [OwnerOnly] - // public async Task Lucky7Test(uint tests) - // { - // if (tests <= 0) - // return; - - // var dict = new Dictionary(); - // var totalWon = 0; - // for (var i = 0; i < tests; i++) - // { - // var g = new Lucky7Game(10); - // while (!g.Ended) - // { - // if (g.CurrentPosition == 0) - // g.Stay(); - // else - // g.Move(); - // } - // totalWon += (int)(g.CurrentMultiplier * g.Bet); - // if (!dict.ContainsKey(g.CurrentMultiplier)) - // dict.Add(g.CurrentMultiplier, 0); - - // dict[g.CurrentMultiplier] ++; - - // } - - // await Context.Channel.EmbedAsync(new EmbedBuilder().WithOkColor() - // .WithTitle("Move Or Stay test") - // .WithDescription(string.Join("\n", - // dict.Select(x => $"x{x.Key} occured {x.Value} times {x.Value * 1.0f / tests * 100:F2}%"))) - // .WithFooter( - // efb => efb.WithText($"Total Bet: {tests * 10} | Payout: {totalWon} | {totalWon *1.0f / tests * 10}%"))); - // } - - // private static readonly ConcurrentDictionary _games = - // new ConcurrentDictionary(); - - // [NadekoCommand, Usage, Description, Aliases] - // [RequireContext(ContextType.Guild)] - // public async Task Lucky7(int bet) - // { - // if (bet < 4) - // return; - // var game = new Lucky7Game(bet); - // if (!_games.TryAdd(Context.User.Id, game)) - // { - // await ReplyAsync("You're already betting on move or stay.").ConfigureAwait(false); - // return; - // } - - // if (!await CurrencyHandler.RemoveCurrencyAsync(Context.User, "MoveOrStay bet", bet, false)) - // { - // _games.TryRemove(Context.User.Id, out game); - // await ReplyConfirmLocalized("not_enough", CurrencySign).ConfigureAwait(false); - // return; - // } - // await Context.Channel.EmbedAsync(GetGameState(game), - // string.Format("{0} rolled {1}.", Context.User, game.Rolled)).ConfigureAwait(false); - // } - - // public enum MoveOrStay - // { - // Move = 1, - // M = 1, - // Stay = 2, - // S = 2 - // } - - // [NadekoCommand, Usage, Description, Aliases] - // [RequireContext(ContextType.Guild)] - // public async Task Lucky7(MoveOrStay action) - // { - // Lucky7Game game; - // if (!_games.TryGetValue(Context.User.Id, out game)) - // { - // await ReplyAsync("You're not betting on move or stay.").ConfigureAwait(false); - // return; - // } - - // if (action == MoveOrStay.Move) - // { - // game.Move(); - // await Context.Channel.EmbedAsync(GetGameState(game), - // string.Format("{0} rolled {1}.", Context.User, game.Rolled)).ConfigureAwait(false); - // if (game.Ended) - // _games.TryRemove(Context.User.Id, out game); - // } - // else if (action == MoveOrStay.Stay) - // { - // var won = game.Stay(); - // await CurrencyHandler.AddCurrencyAsync(Context.User, "MoveOrStay stay", won, false) - // .ConfigureAwait(false); - // _games.TryRemove(Context.User.Id, out game); - // await ReplyAsync(string.Format("You've finished with {0}", - // won + CurrencySign)) - // .ConfigureAwait(false); - // } - - - // } - - // private EmbedBuilder GetGameState(Lucky7Game game) - // { - // var arr = Lucky7Game.Winnings.ToArray(); - // var sb = new StringBuilder(); - // for (var i = 0; i < arr.Length; i++) - // { - // if (i == game.CurrentPosition) - // { - // sb.Append("[" + arr[i] + "]"); - // } - // else - // { - // sb.Append(arr[i].ToString()); - // } - - // if (i != arr.Length - 1) - // sb.Append(' '); - // } - - // return new EmbedBuilder().WithOkColor() - // .WithTitle("Lucky7") - // .WithDescription(sb.ToString()) - // .AddField(efb => efb.WithName("Bet") - // .WithValue(game.Bet.ToString()) - // .WithIsInline(true)) - // .AddField(efb => efb.WithName("Current Value") - // .WithValue((game.CurrentMultiplier * game.Bet).ToString(_cultureInfo)) - // .WithIsInline(true)); - // } - // } - - // public class Lucky7Game - // { - // public int Bet { get; } - // public bool Ended { get; private set; } - // public int PreviousPosition { get; private set; } - // public int CurrentPosition { get; private set; } = -1; - // public int Rolled { get; private set; } - // public float CurrentMultiplier => Winnings[CurrentPosition]; - // private readonly NadekoRandom _rng = new NadekoRandom(); - - // public static readonly ImmutableArray Winnings = new[] - // { - // 1.2f, 0.8f, 0.75f, 0.90f, 0.7f, 0.5f, 1.8f, 0f, 0f - // }.ToImmutableArray(); - - // public Lucky7Game(int bet) - // { - // Bet = bet; - // Move(); - // } - - // public void Move() - // { - // if (Ended) - // return; - // PreviousPosition = CurrentPosition; - // Rolled = _rng.Next(1, 4); - // CurrentPosition += Rolled; - - // if (CurrentPosition >= 6) - // Ended = true; - // } - - // public int Stay() - // { - // if (Ended) - // return 0; - - // Ended = true; - // return (int) (CurrentMultiplier * Bet); - // } - // } - //} -} diff --git a/src/NadekoBot/Modules/Help/Help.cs b/src/NadekoBot/Modules/Help/Help.cs index c492810d..2cd965cb 100644 --- a/src/NadekoBot/Modules/Help/Help.cs +++ b/src/NadekoBot/Modules/Help/Help.cs @@ -11,7 +11,7 @@ using System.Text; using System.Collections.Generic; using NadekoBot.Services.Database.Models; using NadekoBot.Services.Permissions; -using NadekoBot.Services.Help; +using NadekoBot.Modules.Help.Services; namespace NadekoBot.Modules.Help { diff --git a/src/NadekoBot/Services/Help/HelpService.cs b/src/NadekoBot/Modules/Help/Services/HelpService.cs similarity index 97% rename from src/NadekoBot/Services/Help/HelpService.cs rename to src/NadekoBot/Modules/Help/Services/HelpService.cs index b685a50b..0aba1425 100644 --- a/src/NadekoBot/Services/Help/HelpService.cs +++ b/src/NadekoBot/Modules/Help/Services/HelpService.cs @@ -8,8 +8,9 @@ using Discord.Commands; using NadekoBot.Extensions; using System.Linq; using NadekoBot.Attributes; +using NadekoBot.Services; -namespace NadekoBot.Services.Help +namespace NadekoBot.Modules.Help.Services { public class HelpService : ILateExecutor, INService { diff --git a/src/NadekoBot/Modules/Music/Common/Exceptions/NotInVoiceChannelException.cs b/src/NadekoBot/Modules/Music/Common/Exceptions/NotInVoiceChannelException.cs new file mode 100644 index 00000000..b4fbe8a4 --- /dev/null +++ b/src/NadekoBot/Modules/Music/Common/Exceptions/NotInVoiceChannelException.cs @@ -0,0 +1,14 @@ +using System; + +namespace NadekoBot.Modules.Music.Common.Exceptions +{ + // todo use this + public class NotInVoiceChannelException : Exception + { + public NotInVoiceChannelException(string message) : base(message) + { + } + + public NotInVoiceChannelException() : base("You're not in the voice channel on this server.") { } + } +} diff --git a/src/NadekoBot/Modules/Music/Common/Exceptions/QueueFullException.cs b/src/NadekoBot/Modules/Music/Common/Exceptions/QueueFullException.cs new file mode 100644 index 00000000..be92f09d --- /dev/null +++ b/src/NadekoBot/Modules/Music/Common/Exceptions/QueueFullException.cs @@ -0,0 +1,12 @@ +using System; + +namespace NadekoBot.Modules.Music.Common.Exceptions +{ + public class QueueFullException : Exception + { + public QueueFullException(string message) : base(message) + { + } + public QueueFullException() : base("Queue is full.") { } + } +} diff --git a/src/NadekoBot/Modules/Music/Common/Exceptions/SongNotFoundException.cs b/src/NadekoBot/Modules/Music/Common/Exceptions/SongNotFoundException.cs new file mode 100644 index 00000000..823d2776 --- /dev/null +++ b/src/NadekoBot/Modules/Music/Common/Exceptions/SongNotFoundException.cs @@ -0,0 +1,12 @@ +using System; + +namespace NadekoBot.Modules.Music.Common.Exceptions +{ + public class SongNotFoundException : Exception + { + public SongNotFoundException(string message) : base(message) + { + } + public SongNotFoundException() : base("Song is not found.") { } + } +} diff --git a/src/NadekoBot/Services/Music/MusicPlayer.cs b/src/NadekoBot/Modules/Music/Common/MusicPlayer.cs similarity index 98% rename from src/NadekoBot/Services/Music/MusicPlayer.cs rename to src/NadekoBot/Modules/Music/Common/MusicPlayer.cs index 8e47e984..e8411f43 100644 --- a/src/NadekoBot/Services/Music/MusicPlayer.cs +++ b/src/NadekoBot/Modules/Music/Common/MusicPlayer.cs @@ -8,8 +8,11 @@ using System.Linq; using System.Collections.Concurrent; using NadekoBot.Extensions; using System.Diagnostics; +using NadekoBot.Modules.Music.Services; +using NadekoBot.Services; +using NadekoBot.Services.Database.Models; -namespace NadekoBot.Services.Music +namespace NadekoBot.Modules.Music.Common { public enum StreamState { @@ -167,7 +170,7 @@ namespace NadekoBot.Services.Music SongBuffer b = null; try { - b = new SongBuffer(await data.Song.Uri(), "", data.Song.ProviderType == Database.Models.MusicType.Local); + b = new SongBuffer(await data.Song.Uri(), "", data.Song.ProviderType == MusicType.Local); //_log.Info("Created buffer, buffering..."); //var bufferTask = b.StartBuffering(cancelToken); @@ -270,7 +273,7 @@ namespace NadekoBot.Services.Music { //if last song, and autoplay is enabled, and if it's a youtube song // do autplay magix - if (queueCount - 1 == data.Index && Autoplay && data.Song?.ProviderType == Database.Models.MusicType.YouTube) + if (queueCount - 1 == data.Index && Autoplay && data.Song?.ProviderType == MusicType.YouTube) { try { @@ -614,7 +617,7 @@ namespace NadekoBot.Services.Music var sw = Stopwatch.StartNew(); var (_, songs) = Queue.ToArray(); var toUpdate = songs - .Where(x => x.ProviderType == Database.Models.MusicType.YouTube + .Where(x => x.ProviderType == MusicType.YouTube && x.TotalTime == TimeSpan.Zero); var vIds = toUpdate.Select(x => x.VideoId); diff --git a/src/NadekoBot/Services/Music/MusicQueue.cs b/src/NadekoBot/Modules/Music/Common/MusicQueue.cs similarity index 97% rename from src/NadekoBot/Services/Music/MusicQueue.cs rename to src/NadekoBot/Modules/Music/Common/MusicQueue.cs index 861765b3..7fa58a51 100644 --- a/src/NadekoBot/Services/Music/MusicQueue.cs +++ b/src/NadekoBot/Modules/Music/Common/MusicQueue.cs @@ -1,11 +1,13 @@ using NadekoBot.Extensions; +using NadekoBot.Modules.Music.Common.Exceptions; +using NadekoBot.Services; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; -namespace NadekoBot.Services.Music +namespace NadekoBot.Modules.Music.Common { public class MusicQueue : IDisposable { diff --git a/src/NadekoBot/Services/Music/SongBuffer.cs b/src/NadekoBot/Modules/Music/Common/SongBuffer.cs similarity index 99% rename from src/NadekoBot/Services/Music/SongBuffer.cs rename to src/NadekoBot/Modules/Music/Common/SongBuffer.cs index a9d30261..8f76be79 100644 --- a/src/NadekoBot/Services/Music/SongBuffer.cs +++ b/src/NadekoBot/Modules/Music/Common/SongBuffer.cs @@ -5,7 +5,7 @@ using System.IO; using System.Threading; using System.Threading.Tasks; -namespace NadekoBot.Services.Music +namespace NadekoBot.Modules.Music.Common { public class SongBuffer : IDisposable { diff --git a/src/NadekoBot/Services/Music/SongHandler.cs b/src/NadekoBot/Modules/Music/Common/SongHandler.cs similarity index 78% rename from src/NadekoBot/Services/Music/SongHandler.cs rename to src/NadekoBot/Modules/Music/Common/SongHandler.cs index f716196b..660ec8f8 100644 --- a/src/NadekoBot/Services/Music/SongHandler.cs +++ b/src/NadekoBot/Modules/Music/Common/SongHandler.cs @@ -1,6 +1,6 @@ using NLog; -namespace NadekoBot.Services.Music +namespace NadekoBot.Modules.Music.Common { public static class SongHandler { diff --git a/src/NadekoBot/Services/Music/SongInfo.cs b/src/NadekoBot/Modules/Music/Common/SongInfo.cs similarity index 98% rename from src/NadekoBot/Services/Music/SongInfo.cs rename to src/NadekoBot/Modules/Music/Common/SongInfo.cs index db4a65e7..c19f8057 100644 --- a/src/NadekoBot/Services/Music/SongInfo.cs +++ b/src/NadekoBot/Modules/Music/Common/SongInfo.cs @@ -6,7 +6,7 @@ using System.Net; using System.Text.RegularExpressions; using System.Threading.Tasks; -namespace NadekoBot.Services.Music +namespace NadekoBot.Modules.Music.Common { public class SongInfo { diff --git a/src/NadekoBot/Modules/Music/Common/SongResolver/ISongResolverFactory.cs b/src/NadekoBot/Modules/Music/Common/SongResolver/ISongResolverFactory.cs new file mode 100644 index 00000000..c7d79e73 --- /dev/null +++ b/src/NadekoBot/Modules/Music/Common/SongResolver/ISongResolverFactory.cs @@ -0,0 +1,11 @@ +using NadekoBot.Modules.Music.Common.SongResolver.Strategies; +using NadekoBot.Services.Database.Models; +using System.Threading.Tasks; + +namespace NadekoBot.Modules.Music.Common.SongResolver +{ + public interface ISongResolverFactory + { + Task GetResolveStrategy(string query, MusicType? musicType); + } +} diff --git a/src/NadekoBot/Services/Music/SongResolver/SongResolverFactory.cs b/src/NadekoBot/Modules/Music/Common/SongResolver/SongResolverFactory.cs similarity index 92% rename from src/NadekoBot/Services/Music/SongResolver/SongResolverFactory.cs rename to src/NadekoBot/Modules/Music/Common/SongResolver/SongResolverFactory.cs index a70102f1..7e65701c 100644 --- a/src/NadekoBot/Services/Music/SongResolver/SongResolverFactory.cs +++ b/src/NadekoBot/Modules/Music/Common/SongResolver/SongResolverFactory.cs @@ -1,9 +1,9 @@ using System.Threading.Tasks; using NadekoBot.Services.Database.Models; -using NadekoBot.Services.Music.SongResolver.Strategies; using NadekoBot.Services.Impl; +using NadekoBot.Modules.Music.Common.SongResolver.Strategies; -namespace NadekoBot.Services.Music.SongResolver +namespace NadekoBot.Modules.Music.Common.SongResolver { public class SongResolverFactory : ISongResolverFactory { diff --git a/src/NadekoBot/Services/Music/SongResolver/Strategies/IResolverStrategy.cs b/src/NadekoBot/Modules/Music/Common/SongResolver/Strategies/IResolverStrategy.cs similarity index 67% rename from src/NadekoBot/Services/Music/SongResolver/Strategies/IResolverStrategy.cs rename to src/NadekoBot/Modules/Music/Common/SongResolver/Strategies/IResolverStrategy.cs index 42a77637..ec709dab 100644 --- a/src/NadekoBot/Services/Music/SongResolver/Strategies/IResolverStrategy.cs +++ b/src/NadekoBot/Modules/Music/Common/SongResolver/Strategies/IResolverStrategy.cs @@ -1,6 +1,6 @@ using System.Threading.Tasks; -namespace NadekoBot.Services.Music.SongResolver.Strategies +namespace NadekoBot.Modules.Music.Common.SongResolver.Strategies { public interface IResolveStrategy { diff --git a/src/NadekoBot/Services/Music/SongResolver/Strategies/LocalSongResolveStrategy.cs b/src/NadekoBot/Modules/Music/Common/SongResolver/Strategies/LocalSongResolveStrategy.cs similarity index 91% rename from src/NadekoBot/Services/Music/SongResolver/Strategies/LocalSongResolveStrategy.cs rename to src/NadekoBot/Modules/Music/Common/SongResolver/Strategies/LocalSongResolveStrategy.cs index bac28fd8..413dfa9d 100644 --- a/src/NadekoBot/Services/Music/SongResolver/Strategies/LocalSongResolveStrategy.cs +++ b/src/NadekoBot/Modules/Music/Common/SongResolver/Strategies/LocalSongResolveStrategy.cs @@ -2,7 +2,7 @@ using System.IO; using System.Threading.Tasks; -namespace NadekoBot.Services.Music.SongResolver.Strategies +namespace NadekoBot.Modules.Music.Common.SongResolver.Strategies { public class LocalSongResolveStrategy : IResolveStrategy { diff --git a/src/NadekoBot/Services/Music/SongResolver/Strategies/RadioResolveStrategy.cs b/src/NadekoBot/Modules/Music/Common/SongResolver/Strategies/RadioResolveStrategy.cs similarity index 98% rename from src/NadekoBot/Services/Music/SongResolver/Strategies/RadioResolveStrategy.cs rename to src/NadekoBot/Modules/Music/Common/SongResolver/Strategies/RadioResolveStrategy.cs index 212db609..5e11ae4e 100644 --- a/src/NadekoBot/Services/Music/SongResolver/Strategies/RadioResolveStrategy.cs +++ b/src/NadekoBot/Modules/Music/Common/SongResolver/Strategies/RadioResolveStrategy.cs @@ -5,7 +5,7 @@ using System.Net.Http; using System.Text.RegularExpressions; using System.Threading.Tasks; -namespace NadekoBot.Services.Music.SongResolver.Strategies +namespace NadekoBot.Modules.Music.Common.SongResolver.Strategies { public class RadioResolveStrategy : IResolveStrategy { diff --git a/src/NadekoBot/Services/Music/SongResolver/Strategies/SoundCloudResolveStrategy.cs b/src/NadekoBot/Modules/Music/Common/SongResolver/Strategies/SoundCloudResolveStrategy.cs similarity index 82% rename from src/NadekoBot/Services/Music/SongResolver/Strategies/SoundCloudResolveStrategy.cs rename to src/NadekoBot/Modules/Music/Common/SongResolver/Strategies/SoundCloudResolveStrategy.cs index 3e2b9269..66e42075 100644 --- a/src/NadekoBot/Services/Music/SongResolver/Strategies/SoundCloudResolveStrategy.cs +++ b/src/NadekoBot/Modules/Music/Common/SongResolver/Strategies/SoundCloudResolveStrategy.cs @@ -1,8 +1,8 @@ -using NadekoBot.Services.Impl; -using NadekoBot.Services.Music.Extensions; +using NadekoBot.Modules.Music.Extensions; +using NadekoBot.Services.Impl; using System.Threading.Tasks; -namespace NadekoBot.Services.Music.SongResolver.Strategies +namespace NadekoBot.Modules.Music.Common.SongResolver.Strategies { public class SoundcloudResolveStrategy : IResolveStrategy { diff --git a/src/NadekoBot/Services/Music/SongResolver/Strategies/YoutubeResolveStrategy.cs b/src/NadekoBot/Modules/Music/Common/SongResolver/Strategies/YoutubeResolveStrategy.cs similarity index 97% rename from src/NadekoBot/Services/Music/SongResolver/Strategies/YoutubeResolveStrategy.cs rename to src/NadekoBot/Modules/Music/Common/SongResolver/Strategies/YoutubeResolveStrategy.cs index b183e9d4..e4a0058e 100644 --- a/src/NadekoBot/Services/Music/SongResolver/Strategies/YoutubeResolveStrategy.cs +++ b/src/NadekoBot/Modules/Music/Common/SongResolver/Strategies/YoutubeResolveStrategy.cs @@ -5,7 +5,7 @@ using System; using System.Globalization; using System.Threading.Tasks; -namespace NadekoBot.Services.Music.SongResolver.Strategies +namespace NadekoBot.Modules.Music.Common.SongResolver.Strategies { public class YoutubeResolveStrategy : IResolveStrategy { diff --git a/src/NadekoBot/Services/Music/Extensions/Extensions.cs b/src/NadekoBot/Modules/Music/Extensions/Extensions.cs similarity index 82% rename from src/NadekoBot/Services/Music/Extensions/Extensions.cs rename to src/NadekoBot/Modules/Music/Extensions/Extensions.cs index 4403c2dc..b3eb1d38 100644 --- a/src/NadekoBot/Services/Music/Extensions/Extensions.cs +++ b/src/NadekoBot/Modules/Music/Extensions/Extensions.cs @@ -1,9 +1,10 @@ -using NadekoBot.Services.Database.Models; +using NadekoBot.Modules.Music.Common; +using NadekoBot.Services.Database.Models; using NadekoBot.Services.Impl; using System; using System.Threading.Tasks; -namespace NadekoBot.Services.Music.Extensions +namespace NadekoBot.Modules.Music.Extensions { public static class Extensions { diff --git a/src/NadekoBot/Modules/Music/Music.cs b/src/NadekoBot/Modules/Music/Music.cs index b20f1589..1473e247 100644 --- a/src/NadekoBot/Modules/Music/Music.cs +++ b/src/NadekoBot/Modules/Music/Music.cs @@ -9,14 +9,16 @@ using System.Linq; using NadekoBot.Extensions; using System.Collections.Generic; using NadekoBot.Services.Database.Models; -using NadekoBot.Services.Music; using NadekoBot.DataStructures; using System.Collections.Concurrent; using System.IO; using System.Net.Http; using Newtonsoft.Json.Linq; -using NadekoBot.Services.Music.Extensions; using NadekoBot.Services.Impl; +using NadekoBot.Modules.Music.Services; +using NadekoBot.Modules.Music.Common.Exceptions; +using NadekoBot.Modules.Music.Common; +using NadekoBot.Modules.Music.Extensions; namespace NadekoBot.Modules.Music { diff --git a/src/NadekoBot/Services/Music/MusicService.cs b/src/NadekoBot/Modules/Music/Services/MusicService.cs similarity index 98% rename from src/NadekoBot/Services/Music/MusicService.cs rename to src/NadekoBot/Modules/Music/Services/MusicService.cs index 4b498b42..17178cb6 100644 --- a/src/NadekoBot/Services/Music/MusicService.cs +++ b/src/NadekoBot/Modules/Music/Services/MusicService.cs @@ -10,10 +10,13 @@ using System.IO; using System.Collections.Generic; using Discord.Commands; using Discord.WebSocket; -using NadekoBot.Services.Music.SongResolver; using NadekoBot.Services.Impl; +using NadekoBot.Services; +using NadekoBot.Modules.Music.Common; +using NadekoBot.Modules.Music.Common.Exceptions; +using NadekoBot.Modules.Music.Common.SongResolver; -namespace NadekoBot.Services.Music +namespace NadekoBot.Modules.Music.Services { public class MusicService : INService { diff --git a/src/NadekoBot/Modules/Searches/Searches.cs b/src/NadekoBot/Modules/Searches/Searches.cs index 8c45a953..f9961c38 100644 --- a/src/NadekoBot/Modules/Searches/Searches.cs +++ b/src/NadekoBot/Modules/Searches/Searches.cs @@ -29,7 +29,6 @@ namespace NadekoBot.Modules.Searches { private readonly IBotCredentials _creds; private readonly IGoogleApiService _google; - private readonly SearchesService _searches; public Searches(IBotCredentials creds, IGoogleApiService google) { @@ -791,7 +790,7 @@ namespace NadekoBot.Modules.Searches tag = tag?.Trim() ?? ""; - var imgObj = await _searches.DapiSearch(tag, type, Context.Guild?.Id).ConfigureAwait(false); + var imgObj = await _service.DapiSearch(tag, type, Context.Guild?.Id).ConfigureAwait(false); if (imgObj == null) await channel.SendErrorAsync(umsg.Author.Mention + " " + GetText("no_results")); diff --git a/src/NadekoBot/NadekoBot.csproj b/src/NadekoBot/NadekoBot.csproj index 07193a3c..1a906d3b 100644 --- a/src/NadekoBot/NadekoBot.csproj +++ b/src/NadekoBot/NadekoBot.csproj @@ -91,4 +91,8 @@ + + + + diff --git a/src/NadekoBot/Services/Administration/PlayingRotateService.cs b/src/NadekoBot/Services/Administration/PlayingRotateService.cs index 45603150..a0122ae9 100644 --- a/src/NadekoBot/Services/Administration/PlayingRotateService.cs +++ b/src/NadekoBot/Services/Administration/PlayingRotateService.cs @@ -1,7 +1,7 @@ using Discord.WebSocket; using NadekoBot.DataStructures.Replacements; +using NadekoBot.Modules.Music.Services; using NadekoBot.Services.Database.Models; -using NadekoBot.Services.Music; using NLog; using System; using System.Linq; diff --git a/src/NadekoBot/Services/Music/Exceptions.cs b/src/NadekoBot/Services/Music/Exceptions.cs deleted file mode 100644 index 8d4dab72..00000000 --- a/src/NadekoBot/Services/Music/Exceptions.cs +++ /dev/null @@ -1,28 +0,0 @@ -using System; - -namespace NadekoBot.Services.Music -{ - public class QueueFullException : Exception - { - public QueueFullException(string message) : base(message) - { - } - public QueueFullException() : base("Queue is full.") { } - } - - public class SongNotFoundException : Exception - { - public SongNotFoundException(string message) : base(message) - { - } - public SongNotFoundException() : base("Song is not found.") { } - } - public class NotInVoiceChannelException : Exception - { - public NotInVoiceChannelException(string message) : base(message) - { - } - - public NotInVoiceChannelException() : base("You're not in the voice channel on this server.") { } - } -} diff --git a/src/NadekoBot/Services/Music/OldSongResolver.cs b/src/NadekoBot/Services/Music/OldSongResolver.cs deleted file mode 100644 index 147bb6e5..00000000 --- a/src/NadekoBot/Services/Music/OldSongResolver.cs +++ /dev/null @@ -1,111 +0,0 @@ -//using System; -//using System.Collections.Generic; -//using System.Linq; -//using System.Text; -//using System.Threading.Tasks; - -//namespace NadekoBot.Services.Music -//{ -// public class OldSongResolver -// { -// // public async Task ResolveSong(string query, MusicType musicType = MusicType.Normal) -// // { -// // if (string.IsNullOrWhiteSpace(query)) -// // throw new ArgumentNullException(nameof(query)); - -// // if (musicType != MusicType.Local && IsRadioLink(query)) -// // { -// // musicType = MusicType.Radio; -// // query = await HandleStreamContainers(query).ConfigureAwait(false) ?? query; -// // } - -// // try -// // { -// // switch (musicType) -// // { -// // case MusicType.Local: -// // return new Song(new SongInfo -// // { -// // Uri = "\"" + Path.GetFullPath(query) + "\"", -// // Title = Path.GetFileNameWithoutExtension(query), -// // Provider = "Local File", -// // ProviderType = musicType, -// // Query = query, -// // }); -// // case MusicType.Radio: -// // return new Song(new SongInfo -// // { -// // Uri = query, -// // Title = $"{query}", -// // Provider = "Radio Stream", -// // ProviderType = musicType, -// // Query = query -// // }) -// // { TotalTime = TimeSpan.MaxValue }; -// // } -// // if (_sc.IsSoundCloudLink(query)) -// // { -// // var svideo = await _sc.ResolveVideoAsync(query).ConfigureAwait(false); -// // return new Song(new SongInfo -// // { -// // Title = svideo.FullName, -// // Provider = "SoundCloud", -// // Uri = await svideo.StreamLink(), -// // ProviderType = musicType, -// // Query = svideo.TrackLink, -// // AlbumArt = svideo.artwork_url, -// // }) -// // { TotalTime = TimeSpan.FromMilliseconds(svideo.Duration) }; -// // } - -// // if (musicType == MusicType.Soundcloud) -// // { -// // var svideo = await _sc.GetVideoByQueryAsync(query).ConfigureAwait(false); -// // return new Song(new SongInfo -// // { -// // Title = svideo.FullName, -// // Provider = "SoundCloud", -// // Uri = await svideo.StreamLink(), -// // ProviderType = MusicType.Soundcloud, -// // Query = svideo.TrackLink, -// // AlbumArt = svideo.artwork_url, -// // }) -// // { TotalTime = TimeSpan.FromMilliseconds(svideo.Duration) }; -// // } - -// // var link = (await _google.GetVideoLinksByKeywordAsync(query).ConfigureAwait(false)).FirstOrDefault(); -// // if (string.IsNullOrWhiteSpace(link)) -// // throw new OperationCanceledException("Not a valid youtube query."); -// // var allVideos = await Task.Run(async () => { try { return await YouTube.Default.GetAllVideosAsync(link).ConfigureAwait(false); } catch { return Enumerable.Empty(); } }).ConfigureAwait(false); -// // var videos = allVideos.Where(v => v.AdaptiveKind == AdaptiveKind.Audio); -// // var video = videos -// // .Where(v => v.AudioBitrate < 256) -// // .OrderByDescending(v => v.AudioBitrate) -// // .FirstOrDefault(); - -// // if (video == null) // do something with this error -// // throw new Exception("Could not load any video elements based on the query."); -// // var m = Regex.Match(query, @"\?t=(?\d*)"); -// // int gotoTime = 0; -// // if (m.Captures.Count > 0) -// // int.TryParse(m.Groups["t"].ToString(), out gotoTime); -// // var song = new Song(new SongInfo -// // { -// // Title = video.Title.Substring(0, video.Title.Length - 10), // removing trailing "- You Tube" -// // Provider = "YouTube", -// // Uri = await video.GetUriAsync().ConfigureAwait(false), -// // Query = link, -// // ProviderType = musicType, -// // }); -// // song.SkipTo = gotoTime; -// // return song; -// // } -// // catch (Exception ex) -// // { -// // _log.Warn($"Failed resolving the link.{ex.Message}"); -// // _log.Warn(ex); -// // return null; -// // } -// // } -// } -//} diff --git a/src/NadekoBot/Services/Music/SongResolver/ISongResolverFactory.cs b/src/NadekoBot/Services/Music/SongResolver/ISongResolverFactory.cs deleted file mode 100644 index b2ae8aa8..00000000 --- a/src/NadekoBot/Services/Music/SongResolver/ISongResolverFactory.cs +++ /dev/null @@ -1,15 +0,0 @@ -using NadekoBot.Services.Database.Models; -using NadekoBot.Services.Music.SongResolver.Strategies; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace NadekoBot.Services.Music.SongResolver -{ - public interface ISongResolverFactory - { - Task GetResolveStrategy(string query, MusicType? musicType); - } -} diff --git a/src/NadekoBot/Services/Utility/VerboseErrorsService.cs b/src/NadekoBot/Services/Utility/VerboseErrorsService.cs index 8ed89d46..cb885a12 100644 --- a/src/NadekoBot/Services/Utility/VerboseErrorsService.cs +++ b/src/NadekoBot/Services/Utility/VerboseErrorsService.cs @@ -4,9 +4,9 @@ using System.Collections.Generic; using System.Threading.Tasks; using Discord; using NadekoBot.Extensions; -using NadekoBot.Services.Help; using Discord.Commands; using System.Linq; +using NadekoBot.Modules.Help.Services; namespace NadekoBot.Services.Utility {