Refactored Searches

This commit is contained in:
Master Kwoth 2016-04-14 23:19:29 +02:00
parent 73cda7336a
commit eeaf4c4920
8 changed files with 48 additions and 64 deletions

View File

@ -1,7 +1,5 @@
using System; using Discord.Commands;
using System.Threading.Tasks; using NadekoBot.Modules;
using Discord;
using Discord.Commands;
namespace NadekoBot.Commands namespace NadekoBot.Commands
{ {
@ -9,31 +7,28 @@ namespace NadekoBot.Commands
/// Base DiscordCommand Class. /// Base DiscordCommand Class.
/// Inherit this class to create your own command. /// Inherit this class to create your own command.
/// </summary> /// </summary>
public abstract class DiscordCommand internal abstract class DiscordCommand
{ {
/// <summary>
/// Client at the moment of creating this object
/// </summary>
public DiscordClient client { get; set; }
/// <summary> /// <summary>
/// Constructor of the base class /// Parent module
/// </summary> /// </summary>
/// <param name="cb">CommandBuilder which will be modified</param> protected DiscordModule Module { get; }
protected DiscordCommand()
{
client = NadekoBot.Client;
}
/// <summary> /// <summary>
/// Function containing the behaviour of the command. /// Creates a new instance of discord command,
/// use ": base(module)" in the derived class'
/// constructor to make sure module is assigned
/// </summary> /// </summary>
/// <param name="client">Client who will handle the message sending, etc, if any.</param> /// <param name="module">Module this command resides in</param>
/// <returns></returns> protected DiscordCommand(DiscordModule module)
public abstract Func<CommandEventArgs,Task> DoFunc(); {
this.Module = module;
}
/// <summary> /// <summary>
/// Initializes the CommandBuilder with values using CommandGroupBuilder /// Initializes the CommandBuilder with values using CommandGroupBuilder
/// </summary> /// </summary>
public abstract void Init(CommandGroupBuilder cgb); internal abstract void Init(CommandGroupBuilder cgb);
} }
} }

View File

@ -1,31 +0,0 @@
using Discord.Commands;
using NadekoBot.Modules;
namespace NadekoBot.Commands {
/// <summary>
/// Base DiscordCommand Class.
/// Inherit this class to create your own command.
/// </summary>
internal abstract class DiscordCommand {
/// <summary>
/// Parent module
/// </summary>
protected DiscordModule Module { get; }
/// <summary>
/// Creates a new instance of discord command,
/// use ": base(module)" in the derived class'
/// constructor to make sure module is assigned
/// </summary>
/// <param name="module">Module this command resides in</param>
protected DiscordCommand(DiscordModule module) {
this.Module = module;
}
/// <summary>
/// Initializes the CommandBuilder with values using CommandGroupBuilder
/// </summary>
internal abstract void Init(CommandGroupBuilder cgb);
}
}

View File

@ -7,7 +7,7 @@ using System.Globalization;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace NadekoBot.Modules.Search.Commands namespace NadekoBot.Modules.Searches.Commands
{ {
class ConverterCommand : DiscordCommand class ConverterCommand : DiscordCommand
{ {

View File

@ -1,7 +1,7 @@
using Discord.Commands; using Discord.Commands;
using NadekoBot.Classes; using NadekoBot.Classes;
using NadekoBot.Commands;
using NadekoBot.Extensions; using NadekoBot.Extensions;
using NadekoBot.Modules;
using Newtonsoft.Json.Linq; using Newtonsoft.Json.Linq;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
@ -10,7 +10,7 @@ using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace NadekoBot.Commands namespace NadekoBot.Modules.Searches.Commands
{ {
internal class LoLCommands : DiscordCommand internal class LoLCommands : DiscordCommand
{ {
@ -108,7 +108,8 @@ namespace NadekoBot.Commands
return; return;
} }
} }
else { else
{
data = allData[0]; data = allData[0];
role = allData[0]["role"].ToString(); role = allData[0]["role"].ToString();
resolvedRole = ResolvePos(role); resolvedRole = ResolvePos(role);

View File

@ -0,0 +1,18 @@
using Discord.Commands;
using NadekoBot.Commands;
using System;
namespace NadekoBot.Modules.Searches.Commands
{
class RedditCommand : DiscordCommand
{
public RedditCommand(DiscordModule module) : base(module)
{
}
internal override void Init(CommandGroupBuilder cgb)
{
throw new NotImplementedException();
}
}
}

View File

@ -2,7 +2,7 @@
using NadekoBot.Classes; using NadekoBot.Classes;
using NadekoBot.Classes.JSONModels; using NadekoBot.Classes.JSONModels;
using NadekoBot.Classes.Permissions; using NadekoBot.Classes.Permissions;
using NadekoBot.Modules; using NadekoBot.Commands;
using Newtonsoft.Json.Linq; using Newtonsoft.Json.Linq;
using System; using System;
using System.Collections.Concurrent; using System.Collections.Concurrent;
@ -10,7 +10,7 @@ using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Timers; using System.Timers;
namespace NadekoBot.Commands namespace NadekoBot.Modules.Searches.Commands
{ {
internal class StreamNotifications : DiscordCommand internal class StreamNotifications : DiscordCommand
{ {

View File

@ -3,9 +3,8 @@ using Discord.Modules;
using NadekoBot.Classes; using NadekoBot.Classes;
using NadekoBot.Classes.IMDB; using NadekoBot.Classes.IMDB;
using NadekoBot.Classes.JSONModels; using NadekoBot.Classes.JSONModels;
using NadekoBot.Commands;
using NadekoBot.Extensions; using NadekoBot.Extensions;
using NadekoBot.Modules.Search.Commands; using NadekoBot.Modules.Searches.Commands;
using Newtonsoft.Json; using Newtonsoft.Json;
using Newtonsoft.Json.Linq; using Newtonsoft.Json.Linq;
using System; using System;
@ -15,7 +14,7 @@ using System.IO;
using System.Linq; using System.Linq;
using System.Net; using System.Net;
namespace NadekoBot.Modules namespace NadekoBot.Modules.Searches
{ {
internal class Searches : DiscordModule internal class Searches : DiscordModule
{ {
@ -25,6 +24,7 @@ namespace NadekoBot.Modules
commands.Add(new LoLCommands(this)); commands.Add(new LoLCommands(this));
commands.Add(new StreamNotifications(this)); commands.Add(new StreamNotifications(this));
commands.Add(new ConverterCommand(this)); commands.Add(new ConverterCommand(this));
commands.Add(new RedditCommand(this));
rng = new Random(); rng = new Random();
} }

View File

@ -170,10 +170,10 @@
<Compile Include="Commands\FilterWordsCommand.cs" /> <Compile Include="Commands\FilterWordsCommand.cs" />
<Compile Include="Commands\FilterInvitesCommand.cs" /> <Compile Include="Commands\FilterInvitesCommand.cs" />
<Compile Include="Modules\Administration\Commands\LogCommand.cs" /> <Compile Include="Modules\Administration\Commands\LogCommand.cs" />
<Compile Include="Commands\LoLCommands.cs" /> <Compile Include="Modules\Searches\Commands\LoLCommands.cs" />
<Compile Include="Modules\Administration\Commands\MessageRepeater.cs" /> <Compile Include="Modules\Administration\Commands\MessageRepeater.cs" />
<Compile Include="Modules\Administration\Commands\PlayingRotate.cs" /> <Compile Include="Modules\Administration\Commands\PlayingRotate.cs" />
<Compile Include="Commands\StreamNotifications.cs" /> <Compile Include="Modules\Searches\Commands\StreamNotifications.cs" />
<Compile Include="Commands\TriviaCommand.cs" /> <Compile Include="Commands\TriviaCommand.cs" />
<Compile Include="Classes\Trivia\TriviaGame.cs" /> <Compile Include="Classes\Trivia\TriviaGame.cs" />
<Compile Include="Classes\Trivia\TriviaQuestion.cs" /> <Compile Include="Classes\Trivia\TriviaQuestion.cs" />
@ -205,8 +205,9 @@
<Compile Include="Modules\Administration\Commands\RatelimitCommand.cs" /> <Compile Include="Modules\Administration\Commands\RatelimitCommand.cs" />
<Compile Include="Modules\Pokemon\PokemonModule.cs" /> <Compile Include="Modules\Pokemon\PokemonModule.cs" />
<Compile Include="Modules\Pokemon\PokeStats.cs" /> <Compile Include="Modules\Pokemon\PokeStats.cs" />
<Compile Include="Modules\Searches.cs" /> <Compile Include="Modules\Searches\Searches.cs" />
<Compile Include="Modules\Search\Commands\ConverterCommand.cs" /> <Compile Include="Modules\Searches\Commands\ConverterCommand.cs" />
<Compile Include="Modules\Searches\Commands\RedditCommand.cs" />
<Compile Include="Modules\Translator\Helpers\GoogleTranslator.cs" /> <Compile Include="Modules\Translator\Helpers\GoogleTranslator.cs" />
<Compile Include="Modules\Translator\TranslateCommand.cs" /> <Compile Include="Modules\Translator\TranslateCommand.cs" />
<Compile Include="Modules\Translator\TranslatorModule.cs" /> <Compile Include="Modules\Translator\TranslatorModule.cs" />