-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.cs
76 lines (67 loc) · 2.54 KB
/
Program.cs
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
using System;
using System.IO;
using System.Security;
using System.Collections.Generic;
namespace robokins
{
partial class Program
{
public static void Main()
{
const string confFileName = "robokins.conf";
if (!File.Exists(confFileName))
throw new FileNotFoundException("Configuration file not found.", confFileName);
var conf = ConfRead(new StreamReader(confFileName));
string usernm = "";
var passwd = new SecureString();
string chanls = "";
usernm = GetKeyValue(conf, "username");
passwd = GetKeySecureValue(conf, "password");
chanls = GetKeyValue(conf, "channels");
Tests(passwd);
var bot = new Bot(usernm, passwd, chanls);
bot.Server = GetKeyValue(conf, "server");
bot.Port = GetKeyIntValue(conf, "port");
bot.Website = GetKeyValue(conf, "website");
bot.Start();
}
private static string GetKeyValue(Dictionary<string, string> table, string Key)
{
string Value = "";
if (table.ContainsKey(Key) && !string.IsNullOrEmpty(table[Key]))
{
Value = table[Key];
table.Remove(Key);
}
if (Value.Length == 0)
throw new ArgumentNullException("Key '" + Key + "' is blank.");
return Value;
}
private static int GetKeyIntValue(Dictionary<string, string> table, string Key)
{
String Value = "";
if (table.ContainsKey(Key) && !string.IsNullOrEmpty(table[Key]))
{
Value = table[Key];
table.Remove(Key);
}
if (Value.Length == 0)
throw new ArgumentNullException("Key '" + Key + "' is blank.");
return Convert.ToInt32(Value);
}
private static SecureString GetKeySecureValue(Dictionary<string, string> table, string Key)
{
var Value = new SecureString();
if (table.ContainsKey(Key) && !string.IsNullOrEmpty(table[Key]))
{
foreach (char letter in table[Key])
Value.AppendChar(letter);
Value.MakeReadOnly();
table.Remove(Key);
}
if (Value.Length == 0)
throw new ArgumentNullException("Key '" + Key + "' is blank.");
return Value;
}
}
}