refactor: make properties readonly

This commit is contained in:
ZavaruKitsu 2022-10-15 19:01:29 +03:00
parent a2b75654d8
commit fb51677429
3 changed files with 23 additions and 26 deletions

View File

@ -94,7 +94,7 @@ public class MessageClient
}
public string ApiKey { get; set; }
public string ApiKey { get; }
public ITelegramBotClient TelegramClient { get; set; }

View File

@ -15,13 +15,16 @@ using Console = TelegramBotBase.Tools.Console;
namespace TelegramBotBase;
/// <summary>
/// Bot base class for full Device/Context and Messagehandling
/// Bot base class for full Device/Context and message handling
/// </summary>
/// <typeparam name="T"></typeparam>
public sealed class BotBase
{
internal BotBase()
internal BotBase(string apiKey, MessageClient client)
{
ApiKey = apiKey;
Client = client;
SystemSettings = new Dictionary<ESettings, uint>();
SetSetting(ESettings.MaxNumberOfRetries, 5);
@ -35,38 +38,38 @@ public sealed class BotBase
Sessions = new SessionManager(this);
}
public MessageClient Client { get; set; }
public MessageClient Client { get; }
/// <summary>
/// Your TelegramBot APIKey
/// </summary>
public string ApiKey { get; set; } = "";
public string ApiKey { get; }
/// <summary>
/// List of all running/active sessions
/// </summary>
public SessionManager Sessions { get; set; }
public SessionManager Sessions { get; }
/// <summary>
/// Contains System commands which will be available at everytime and didnt get passed to forms, i.e. /start
/// </summary>
public Dictionary<BotCommandScope, List<BotCommand>> BotCommandScopes { get; set; } = new();
public Dictionary<BotCommandScope, List<BotCommand>> BotCommandScopes { get; internal set; }
/// <summary>
/// Enable the SessionState (you need to implement on call forms the IStateForm interface)
/// </summary>
public IStateMachine StateMachine { get; set; }
public IStateMachine StateMachine { get; internal set; }
/// <summary>
/// Offers functionality to manage the creation process of the start form.
/// </summary>
public IStartFormFactory StartFormFactory { get; set; }
public IStartFormFactory StartFormFactory { get; internal set; }
/// <summary>
/// Contains the message loop factory, which cares about "message-management."
/// </summary>
public IMessageLoopFactory MessageLoopFactory { get; set; }
public IMessageLoopFactory MessageLoopFactory { get; internal set; }
/// <summary>
/// All internal used settings.
@ -210,7 +213,6 @@ public sealed class BotBase
e.Device = ds;
await MessageLoopFactory.MessageLoop(this, ds, new UpdateResult(e.UpdateData, ds), e);
//await Client_Loop(this, e);
}
catch (Exception ex)
{
@ -315,7 +317,7 @@ public sealed class BotBase
return defaultValue;
}
return SystemSettings[set] == 0u ? false : true;
return SystemSettings[set] != 0u;
}

View File

@ -27,7 +27,7 @@ public class BotBaseBuilder : IAPIKeySelectionStage, IMessageLoopSelectionStage,
private IMessageLoopFactory _messageLoopFactory;
private IStateMachine _statemachine;
private IStateMachine _stateMachine;
private BotBaseBuilder()
{
@ -41,19 +41,14 @@ public class BotBaseBuilder : IAPIKeySelectionStage, IMessageLoopSelectionStage,
public BotBase Build()
{
var bot = new BotBase
var bot = new BotBase(_apiKey, _client)
{
ApiKey = _apiKey,
StartFormFactory = _factory,
Client = _client
BotCommandScopes = BotCommandScopes,
StateMachine = _stateMachine,
MessageLoopFactory = _messageLoopFactory
};
bot.BotCommandScopes = BotCommandScopes;
bot.StateMachine = _statemachine;
bot.MessageLoopFactory = _messageLoopFactory;
bot.MessageLoopFactory.UnhandledCall += bot.MessageLoopFactory_UnhandledCall;
return bot;
@ -315,26 +310,26 @@ public class BotBaseBuilder : IAPIKeySelectionStage, IMessageLoopSelectionStage,
public ILanguageSelectionStage UseSerialization(IStateMachine machine)
{
_statemachine = machine;
_stateMachine = machine;
return this;
}
public ILanguageSelectionStage UseJSON(string path)
{
_statemachine = new JsonStateMachine(path);
_stateMachine = new JsonStateMachine(path);
return this;
}
public ILanguageSelectionStage UseSimpleJSON(string path)
{
_statemachine = new SimpleJsonStateMachine(path);
_stateMachine = new SimpleJsonStateMachine(path);
return this;
}
public ILanguageSelectionStage UseXML(string path)
{
_statemachine = new XmlStateMachine(path);
_stateMachine = new XmlStateMachine(path);
return this;
}