MystBin
/InexpensiveThumbsBased Created 1 year, 7 months ago...
Raw
file.txt Hide Copy Raw
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
using System; using System.IO; using System.Windows.Forms; namespace DiscordBotController { [System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044")] public partial class MainForm : Form { private SSHManager sshManager = null!; #pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable. private TextBox txtConsoleOutput; // Add TextBox control private Button btnCopy; // Add Button control #pragma warning restore CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable. public MainForm() { InitializeComponent(); InitializeSSHManager(); } private void InitializeSSHManager() { string botIp = Environment.GetEnvironmentVariable("RHPC_IP") ?? string.Empty; string botUsername = Environment.GetEnvironmentVariable("RHPC_USERNAME") ?? string.Empty; string password = Environment.GetEnvironmentVariable("RHPC_PASSWORD") ?? string.Empty; if (string.IsNullOrEmpty(botIp) || string.IsNullOrEmpty(botUsername) || string.IsNullOrEmpty(password)) { ShowErrorMessage("Missing environment variables. Please make sure RHPC_IP, RHPC_USERNAME, and RHPC_PASSWORD are set."); Environment.Exit(1); } try { sshManager = new SSHManager(botIp, botUsername, password); // Pass password } catch (Exception ex) { ShowErrorMessage("An error occurred: " + ex.Message); Environment.Exit(1); } } private void btnStartBot_Click(object sender, EventArgs e) { sshManager.StartBotService(output => AppendConsoleOutput(output)); } private void btnStopBot_Click(object sender, EventArgs e) { try { if (sshManager != null) { sshManager.StopBotService(output => AppendConsoleOutput(output)); } else { ShowErrorMessage("SSHManager is not properly initialized."); } } catch (Exception ex) { ShowErrorMessage("An error occurred: " + ex.Message); } } private void ShowErrorMessage(string message) { using (var errorDialog = new ErrorDialog(message)) { errorDialog.ShowDialog(); } } private void AppendConsoleOutput(string output) { if (txtConsoleOutput != null) { txtConsoleOutput.AppendText(output + Environment.NewLine); } } } public class ErrorDialog : Form { private TextBox txtErrorMessage; private Button? btnCopy; public ErrorDialog(string errorMessage) { InitializeComponent(); txtErrorMessage.Text = errorMessage; } private void InitializeComponent() { txtErrorMessage = new TextBox(); btnCopy = new Button(); // Set properties for txtErrorMessage txtErrorMessage.Multiline = true; txtErrorMessage.Dock = DockStyle.Fill; txtErrorMessage.ReadOnly = true; // Set properties for btnCopy btnCopy.Text = "Copy"; btnCopy.Dock = DockStyle.Bottom; btnCopy.Click += BtnCopy_Click; // Add controls to the form Controls.Add(txtErrorMessage); Controls.Add(btnCopy); // Arrange controls using layout logic (e.g., FlowLayoutPanel) } private void BtnCopy_Click(object? sender, EventArgs e) { if (txtErrorMessage != null) { Clipboard.SetText(txtErrorMessage.Text); MessageBox.Show("Error message copied to clipboard."); } } } }