-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinisettings.cs
More file actions
186 lines (155 loc) · 8.07 KB
/
inisettings.cs
File metadata and controls
186 lines (155 loc) · 8.07 KB
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
using Microsoft.VisualBasic;
using Microsoft.VisualBasic.CompilerServices;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
//
// ByteKnight - Console
// Version: 1.4.0 (Public Release - Console Version)
// Author: ByteKnight Development Team (Voidpool)
// Release Date: [01/08/2025]
//
// Description:
// ByteKnight is a powerful, multi-purpose Discord bot built on top of Discord.Net and MongoDB, presented here in a streamlined console-based application.
// It offers a robust set of moderation tools (mute, ban, warn), a flexible leveling/XP system, numerous slash commands, automated role assignments, and more.
// Perfect for server admins who want a feature-rich, easily customizable bot—no GUI overhead required.
//
// Current Features:
// - Verification & Auto Role assignment on join
// - Role management (e.g., mute system)
// - User XP and level tracking, complete with leaderboards
// - Customizable welcome messages and channels
// - Full moderation toolkit: warnings, kicks, bans, purge, etc.
// - Slash commands (roll, coinflip, 8ball, YouTube search, and more)
//
// Future Features (Subject to change as development continues):
// - Custom embed creation for server admins
// - Advanced moderation logging and analytics
// - Expanded slash commands and interactive event handling
// - Additional integrations for streaming and social platforms
//
// Notes:
// - This public release focuses on the console-based core bot features.
// - CodeForge offers a GUI-based version of ByteKnight with working examples for in-app backend settings (MongoDB, etc.)
// available under the "ByteKnight Apprentice" tier and the "ByteKnight Champion (AI)" tier.
// - Both paid tiers provide more command modules, advanced commands in easy-to-use module formats, and dedicated support
// for additions/customizations.
// - Expect ongoing updates, new commands, and refinements.
// - Community feedback and contributions are always welcome!
// - Support/donate at: https://buymeacoffee.com/byteknight
// - Join the ByteKnight Discord (support, coding help, feature requests): https://discord.gg/trm9qEzcuw
//
namespace Botv1
{
public class inisettings
{
[DllImport("kernel32", EntryPoint = "GetPrivateProfileStringA", CharSet = CharSet.Ansi)]
private static extern int GetPrivateProfileString(string lpApplicationName, string lpSchlüsselName, string lpDefault, string lpReturnedString, int nSize, string lpFileName);
[DllImport("kernel32", EntryPoint = "WritePrivateProfileStringA", CharSet = CharSet.Ansi)]
private static extern int WritePrivateProfileString(string lpApplicationName, string lpKeyName, string lpString, string lpFileName);
[DllImport("kernel32", EntryPoint = "WritePrivateProfileStringA", CharSet = CharSet.Ansi)]
private static extern int DeletePrivateProfileSection(string Section, int NoKey, int NoSetting, string FileName);
[DllImport("kernel32.dll", EntryPoint = "GetPrivateProfileIntA", CharSet = CharSet.Ansi)]
private static extern int GetPrivateProfileInt(string lpApplicationName, string lpKeyName, int nDefault, string lpFileName);
private string strFilename;
public string Path;
private void LogMessage(string message, string logFilePath)
{
try
{
// Append the message to the log file
System.IO.File.AppendAllText(logFilePath, $"{DateTime.Now}: {message}{Environment.NewLine}");
}
catch (Exception ex)
{
//ExceptionHandler.LogError(ex);
// Handle any exceptions that may occur while writing to the log file
Console.WriteLine($"Error writing to log file: {ex.Message}");
}
}
public string ReadValue(string Section, string Key, string DefaultValue = "", int BufferSize = 1024)
{
string ReadValueRet = default;
if (string.IsNullOrEmpty(Path))
{
Interaction.MsgBox("No path given" + Constants.vbNewLine + "Could not read Value", MsgBoxStyle.Critical, "No path given");
ReadValueRet = "Error";
return ReadValueRet;
}
if (System.IO.File.Exists(Path) == false)
{
Interaction.MsgBox("File does not exist" + Constants.vbNewLine + "Could not read Value", MsgBoxStyle.Critical, "File does not exist");
ReadValueRet = "Error";
return ReadValueRet;
}
string sTemp = Strings.Space(BufferSize);
int Length = inisettings.GetPrivateProfileString(Section, Key, DefaultValue, sTemp, BufferSize, Path);
return Strings.Left(sTemp, Length);
}
public bool GetBoolean(string Section, string Key, bool Default)
{
// Returns a boolean from your INI file
return inisettings.GetPrivateProfileInt(Section, Key, Conversions.ToInteger(Default), strFilename) == 1;
}
public string GetPath()
{
return Path;
}
public void WriteValue(string Section, string Key, string Value, string path)
{
if (string.IsNullOrEmpty(Path))
{
//do nothing
//Interaction.MsgBox("No path given" + Constants.vbNewLine + "Could not write Value", MsgBoxStyle.Critical, "No path given");
return;
}
string Ordner;
Ordner = System.IO.Path.GetDirectoryName(path);
if (System.IO.Directory.Exists(Ordner) == false)
{
//do nothing
//Interaction.MsgBox("File does not exist" + Constants.vbNewLine + "Could not write Value", MsgBoxStyle.Critical, "Files does not exist");
return;
}
inisettings.WritePrivateProfileString(Section, Key, Value, Path);
}
public void DeleteKey(string Section, string Key)
{
if (string.IsNullOrEmpty(Path))
{
Interaction.MsgBox("No path given" + Constants.vbNewLine + "Could not delete Key", MsgBoxStyle.Critical, "No path given");
return;
}
string Ordner;
Ordner = System.IO.Path.GetDirectoryName(Path);
if (System.IO.Directory.Exists(Ordner) == false)
{
Interaction.MsgBox("File does not exist" + Constants.vbNewLine + "Could not delete Key", MsgBoxStyle.Critical, "File does not exist");
return;
}
string arglpString = null;
inisettings.WritePrivateProfileString(Section, Key, arglpString, Path);
}
public void DeleteSection(string Section)
{
if (string.IsNullOrEmpty(Path))
{
Interaction.MsgBox("No path given" + Constants.vbNewLine + "Could not delete Section", MsgBoxStyle.Critical, "No path given");
return;
}
if (System.IO.File.Exists(Path) == false)
{
Interaction.MsgBox("File does not exist (anymore)" + Constants.vbNewLine + "Could not delete Section", MsgBoxStyle.Critical, "File does not exist");
return;
}
inisettings.DeletePrivateProfileSection(Section, 0, 0, Path);
}
//destructor
~inisettings()
{
}
}
}