refactor: example projects

This commit is contained in:
ZavaruKitsu
2022-10-15 18:51:26 +03:00
parent b9a177c152
commit a2b75654d8
61 changed files with 271 additions and 795 deletions
@@ -1,6 +1,6 @@
namespace SystemCommandsBot.commands;
namespace SystemCommandsBot;
public class Commando
public class Command
{
public int Id { get; set; }
@@ -18,4 +18,4 @@ public class Commando
public int? MaxInstances { get; set; }
public string ProcName { get; set; }
}
}
@@ -1,30 +1,27 @@
using System;
using System.Collections.Generic;
using System.IO;
using Newtonsoft.Json;
using SystemCommandsBot.commands;
using Newtonsoft.Json;
namespace SystemCommandsBot.config;
namespace SystemCommandsBot;
public class Config
{
public Config()
{
Commandos = new List<Commando>();
Commands = new List<Command>();
}
public string Password { get; set; }
public string ApiKey { get; set; }
public List<Commando> Commandos { get; set; }
public List<Command> Commands { get; set; }
public void LoadDefaultValues()
{
ApiKey = "";
Commandos.Add(new Commando
Commands.Add(new Command
{
Id = 0, Enabled = true, Title = "Test Befehl", ShellCmd = "explorer.exe", Action = "start", MaxInstances = 2
Id = 0, Enabled = true, Title = "Test Befehl", ShellCmd = "explorer.exe", Action = "start",
MaxInstances = 2
});
}
@@ -90,4 +87,4 @@ public class Config
{
}
}
}
}
@@ -6,7 +6,7 @@ using System.Threading.Tasks;
using TelegramBotBase.Base;
using TelegramBotBase.Form;
namespace SystemCommandsBot.forms;
namespace SystemCommandsBot.Forms;
public class CmdForm : AutoCleanForm
{
@@ -30,7 +30,7 @@ public class CmdForm : AutoCleanForm
return;
}
var cmd = Program.BotConfig.Commandos.Where(a => a.Enabled && a.Id == id).FirstOrDefault();
var cmd = Program.BotConfig.Commands.Where(a => a.Enabled && a.Id == id).FirstOrDefault();
if (cmd == null)
{
await Device.Send("Cmd nicht verfügbar.");
@@ -145,7 +145,7 @@ public class CmdForm : AutoCleanForm
{
if (MessageId == null)
{
var buttons = Program.BotConfig.Commandos.Where(a => a.Enabled)
var buttons = Program.BotConfig.Commands.Where(a => a.Enabled)
.Select(a => new ButtonBase(a.Title, a.Id.ToString()));
var bf = new ButtonForm();
@@ -153,4 +153,4 @@ public class CmdForm : AutoCleanForm
await Device.Send("Deine Optionen", bf);
}
}
}
}
@@ -3,7 +3,7 @@ using System.Threading.Tasks;
using TelegramBotBase.Base;
using TelegramBotBase.Form;
namespace SystemCommandsBot.forms;
namespace SystemCommandsBot.Forms;
public class StartForm : FormBase
{
+6 -8
View File
@@ -1,6 +1,6 @@
using System;
using SystemCommandsBot.config;
using SystemCommandsBot.forms;
using System.Threading.Tasks;
using SystemCommandsBot.Forms;
using TelegramBotBase.Builder;
namespace SystemCommandsBot;
@@ -9,8 +9,7 @@ internal class Program
{
public static Config BotConfig { get; set; }
private static void Main(string[] args)
private static async Task Main(string[] args)
{
BotConfig = Config.Load();
@@ -25,13 +24,12 @@ internal class Program
.QuickStart<StartForm>(BotConfig.ApiKey)
.Build();
bot.Start();
await bot.Start();
Console.WriteLine("Bot started");
Console.ReadLine();
bot.Stop();
await bot.Stop();
}
}
}
@@ -3,11 +3,12 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>disable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="13.0.1"/>
<PackageReference Include="TelegramBotBase" Version="5.0.0"/>
<ProjectReference Include="..\..\TelegramBotBase\TelegramBotBase.csproj"/>
</ItemGroup>
</Project>