Integrate new Message Loop
This commit is contained in:
parent
e0ec133209
commit
f1c626a7ba
@ -0,0 +1,44 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using TelegramBotBase.Form;
|
||||
using TelegramBotBase.Interfaces;
|
||||
|
||||
namespace TelegramBotBase.Builder.Interfaces
|
||||
{
|
||||
public interface IMessageLoopSelectionStage
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Chooses a default message loop.
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <returns></returns>
|
||||
IStartFormSelectionStage DefaultMessageLoop();
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Chooses a minimalistic message loop, which catches all update types and only calls the Load function.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
IStartFormSelectionStage MinimalMessageLoop();
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Chooses a custom message loop.
|
||||
/// </summary>
|
||||
/// <param name="startFormClass"></param>
|
||||
/// <returns></returns>
|
||||
IStartFormSelectionStage CustomMessageLoop(IMessageLoopFactory startFormClass);
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Chooses a custom message loop.
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <returns></returns>
|
||||
IStartFormSelectionStage CustomMessageLoop<T>() where T : class, new();
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
62
TelegramBotBase/Factories/MessageLoops/MinimalMessageLoop.cs
Normal file
62
TelegramBotBase/Factories/MessageLoops/MinimalMessageLoop.cs
Normal file
@ -0,0 +1,62 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Telegram.Bot.Types;
|
||||
using TelegramBotBase.Args;
|
||||
using TelegramBotBase.Base;
|
||||
using TelegramBotBase.Enums;
|
||||
using TelegramBotBase.Interfaces;
|
||||
using TelegramBotBase.Sessions;
|
||||
|
||||
namespace TelegramBotBase.Factories.MessageLoops
|
||||
{
|
||||
public class MinimalMessageLoop : IMessageLoopFactory
|
||||
{
|
||||
private static object __evUnhandledCall = new object();
|
||||
|
||||
private EventHandlerList __Events = new EventHandlerList();
|
||||
|
||||
public MinimalMessageLoop()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public async Task MessageLoop(BotBase Bot, DeviceSession session, UpdateResult ur, MessageResult mr)
|
||||
{
|
||||
var update = ur.RawData;
|
||||
|
||||
|
||||
mr.Device = session;
|
||||
|
||||
var activeForm = session.ActiveForm;
|
||||
|
||||
//Loading Event
|
||||
await activeForm.Load(mr);
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Will be called if no form handeled this call
|
||||
/// </summary>
|
||||
public event EventHandler<UnhandledCallEventArgs> UnhandledCall
|
||||
{
|
||||
add
|
||||
{
|
||||
this.__Events.AddHandler(__evUnhandledCall, value);
|
||||
}
|
||||
remove
|
||||
{
|
||||
this.__Events.RemoveHandler(__evUnhandledCall, value);
|
||||
}
|
||||
}
|
||||
|
||||
public void OnUnhandledCall(UnhandledCallEventArgs e)
|
||||
{
|
||||
(this.__Events[__evUnhandledCall] as EventHandler<UnhandledCallEventArgs>)?.Invoke(this, e);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user