refactor: make properties readonly
This commit is contained in:
parent
a2b75654d8
commit
fb51677429
@ -94,7 +94,7 @@ public class MessageClient
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public string ApiKey { get; set; }
|
public string ApiKey { get; }
|
||||||
|
|
||||||
public ITelegramBotClient TelegramClient { get; set; }
|
public ITelegramBotClient TelegramClient { get; set; }
|
||||||
|
|
||||||
|
|||||||
@ -15,13 +15,16 @@ using Console = TelegramBotBase.Tools.Console;
|
|||||||
namespace TelegramBotBase;
|
namespace TelegramBotBase;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Bot base class for full Device/Context and Messagehandling
|
/// Bot base class for full Device/Context and message handling
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <typeparam name="T"></typeparam>
|
/// <typeparam name="T"></typeparam>
|
||||||
public sealed class BotBase
|
public sealed class BotBase
|
||||||
{
|
{
|
||||||
internal BotBase()
|
internal BotBase(string apiKey, MessageClient client)
|
||||||
{
|
{
|
||||||
|
ApiKey = apiKey;
|
||||||
|
Client = client;
|
||||||
|
|
||||||
SystemSettings = new Dictionary<ESettings, uint>();
|
SystemSettings = new Dictionary<ESettings, uint>();
|
||||||
|
|
||||||
SetSetting(ESettings.MaxNumberOfRetries, 5);
|
SetSetting(ESettings.MaxNumberOfRetries, 5);
|
||||||
@ -35,38 +38,38 @@ public sealed class BotBase
|
|||||||
Sessions = new SessionManager(this);
|
Sessions = new SessionManager(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public MessageClient Client { get; set; }
|
public MessageClient Client { get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Your TelegramBot APIKey
|
/// Your TelegramBot APIKey
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string ApiKey { get; set; } = "";
|
public string ApiKey { get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// List of all running/active sessions
|
/// List of all running/active sessions
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public SessionManager Sessions { get; set; }
|
public SessionManager Sessions { get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Contains System commands which will be available at everytime and didnt get passed to forms, i.e. /start
|
/// Contains System commands which will be available at everytime and didnt get passed to forms, i.e. /start
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public Dictionary<BotCommandScope, List<BotCommand>> BotCommandScopes { get; set; } = new();
|
public Dictionary<BotCommandScope, List<BotCommand>> BotCommandScopes { get; internal set; }
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Enable the SessionState (you need to implement on call forms the IStateForm interface)
|
/// Enable the SessionState (you need to implement on call forms the IStateForm interface)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public IStateMachine StateMachine { get; set; }
|
public IStateMachine StateMachine { get; internal set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Offers functionality to manage the creation process of the start form.
|
/// Offers functionality to manage the creation process of the start form.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public IStartFormFactory StartFormFactory { get; set; }
|
public IStartFormFactory StartFormFactory { get; internal set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Contains the message loop factory, which cares about "message-management."
|
/// Contains the message loop factory, which cares about "message-management."
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public IMessageLoopFactory MessageLoopFactory { get; set; }
|
public IMessageLoopFactory MessageLoopFactory { get; internal set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// All internal used settings.
|
/// All internal used settings.
|
||||||
@ -210,7 +213,6 @@ public sealed class BotBase
|
|||||||
e.Device = ds;
|
e.Device = ds;
|
||||||
|
|
||||||
await MessageLoopFactory.MessageLoop(this, ds, new UpdateResult(e.UpdateData, ds), e);
|
await MessageLoopFactory.MessageLoop(this, ds, new UpdateResult(e.UpdateData, ds), e);
|
||||||
//await Client_Loop(this, e);
|
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
@ -315,7 +317,7 @@ public sealed class BotBase
|
|||||||
return defaultValue;
|
return defaultValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
return SystemSettings[set] == 0u ? false : true;
|
return SystemSettings[set] != 0u;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -27,7 +27,7 @@ public class BotBaseBuilder : IAPIKeySelectionStage, IMessageLoopSelectionStage,
|
|||||||
|
|
||||||
private IMessageLoopFactory _messageLoopFactory;
|
private IMessageLoopFactory _messageLoopFactory;
|
||||||
|
|
||||||
private IStateMachine _statemachine;
|
private IStateMachine _stateMachine;
|
||||||
|
|
||||||
private BotBaseBuilder()
|
private BotBaseBuilder()
|
||||||
{
|
{
|
||||||
@ -41,19 +41,14 @@ public class BotBaseBuilder : IAPIKeySelectionStage, IMessageLoopSelectionStage,
|
|||||||
|
|
||||||
public BotBase Build()
|
public BotBase Build()
|
||||||
{
|
{
|
||||||
var bot = new BotBase
|
var bot = new BotBase(_apiKey, _client)
|
||||||
{
|
{
|
||||||
ApiKey = _apiKey,
|
|
||||||
StartFormFactory = _factory,
|
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;
|
bot.MessageLoopFactory.UnhandledCall += bot.MessageLoopFactory_UnhandledCall;
|
||||||
|
|
||||||
return bot;
|
return bot;
|
||||||
@ -315,26 +310,26 @@ public class BotBaseBuilder : IAPIKeySelectionStage, IMessageLoopSelectionStage,
|
|||||||
|
|
||||||
public ILanguageSelectionStage UseSerialization(IStateMachine machine)
|
public ILanguageSelectionStage UseSerialization(IStateMachine machine)
|
||||||
{
|
{
|
||||||
_statemachine = machine;
|
_stateMachine = machine;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public ILanguageSelectionStage UseJSON(string path)
|
public ILanguageSelectionStage UseJSON(string path)
|
||||||
{
|
{
|
||||||
_statemachine = new JsonStateMachine(path);
|
_stateMachine = new JsonStateMachine(path);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ILanguageSelectionStage UseSimpleJSON(string path)
|
public ILanguageSelectionStage UseSimpleJSON(string path)
|
||||||
{
|
{
|
||||||
_statemachine = new SimpleJsonStateMachine(path);
|
_stateMachine = new SimpleJsonStateMachine(path);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ILanguageSelectionStage UseXML(string path)
|
public ILanguageSelectionStage UseXML(string path)
|
||||||
{
|
{
|
||||||
_statemachine = new XmlStateMachine(path);
|
_stateMachine = new XmlStateMachine(path);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user