بله | کانال BaleBotNet
عکس پروفایل BaleBotNetB

BaleBotNet

۱۹۷ عضو
عکس پروفایل BaleBotNetB
۱۹۷ عضو

BaleBotNet

ابزار متن‌باز توسعه بازو برای بله در دات نتOpen source sdk for development bots with dotnet
ناگت:nuget.org/packages/BaleBotNet
ریپو:github.com/RavaqeMehr/BaleBotNet
گروه گفتگو:ble.ir/join/6jpNUuVFZR
ثبت سفارش، توسعه‌دهنده: @moqavem8
گام ششم: واکنش به آپدیت بخش 1
جهت ساده‌سازی کدهای تکراری 2 کلاس هلپر ساختیم.Helpers\ScopeHelpers.cs

namespace MyBaleBot.Helpers;

public static class ScopeHelpers
{
    public static T Get<T>(this IServiceScope scope)
        where T : notnull => scope.ServiceProvider.GetRequiredService<T>();
}
Helpers\UpdateReciverHelpers.cs

using BaleBotNet.Enums;
using BaleBotNet.Types;

namespace MyBaleBot.Helpers;

public static class UpdateReciverHelpers
{
    public static bool IsPrivate(this Message message) => message.Chat.Type == ChatType.Private;

    public static bool IsGroup(this Message message) => message.Chat.Type == ChatType.Group;

    public static bool IsFromChat(this Message message, long chatId) => message.Chat.Id == chatId;

    public static bool IsFromChat(this CallbackQuery query, long chatId) =>
        query.Message?.Chat?.Id == chatId;

    public static bool IsCommand(this Message message, string command)
    {
        var firstPart = message.Text?.Split(" ").ElementAtOrDefault(0);

        if (firstPart == null)
            return false;

        return firstPart.Equals(command, StringComparison.OrdinalIgnoreCase);
    }
}

و برای جلوگیری از هاردکد کردن یک کلاس ثوابت ساختیم:Services\Bot\BotConsts.cs

namespace MyBaleBot.Services.Bot;

public static class BotConsts
{
    public static class Commands
    {
        public const string Start = "/start";
        public const string Whois = "/whois";
    }

    public static readonly Dictionary<string, string> CommandsMenu =
        new() { { Commands.Start, "شروع مجدد" }, { Commands.Whois, "من کی‌ام؟" } };
}

فهرست آموزش@BaleBotNet | کلاینت دات‌نت بازوی بله

۱۷:۴۵