Skip to content

Commands Creating

Назар edited this page Sep 11, 2018 · 5 revisions

First of all

We have some base types of Command:

    public enum TypeOfCommand {
        Standart,
        Query,
        InlineQuery,
        AllwaysInWebHook,
        Service,
        Photo
    }

We have some base Type of Access to Commands:

    public enum TypeOfAccess{
        Public,
        Hide,
        Admin,
        Named
    }

Standart

This is command that provide you with trigger of simple text message to bot or in chat with bot. Standart command creates with Action<Message, IBot, List> parameter.

Photo

As a message message but it contains Image

Query

This is command that calls when bot reacive Query from buttons and etc. Query command creates with Action<CallbackQuery, IBot> parameter.

InlineQuery

This command calls when reacive Query from inline buttons and etc. InlineQuery command creates with Action<InlineQuery, IBot> parameter.

AllwaysInWebHook

This type of command uses allways when any Update entere in WebHook. AllwaysInWebHook command creates with Action<Update, IBot, List> parameter.

Service

This type of command uses for Service Messages from Telegram. Service command creates with Action<Update, IBot> parameter.

We have some types of command bases

  • Common Synk Command
  • Query Synk Command for Inline Messages
  • Query Synk Command for Buttons
  • Allways in WebHook
  • Service Synk Command U can see it in SynkCommand.cs

How to create command?

Structure of commands adding.

public SynkCommand(
Action<Telegram.Bot.Types.Message, IBot, List<ArgC>> act, //Action of command
 List<string> cm, //Command names, that will be /command, but u can write just "command"
 TypeOfAccess access = TypeOfAccess.Public, //Acces to command
 string commandName = null, //String name of command for alternative input
 string descr = null, //Description of command
 bool clearcommand = true) //Clear command after input or nope

1. (command from module)

Bot.SynkCommands.Add(new SynkCommand(new WebmModule().WebmFuncForBot, new List<string>()
            {
                "/sendrandwebm"
            }, commandName:"картика", descr:"Webm с личной колекции."));

Or

Bot.SynkCommands.Add(Bot.GetModule<FunFunc>()._ChtoEto);

2. (Lamda Command)

Bot.SynkCommands.Add(new SynkCommand((Telegram.Bot.Types.Message ms, IBot parent, List<ArgC> args)=> {
                parent.Client.SendTextMessageAsync(ms.Chat.Id,"Слушаюсь, уже сплю...");
                Bot.GetModule<SaveLoadModule>().saveIt();
                Bot.Dispose();
                Application.Exit();
            }, new List<string>()
            {
                "_"
            },commandName:"спать", access:TypeOfAccess.Named, descr: "Бот ложиться спать."));

3. (Full command)

    public class Help : SynkCommand
      {
          public BotBase Parent { get; set; }
          public Help(BotBase bot) : base(Act, new List<string>() { "/help" },descr:"List of commands.") { Parent = bot; }
          public static void Act(Message re, IBot Parent, List<ArgC> args)
          {
              Parent.Client.SendTextMessageAsync(re.Chat.Id,$"This bot[{Parent.Name}] was created with pes7's Bot Creator.");
              string coms = "";
              foreach(SynkCommand sn in Parent.SynkCommands.Where(fn=>fn.Type==TypeOfCommand.Standart && fn.CommandLine.First() != "Default"))
              {
                  if(sn.Description != null)
                      coms += $"\n{sn.CommandLine.First()} - {sn.Description}";
                  else
                      coms += $"\n{sn.CommandLine.First()}";
              }
              Parent.Client.SendTextMessageAsync(re.Chat.Id, $"Commands: {coms}");
          }
      }

Next Page