123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- using System;
- using sera_slackbot.Commands;
- namespace sera_slackbot.Library
- {
- public class BotCommandFactory
- {
- private JsonFileReader reader;
- private JsonFileSaver saver;
- public BotCommandFactory(JsonFileReader reader, JsonFileSaver saver)
- {
- this.reader = reader;
- this.saver = saver;
- }
- public IBotCommand CreateCommand(string commandString)
- {
- var typeString = "sera_slackbot.Commands." + commandString + "BotCommand";
- try
- {
- return (IBotCommand)Activator.CreateInstance(Type.GetType(typeString), this.reader, this.saver);
- }
- catch (Exception)
- {
- return new InvalidBotCommand(commandString);
- }
- }
- public IBotInteraction CreateInteraction(string interactionString)
- {
- var commandString = interactionString;
- switch (interactionString)
- {
- case "pointingpoker":
- commandString = "PointingPoker";
- break;
- }
- var typeString = "sera_slackbot.Commands." + commandString + "BotCommand";
- try
- {
- return (IBotInteraction)Activator.CreateInstance(Type.GetType(typeString), this.reader, this.saver);
- }
- catch (Exception)
- {
- return new InvalidBotCommand(commandString);
- }
- }
- }
- }
|