-
Notifications
You must be signed in to change notification settings - Fork 0
/
Configuration.cs
123 lines (112 loc) · 3.44 KB
/
Configuration.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
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
using System;
using System.Collections.Generic;
using System.IO;
using System.Xml;
using System.Xml.Serialization;
namespace Sevenisko.IceBot
{
public class RemoteUser
{
[XmlElement("Username")]
public string Username { get; set; }
[XmlElement("Password")]
public string Password { get; set; }
}
public class Message
{
[XmlElement("Question")]
public string Question { get; set; }
[XmlElement("Answer")]
public string Answer { get; set; }
}
public class RadioStation
{
[XmlElement("Name")]
public string Name { get; set; }
[XmlElement("Filename")]
public string Filename { get; set; }
[XmlElement("Thumbnail")]
public string Thumbnail { get; set; }
}
[Serializable()]
public class YouTube
{
public bool Enabled { get; set; }
public string APIToken { get; set; }
}
[Serializable()]
public class HTTPSettings
{
public bool Enabled { get; set; }
public string Address { get; set; }
public int Port { get; set; }
}
[Serializable()]
public class Soundcloud
{
public bool Enabled { get; set; }
public string APIToken { get; set; }
}
[Serializable()]
[XmlRoot("IceBotConfig")]
public class ConfigFile
{
[XmlElement("BotToken")]
public string BotToken { get; set; }
[XmlElement("HTTPSettings")]
public HTTPSettings WebSettings { get; set; }
[XmlElement("SCSettings")]
public Soundcloud SCSettings { get; set; }
[XmlElement("YTSettings")]
public YouTube YTSettings { get; set; }
[XmlElement("StatusOnJoin")]
public string StatusOnJoin { get; set; }
public string YoutubeToken { get; set; }
[XmlElement("CommandPrefix")]
public string CommandPrefix { get; set; }
[XmlElement("RemoteAdminEnabled")]
public bool RemoteEnabled { get; set; }
[XmlElement("RemoteAdminPort")]
public int RemotePort { get; set; }
[XmlElement("AntiBadWord")]
public bool AntiBWEnabled { get; set; }
[XmlArray("Users")]
[XmlArrayItem("User")]
public List<RemoteUser> Users { get; set; }
[XmlArray("BadWords")]
[XmlArrayItem("BadWord")]
public List<string> BadWords { get; set; }
[XmlArray("Messages")]
[XmlArrayItem("Message")]
public List<Message> Messages { get; set; }
[XmlArray("Radio")]
[XmlArrayItem("RadioStation")]
public List<RadioStation> Stations { get; set; }
}
public class Configuration
{
public static ConfigFile LoadConfig(string path)
{
XmlSerializer serializer = new XmlSerializer(typeof(ConfigFile));
StreamReader reader = new StreamReader(path);
ConfigFile returnConf = (ConfigFile)serializer.Deserialize(reader);
reader.Close();
return returnConf;
}
public static bool SaveConfig(string path, ConfigFile config)
{
try
{
XmlSerializer serializer = new XmlSerializer(typeof(ConfigFile));
FileStream file = File.Create(path);
serializer.Serialize(file, config);
file.Close();
return true;
}
catch
{
return false;
}
}
}
}