Skip to content

Commit

Permalink
Check for null telegram token
Browse files Browse the repository at this point in the history
  • Loading branch information
stanriders committed Feb 1, 2019
1 parent 69da2e0 commit 02660cf
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion den0bot/API.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace den0bot
static class API
{
public static User BotUser;
private static readonly TelegramBotClient api = new TelegramBotClient(Config.Params.TelegamToken);
private static TelegramBotClient api;

public static bool IsConnected => api.IsReceiving;

Expand All @@ -27,9 +27,16 @@ static class API
/// </summary>
public static bool Connect()
{
if (string.IsNullOrEmpty(Config.Params.TelegamToken))
{
Log.Error("API", "Telegram token is null or empty!");
return false;
}

Log.Info("API", "Connecting...");
try
{
api = new TelegramBotClient(Config.Params.TelegamToken);
api.OnMessage += OnMessage;
api.OnCallbackQuery += OnCallback;
api.OnReceiveGeneralError += delegate (object sender, ReceiveGeneralErrorEventArgs args) { Log.Error("API - OnReceiveGeneralError", args.Exception.InnerMessageIfAny()); };
Expand Down

0 comments on commit 02660cf

Please sign in to comment.