fix: some build & linter warnings

This commit is contained in:
ZavaruKitsu
2022-10-08 19:15:51 +03:00
parent 3f0d109fe2
commit a731e2a8d0
159 changed files with 2738 additions and 3742 deletions
+13 -15
View File
@@ -1,26 +1,24 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Timers;
using AsyncFormUpdates.forms;
using TelegramBotBase;
using TelegramBotBase.Builder;
namespace AsyncFormUpdates
{
class Program
internal class Program
{
static TelegramBotBase.BotBase bot = null;
private static BotBase __bot;
static void Main(string[] args)
private static void Main(string[] args)
{
String apiKey = "APIKey";
var apiKey = "APIKey";
bot = BotBaseBuilder.Create()
.QuickStart<forms.Start>(apiKey)
__bot = BotBaseBuilder.Create()
.QuickStart<Start>(apiKey)
.Build();
bot.Start();
__bot.Start();
var timer = new Timer(5000);
@@ -30,19 +28,19 @@ namespace AsyncFormUpdates
Console.ReadLine();
timer.Stop();
bot.Stop();
__bot.Stop();
}
private static async void Timer_Elapsed(object sender, ElapsedEventArgs e)
{
foreach(var s in bot.Sessions.SessionList)
foreach(var s in __bot.Sessions.SessionList)
{
//Only for AsyncUpdateForm
if (s.Value.ActiveForm.GetType() != typeof(forms.AsyncFormUpdate) && s.Value.ActiveForm.GetType() != typeof(forms.AsyncFormEdit))
if (s.Value.ActiveForm.GetType() != typeof(AsyncFormUpdate) && s.Value.ActiveForm.GetType() != typeof(AsyncFormEdit))
continue;
await bot.InvokeMessageLoop(s.Key);
await __bot.InvokeMessageLoop(s.Key);
}
@@ -1,5 +1,4 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// Allgemeine Informationen über eine Assembly werden über die folgenden
@@ -1,8 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Threading.Tasks;
using TelegramBotBase.Attributes;
using TelegramBotBase.Base;
using TelegramBotBase.Form;
@@ -11,19 +7,19 @@ namespace AsyncFormUpdates.forms
{
public class AsyncFormEdit : FormBase
{
[SaveState]
int counter = 0;
[SaveState] private int _counter;
int MessageId = 0;
private int _messageId;
public override async Task Load(MessageResult message)
public override Task Load(MessageResult message)
{
counter++;
_counter++;
return Task.CompletedTask;
}
public override async Task Action(MessageResult message)
{
await message.ConfirmAction("");
await message.ConfirmAction();
switch (message.RawData ?? "")
{
@@ -41,14 +37,14 @@ namespace AsyncFormUpdates.forms
var bf = new ButtonForm();
bf.AddButtonRow("Back", "back");
if (MessageId != 0)
if (_messageId != 0)
{
await Device.Edit(MessageId, $"Your current count is at: {counter}", bf);
await Device.Edit(_messageId, $"Your current count is at: {_counter}", bf);
}
else
{
var m = await Device.Send($"Your current count is at: {counter}", bf, disableNotification: true);
MessageId = m.MessageId;
var m = await Device.Send($"Your current count is at: {_counter}", bf, disableNotification: true);
_messageId = m.MessageId;
}
}
@@ -1,8 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Threading.Tasks;
using TelegramBotBase.Attributes;
using TelegramBotBase.Base;
using TelegramBotBase.Form;
@@ -11,18 +7,18 @@ namespace AsyncFormUpdates.forms
{
public class AsyncFormUpdate : AutoCleanForm
{
[SaveState]
int counter = 0;
[SaveState] private int _counter;
public override async Task Load(MessageResult message)
public override Task Load(MessageResult message)
{
counter++;
_counter++;
return Task.CompletedTask;
}
public override async Task Action(MessageResult message)
{
await message.ConfirmAction("");
await message.ConfirmAction();
switch (message.RawData ?? "")
{
@@ -40,7 +36,7 @@ namespace AsyncFormUpdates.forms
var bf = new ButtonForm();
bf.AddButtonRow("Back", "back");
await Device.Send($"Your current count is at: {counter}", bf, disableNotification: true);
await Device.Send($"Your current count is at: {_counter}", bf, disableNotification: true);
}
+2 -6
View File
@@ -1,8 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Threading.Tasks;
using TelegramBotBase.Base;
using TelegramBotBase.Form;
@@ -14,7 +10,7 @@ namespace AsyncFormUpdates.forms
public override async Task Action(MessageResult message)
{
await message.ConfirmAction("");
await message.ConfirmAction();
switch (message.RawData ?? "")
{
+5 -4
View File
@@ -1,17 +1,18 @@
using System;
using JoinHiderBot.forms;
using TelegramBotBase.Builder;
namespace JoinHiderBot
{
class Program
internal class Program
{
static void Main(string[] args)
private static void Main(string[] args)
{
String apiKey = "";
var apiKey = "";
var bot = BotBaseBuilder.Create()
.QuickStart<forms.Start>(apiKey)
.QuickStart<Start>(apiKey)
.Build();
bot.Start();
@@ -1,7 +1,5 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using System.Threading.Tasks;
using Telegram.Bot.Types.Enums;
using TelegramBotBase.Args;
using TelegramBotBase.Form;
@@ -12,13 +10,13 @@ namespace JoinHiderBot.forms
public override async Task OnMemberChanges(MemberChangeEventArgs e)
{
if (e.Type != Telegram.Bot.Types.Enums.MessageType.ChatMembersAdded && e.Type != Telegram.Bot.Types.Enums.MessageType.ChatMemberLeft)
if (e.Type != MessageType.ChatMembersAdded && e.Type != MessageType.ChatMemberLeft)
return;
var m = e.Result.Message;
await this.Device.DeleteMessage(m);
await Device.DeleteMessage(m);
}
}
+3 -6
View File
@@ -1,7 +1,4 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using System.Threading.Tasks;
using TelegramBotBase.Base;
using TelegramBotBase.Form;
@@ -11,7 +8,7 @@ namespace JoinHiderBot.forms
{
public override async Task<bool> Open(MessageResult e)
{
await this.Device.Send("This bot works only in groups.");
await Device.Send("This bot works only in groups.");
return true;
}
@@ -20,7 +17,7 @@ namespace JoinHiderBot.forms
{
var gmf = new GroupManageForm();
await this.NavigateTo(gmf);
await NavigateTo(gmf);
return true;
}
+7 -5
View File
@@ -1,17 +1,19 @@
using System;
using SystemCommandsBot.config;
using SystemCommandsBot.forms;
using TelegramBotBase.Builder;
namespace SystemCommandsBot
{
class Program
internal class Program
{
public static config.Config BotConfig { get; set; }
public static Config BotConfig { get; set; }
static void Main(string[] args)
private static void Main(string[] args)
{
BotConfig = config.Config.load();
BotConfig = Config.Load();
if (BotConfig.ApiKey == null || BotConfig.ApiKey.Trim() == "")
{
@@ -21,7 +23,7 @@ namespace SystemCommandsBot
}
var bot = BotBaseBuilder.Create()
.QuickStart<forms.StartForm>(BotConfig.ApiKey)
.QuickStart<StartForm>(BotConfig.ApiKey)
.Build();
bot.Start();
@@ -1,28 +1,23 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
namespace SystemCommandsBot.commands
namespace SystemCommandsBot.commands
{
public class Commando
{
public int ID { get; set; }
public int Id { get; set; }
public String Title { get; set; }
public string Title { get; set; }
public String ShellCmd { get; set; }
public string ShellCmd { get; set; }
public bool Enabled { get; set; } = true;
public String Action { get; set; }
public string Action { get; set; }
public bool UseShell { get; set; } = true;
public int? MaxInstances { get; set; }
public String ProcName
public string ProcName
{
get;set;
}
+22 -21
View File
@@ -1,36 +1,37 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using Newtonsoft.Json;
using SystemCommandsBot.commands;
namespace SystemCommandsBot.config
{
public class Config
{
public String Password { get; set; }
public string Password { get; set; }
public String ApiKey { get; set; }
public string ApiKey { get; set; }
public List<commands.Commando> Commandos { get; set; }
public List<Commando> Commandos { get; set; }
public Config()
{
this.Commandos = new List<commands.Commando>();
Commandos = new List<Commando>();
}
public void loadDefaultValues()
public void LoadDefaultValues()
{
this.ApiKey = "";
this.Commandos.Add(new commands.Commando() { ID = 0, Enabled = true, Title = "Test Befehl", ShellCmd = "explorer.exe", Action = "start", MaxInstances = 2 });
ApiKey = "";
Commandos.Add(new Commando { Id = 0, Enabled = true, Title = "Test Befehl", ShellCmd = "explorer.exe", Action = "start", MaxInstances = 2 });
}
public static Config load()
public static Config Load()
{
try
{
return load(AppContext.BaseDirectory + "config\\default.cfg");
return Load(AppContext.BaseDirectory + "config\\default.cfg");
}
@@ -42,16 +43,16 @@ namespace SystemCommandsBot.config
}
public static Config load(String path)
public static Config Load(string path)
{
try
{
var cfg = Newtonsoft.Json.JsonConvert.DeserializeObject<Config>(File.ReadAllText(path)) as Config;
var cfg = JsonConvert.DeserializeObject<Config>(File.ReadAllText(path));
return cfg;
}
catch (DirectoryNotFoundException ex)
catch (DirectoryNotFoundException)
{
DirectoryInfo di = new DirectoryInfo(path);
var di = new DirectoryInfo(path);
if (!Directory.Exists(di.Parent.FullName))
{
@@ -59,15 +60,15 @@ namespace SystemCommandsBot.config
}
var cfg = new Config();
cfg.loadDefaultValues();
cfg.save(path);
cfg.LoadDefaultValues();
cfg.Save(path);
return cfg;
}
catch (FileNotFoundException ex)
catch (FileNotFoundException)
{
var cfg = new Config();
cfg.loadDefaultValues();
cfg.save(path);
cfg.LoadDefaultValues();
cfg.Save(path);
return cfg;
}
catch(Exception ex)
@@ -77,11 +78,11 @@ namespace SystemCommandsBot.config
return null;
}
public void save(String path)
public void Save(string path)
{
try
{
File.WriteAllText(path, Newtonsoft.Json.JsonConvert.SerializeObject(this));
File.WriteAllText(path, JsonConvert.SerializeObject(this));
}
catch
{
+31 -31
View File
@@ -1,31 +1,29 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TelegramBotBase.Base;
using TelegramBotBase.Form;
namespace SystemCommandsBot.forms
{
public class CmdForm : TelegramBotBase.Form.AutoCleanForm
public class CmdForm : AutoCleanForm
{
public DateTime ExpiresAt { get; set; }
public int? MessageId { get; set; }
public override async Task Load(MessageResult message)
public override Task Load(MessageResult message)
{
return Task.CompletedTask;
}
public override async Task Action(MessageResult message)
{
var btn = message.RawData;
int id = -1;
var id = -1;
if (!int.TryParse(btn, out id))
{
@@ -33,10 +31,10 @@ namespace SystemCommandsBot.forms
return;
}
var cmd = Program.BotConfig.Commandos.Where(a => a.Enabled && a.ID == id).FirstOrDefault();
var cmd = Program.BotConfig.Commandos.Where(a => a.Enabled && a.Id == id).FirstOrDefault();
if (cmd == null)
{
await this.Device.Send("Cmd nicht verfügbar.");
await Device.Send("Cmd nicht verfügbar.");
return;
}
@@ -46,14 +44,14 @@ namespace SystemCommandsBot.forms
{
case "start":
FileInfo fi = new FileInfo(cmd.ShellCmd);
var fi = new FileInfo(cmd.ShellCmd);
if (cmd.MaxInstances != null && cmd.MaxInstances >= 0)
{
if (Process.GetProcessesByName(cmd.ProcName).Count() >= cmd.MaxInstances)
{
await this.Device.Send("Anwendung läuft bereits.");
await Device.Send("Anwendung läuft bereits.");
await message.ConfirmAction("Anwendung läuft bereits.");
return;
@@ -61,14 +59,16 @@ namespace SystemCommandsBot.forms
}
ProcessStartInfo psi = new ProcessStartInfo();
psi.FileName = cmd.ShellCmd;
psi.WorkingDirectory = fi.DirectoryName;
psi.UseShellExecute = cmd.UseShell;
var psi = new ProcessStartInfo
{
FileName = cmd.ShellCmd,
WorkingDirectory = fi.DirectoryName,
UseShellExecute = cmd.UseShell
};
Process.Start(psi);
await this.Device.Send(fi.Name + " wurde gestarted.");
await Device.Send(fi.Name + " wurde gestarted.");
await message.ConfirmAction(fi.Name + " wurde gestarted.");
@@ -76,9 +76,9 @@ namespace SystemCommandsBot.forms
case "kill":
FileInfo fi2 = new FileInfo(cmd.ShellCmd);
var fi2 = new FileInfo(cmd.ShellCmd);
String pros = fi2.Name.Replace(fi2.Extension, "");
var pros = fi2.Name.Replace(fi2.Extension, "");
var proc = Process.GetProcessesByName(pros).ToList();
@@ -94,7 +94,7 @@ namespace SystemCommandsBot.forms
}
}
await this.Device.Send(fi2.Name + " wurde beendet.");
await Device.Send(fi2.Name + " wurde beendet.");
await message.ConfirmAction(fi2.Name + " wurde beendet.");
@@ -102,9 +102,9 @@ namespace SystemCommandsBot.forms
case "restart":
FileInfo fi3 = new FileInfo(cmd.ShellCmd);
var fi3 = new FileInfo(cmd.ShellCmd);
String pros2 = fi3.Name.Replace(fi3.Extension, "");
var pros2 = fi3.Name.Replace(fi3.Extension, "");
var proc2 = Process.GetProcessesByName(pros2).ToList();
@@ -120,17 +120,19 @@ namespace SystemCommandsBot.forms
}
}
FileInfo fi4 = new FileInfo(cmd.ShellCmd);
var fi4 = new FileInfo(cmd.ShellCmd);
ProcessStartInfo psi2 = new ProcessStartInfo();
psi2.FileName = cmd.ShellCmd;
psi2.WorkingDirectory = fi4.DirectoryName;
var psi2 = new ProcessStartInfo
{
FileName = cmd.ShellCmd,
WorkingDirectory = fi4.DirectoryName
};
psi2.FileName = cmd.ShellCmd;
psi2.UseShellExecute = cmd.UseShell;
Process.Start(psi2);
await this.Device.Send(fi3.Name + " wurde neugestarted.");
await Device.Send(fi3.Name + " wurde neugestarted.");
await message.ConfirmAction(fi3.Name + " wurde neugestarted.");
@@ -151,15 +153,13 @@ namespace SystemCommandsBot.forms
public override async Task Render(MessageResult message)
{
if (this.MessageId == null)
if (MessageId == null)
{
var buttons = Program.BotConfig.Commandos.Where(a => a.Enabled).Select(a => new ButtonBase(a.Title, a.ID.ToString()));
var buttons = Program.BotConfig.Commandos.Where(a => a.Enabled).Select(a => new ButtonBase(a.Title, a.Id.ToString()));
ButtonForm bf = new ButtonForm();
var bf = new ButtonForm();
bf.AddSplitted(buttons, 1);
await this.Device.Send("Deine Optionen", bf);
return;
await Device.Send("Deine Optionen", bf);
}
+10 -11
View File
@@ -1,40 +1,39 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using TelegramBotBase.Base;
using TelegramBotBase.Form;
namespace SystemCommandsBot.forms
{
public class StartForm : TelegramBotBase.Form.FormBase
public class StartForm : FormBase
{
public String Password { get; set; }
public string Password { get; set; }
public override async Task Load(MessageResult message)
public override Task Load(MessageResult message)
{
var inp = message.MessageText;
if (Program.BotConfig.Password == inp)
{
this.Password = inp;
Password = inp;
}
return Task.CompletedTask;
}
public override async Task Render(MessageResult message)
{
if (this.Password == null || this.Password.Trim() == "")
if (Password == null || Password.Trim() == "")
{
await this.Device.Send("Bitte gib dein Passwort an.");
await Device.Send("Bitte gib dein Passwort an.");
return;
}
var cmd = new forms.CmdForm();
var cmd = new CmdForm();
cmd.ExpiresAt = DateTime.Now.AddDays(14);
await this.NavigateTo(cmd);
await NavigateTo(cmd);
}