Compare commits
23 Commits
v1.0.7-pre
...
v1.0.1.0
| Author | SHA1 | Date | |
|---|---|---|---|
| b5cc8d2bc1 | |||
| 9dcd1e16b0 | |||
| 28b45da382 | |||
| b20872222a | |||
| f6442af30c | |||
| b98f57fcf8 | |||
| 77aad985fa | |||
|
|
f8ebf76f92 | ||
| 6da9828e5c | |||
| 3ba45790e7 | |||
| e440e97948 | |||
|
|
938c73c810 | ||
| a8520c8c96 | |||
| debdc58646 | |||
|
|
c08496e819 | ||
|
|
0f4a82171c | ||
|
|
cbad45605c | ||
| 208d7638c9 | |||
| 26a74a9269 | |||
| ffa6692e07 | |||
| 44690f8e9d | |||
| 9aa9d5ab03 | |||
|
|
88ff621f22 |
13
.idea/.idea.SethDiscordBot/.idea/.gitignore
generated
vendored
13
.idea/.idea.SethDiscordBot/.idea/.gitignore
generated
vendored
@@ -1,13 +0,0 @@
|
|||||||
# Default ignored files
|
|
||||||
/shelf/
|
|
||||||
/workspace.xml
|
|
||||||
# Rider ignored files
|
|
||||||
/projectSettingsUpdater.xml
|
|
||||||
/contentModel.xml
|
|
||||||
/.idea.SethDiscordBot.iml
|
|
||||||
/modules.xml
|
|
||||||
# Editor-based HTTP Client requests
|
|
||||||
/httpRequests/
|
|
||||||
# Datasource local storage ignored files
|
|
||||||
/dataSources/
|
|
||||||
/dataSources.local.xml
|
|
||||||
1
.idea/.idea.SethDiscordBot/.idea/.name
generated
1
.idea/.idea.SethDiscordBot/.idea/.name
generated
@@ -1 +0,0 @@
|
|||||||
SethDiscordBot
|
|
||||||
4
.idea/.idea.SethDiscordBot/.idea/encodings.xml
generated
4
.idea/.idea.SethDiscordBot/.idea/encodings.xml
generated
@@ -1,4 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project version="4">
|
|
||||||
<component name="Encoding" addBOMForNewFiles="with BOM under Windows, with no BOM otherwise" />
|
|
||||||
</project>
|
|
||||||
8
.idea/.idea.SethDiscordBot/.idea/indexLayout.xml
generated
8
.idea/.idea.SethDiscordBot/.idea/indexLayout.xml
generated
@@ -1,8 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project version="4">
|
|
||||||
<component name="UserContentModel">
|
|
||||||
<attachedFolders />
|
|
||||||
<explicitIncludes />
|
|
||||||
<explicitExcludes />
|
|
||||||
</component>
|
|
||||||
</project>
|
|
||||||
6
.idea/.idea.SethDiscordBot/.idea/projectSettingsUpdater.xml
generated
Normal file
6
.idea/.idea.SethDiscordBot/.idea/projectSettingsUpdater.xml
generated
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="RiderProjectSettingsUpdater">
|
||||||
|
<option name="vcsConfiguration" value="2" />
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
6
.idea/.idea.SethDiscordBot/.idea/vcs.xml
generated
6
.idea/.idea.SethDiscordBot/.idea/vcs.xml
generated
@@ -1,6 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project version="4">
|
|
||||||
<component name="VcsDirectoryMappings">
|
|
||||||
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
|
||||||
</component>
|
|
||||||
</project>
|
|
||||||
107
.idea/.idea.SethDiscordBot/.idea/workspace.xml
generated
Normal file
107
.idea/.idea.SethDiscordBot/.idea/workspace.xml
generated
Normal file
@@ -0,0 +1,107 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="AutoGeneratedRunConfigurationManager">
|
||||||
|
<projectFile>DiscordBot/DiscordBot.csproj</projectFile>
|
||||||
|
<projectFile pubXmlPath="DiscordBot/Properties/PublishProfiles/WindowsBuild.pubxml">DiscordBot/DiscordBot.csproj</projectFile>
|
||||||
|
</component>
|
||||||
|
<component name="AutoImportSettings">
|
||||||
|
<option name="autoReloadType" value="SELECTIVE" />
|
||||||
|
</component>
|
||||||
|
<component name="ChangeListManager">
|
||||||
|
<list default="true" id="ab173b07-aba1-4bb8-94c1-ae9846bbdb0a" name="Changes" comment="">
|
||||||
|
<change afterPath="$PROJECT_DIR$/Roles/AddRole.cs" afterDir="false" />
|
||||||
|
<change afterPath="$PROJECT_DIR$/Roles/Internals/RoleManagement.cs" afterDir="false" />
|
||||||
|
<change afterPath="$PROJECT_DIR$/Roles/Roles.csproj" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/BUILDS/net6.0/CMD_Utils.dll" beforeDir="false" afterPath="$PROJECT_DIR$/BUILDS/net6.0/CMD_Utils.dll" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/BUILDS/net6.0/Music Commands.dll" beforeDir="false" afterPath="$PROJECT_DIR$/BUILDS/net6.0/Music Commands.dll" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/BUILDS/net6.0/PluginManager.dll" beforeDir="false" afterPath="$PROJECT_DIR$/BUILDS/net6.0/PluginManager.dll" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/CMD_LevelingSystem/Level.cs" beforeDir="false" afterPath="$PROJECT_DIR$/CMD_LevelingSystem/Level.cs" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/CMD_Utils/Echo.cs" beforeDir="false" afterPath="$PROJECT_DIR$/CMD_Utils/Echo.cs" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/CMD_Utils/FlipCoin.cs" beforeDir="false" afterPath="$PROJECT_DIR$/CMD_Utils/FlipCoin.cs" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/CMD_Utils/Poll.cs" beforeDir="false" afterPath="$PROJECT_DIR$/CMD_Utils/Poll.cs" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/CMD_Utils/Random.cs" beforeDir="false" afterPath="$PROJECT_DIR$/CMD_Utils/Random.cs" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/DiscordBot/Discord/Commands/Help.cs" beforeDir="false" afterPath="$PROJECT_DIR$/DiscordBot/Discord/Commands/Help.cs" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/DiscordBot/Discord/Commands/Restart.cs" beforeDir="false" afterPath="$PROJECT_DIR$/DiscordBot/Discord/Commands/Restart.cs" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/DiscordBot/Discord/Commands/Settings.cs" beforeDir="false" afterPath="$PROJECT_DIR$/DiscordBot/Discord/Commands/Settings.cs" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/DiscordBot/Discord/Core/Boot.cs" beforeDir="false" afterPath="$PROJECT_DIR$/DiscordBot/Discord/Core/Boot.cs" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/DiscordBot/Discord/Core/CommandHandler.cs" beforeDir="false" afterPath="$PROJECT_DIR$/DiscordBot/Discord/Core/CommandHandler.cs" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/DiscordBot/DiscordBot.csproj" beforeDir="false" afterPath="$PROJECT_DIR$/DiscordBot/DiscordBot.csproj" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/DiscordBot/Program.cs" beforeDir="false" afterPath="$PROJECT_DIR$/DiscordBot/Program.cs" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/MusicCommands/Leave.cs" beforeDir="false" afterPath="$PROJECT_DIR$/MusicCommands/Leave.cs" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/MusicCommands/MusicPlayer.cs" beforeDir="false" afterPath="$PROJECT_DIR$/MusicCommands/MusicPlayer.cs" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/MusicCommands/Pause.cs" beforeDir="false" afterPath="$PROJECT_DIR$/MusicCommands/Pause.cs" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/MusicCommands/Play.cs" beforeDir="false" afterPath="$PROJECT_DIR$/MusicCommands/Play.cs" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/MusicCommands/Skip.cs" beforeDir="false" afterPath="$PROJECT_DIR$/MusicCommands/Skip.cs" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/MusicCommands/queue.cs" beforeDir="false" afterPath="$PROJECT_DIR$/MusicCommands/queue.cs" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/PluginManager/Config.cs" beforeDir="false" afterPath="$PROJECT_DIR$/PluginManager/Config.cs" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/PluginManager/Interfaces/DBCommand.cs" beforeDir="false" afterPath="$PROJECT_DIR$/PluginManager/Interfaces/DBCommand.cs" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/PluginManager/Items/Command.cs" beforeDir="false" afterPath="$PROJECT_DIR$/PluginManager/Items/Command.cs" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/PluginManager/Items/ConsoleCommandsHandler.cs" beforeDir="false" afterPath="$PROJECT_DIR$/PluginManager/Items/ConsoleCommandsHandler.cs" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/SethDiscordBot.sln" beforeDir="false" afterPath="$PROJECT_DIR$/SethDiscordBot.sln" afterDir="false" />
|
||||||
|
</list>
|
||||||
|
<option name="SHOW_DIALOG" value="false" />
|
||||||
|
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
||||||
|
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
|
||||||
|
<option name="LAST_RESOLUTION" value="IGNORE" />
|
||||||
|
</component>
|
||||||
|
<component name="MarkdownSettingsMigration">
|
||||||
|
<option name="stateVersion" value="1" />
|
||||||
|
</component>
|
||||||
|
<component name="ProjectId" id="2CUQteUHoNWL2Ok4DVEh1GfFaXk" />
|
||||||
|
<component name="ProjectViewState">
|
||||||
|
<option name="hideEmptyMiddlePackages" value="true" />
|
||||||
|
<option name="showLibraryContents" value="true" />
|
||||||
|
</component>
|
||||||
|
<component name="PropertiesComponent"><![CDATA[{
|
||||||
|
"keyToString": {
|
||||||
|
"ASKED_SHARE_PROJECT_CONFIGURATION_FILES": "true",
|
||||||
|
"RunOnceActivity.OpenProjectViewOnStart": "true",
|
||||||
|
"RunOnceActivity.ShowReadmeOnStart": "true",
|
||||||
|
"WebServerToolWindowFactoryState": "false",
|
||||||
|
"node.js.detected.package.eslint": "true",
|
||||||
|
"node.js.detected.package.tslint": "true",
|
||||||
|
"node.js.selected.package.eslint": "(autodetect)",
|
||||||
|
"node.js.selected.package.tslint": "(autodetect)",
|
||||||
|
"nodejs_package_manager_path": "npm",
|
||||||
|
"settings.editor.selected.configurable": "preferences.pluginManager",
|
||||||
|
"vue.rearranger.settings.migration": "true"
|
||||||
|
}
|
||||||
|
}]]></component>
|
||||||
|
<component name="RunManager">
|
||||||
|
<configuration name="DiscordBot: WindowsBuild" type="DotNetMsBuildPublish" factoryName="Publish to IIS">
|
||||||
|
<riderPublish publish_profile="WindowsBuild.pubxml" pubxml_path="$PROJECT_DIR$/DiscordBot/Properties/PublishProfiles/WindowsBuild.pubxml" uuid_high="612037599008934041" uuid_low="-9069359786678974134" />
|
||||||
|
<method v="2" />
|
||||||
|
</configuration>
|
||||||
|
</component>
|
||||||
|
<component name="SpellCheckerSettings" RuntimeDictionaries="0" Folders="0" CustomDictionaries="0" DefaultDictionary="application-level" UseSingleDictionary="true" transferred="true" />
|
||||||
|
<component name="TaskManager">
|
||||||
|
<task active="true" id="Default" summary="Default task">
|
||||||
|
<changelist id="ab173b07-aba1-4bb8-94c1-ae9846bbdb0a" name="Changes" comment="" />
|
||||||
|
<created>1658854902538</created>
|
||||||
|
<option name="number" value="Default" />
|
||||||
|
<option name="presentableId" value="Default" />
|
||||||
|
<updated>1658854902538</updated>
|
||||||
|
<workItem from="1658854908500" duration="1731000" />
|
||||||
|
</task>
|
||||||
|
<servers />
|
||||||
|
</component>
|
||||||
|
<component name="TypeScriptGeneratedFilesManager">
|
||||||
|
<option name="version" value="3" />
|
||||||
|
</component>
|
||||||
|
<component name="UnityCheckinConfiguration" checkUnsavedScenes="true" />
|
||||||
|
<component name="UnityUnitTestConfiguration" currentTestLauncher="NUnit" />
|
||||||
|
<component name="Vcs.Log.Tabs.Properties">
|
||||||
|
<option name="TAB_STATES">
|
||||||
|
<map>
|
||||||
|
<entry key="MAIN">
|
||||||
|
<value>
|
||||||
|
<State />
|
||||||
|
</value>
|
||||||
|
</entry>
|
||||||
|
</map>
|
||||||
|
</option>
|
||||||
|
</component>
|
||||||
|
<component name="VcsManagerConfiguration">
|
||||||
|
<option name="CLEAR_INITIAL_COMMIT_MESSAGE" value="true" />
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
Binary file not shown.
Binary file not shown.
@@ -1,8 +1,11 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
|
||||||
using Discord;
|
using Discord;
|
||||||
using Discord.Commands;
|
using Discord.Commands;
|
||||||
using Discord.WebSocket;
|
using Discord.WebSocket;
|
||||||
|
|
||||||
|
using PluginManager;
|
||||||
using PluginManager.Interfaces;
|
using PluginManager.Interfaces;
|
||||||
using PluginManager.Loaders;
|
using PluginManager.Loaders;
|
||||||
using PluginManager.Others;
|
using PluginManager.Others;
|
||||||
@@ -31,16 +34,6 @@ internal class Help : DBCommand
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public string Usage => "help <command>";
|
public string Usage => "help <command>";
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Check if the command can be used <inheritdoca DM <see cref="IChannel" />/>
|
|
||||||
/// </summary>
|
|
||||||
public bool canUseDM => true;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Check if the command can be used in a server
|
|
||||||
/// </summary>
|
|
||||||
public bool canUseServer => true;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Check if the command require administrator to be executed
|
/// Check if the command require administrator to be executed
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -50,12 +43,9 @@ internal class Help : DBCommand
|
|||||||
/// The main body of the command
|
/// The main body of the command
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="context">The command context</param>
|
/// <param name="context">The command context</param>
|
||||||
/// <param name="message">The command message</param>
|
public void ExecuteServer(SocketCommandContext context)
|
||||||
/// <param name="client">The discord bot client</param>
|
|
||||||
/// <param name="isDM">True if the message was sent from a DM channel, false otherwise</param>
|
|
||||||
public void Execute(SocketCommandContext context, SocketMessage message, DiscordSocketClient client, bool isDM)
|
|
||||||
{
|
{
|
||||||
var args = Functions.GetArguments(message);
|
var args = Functions.GetArguments(context.Message);
|
||||||
if (args.Count != 0)
|
if (args.Count != 0)
|
||||||
{
|
{
|
||||||
foreach (var item in args)
|
foreach (var item in args)
|
||||||
@@ -74,21 +64,17 @@ internal class Help : DBCommand
|
|||||||
|
|
||||||
var adminCommands = "";
|
var adminCommands = "";
|
||||||
var normalCommands = "";
|
var normalCommands = "";
|
||||||
var DMCommands = "";
|
|
||||||
|
|
||||||
foreach (var cmd in PluginLoader.Commands!)
|
foreach (var cmd in PluginLoader.Commands!)
|
||||||
{
|
{
|
||||||
if (cmd.canUseDM)
|
|
||||||
DMCommands += cmd.Command + " ";
|
|
||||||
if (cmd.requireAdmin)
|
if (cmd.requireAdmin)
|
||||||
adminCommands += cmd.Command + " ";
|
adminCommands += cmd.Command + " ";
|
||||||
if (cmd.canUseServer)
|
else
|
||||||
normalCommands += cmd.Command + " ";
|
normalCommands += cmd.Command + " ";
|
||||||
}
|
}
|
||||||
|
|
||||||
embedBuilder.AddField("Admin Commands", adminCommands);
|
embedBuilder.AddField("Admin Commands", adminCommands);
|
||||||
embedBuilder.AddField("Normal Commands", normalCommands);
|
embedBuilder.AddField("Normal Commands", normalCommands);
|
||||||
embedBuilder.AddField("DM Commands", DMCommands);
|
|
||||||
context.Channel.SendMessageAsync(embed: embedBuilder.Build());
|
context.Channel.SendMessageAsync(embed: embedBuilder.Build());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -98,7 +84,7 @@ internal class Help : DBCommand
|
|||||||
var cmd = PluginLoader.Commands!.Find(p => p.Command == command || (p.Aliases is not null && p.Aliases.Contains(command)));
|
var cmd = PluginLoader.Commands!.Find(p => p.Command == command || (p.Aliases is not null && p.Aliases.Contains(command)));
|
||||||
if (cmd == null) return null;
|
if (cmd == null) return null;
|
||||||
|
|
||||||
embedBuilder.AddField("Usage", cmd.Usage);
|
embedBuilder.AddField("Usage", Config.GetValue<string>("prefix") + cmd.Usage);
|
||||||
embedBuilder.AddField("Description", cmd.Description);
|
embedBuilder.AddField("Description", cmd.Description);
|
||||||
if (cmd.Aliases is null)
|
if (cmd.Aliases is null)
|
||||||
return embedBuilder;
|
return embedBuilder;
|
||||||
|
|||||||
@@ -30,32 +30,18 @@ internal class Restart : DBCommand
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public string Usage => "restart [-p | -c | -args | -cmd] <args>";
|
public string Usage => "restart [-p | -c | -args | -cmd] <args>";
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Check if the command can be used <inheritdoca DM <see cref="IChannel" />/>
|
|
||||||
/// </summary>
|
|
||||||
public bool canUseDM => false;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Check if the command can be used in a server
|
|
||||||
/// </summary>
|
|
||||||
public bool canUseServer => true;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Check if the command require administrator to be executed
|
/// Check if the command require administrator to be executed
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public bool requireAdmin => false;
|
public bool requireAdmin => true;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The main body of the command
|
/// The main body of the command
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="context">The command context</param>
|
/// <param name="context">The command context</param>
|
||||||
/// <param name="message">The command message</param>
|
public async void ExecuteServer(DiscordLibCommands.SocketCommandContext context)
|
||||||
/// <param name="client">The discord bot client</param>
|
|
||||||
/// <param name="isDM">True if the message was sent from a DM channel, false otherwise</param>
|
|
||||||
public async void Execute(DiscordLibCommands.SocketCommandContext context, SocketMessage message, DiscordSocketClient client, bool isDM)
|
|
||||||
{
|
{
|
||||||
if (!(message.Author as SocketGuildUser).hasPermission(DiscordLib.GuildPermission.Administrator)) return;
|
var args = Functions.GetArguments(context.Message);
|
||||||
var args = Functions.GetArguments(message);
|
|
||||||
var OS = Functions.GetOperatingSystem();
|
var OS = Functions.GetOperatingSystem();
|
||||||
if (args.Count == 0)
|
if (args.Count == 0)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,8 +1,10 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
|
||||||
using Discord;
|
using Discord;
|
||||||
using Discord.Commands;
|
using Discord.Commands;
|
||||||
using Discord.WebSocket;
|
using Discord.WebSocket;
|
||||||
|
|
||||||
using PluginManager;
|
using PluginManager;
|
||||||
using PluginManager.Interfaces;
|
using PluginManager.Interfaces;
|
||||||
|
|
||||||
@@ -27,16 +29,6 @@ internal class Settings : DBCommand
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public string Usage => "set [keyword] [new Value]";
|
public string Usage => "set [keyword] [new Value]";
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Check if the command can be used <inheritdoca DM <see cref="IChannel" />/>
|
|
||||||
/// </summary>
|
|
||||||
public bool canUseDM => true;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Check if the command can be used in a server
|
|
||||||
/// </summary>
|
|
||||||
public bool canUseServer => true;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Check if the command require administrator to be executed
|
/// Check if the command require administrator to be executed
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -46,15 +38,12 @@ internal class Settings : DBCommand
|
|||||||
/// The main body of the command
|
/// The main body of the command
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="context">The command context</param>
|
/// <param name="context">The command context</param>
|
||||||
/// <param name="message">The command message</param>
|
public async void Execute(SocketCommandContext context)
|
||||||
/// <param name="client">The discord bot client</param>
|
|
||||||
/// <param name="isDM">True if the message was sent from a DM channel, false otherwise</param>
|
|
||||||
public async void Execute(SocketCommandContext context, SocketMessage message, DiscordSocketClient client, bool isDM)
|
|
||||||
{
|
{
|
||||||
var channel = message.Channel;
|
var channel = context.Message.Channel;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var content = message.Content;
|
var content = context.Message.Content;
|
||||||
var data = content.Split(' ');
|
var data = content.Split(' ');
|
||||||
var keyword = data[1];
|
var keyword = data[1];
|
||||||
if (keyword.ToLower() == "help")
|
if (keyword.ToLower() == "help")
|
||||||
|
|||||||
@@ -1,10 +1,13 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
using Discord;
|
using Discord;
|
||||||
using Discord.Commands;
|
using Discord.Commands;
|
||||||
using Discord.WebSocket;
|
using Discord.WebSocket;
|
||||||
|
|
||||||
using PluginManager;
|
using PluginManager;
|
||||||
|
|
||||||
using static PluginManager.Others.Functions;
|
using static PluginManager.Others.Functions;
|
||||||
|
|
||||||
namespace DiscordBot.Discord.Core;
|
namespace DiscordBot.Discord.Core;
|
||||||
@@ -138,4 +141,5 @@ internal class Boot
|
|||||||
|
|
||||||
return Task.CompletedTask;
|
return Task.CompletedTask;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,10 @@
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
using Discord.Commands;
|
using Discord.Commands;
|
||||||
using Discord.WebSocket;
|
using Discord.WebSocket;
|
||||||
|
|
||||||
using PluginManager.Loaders;
|
using PluginManager.Loaders;
|
||||||
using PluginManager.Others;
|
using PluginManager.Others;
|
||||||
using PluginManager.Others.Permissions;
|
using PluginManager.Others.Permissions;
|
||||||
@@ -75,57 +77,19 @@ internal class CommandHandler
|
|||||||
|
|
||||||
var plugin = PluginLoader.Commands!.Where(p => p.Command == message.Content.Split(' ')[0].Substring(botPrefix.Length) || (p.Aliases is not null && p.Aliases.Contains(message.Content.Split(' ')[0].Substring(botPrefix.Length)))).FirstOrDefault();
|
var plugin = PluginLoader.Commands!.Where(p => p.Command == message.Content.Split(' ')[0].Substring(botPrefix.Length) || (p.Aliases is not null && p.Aliases.Contains(message.Content.Split(' ')[0].Substring(botPrefix.Length)))).FirstOrDefault();
|
||||||
|
|
||||||
|
if (plugin is null) throw new System.Exception("Failed to run command. !");
|
||||||
|
|
||||||
if (plugin != null)
|
if (plugin.requireAdmin && !context.Message.Author.isAdmin())
|
||||||
{
|
|
||||||
if (message.Channel == await message.Author.CreateDMChannelAsync())
|
|
||||||
{
|
|
||||||
if (plugin.canUseDM)
|
|
||||||
{
|
|
||||||
if (plugin.requireAdmin)
|
|
||||||
{
|
|
||||||
if (message.Author.isAdmin())
|
|
||||||
{
|
|
||||||
plugin.Execute(context, message, client, true);
|
|
||||||
Functions.WriteLogFile($"[{message.Author.Id}] Executed command (DM) : " + plugin.Command);
|
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
await message.Channel.SendMessageAsync("This command is for administrators only !");
|
if (context.Channel is SocketDMChannel)
|
||||||
return;
|
plugin.ExecuteDM(context);
|
||||||
}
|
else plugin.ExecuteServer(context);
|
||||||
|
|
||||||
plugin.Execute(context, message, client, true);
|
|
||||||
Functions.WriteLogFile($"[{message.Author.Id}] Executed command (DM) : " + plugin.Command);
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
catch (System.Exception ex)
|
||||||
await message.Channel.SendMessageAsync("This command is not for DMs");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (plugin.canUseServer)
|
|
||||||
{
|
|
||||||
if (plugin.requireAdmin)
|
|
||||||
{
|
|
||||||
if (message.Author.isAdmin())
|
|
||||||
{
|
|
||||||
plugin.Execute(context, message, client, false);
|
|
||||||
Functions.WriteLogFile($"[{message.Author.Id}] Executed command : " + plugin.Command);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
await message.Channel.SendMessageAsync("This command is for administrators only !");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
plugin.Execute(context, message, client, false);
|
|
||||||
Functions.WriteLogFile($"[{message.Author.Id}] Executed command : " + plugin.Command);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch
|
|
||||||
{
|
{
|
||||||
|
ex.WriteErrFile();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
<StartupObject />
|
<StartupObject />
|
||||||
<SignAssembly>False</SignAssembly>
|
<SignAssembly>False</SignAssembly>
|
||||||
<IsPublishable>True</IsPublishable>
|
<IsPublishable>True</IsPublishable>
|
||||||
<AssemblyVersion>1.0.0.2</AssemblyVersion>
|
<AssemblyVersion>1.0.0.13</AssemblyVersion>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
|
||||||
|
|||||||
@@ -1,11 +1,14 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Diagnostics;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
using Discord;
|
||||||
|
|
||||||
using DiscordBot.Discord.Core;
|
using DiscordBot.Discord.Core;
|
||||||
|
|
||||||
using PluginManager;
|
using PluginManager;
|
||||||
@@ -19,6 +22,7 @@ public class Program
|
|||||||
{
|
{
|
||||||
private static bool loadPluginsOnStartup;
|
private static bool loadPluginsOnStartup;
|
||||||
private static bool listPluginsAtStartup;
|
private static bool listPluginsAtStartup;
|
||||||
|
private static ConsoleCommandsHandler consoleCommandsHandler;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The main entry point for the application.
|
/// The main entry point for the application.
|
||||||
@@ -27,17 +31,14 @@ public class Program
|
|||||||
[Obsolete]
|
[Obsolete]
|
||||||
public static void Main(string[] args)
|
public static void Main(string[] args)
|
||||||
{
|
{
|
||||||
|
Console.WriteLine("Loading resources ...");
|
||||||
Directory.CreateDirectory("./Data/Resources");
|
|
||||||
Directory.CreateDirectory("./Data/Plugins/Commands");
|
|
||||||
Directory.CreateDirectory("./Data/Plugins/Events");
|
|
||||||
PreLoadComponents().Wait();
|
PreLoadComponents().Wait();
|
||||||
|
|
||||||
if (!Config.ContainsKey("ServerID"))
|
|
||||||
{
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
Console.Clear();
|
if (!Config.ContainsKey("ServerID"))
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
Console.WriteLine("Please enter the server ID: ");
|
Console.WriteLine("Please enter the server ID: ");
|
||||||
Console_Utilities.WriteColorText("You can find it in the Server Settings at &r\"Widget\"&c section");
|
Console_Utilities.WriteColorText("You can find it in the Server Settings at &r\"Widget\"&c section");
|
||||||
Console.WriteLine("Example: 1234567890123456789");
|
Console.WriteLine("Example: 1234567890123456789");
|
||||||
@@ -52,20 +53,16 @@ public class Program
|
|||||||
string SID = key.KeyChar + Console.ReadLine();
|
string SID = key.KeyChar + Console.ReadLine();
|
||||||
if (SID.Length != 18)
|
if (SID.Length != 18)
|
||||||
{
|
{
|
||||||
Console.WriteLine("Your server ID is not 18 characters long. Please try again.");
|
Console.Clear();
|
||||||
|
Console_Utilities.WriteColorText("&rYour server ID is not 18 characters long. Please try again. \n");
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Config.AddValueToVariables("ServerID", SID, false);
|
Config.AddValueToVariables("ServerID", SID, false);
|
||||||
|
|
||||||
}
|
}
|
||||||
break;
|
|
||||||
} while (true);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!Config.ContainsKey("token") || Config.GetValue<string>("token") == null || Config.GetValue<string>("token")?.Length != 70)
|
if (!Config.ContainsKey("token") || Config.GetValue<string>("token") == null || (Config.GetValue<string>("token")?.Length != 70 && Config.GetValue<string>("token")?.Length != 59))
|
||||||
{
|
{
|
||||||
Console.WriteLine("Please insert your token");
|
Console.WriteLine("Please insert your token");
|
||||||
Console.Write("Token = ");
|
Console.Write("Token = ");
|
||||||
@@ -73,28 +70,31 @@ public class Program
|
|||||||
if (token?.Length == 59 || token?.Length == 70)
|
if (token?.Length == 59 || token?.Length == 70)
|
||||||
Config.AddValueToVariables("token", token, true);
|
Config.AddValueToVariables("token", token, true);
|
||||||
else
|
else
|
||||||
Console.WriteLine("Invalid token");
|
{
|
||||||
|
Console.Clear();
|
||||||
Console.WriteLine("Please insert your prefix (max. 1 character long):");
|
Console_Utilities.WriteColorText("&rThe token length is invalid !");
|
||||||
Console.WriteLine("For a prefix longer then one character, the first character will be saved and the others will be ignored.\n No spaces or numbers allowed");
|
continue;
|
||||||
Console.Write("Prefix = ");
|
}
|
||||||
var prefix = Console.ReadLine()![0];
|
|
||||||
|
|
||||||
if (prefix == ' ' || char.IsDigit(prefix))
|
|
||||||
return;
|
|
||||||
Config.AddValueToVariables("prefix", prefix.ToString(), false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!Config.ContainsKey("prefix") || Config.GetValue<string>("prefix") == default)
|
if (!Config.ContainsKey("prefix") || Config.GetValue<string>("prefix") == null || Config.GetValue<string>("prefix")?.Length != 1)
|
||||||
{
|
{
|
||||||
Console.WriteLine("Please insert your prefix (max. 1 character long):");
|
Console.WriteLine("Please insert your prefix (max. 1 character long):");
|
||||||
Console.WriteLine("For a prefix longer then one character, the first character will be saved and the others will be ignored.\n No spaces or numbers allowed");
|
Console.WriteLine("For a prefix longer then one character, the first character will be saved and the others will be ignored.\n No spaces, numbers, '/' or '\\' allowed");
|
||||||
Console.Write("Prefix = ");
|
Console.Write("Prefix = ");
|
||||||
var prefix = Console.ReadLine()![0];
|
var prefix = Console.ReadLine()![0];
|
||||||
if (prefix == ' ') return;
|
|
||||||
|
if (prefix == ' ' || char.IsDigit(prefix) || prefix == '/' || prefix == '\\')
|
||||||
|
{
|
||||||
|
Console.Clear();
|
||||||
|
Console_Utilities.WriteColorText("&rThe prefix is invalid");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
Config.AddValueToVariables("prefix", prefix.ToString(), false);
|
Config.AddValueToVariables("prefix", prefix.ToString(), false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
} while (true);
|
||||||
|
|
||||||
HandleInput(args).Wait();
|
HandleInput(args).Wait();
|
||||||
}
|
}
|
||||||
@@ -105,23 +105,25 @@ public class Program
|
|||||||
/// <param name="discordbooter">The discord booter used to start the application</param>
|
/// <param name="discordbooter">The discord booter used to start the application</param>
|
||||||
private static void NoGUI(Boot discordbooter)
|
private static void NoGUI(Boot discordbooter)
|
||||||
{
|
{
|
||||||
var consoleCommandsHandler = new ConsoleCommandsHandler(discordbooter.client);
|
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
Console.WriteLine();
|
Console.WriteLine();
|
||||||
consoleCommandsHandler.HandleCommand("lp");
|
ConsoleCommandsHandler.ExecuteCommad("lp").Wait();
|
||||||
#else
|
#else
|
||||||
if (loadPluginsOnStartup) consoleCommandsHandler.HandleCommand("lp");
|
if (loadPluginsOnStartup) consoleCommandsHandler.HandleCommand("lp");
|
||||||
if (listPluginsAtStartup) consoleCommandsHandler.HandleCommand("listplugs");
|
if (listPluginsAtStartup) consoleCommandsHandler.HandleCommand("listplugs");
|
||||||
#endif
|
#endif
|
||||||
Config.SaveConfig();
|
Config.SaveConfig(SaveType.NORMAL).Wait();
|
||||||
|
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
//Console_Utilities.WriteColorText("&rSethBot (&yDEBUG&r) &c> ", false);
|
|
||||||
var cmd = Console.ReadLine();
|
var cmd = Console.ReadLine();
|
||||||
if (!consoleCommandsHandler.HandleCommand(cmd!,
|
if (!consoleCommandsHandler.HandleCommand(cmd!
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
false
|
, false
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
) && cmd.Length > 0)
|
) && cmd.Length > 0)
|
||||||
Console.WriteLine("Failed to run command " + cmd);
|
Console.WriteLine("Failed to run command " + cmd);
|
||||||
}
|
}
|
||||||
@@ -146,6 +148,14 @@ public class Program
|
|||||||
|
|
||||||
Console_Utilities.WriteColorText("&rRemember to close the bot using the ShutDown command (&ysd&r) or some settings won't be saved\n");
|
Console_Utilities.WriteColorText("&rRemember to close the bot using the ShutDown command (&ysd&r) or some settings won't be saved\n");
|
||||||
Console.ForegroundColor = ConsoleColor.White;
|
Console.ForegroundColor = ConsoleColor.White;
|
||||||
|
|
||||||
|
if (Config.ContainsKey("LaunchMessage"))
|
||||||
|
{
|
||||||
|
Console_Utilities.WriteColorText(Config.GetValue<string>("LaunchMessage"));
|
||||||
|
Config.RemoveKey("LaunchMessage");
|
||||||
|
}
|
||||||
|
|
||||||
|
Console_Utilities.WriteColorText("Please note that the bot saves a backup save file every time you are using the shudown command (&ysd&c)");
|
||||||
Console.WriteLine($"============================ LOG ============================");
|
Console.WriteLine($"============================ LOG ============================");
|
||||||
|
|
||||||
try
|
try
|
||||||
@@ -164,7 +174,6 @@ public class Program
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
var prefix = Config.GetValue<string>("prefix");
|
var prefix = Config.GetValue<string>("prefix");
|
||||||
|
|
||||||
var discordbooter = new Boot(token, prefix);
|
var discordbooter = new Boot(token, prefix);
|
||||||
await discordbooter.Awake();
|
await discordbooter.Awake();
|
||||||
return discordbooter;
|
return discordbooter;
|
||||||
@@ -199,6 +208,7 @@ public class Program
|
|||||||
/// <param name="args">The arguments</param>
|
/// <param name="args">The arguments</param>
|
||||||
private static async Task HandleInput(string[] args)
|
private static async Task HandleInput(string[] args)
|
||||||
{
|
{
|
||||||
|
|
||||||
var len = args.Length;
|
var len = args.Length;
|
||||||
|
|
||||||
if (len == 3 && args[0] == "/download")
|
if (len == 3 && args[0] == "/download")
|
||||||
@@ -222,11 +232,50 @@ public class Program
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
var b = await StartNoGUI();
|
||||||
|
consoleCommandsHandler = new ConsoleCommandsHandler(b.client);
|
||||||
|
|
||||||
|
if (len > 0 && args[0] == "/remplug")
|
||||||
|
{
|
||||||
|
|
||||||
|
string plugName = Functions.MergeStrings(args, 1);
|
||||||
|
Console.WriteLine("Starting to remove " + plugName);
|
||||||
|
await ConsoleCommandsHandler.ExecuteCommad("remplug " + plugName);
|
||||||
|
loadPluginsOnStartup = true;
|
||||||
|
len = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (len > 0 && args[0] == "/updateplug")
|
||||||
|
{
|
||||||
|
string plugName = args.MergeStrings(1);
|
||||||
|
Console.WriteLine("Updating " + plugName);
|
||||||
|
await ConsoleCommandsHandler.ExecuteCommad("dwplug" + plugName);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (len == 0 || (args[0] != "--exec" && args[0] != "--execute"))
|
if (len == 0 || (args[0] != "--exec" && args[0] != "--execute"))
|
||||||
{
|
{
|
||||||
var b = await StartNoGUI();
|
|
||||||
|
|
||||||
Thread mainThread = new Thread(() => NoGUI(b));
|
Thread mainThread = new Thread(() =>
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
NoGUI(b);
|
||||||
|
}
|
||||||
|
catch (IOException ex)
|
||||||
|
{
|
||||||
|
if (ex.Message == "No process is on the other end of the pipe." || (uint)ex.HResult == 0x800700E9)
|
||||||
|
{
|
||||||
|
if (!Config.ContainsKey("LaunchMessage"))
|
||||||
|
Config.AddValueToVariables("LaunchMessage", "An error occured while closing the bot last time. Please consider closing the bot using the &rsd&c method !\nThere is a risk of losing all data or corruption of the save file, which in some cases requires to reinstall the bot !", false);
|
||||||
|
Functions.WriteErrFile(ex.ToString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
});
|
||||||
mainThread.Start();
|
mainThread.Start();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -283,6 +332,12 @@ public class Program
|
|||||||
|
|
||||||
private static async Task PreLoadComponents()
|
private static async Task PreLoadComponents()
|
||||||
{
|
{
|
||||||
|
Console_Utilities.ProgressBar main = new Console_Utilities.ProgressBar(ProgressBarType.NO_END);
|
||||||
|
main.Start();
|
||||||
|
Directory.CreateDirectory("./Data/Resources");
|
||||||
|
Directory.CreateDirectory("./Data/Plugins/Commands");
|
||||||
|
Directory.CreateDirectory("./Data/Plugins/Events");
|
||||||
|
Directory.CreateDirectory("./Data/PAKS");
|
||||||
await Config.LoadConfig();
|
await Config.LoadConfig();
|
||||||
if (Config.ContainsKey("DeleteLogsAtStartup"))
|
if (Config.ContainsKey("DeleteLogsAtStartup"))
|
||||||
if (Config.GetValue<bool>("DeleteLogsAtStartup"))
|
if (Config.GetValue<bool>("DeleteLogsAtStartup"))
|
||||||
@@ -312,7 +367,11 @@ public class Program
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
List<string> onlineSettingsList = await ServerCom.ReadTextFromURL("https://raw.githubusercontent.com/Wizzy69/installer/discord-bot-files/OnlineData");
|
List<string> onlineSettingsList = await ServerCom.ReadTextFromURL("https://raw.githubusercontent.com/Wizzy69/installer/discord-bot-files/OnlineData");
|
||||||
|
main.Stop("Loaded online settings. Loading updates ...");
|
||||||
foreach (var key in onlineSettingsList)
|
foreach (var key in onlineSettingsList)
|
||||||
{
|
{
|
||||||
if (key.Length <= 3 || !key.Contains(' ')) continue;
|
if (key.Length <= 3 || !key.Contains(' ')) continue;
|
||||||
@@ -324,42 +383,47 @@ public class Program
|
|||||||
string newVersion = s[1];
|
string newVersion = s[1];
|
||||||
if (!newVersion.Equals(Config.GetValue<string>("Version")))
|
if (!newVersion.Equals(Config.GetValue<string>("Version")))
|
||||||
{
|
{
|
||||||
Console.WriteLine("A new version has been released on github page.");
|
if (Functions.GetOperatingSystem() == PluginManager.Others.OperatingSystem.WINDOWS)
|
||||||
Console.WriteLine("Download the new version using the following link wrote in yellow");
|
|
||||||
Console_Utilities.WriteColorText("&y" + Config.GetValue<string>("GitURL") + "&c");
|
|
||||||
|
|
||||||
Console.WriteLine();
|
|
||||||
Console.WriteLine("Your product will work just fine on this outdated version, but an update is recommended.\n" +
|
|
||||||
"From now on, this version is no longer supported"
|
|
||||||
);
|
|
||||||
Console_Utilities.WriteColorText("&rUse at your own risk&c");
|
|
||||||
|
|
||||||
Console_Utilities.WriteColorText("&mCurrent Version: " + Config.GetValue<string>("Version") + "&c");
|
|
||||||
Console_Utilities.WriteColorText("&gNew Version: " + newVersion + "&c");
|
|
||||||
|
|
||||||
Console.WriteLine("\n\n");
|
|
||||||
await Task.Delay(1000);
|
|
||||||
|
|
||||||
int waitTime = 10; //wait time to proceed
|
|
||||||
|
|
||||||
Console.Write($"The bot will start in {waitTime} seconds");
|
|
||||||
while (waitTime > 0)
|
|
||||||
{
|
{
|
||||||
await Task.Delay(1000);
|
|
||||||
waitTime--;
|
string url = $"https://github.com/Wizzy69/SethDiscordBot/releases/download/v{newVersion}/net6.0.zip";
|
||||||
Console.SetCursorPosition("The bot will start in ".Length, Console.CursorTop);
|
//string url2 = $"https://github.com/Wizzy69/SethDiscordBot/releases/download/v{newVersion}-preview/net6.0.zip";
|
||||||
Console.Write(" ");
|
|
||||||
Console.SetCursorPosition("The bot will start in ".Length, Console.CursorTop);
|
Process.Start(".\\Updater\\Updater.exe", $"{newVersion} {url} {Process.GetCurrentProcess().ProcessName}");
|
||||||
Console.Write(waitTime + " seconds");
|
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
string url = $"https://github.com/Wizzy69/SethDiscordBot/releases/download/v{newVersion}/net6.0_linux.zip";
|
||||||
|
Process.Start("./Updater/Updater", $"/update {url} ./DiscordBot ./");
|
||||||
|
}
|
||||||
|
//Environment.Exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
case "UpdaterVersion":
|
||||||
|
string updaternewversion = s[1];
|
||||||
|
if (Config.UpdaterVersion != updaternewversion)
|
||||||
|
{
|
||||||
|
Console.Clear();
|
||||||
|
Console.WriteLine("Installing updater ...\nDo NOT close the bot during update !");
|
||||||
|
Console_Utilities.ProgressBar bar = new Console_Utilities.ProgressBar(ProgressBarType.NO_END);
|
||||||
|
bar.Start();
|
||||||
|
await ServerCom.DownloadFileNoProgressAsync("https://github.com/Wizzy69/installer/releases/download/release-1-discordbot/Updater.zip", "./Updater.zip");
|
||||||
|
await Functions.ExtractArchive("./Updater.zip", "./", null, UnzipProgressType.PercentageFromTotalSize);
|
||||||
|
Config.UpdaterVersion = updaternewversion;
|
||||||
|
File.Delete("Updater.zip");
|
||||||
|
await Config.SaveConfig(SaveType.NORMAL);
|
||||||
|
bar.Stop("Updater has been updated !");
|
||||||
|
Console.Clear();
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Console_Utilities.Initialize();
|
|
||||||
|
|
||||||
Config.SaveConfig();
|
Console_Utilities.Initialize();
|
||||||
|
await Config.SaveConfig(SaveType.NORMAL);
|
||||||
|
Console.Clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,14 +0,0 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
|
||||||
|
|
||||||
<PropertyGroup>
|
|
||||||
<OutputType>Exe</OutputType>
|
|
||||||
<TargetFramework>net6.0</TargetFramework>
|
|
||||||
<ImplicitUsings>enable</ImplicitUsings>
|
|
||||||
<Nullable>enable</Nullable>
|
|
||||||
</PropertyGroup>
|
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<ProjectReference Include="..\PluginManager\PluginManager.csproj" />
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
</Project>
|
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
using PluginManager.Online.Updates;
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
bool requireUpdate = await PluginUpdater.CheckForUpdates("DiscordBotConsoleLauncher");
|
|
||||||
if (requireUpdate)
|
|
||||||
{
|
|
||||||
var update = await PluginUpdater.DownloadUpdateInfo("DiscordBotConsoleLauncher");
|
|
||||||
if (update == Update.Empty)
|
|
||||||
return;
|
|
||||||
|
|
||||||
Console.WriteLine("Found an update: ");
|
|
||||||
Console.WriteLine(update.ToString());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
Console.WriteLine("An exception was thrown. ");
|
|
||||||
Console.WriteLine(ex.Message);
|
|
||||||
Environment.Exit(-2);
|
|
||||||
}
|
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
using AngleSharp.Dom;
|
using AngleSharp.Dom;
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
@@ -22,7 +23,7 @@ namespace MusicCommands
|
|||||||
internal async Task DownloadAudioFile()
|
internal async Task DownloadAudioFile()
|
||||||
{
|
{
|
||||||
Process proc = new Process();
|
Process proc = new Process();
|
||||||
proc.StartInfo.FileName = "MusicDownloader.exe";
|
proc.StartInfo.FileName = "MusicDownloader";
|
||||||
proc.StartInfo.Arguments = $"{Url},{Name}";
|
proc.StartInfo.Arguments = $"{Url},{Name}";
|
||||||
proc.StartInfo.UseShellExecute = false;
|
proc.StartInfo.UseShellExecute = false;
|
||||||
proc.StartInfo.RedirectStandardOutput = true;
|
proc.StartInfo.RedirectStandardOutput = true;
|
||||||
|
|||||||
@@ -11,10 +11,10 @@ namespace PluginManager
|
|||||||
{
|
{
|
||||||
internal class AppConfig
|
internal class AppConfig
|
||||||
{
|
{
|
||||||
|
public string? UpdaterVersion { get; set; }
|
||||||
public Dictionary<string, object>? ApplicationVariables { get; init; }
|
public Dictionary<string, object>? ApplicationVariables { get; init; }
|
||||||
public List<string>? ProtectedKeyWords { get; init; }
|
public List<string>? ProtectedKeyWords { get; init; }
|
||||||
|
public Dictionary<string, string>? PluginVersions { get; init; }
|
||||||
public Dictionary<string, string> PluginVersions { get; init; }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class Config
|
public static class Config
|
||||||
@@ -59,9 +59,8 @@ namespace PluginManager
|
|||||||
public static bool Contains(string pluginName)
|
public static bool Contains(string pluginName)
|
||||||
{
|
{
|
||||||
foreach (var tuple in InstalledPlugins)
|
foreach (var tuple in InstalledPlugins)
|
||||||
{
|
if (tuple.Item1 == pluginName)
|
||||||
if (tuple.Item1 == pluginName) return true;
|
return true;
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -79,18 +78,20 @@ namespace PluginManager
|
|||||||
|
|
||||||
private static AppConfig? appConfig { get; set; }
|
private static AppConfig? appConfig { get; set; }
|
||||||
|
|
||||||
public static string GetPluginVersion(string pluginName) => appConfig.PluginVersions[pluginName];
|
public static string UpdaterVersion { get => appConfig.UpdaterVersion; set => appConfig.UpdaterVersion = value; }
|
||||||
|
|
||||||
|
public static string GetPluginVersion(string pluginName) => appConfig!.PluginVersions![pluginName];
|
||||||
public static void SetPluginVersion(string pluginName, string newVersion)
|
public static void SetPluginVersion(string pluginName, string newVersion)
|
||||||
{
|
{
|
||||||
if (appConfig.PluginVersions.ContainsKey(pluginName))
|
if (appConfig!.PluginVersions!.ContainsKey(pluginName))
|
||||||
appConfig.PluginVersions[pluginName] = newVersion;
|
appConfig.PluginVersions[pluginName] = newVersion;
|
||||||
else appConfig.PluginVersions.Add(pluginName, newVersion);
|
else appConfig.PluginVersions.Add(pluginName, newVersion);
|
||||||
|
|
||||||
// SaveConfig();
|
// SaveConfig();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void RemovePluginVersion(string pluginName) => appConfig.PluginVersions.Remove(pluginName);
|
public static void RemovePluginVersion(string pluginName) => appConfig!.PluginVersions!.Remove(pluginName);
|
||||||
public static bool PluginVersionsContainsKey(string pluginName) => appConfig.PluginVersions.ContainsKey(pluginName);
|
public static bool PluginVersionsContainsKey(string pluginName) => appConfig!.PluginVersions!.ContainsKey(pluginName);
|
||||||
|
|
||||||
public static void AddValueToVariables<T>(string key, T value, bool isProtected)
|
public static void AddValueToVariables<T>(string key, T value, bool isProtected)
|
||||||
{
|
{
|
||||||
@@ -103,7 +104,7 @@ namespace PluginManager
|
|||||||
if (isProtected && key != "Version")
|
if (isProtected && key != "Version")
|
||||||
appConfig.ProtectedKeyWords!.Add(key);
|
appConfig.ProtectedKeyWords!.Add(key);
|
||||||
|
|
||||||
SaveConfig();
|
SaveConfig(SaveType.NORMAL);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Type GetVariableType(string value)
|
public static Type GetVariableType(string value)
|
||||||
@@ -171,7 +172,7 @@ namespace PluginManager
|
|||||||
throw new Exception("Key is protected");
|
throw new Exception("Key is protected");
|
||||||
|
|
||||||
appConfig.ApplicationVariables[key] = JsonSerializer.SerializeToElement(value);
|
appConfig.ApplicationVariables[key] = JsonSerializer.SerializeToElement(value);
|
||||||
SaveConfig();
|
SaveConfig(SaveType.NORMAL);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void RemoveKey(string key)
|
public static void RemoveKey(string key)
|
||||||
@@ -180,30 +181,59 @@ namespace PluginManager
|
|||||||
throw new Exception("Key is protected");
|
throw new Exception("Key is protected");
|
||||||
appConfig!.ApplicationVariables!.Remove(key);
|
appConfig!.ApplicationVariables!.Remove(key);
|
||||||
appConfig.ProtectedKeyWords!.Remove(key);
|
appConfig.ProtectedKeyWords!.Remove(key);
|
||||||
SaveConfig();
|
SaveConfig(SaveType.NORMAL);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static async void SaveConfig()
|
public static bool IsReadOnly(string key)
|
||||||
|
{
|
||||||
|
return appConfig.ProtectedKeyWords.Contains(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static async Task SaveConfig(SaveType type)
|
||||||
|
{
|
||||||
|
if (type == SaveType.NORMAL)
|
||||||
{
|
{
|
||||||
string path = Functions.dataFolder + "config.json";
|
string path = Functions.dataFolder + "config.json";
|
||||||
await Functions.SaveToJsonFile<AppConfig>(path, appConfig!);
|
await Functions.SaveToJsonFile<AppConfig>(path, appConfig!);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (type == SaveType.BACKUP)
|
||||||
|
{
|
||||||
|
string path = Functions.dataFolder + "config.json.bak";
|
||||||
|
await Functions.SaveToJsonFile<AppConfig>(path, appConfig!);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static async Task LoadConfig()
|
public static async Task LoadConfig()
|
||||||
{
|
{
|
||||||
string path = Functions.dataFolder + "config.json";
|
string path = Functions.dataFolder + "config.json";
|
||||||
if (File.Exists(path))
|
if (File.Exists(path))
|
||||||
|
{
|
||||||
|
try
|
||||||
{
|
{
|
||||||
appConfig = await Functions.ConvertFromJson<AppConfig>(path);
|
appConfig = await Functions.ConvertFromJson<AppConfig>(path);
|
||||||
Functions.WriteLogFile($"Loaded {appConfig.ApplicationVariables!.Keys.Count} application variables.\nLoaded {appConfig.ProtectedKeyWords!.Count} readonly variables.");
|
|
||||||
}
|
}
|
||||||
else
|
catch (Exception ex)
|
||||||
appConfig = new() { ApplicationVariables = new Dictionary<string, object>(), ProtectedKeyWords = new List<string>(), PluginVersions = new Dictionary<string, string>() };
|
{
|
||||||
|
File.Delete(path);
|
||||||
|
Console.WriteLine("An error occured while loading the settings. Importing from backup file...");
|
||||||
|
path = Functions.dataFolder + "config.json.bak";
|
||||||
|
appConfig = await Functions.ConvertFromJson<AppConfig>(path);
|
||||||
|
Functions.WriteErrFile(ex.Message);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Functions.WriteLogFile($"Loaded {appConfig.ApplicationVariables!.Keys.Count} application variables.\nLoaded {appConfig.ProtectedKeyWords!.Count} readonly variables.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
appConfig = new() { ApplicationVariables = new Dictionary<string, object>(), ProtectedKeyWords = new List<string>(), PluginVersions = new Dictionary<string, string>(), UpdaterVersion = "-1" };
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool ContainsValue<T>(T value) => appConfig!.ApplicationVariables!.ContainsValue(value!);
|
public static bool ContainsValue<T>(T value) => appConfig!.ApplicationVariables!.ContainsValue(value!);
|
||||||
public static bool ContainsKey(string key) => appConfig!.ApplicationVariables!.ContainsKey(key);
|
public static bool ContainsKey(string key) => appConfig!.ApplicationVariables!.ContainsKey(key);
|
||||||
|
|
||||||
public static ReadOnlyDictionary<string, object> GetAllVariables() => new(appConfig!.ApplicationVariables!);
|
public static IDictionary<string, object> GetAllVariables() => appConfig.ApplicationVariables;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
|
||||||
using Discord.Commands;
|
using Discord.Commands;
|
||||||
using Discord.WebSocket;
|
using Discord.WebSocket;
|
||||||
|
|
||||||
@@ -28,27 +29,20 @@ public interface DBCommand
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
string Usage { get; }
|
string Usage { get; }
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// true if the command can be used in a DM channel, otherwise false
|
|
||||||
/// </summary>
|
|
||||||
bool canUseDM { get; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// true if the command can be used in a server, otherwise false
|
|
||||||
/// </summary>
|
|
||||||
bool canUseServer { get; }
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// true if the command requre admin, otherwise false
|
/// true if the command requre admin, otherwise false
|
||||||
/// </summary>
|
/// </summary>
|
||||||
bool requireAdmin { get; }
|
bool requireAdmin { get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The main body of the command. This is what is executed when user calls the command
|
/// The main body of the command. This is what is executed when user calls the command in Server
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="context">The disocrd Context</param>
|
/// <param name="context">The disocrd Context</param>
|
||||||
/// <param name="message">The message that the user types</param>
|
void ExecuteServer(SocketCommandContext context) { }
|
||||||
/// <param name="client">The discord client of the bot</param>
|
|
||||||
/// <param name="isDM">true if the message was sent from DM, otherwise false. It is always false if canUseDM is false</param>
|
/// <summary>
|
||||||
void Execute(SocketCommandContext context, SocketMessage message, DiscordSocketClient client, bool isDM);
|
/// The main body of the command. This is what is executed when user calls the command in DM
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="context">The disocrd Context</param>
|
||||||
|
void ExecuteDM(SocketCommandContext context) { }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Diagnostics;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Net.Http;
|
using System.Net.Http;
|
||||||
@@ -13,9 +14,7 @@ using PluginManager.Interfaces;
|
|||||||
using PluginManager.Loaders;
|
using PluginManager.Loaders;
|
||||||
using PluginManager.Online;
|
using PluginManager.Online;
|
||||||
using PluginManager.Online.Helpers;
|
using PluginManager.Online.Helpers;
|
||||||
using PluginManager.Online.Updates;
|
|
||||||
using PluginManager.Others;
|
using PluginManager.Others;
|
||||||
|
|
||||||
namespace PluginManager.Items;
|
namespace PluginManager.Items;
|
||||||
|
|
||||||
public class ConsoleCommandsHandler
|
public class ConsoleCommandsHandler
|
||||||
@@ -81,30 +80,48 @@ public class ConsoleCommandsHandler
|
|||||||
if (pluginsLoaded)
|
if (pluginsLoaded)
|
||||||
return;
|
return;
|
||||||
var loader = new PluginLoader(client!);
|
var loader = new PluginLoader(client!);
|
||||||
|
ConsoleColor cc = Console.ForegroundColor;
|
||||||
loader.onCMDLoad += (name, typeName, success, exception) =>
|
loader.onCMDLoad += (name, typeName, success, exception) =>
|
||||||
{
|
{
|
||||||
Console.ForegroundColor = ConsoleColor.Green;
|
|
||||||
if (name == null || name.Length < 2)
|
if (name == null || name.Length < 2)
|
||||||
name = typeName;
|
name = typeName;
|
||||||
if (success)
|
if (success)
|
||||||
|
{
|
||||||
|
Console.ForegroundColor = ConsoleColor.Green;
|
||||||
Console.WriteLine("[CMD] Successfully loaded command : " + name);
|
Console.WriteLine("[CMD] Successfully loaded command : " + name);
|
||||||
|
}
|
||||||
|
|
||||||
else
|
else
|
||||||
Console.WriteLine("[CMD] Failed to load command : " + name + " because " + exception!.Message);
|
{
|
||||||
Console.ForegroundColor = ConsoleColor.Red;
|
Console.ForegroundColor = ConsoleColor.Red;
|
||||||
|
|
||||||
|
Console.WriteLine("[CMD] Failed to load command : " + name + " because " + exception!.Message);
|
||||||
|
}
|
||||||
|
Console.ForegroundColor = cc;
|
||||||
};
|
};
|
||||||
loader.onEVELoad += (name, typeName, success, exception) =>
|
loader.onEVELoad += (name, typeName, success, exception) =>
|
||||||
{
|
{
|
||||||
if (name == null || name.Length < 2)
|
if (name == null || name.Length < 2)
|
||||||
name = typeName;
|
name = typeName;
|
||||||
Console.ForegroundColor = ConsoleColor.Green;
|
|
||||||
if (success)
|
if (success)
|
||||||
|
{
|
||||||
|
Console.ForegroundColor = ConsoleColor.Green;
|
||||||
Console.WriteLine("[EVENT] Successfully loaded event : " + name);
|
Console.WriteLine("[EVENT] Successfully loaded event : " + name);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
Console.WriteLine("[EVENT] Failed to load event : " + name + " because " + exception!.Message);
|
{
|
||||||
Console.ForegroundColor = ConsoleColor.Red;
|
Console.ForegroundColor = ConsoleColor.Red;
|
||||||
|
Console.WriteLine("[EVENT] Failed to load event : " + name + " because " + exception!.Message);
|
||||||
|
}
|
||||||
|
Console.ForegroundColor = cc;
|
||||||
};
|
};
|
||||||
|
|
||||||
loader.LoadPlugins();
|
loader.LoadPlugins();
|
||||||
|
Console.ForegroundColor = cc;
|
||||||
pluginsLoaded = true;
|
pluginsLoaded = true;
|
||||||
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -143,9 +160,18 @@ public class ConsoleCommandsHandler
|
|||||||
path = "./Data/Plugins/" + info[0] + "s/" + name + "." + (info[0] == "Command" ? PluginLoader.pluginCMDExtension : PluginLoader.pluginEVEExtension);
|
path = "./Data/Plugins/" + info[0] + "s/" + name + "." + (info[0] == "Command" ? PluginLoader.pluginCMDExtension : PluginLoader.pluginEVEExtension);
|
||||||
else
|
else
|
||||||
path = $"./{info[1].Split('/')[info[1].Split('/').Length - 1]}";
|
path = $"./{info[1].Split('/')[info[1].Split('/').Length - 1]}";
|
||||||
//Console.WriteLine("Downloading: " + path + " [" + info[1] + "]");
|
if (Others.OperatingSystem.WINDOWS == Functions.GetOperatingSystem())
|
||||||
|
{
|
||||||
await ServerCom.DownloadFileAsync(info[1], path);
|
await ServerCom.DownloadFileAsync(info[1], path);
|
||||||
if (info[0] == "Command" || info[0] == "Event")
|
}
|
||||||
|
else if (Others.OperatingSystem.LINUX == Functions.GetOperatingSystem())
|
||||||
|
{
|
||||||
|
Others.Console_Utilities.ProgressBar bar = new Console_Utilities.ProgressBar(ProgressBarType.NO_END);
|
||||||
|
bar.Start();
|
||||||
|
await ServerCom.DownloadFileNoProgressAsync(info[1], path);
|
||||||
|
bar.Stop("Plugin Downloaded !");
|
||||||
|
}
|
||||||
|
|
||||||
if (info[0] == "Event")
|
if (info[0] == "Event")
|
||||||
Config.PluginConfig.InstalledPlugins.Add(new(name, PluginType.Event));
|
Config.PluginConfig.InstalledPlugins.Add(new(name, PluginType.Event));
|
||||||
else if (info[0] == "Command")
|
else if (info[0] == "Command")
|
||||||
@@ -168,34 +194,27 @@ public class ConsoleCommandsHandler
|
|||||||
continue;
|
continue;
|
||||||
var split = line.Split(',');
|
var split = line.Split(',');
|
||||||
Console.WriteLine($"\nDownloading item: {split[1]}");
|
Console.WriteLine($"\nDownloading item: {split[1]}");
|
||||||
|
if (File.Exists("./" + split[1])) File.Delete("./" + split[1]);
|
||||||
|
if (Others.OperatingSystem.WINDOWS == Functions.GetOperatingSystem())
|
||||||
await ServerCom.DownloadFileAsync(split[0], "./" + split[1]);
|
await ServerCom.DownloadFileAsync(split[0], "./" + split[1]);
|
||||||
|
else if (Others.OperatingSystem.LINUX == Functions.GetOperatingSystem())
|
||||||
|
{
|
||||||
|
Others.Console_Utilities.ProgressBar bar = new Console_Utilities.ProgressBar(ProgressBarType.NO_END);
|
||||||
|
bar.Start();
|
||||||
|
await ServerCom.DownloadFileNoProgressAsync(split[0], "./" + split[1]);
|
||||||
|
bar.Stop("Item downloaded !");
|
||||||
|
|
||||||
|
}
|
||||||
Console.WriteLine();
|
Console.WriteLine();
|
||||||
|
if (split[0].EndsWith(".pak"))
|
||||||
if (split[0].EndsWith(".zip") || split[0].EndsWith(".pak") || split[0].EndsWith(".pkg"))
|
File.Move("./" + split[1], "./Data/PAKS/" + split[1], true);
|
||||||
|
else if (split[0].EndsWith(".zip") || split[0].EndsWith(".pkg"))
|
||||||
{
|
{
|
||||||
Console.WriteLine($"Extracting {split[1]}");
|
Console.WriteLine($"Extracting {split[1]} ...");
|
||||||
var proc = 0f;
|
var bar = new Console_Utilities.ProgressBar(ProgressBarType.NO_END);// { Max = 100f, Color = ConsoleColor.Green };
|
||||||
var isExtracting = true;
|
bar.Start();
|
||||||
var bar = new Console_Utilities.ProgressBar { Max = 100f, Color = ConsoleColor.Green };
|
await Functions.ExtractArchive("./" + split[1], "./", null, UnzipProgressType.PercentageFromTotalSize);
|
||||||
|
bar.Stop("Extracted");
|
||||||
IProgress<float> extractProgress = new Progress<float>(value => { proc = value; });
|
|
||||||
new Thread(new Task(() =>
|
|
||||||
{
|
|
||||||
while (isExtracting)
|
|
||||||
{
|
|
||||||
bar.Update(proc);
|
|
||||||
if (proc >= 99.9f)
|
|
||||||
isExtracting = false;
|
|
||||||
Thread.Sleep(500);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
).Start
|
|
||||||
).Start();
|
|
||||||
await Functions.ExtractArchive("./" + split[1], "./", extractProgress, UnzipProgressType.PercentageFromTotalSize);
|
|
||||||
bar.Update(100f);
|
|
||||||
isExtracting = false;
|
|
||||||
await Task.Delay(1000);
|
|
||||||
bar.Update(100);
|
|
||||||
Console.WriteLine("\n");
|
Console.WriteLine("\n");
|
||||||
File.Delete("./" + split[1]);
|
File.Delete("./" + split[1]);
|
||||||
}
|
}
|
||||||
@@ -205,11 +224,13 @@ public class ConsoleCommandsHandler
|
|||||||
}
|
}
|
||||||
VersionString? ver = await VersionString.GetVersionOfPackageFromWeb(name);
|
VersionString? ver = await VersionString.GetVersionOfPackageFromWeb(name);
|
||||||
if (ver is null) throw new Exception("Incorrect version");
|
if (ver is null) throw new Exception("Incorrect version");
|
||||||
Config.SetPluginVersion(name, $"{ver.PackageID}.{ver.PackageMainVersion}.{ver.PackageCheckVersion}");
|
Config.SetPluginVersion(name, $"{ver.PackageVersionID}.{ver.PackageMainVersion}.{ver.PackageCheckVersion}");
|
||||||
// Console.WriteLine();
|
|
||||||
|
|
||||||
isDownloading = false;
|
isDownloading = false;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
@@ -253,20 +274,27 @@ public class ConsoleCommandsHandler
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
AddCommand("sd", "Shuts down the discord bot", () =>
|
AddCommand("sd", "Shuts down the discord bot", async () =>
|
||||||
{
|
{
|
||||||
if (client is null)
|
if (client is null)
|
||||||
return;
|
return;
|
||||||
client.StopAsync();
|
Console_Utilities.ProgressBar bar = new Console_Utilities.ProgressBar(ProgressBarType.NO_END);
|
||||||
client.DisposeAsync();
|
|
||||||
Config.SaveConfig();
|
bar.Start();
|
||||||
Console.WriteLine("Bot is closing in 2 seconds ! Please wait to save data !");
|
await Config.SaveConfig(SaveType.NORMAL);
|
||||||
Thread.Sleep(2000);
|
await Config.SaveConfig(SaveType.BACKUP);
|
||||||
|
bar.Stop("Saved config !");
|
||||||
|
Console.WriteLine();
|
||||||
|
await client.StopAsync();
|
||||||
|
await client.DisposeAsync();
|
||||||
|
|
||||||
|
await Task.Delay(1000);
|
||||||
Environment.Exit(0);
|
Environment.Exit(0);
|
||||||
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
AddCommand("extern", "Load an external command", "extern [pluginName]", async (args) =>
|
AddCommand("import", "Load an external command", "import [pluginName]", async (args) =>
|
||||||
{
|
{
|
||||||
if (args.Length <= 1) return;
|
if (args.Length <= 1) return;
|
||||||
string pName = Functions.MergeStrings(args, 1);
|
string pName = Functions.MergeStrings(args, 1);
|
||||||
@@ -294,6 +322,99 @@ public class ConsoleCommandsHandler
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
AddCommand("remplug", "Remove a plugin", "remplug [plugName]", async args =>
|
||||||
|
{
|
||||||
|
|
||||||
|
if (args.Length <= 1) return;
|
||||||
|
|
||||||
|
isDownloading = true;
|
||||||
|
string plugName = Functions.MergeStrings(args, 1);
|
||||||
|
if (pluginsLoaded)
|
||||||
|
{
|
||||||
|
if (Functions.GetOperatingSystem() == Others.OperatingSystem.WINDOWS)
|
||||||
|
{
|
||||||
|
Process.Start("DiscordBot.exe", $"/remplug {plugName}");
|
||||||
|
await Task.Delay(100);
|
||||||
|
Environment.Exit(0);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Process.Start("./DiscordBot", $"/remplug {plugName}");
|
||||||
|
await Task.Delay(100);
|
||||||
|
Environment.Exit(0);
|
||||||
|
}
|
||||||
|
isDownloading = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
string location = "./Data/Plugins/";
|
||||||
|
|
||||||
|
location = Config.PluginConfig.GetPluginType(plugName) switch
|
||||||
|
{
|
||||||
|
PluginType.Command => location + "Commands/" + plugName + "." + PluginLoader.pluginCMDExtension,
|
||||||
|
PluginType.Event => location + "Events/" + plugName + "." + PluginLoader.pluginEVEExtension,
|
||||||
|
PluginType.Unknown => "./",
|
||||||
|
_ => throw new NotImplementedException("Plugin type incorrect")
|
||||||
|
};
|
||||||
|
|
||||||
|
if (!File.Exists(location))
|
||||||
|
{
|
||||||
|
Console.WriteLine("The plugin does not exist");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
File.Delete(location);
|
||||||
|
if (Config.PluginConfig.Contains(plugName))
|
||||||
|
{
|
||||||
|
var tuple = Config.PluginConfig.InstalledPlugins.Where(t => t.Item1 == plugName).FirstOrDefault();
|
||||||
|
Console.WriteLine("Found: " + tuple.ToString());
|
||||||
|
Config.PluginConfig.InstalledPlugins.Remove(tuple);
|
||||||
|
Config.RemovePluginVersion(plugName);
|
||||||
|
await Config.SaveConfig(SaveType.NORMAL);
|
||||||
|
}
|
||||||
|
Console.WriteLine("Removed the plugin DLL. Checking for other files ...");
|
||||||
|
|
||||||
|
var info = await manager.GetPluginLinkByName(plugName);
|
||||||
|
if (info[2] != string.Empty)
|
||||||
|
{
|
||||||
|
var lines = await ServerCom.ReadTextFromURL(info[2]);
|
||||||
|
foreach (var line in lines)
|
||||||
|
{
|
||||||
|
if (!(line.Length > 0 && line.Contains(",")))
|
||||||
|
continue;
|
||||||
|
var split = line.Split(',');
|
||||||
|
if (File.Exists("./" + split[1]))
|
||||||
|
File.Delete("./" + split[1]);
|
||||||
|
|
||||||
|
|
||||||
|
Console.WriteLine("Removed: " + split[1]);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (Directory.Exists(plugName))
|
||||||
|
Directory.Delete(plugName, true);
|
||||||
|
}
|
||||||
|
isDownloading = false;
|
||||||
|
Console.WriteLine(plugName + " has been successfully deleted !");
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
AddCommand("reload", "Reload the bot with all plugins", () =>
|
||||||
|
{
|
||||||
|
if (Functions.GetOperatingSystem() == Others.OperatingSystem.WINDOWS)
|
||||||
|
{
|
||||||
|
Process.Start("DiscordBot.exe", $"lp");
|
||||||
|
HandleCommand("sd");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
|
||||||
|
Process.Start("./DiscordBot", $"lp");
|
||||||
|
HandleCommand("sd");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
//Sort the commands by name
|
//Sort the commands by name
|
||||||
commandList.Sort((x, y) => x.CommandName.CompareTo(y.CommandName));
|
commandList.Sort((x, y) => x.CommandName.CompareTo(y.CommandName));
|
||||||
}
|
}
|
||||||
@@ -325,9 +446,10 @@ public class ConsoleCommandsHandler
|
|||||||
return commandList.FirstOrDefault(t => t.CommandName == command);
|
return commandList.FirstOrDefault(t => t.CommandName == command);
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static async Task ExecuteCommad(string command)
|
public static async Task ExecuteCommad(string command)
|
||||||
{
|
{
|
||||||
var args = command.Split(' ');
|
var args = command.Split(' ');
|
||||||
|
// Console.WriteLine(command);
|
||||||
foreach (var item in commandList.ToList())
|
foreach (var item in commandList.ToList())
|
||||||
if (item.CommandName == args[0])
|
if (item.CommandName == args[0])
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -69,7 +69,7 @@ public class PluginLoader
|
|||||||
{
|
{
|
||||||
string name = new FileInfo(file).Name.Split('.')[0];
|
string name = new FileInfo(file).Name.Split('.')[0];
|
||||||
if (!Config.PluginVersionsContainsKey(name))
|
if (!Config.PluginVersionsContainsKey(name))
|
||||||
Config.SetPluginVersion(name, (await VersionString.GetVersionOfPackageFromWeb(name))?.PackageID + ".0.0");
|
Config.SetPluginVersion(name, (await VersionString.GetVersionOfPackageFromWeb(name))?.PackageVersionID + ".0.0");
|
||||||
|
|
||||||
if (await PluginUpdater.CheckForUpdates(name))
|
if (await PluginUpdater.CheckForUpdates(name))
|
||||||
await PluginUpdater.Download(name);
|
await PluginUpdater.Download(name);
|
||||||
@@ -84,7 +84,7 @@ public class PluginLoader
|
|||||||
{
|
{
|
||||||
string name = new FileInfo(file).Name.Split('.')[0];
|
string name = new FileInfo(file).Name.Split('.')[0];
|
||||||
if (!Config.PluginVersionsContainsKey(name))
|
if (!Config.PluginVersionsContainsKey(name))
|
||||||
Config.SetPluginVersion(name, (await VersionString.GetVersionOfPackageFromWeb(name))?.PackageID + ".0.0");
|
Config.SetPluginVersion(name, (await VersionString.GetVersionOfPackageFromWeb(name))?.PackageVersionID + ".0.0");
|
||||||
|
|
||||||
if (await PluginUpdater.CheckForUpdates(name))
|
if (await PluginUpdater.CheckForUpdates(name))
|
||||||
await PluginUpdater.Download(name);
|
await PluginUpdater.Download(name);
|
||||||
@@ -94,7 +94,7 @@ public class PluginLoader
|
|||||||
|
|
||||||
|
|
||||||
//Save the new config file (after the updates)
|
//Save the new config file (after the updates)
|
||||||
Config.SaveConfig();
|
await Config.SaveConfig(SaveType.NORMAL);
|
||||||
|
|
||||||
|
|
||||||
//Load all plugins
|
//Load all plugins
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ namespace PluginManager.Online.Helpers
|
|||||||
{
|
{
|
||||||
public class VersionString
|
public class VersionString
|
||||||
{
|
{
|
||||||
public int PackageID;
|
public int PackageVersionID;
|
||||||
public int PackageMainVersion;
|
public int PackageMainVersion;
|
||||||
public int PackageCheckVersion;
|
public int PackageCheckVersion;
|
||||||
|
|
||||||
@@ -18,7 +18,7 @@ namespace PluginManager.Online.Helpers
|
|||||||
string[] data = version.Split('.');
|
string[] data = version.Split('.');
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
PackageID = int.Parse(data[0]);
|
PackageVersionID = int.Parse(data[0]);
|
||||||
PackageMainVersion = int.Parse(data[1]);
|
PackageMainVersion = int.Parse(data[1]);
|
||||||
PackageCheckVersion = int.Parse(data[2]);
|
PackageCheckVersion = int.Parse(data[2]);
|
||||||
}
|
}
|
||||||
@@ -28,20 +28,25 @@ namespace PluginManager.Online.Helpers
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#region operators
|
||||||
public static bool operator >(VersionString s1, VersionString s2)
|
public static bool operator >(VersionString s1, VersionString s2)
|
||||||
{
|
{
|
||||||
if (s1.PackageID != s2.PackageID) throw new Exception("Can not compare two different paks");
|
if (s1.PackageVersionID > s2.PackageVersionID) return true;
|
||||||
|
if (s1.PackageVersionID == s2.PackageVersionID)
|
||||||
|
{
|
||||||
if (s1.PackageMainVersion > s2.PackageMainVersion) return true;
|
if (s1.PackageMainVersion > s2.PackageMainVersion) return true;
|
||||||
if (s1.PackageMainVersion == s2.PackageMainVersion && s1.PackageCheckVersion > s2.PackageCheckVersion) return true;
|
if (s1.PackageMainVersion == s2.PackageMainVersion && s1.PackageCheckVersion > s2.PackageCheckVersion) return true;
|
||||||
|
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool operator <(VersionString s1, VersionString s2) => !(s1 > s2) && s1 != s2;
|
public static bool operator <(VersionString s1, VersionString s2) => !(s1 > s2) && s1 != s2;
|
||||||
|
|
||||||
public static bool operator ==(VersionString s1, VersionString s2)
|
public static bool operator ==(VersionString s1, VersionString s2)
|
||||||
{
|
{
|
||||||
if (s1.PackageID == s2.PackageID && s1.PackageMainVersion == s2.PackageMainVersion && s1.PackageCheckVersion == s2.PackageCheckVersion) return true;
|
if (s1.PackageVersionID == s2.PackageVersionID && s1.PackageMainVersion == s2.PackageMainVersion && s1.PackageCheckVersion == s2.PackageCheckVersion) return true;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -50,14 +55,18 @@ namespace PluginManager.Online.Helpers
|
|||||||
public static bool operator <=(VersionString s1, VersionString s2) => (s1 < s2 || s1 == s2);
|
public static bool operator <=(VersionString s1, VersionString s2) => (s1 < s2 || s1 == s2);
|
||||||
public static bool operator >=(VersionString s1, VersionString s2) => (s1 > s2 || s1 == s2);
|
public static bool operator >=(VersionString s1, VersionString s2) => (s1 > s2 || s1 == s2);
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
public override string ToString()
|
public override string ToString()
|
||||||
{
|
{
|
||||||
return "{PackageID: " + PackageID + ", PackageVersion: " + PackageMainVersion + ", PackageCheckVersion: " + PackageCheckVersion + "}";
|
return "{PackageID: " + PackageVersionID + ", PackageVersion: " + PackageMainVersion + ", PackageCheckVersion: " + PackageCheckVersion + "}";
|
||||||
}
|
}
|
||||||
|
|
||||||
public string ToShortString()
|
public string ToShortString()
|
||||||
{
|
{
|
||||||
return $"{PackageID}.{PackageMainVersion}.{PackageCheckVersion}";
|
if (PackageVersionID == 0 && PackageCheckVersion == 0 && PackageMainVersion == 0)
|
||||||
|
return "Unknown";
|
||||||
|
return $"{PackageVersionID}.{PackageMainVersion}.{PackageCheckVersion}";
|
||||||
}
|
}
|
||||||
|
|
||||||
public static VersionString? GetVersionOfPackage(string pakName)
|
public static VersionString? GetVersionOfPackage(string pakName)
|
||||||
|
|||||||
@@ -1,7 +1,10 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
using PluginManager.Online.Helpers;
|
||||||
using PluginManager.Others;
|
using PluginManager.Others;
|
||||||
|
|
||||||
using OperatingSystem = PluginManager.Others.OperatingSystem;
|
using OperatingSystem = PluginManager.Others.OperatingSystem;
|
||||||
|
|
||||||
namespace PluginManager.Online;
|
namespace PluginManager.Online;
|
||||||
@@ -37,7 +40,7 @@ public class PluginsManager
|
|||||||
var op = Functions.GetOperatingSystem();
|
var op = Functions.GetOperatingSystem();
|
||||||
|
|
||||||
var len = lines.Length;
|
var len = lines.Length;
|
||||||
string[] titles = { "Name", "Description", "Plugin Type", "Libraries", "Installed" };
|
string[] titles = { "Name", "Description", "Type", "Version", "Installed" };
|
||||||
data.Add(new[] { "-", "-", "-", "-", "-" });
|
data.Add(new[] { "-", "-", "-", "-", "-" });
|
||||||
data.Add(titles);
|
data.Add(titles);
|
||||||
data.Add(new[] { "-", "-", "-", "-", "-" });
|
data.Add(new[] { "-", "-", "-", "-", "-" });
|
||||||
@@ -54,11 +57,7 @@ public class PluginsManager
|
|||||||
display[0] = content[0];
|
display[0] = content[0];
|
||||||
display[1] = content[1];
|
display[1] = content[1];
|
||||||
display[2] = content[2];
|
display[2] = content[2];
|
||||||
if (content.Length == 6 && (content[5] != null || content[5].Length > 2))
|
display[3] = (await VersionString.GetVersionOfPackageFromWeb(content[0]) ?? new VersionString("0.0.0")).ToShortString();
|
||||||
display[3] = ((await ServerCom.ReadTextFromURL(content[5])).Count + 1).ToString();
|
|
||||||
|
|
||||||
else
|
|
||||||
display[3] = "1";
|
|
||||||
if (Config.PluginConfig.Contains(content[0]) || Config.PluginConfig.Contains(content[0]))
|
if (Config.PluginConfig.Contains(content[0]) || Config.PluginConfig.Contains(content[0]))
|
||||||
display[4] = "✓";
|
display[4] = "✓";
|
||||||
else
|
else
|
||||||
@@ -73,8 +72,7 @@ public class PluginsManager
|
|||||||
display[0] = content[0];
|
display[0] = content[0];
|
||||||
display[1] = content[1];
|
display[1] = content[1];
|
||||||
display[2] = content[2];
|
display[2] = content[2];
|
||||||
if (content.Length == 6 && (content[5] != null || content[5].Length > 2))
|
display[3] = (await VersionString.GetVersionOfPackageFromWeb(content[0]) ?? new VersionString("0.0.0")).ToShortString();
|
||||||
display[3] = ((await ServerCom.ReadTextFromURL(content[5])).Count + 1).ToString();
|
|
||||||
if (Config.PluginConfig.Contains(content[0]) || Config.PluginConfig.Contains(content[0]))
|
if (Config.PluginConfig.Contains(content[0]) || Config.PluginConfig.Contains(content[0]))
|
||||||
display[4] = "✓";
|
display[4] = "✓";
|
||||||
else
|
else
|
||||||
@@ -86,7 +84,7 @@ public class PluginsManager
|
|||||||
|
|
||||||
data.Add(new[] { "-", "-", "-", "-", "-" });
|
data.Add(new[] { "-", "-", "-", "-", "-" });
|
||||||
|
|
||||||
Console_Utilities.FormatAndAlignTable(data);
|
Console_Utilities.FormatAndAlignTable(data, TableFormat.CENTER_EACH_COLUMN_BASED);
|
||||||
}
|
}
|
||||||
catch (Exception exception)
|
catch (Exception exception)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ namespace PluginManager.Online
|
|||||||
bool isDownloading = true;
|
bool isDownloading = true;
|
||||||
float c_progress = 0;
|
float c_progress = 0;
|
||||||
|
|
||||||
Console_Utilities.ProgressBar pbar = new Console_Utilities.ProgressBar { Max = 100f, NoColor = true };
|
Console_Utilities.ProgressBar pbar = new Console_Utilities.ProgressBar(ProgressBarType.NORMAL) { Max = 100f, NoColor = true };
|
||||||
|
|
||||||
IProgress<float> progress = new Progress<float>(percent => { c_progress = percent; });
|
IProgress<float> progress = new Progress<float>(percent => { c_progress = percent; });
|
||||||
|
|
||||||
@@ -79,5 +79,11 @@ namespace PluginManager.Online
|
|||||||
pbar.Update(100f);
|
pbar.Update(100f);
|
||||||
isDownloading = false;
|
isDownloading = false;
|
||||||
}
|
}
|
||||||
|
public static async Task DownloadFileNoProgressAsync(string URL, string location)
|
||||||
|
{
|
||||||
|
IProgress<float> progress = new Progress<float>();
|
||||||
|
await DownloadFileAsync(URL, location, progress);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
using Discord;
|
using Discord;
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
|
||||||
|
|
||||||
namespace PluginManager.Others
|
namespace PluginManager.Others
|
||||||
{
|
{
|
||||||
@@ -32,16 +32,131 @@ namespace PluginManager.Others
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public class ProgressBar
|
public class ProgressBar
|
||||||
{
|
{
|
||||||
|
public ProgressBar(ProgressBarType type)
|
||||||
|
{
|
||||||
|
this.type = type;
|
||||||
|
}
|
||||||
|
|
||||||
public float Max { get; init; }
|
public float Max { get; init; }
|
||||||
public ConsoleColor Color { get; init; }
|
public ConsoleColor Color { get; init; }
|
||||||
public bool NoColor { get; init; }
|
public bool NoColor { get; init; }
|
||||||
|
public ProgressBarType type { get; set; }
|
||||||
|
|
||||||
|
public int TotalLength { get; private set; }
|
||||||
|
|
||||||
|
private int BarLength = 32;
|
||||||
|
private int position = 1;
|
||||||
|
private bool positive = true;
|
||||||
|
|
||||||
|
private bool isRunning;
|
||||||
|
|
||||||
|
|
||||||
public void Update(float progress, double speed = -1, string? unit = null)
|
public async void Start()
|
||||||
|
{
|
||||||
|
if (type != ProgressBarType.NO_END)
|
||||||
|
throw new Exception("Only NO_END progress bar can use this method");
|
||||||
|
if (isRunning)
|
||||||
|
throw new Exception("This progress bar is already running");
|
||||||
|
|
||||||
|
isRunning = true;
|
||||||
|
while (isRunning)
|
||||||
|
{
|
||||||
|
UpdateNoEnd();
|
||||||
|
await System.Threading.Tasks.Task.Delay(100);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public async void Start(string message)
|
||||||
|
{
|
||||||
|
if (type != ProgressBarType.NO_END)
|
||||||
|
throw new Exception("Only NO_END progress bar can use this method");
|
||||||
|
if (isRunning)
|
||||||
|
throw new Exception("This progress bar is already running");
|
||||||
|
|
||||||
|
isRunning = true;
|
||||||
|
|
||||||
|
TotalLength = message.Length + BarLength + 5;
|
||||||
|
while (isRunning)
|
||||||
|
{
|
||||||
|
UpdateNoEnd(message);
|
||||||
|
await System.Threading.Tasks.Task.Delay(100);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Stop()
|
||||||
|
{
|
||||||
|
if (type != ProgressBarType.NO_END)
|
||||||
|
throw new Exception("Only NO_END progress bar can use this method");
|
||||||
|
if (!isRunning)
|
||||||
|
throw new Exception("Can not stop a progressbar that did not start");
|
||||||
|
isRunning = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Stop(string message)
|
||||||
|
{
|
||||||
|
Stop();
|
||||||
|
|
||||||
|
if (message is not null)
|
||||||
|
{
|
||||||
|
Console.CursorLeft = 0;
|
||||||
|
for (int i = 0; i < BarLength + message.Length + 1; i++)
|
||||||
|
Console.Write(" ");
|
||||||
|
Console.CursorLeft = 0;
|
||||||
|
Console.WriteLine(message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Update(float progress)
|
||||||
|
{
|
||||||
|
if (type == ProgressBarType.NO_END)
|
||||||
|
throw new Exception("This function is for progress bars with end");
|
||||||
|
|
||||||
|
UpdateNormal(progress);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void UpdateNoEnd(string message)
|
||||||
{
|
{
|
||||||
Console.CursorLeft = 0;
|
Console.CursorLeft = 0;
|
||||||
Console.Write("[");
|
Console.Write("[");
|
||||||
Console.CursorLeft = 32;
|
for (int i = 1; i <= position; i++)
|
||||||
|
Console.Write(" ");
|
||||||
|
Console.Write("<==()==>");
|
||||||
|
position += positive ? 1 : -1;
|
||||||
|
for (int i = position; i <= BarLength - 1 - (positive ? 0 : 2); i++)
|
||||||
|
Console.Write(" ");
|
||||||
|
Console.Write("] " + message);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if (position == BarLength - 1 || position == 1)
|
||||||
|
positive = !positive;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void UpdateNoEnd()
|
||||||
|
{
|
||||||
|
Console.CursorLeft = 0;
|
||||||
|
Console.Write("[");
|
||||||
|
for (int i = 1; i <= position; i++)
|
||||||
|
Console.Write(" ");
|
||||||
|
Console.Write("<==()==>");
|
||||||
|
position += positive ? 1 : -1;
|
||||||
|
for (int i = position; i <= BarLength - 1 - (positive ? 0 : 2); i++)
|
||||||
|
Console.Write(" ");
|
||||||
|
Console.Write("]");
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if (position == BarLength - 1 || position == 1)
|
||||||
|
positive = !positive;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void UpdateNormal(float progress)
|
||||||
|
{
|
||||||
|
Console.CursorLeft = 0;
|
||||||
|
Console.Write("[");
|
||||||
|
Console.CursorLeft = BarLength;
|
||||||
Console.Write("]");
|
Console.Write("]");
|
||||||
Console.CursorLeft = 1;
|
Console.CursorLeft = 1;
|
||||||
float onechunk = 30.0f / Max;
|
float onechunk = 30.0f / Max;
|
||||||
@@ -55,25 +170,20 @@ namespace PluginManager.Others
|
|||||||
Console.Write("#");
|
Console.Write("#");
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = position; i <= 31; i++)
|
for (int i = position; i < BarLength; i++)
|
||||||
{
|
{
|
||||||
Console.BackgroundColor = NoColor ? ConsoleColor.Black : ConsoleColor.DarkGray;
|
Console.BackgroundColor = NoColor ? ConsoleColor.Black : ConsoleColor.DarkGray;
|
||||||
Console.CursorLeft = position++;
|
Console.CursorLeft = position++;
|
||||||
Console.Write(" ");
|
Console.Write(" ");
|
||||||
}
|
}
|
||||||
|
|
||||||
Console.CursorLeft = 35;
|
Console.CursorLeft = BarLength + 4;
|
||||||
Console.BackgroundColor = ConsoleColor.Black;
|
Console.BackgroundColor = ConsoleColor.Black;
|
||||||
if (speed is -1 || unit == null)
|
|
||||||
{
|
|
||||||
if (progress.CanAproximateTo(Max))
|
if (progress.CanAproximateTo(Max))
|
||||||
Console.Write(progress + " % ✓");
|
Console.Write(progress + " % ✓");
|
||||||
else
|
else
|
||||||
Console.Write(MathF.Round(progress, 2) + " % ");
|
Console.Write(MathF.Round(progress, 2) + " % ");
|
||||||
}
|
}
|
||||||
else
|
|
||||||
Console.Write(progress + $"{speed} {unit}/s ");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -84,7 +194,7 @@ namespace PluginManager.Others
|
|||||||
/// A way to create a table based on input data
|
/// A way to create a table based on input data
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="data">The List of arrays of strings that represent the rows.</param>
|
/// <param name="data">The List of arrays of strings that represent the rows.</param>
|
||||||
public static void FormatAndAlignTable(List<string[]> data, TableFormat format = TableFormat.CENTER_EACH_COLUMN_BASED)
|
public static void FormatAndAlignTable(List<string[]> data, TableFormat format)
|
||||||
{
|
{
|
||||||
if (format == TableFormat.CENTER_EACH_COLUMN_BASED)
|
if (format == TableFormat.CENTER_EACH_COLUMN_BASED)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -31,3 +31,6 @@ public enum PluginType { Command, Event, Unknown }
|
|||||||
public enum UnzipProgressType { PercentageFromNumberOfFiles, PercentageFromTotalSize }
|
public enum UnzipProgressType { PercentageFromNumberOfFiles, PercentageFromTotalSize }
|
||||||
|
|
||||||
public enum TableFormat { CENTER_EACH_COLUMN_BASED, CENTER_OVERALL_LENGTH, DEFAULT }
|
public enum TableFormat { CENTER_EACH_COLUMN_BASED, CENTER_OVERALL_LENGTH, DEFAULT }
|
||||||
|
|
||||||
|
public enum SaveType { NORMAL, BACKUP }
|
||||||
|
public enum ProgressBarType { NORMAL, NO_END }
|
||||||
@@ -26,17 +26,17 @@ namespace PluginManager.Others
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// The location for all logs
|
/// The location for all logs
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static readonly string logFolder = @"./Output/Logs/";
|
public static readonly string logFolder = @"./Data/Output/Logs/";
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The location for all errors
|
/// The location for all errors
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static readonly string errFolder = @"./Output/Errors/";
|
public static readonly string errFolder = @"./Data/Output/Errors/";
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Archives folder
|
/// Archives folder
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static readonly string pakFolder = @"./Data/Resources/PAK/";
|
public static readonly string pakFolder = @"./Data/PAKS/";
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Beta testing folder
|
/// Beta testing folder
|
||||||
@@ -50,16 +50,41 @@ namespace PluginManager.Others
|
|||||||
/// <param name="FileName">The file name that is inside the archive or its full path</param>
|
/// <param name="FileName">The file name that is inside the archive or its full path</param>
|
||||||
/// <param name="archFile">The archive location from the PAKs folder</param>
|
/// <param name="archFile">The archive location from the PAKs folder</param>
|
||||||
/// <returns>A string that represents the content of the file or null if the file does not exists or it has no content</returns>
|
/// <returns>A string that represents the content of the file or null if the file does not exists or it has no content</returns>
|
||||||
public static Stream? ReadFromPakAsync(string FileName, string archFile)
|
public static async Task<string> ReadFromPakAsync(string FileName, string archFile)
|
||||||
{
|
{
|
||||||
archFile = pakFolder + archFile;
|
archFile = pakFolder + archFile;
|
||||||
Directory.CreateDirectory(pakFolder);
|
if (!File.Exists(archFile))
|
||||||
if (!File.Exists(archFile)) throw new FileNotFoundException("Failed to load file !");
|
throw new Exception("Failed to load file !");
|
||||||
|
|
||||||
using ZipArchive archive = ZipFile.OpenRead(archFile);
|
try
|
||||||
ZipArchiveEntry? entry = archive.GetEntry(FileName);
|
{
|
||||||
return entry?.Open();
|
string textValue = null;
|
||||||
|
using (var fs = new FileStream(archFile, FileMode.Open))
|
||||||
|
using (var zip = new ZipArchive(fs, ZipArchiveMode.Read))
|
||||||
|
foreach (var entry in zip.Entries)
|
||||||
|
{
|
||||||
|
if (entry.Name == FileName || entry.FullName == FileName)
|
||||||
|
{
|
||||||
|
using (Stream s = entry.Open())
|
||||||
|
using (StreamReader reader = new StreamReader(s))
|
||||||
|
{
|
||||||
|
textValue = await reader.ReadToEndAsync();
|
||||||
|
reader.Close();
|
||||||
|
s.Close();
|
||||||
|
fs.Close();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return textValue;
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
await Task.Delay(100);
|
||||||
|
return await ReadFromPakAsync(FileName, archFile);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Write logs to file
|
/// Write logs to file
|
||||||
@@ -83,6 +108,11 @@ namespace PluginManager.Others
|
|||||||
File.AppendAllText(errPath, ErrMessage + " \n");
|
File.AppendAllText(errPath, ErrMessage + " \n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void WriteErrFile(this Exception ex)
|
||||||
|
{
|
||||||
|
WriteErrFile(ex.ToString());
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Merge one array of strings into one string
|
/// Merge one array of strings into one string
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -164,9 +194,7 @@ namespace PluginManager.Others
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static async Task ExtractArchive(string zip, string folder, IProgress<float> progress, UnzipProgressType type)
|
public static async Task ExtractArchive(string zip, string folder, IProgress<float> progress, UnzipProgressType type)
|
||||||
{
|
{
|
||||||
if (!Directory.Exists(folder)) Directory.CreateDirectory(folder);
|
Directory.CreateDirectory(folder);
|
||||||
|
|
||||||
|
|
||||||
using (ZipArchive archive = ZipFile.OpenRead(zip))
|
using (ZipArchive archive = ZipFile.OpenRead(zip))
|
||||||
{
|
{
|
||||||
if (type == UnzipProgressType.PercentageFromNumberOfFiles)
|
if (type == UnzipProgressType.PercentageFromNumberOfFiles)
|
||||||
@@ -190,6 +218,7 @@ namespace PluginManager.Others
|
|||||||
|
|
||||||
currentZIPFile++;
|
currentZIPFile++;
|
||||||
await Task.Delay(10);
|
await Task.Delay(10);
|
||||||
|
if (progress != null)
|
||||||
progress.Report((float)currentZIPFile / totalZIPFiles * 100);
|
progress.Report((float)currentZIPFile / totalZIPFiles * 100);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -220,6 +249,7 @@ namespace PluginManager.Others
|
|||||||
}
|
}
|
||||||
|
|
||||||
await Task.Delay(10);
|
await Task.Delay(10);
|
||||||
|
if (progress != null)
|
||||||
progress.Report((float)currentSize / zipSize * 100);
|
progress.Report((float)currentSize / zipSize * 100);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -261,10 +291,9 @@ namespace PluginManager.Others
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static async Task SaveToJsonFile<T>(string file, T Data)
|
public static async Task SaveToJsonFile<T>(string file, T Data)
|
||||||
{
|
{
|
||||||
File.Delete(file);
|
MemoryStream str = new MemoryStream();
|
||||||
var s = File.Open(file, FileMode.OpenOrCreate);
|
await JsonSerializer.SerializeAsync(str, Data, typeof(T), new JsonSerializerOptions { WriteIndented = true });
|
||||||
await JsonSerializer.SerializeAsync(s, Data, typeof(T), new JsonSerializerOptions { WriteIndented = true });
|
await File.WriteAllBytesAsync(file, str.ToArray());
|
||||||
s.Close();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -277,8 +306,7 @@ namespace PluginManager.Others
|
|||||||
{
|
{
|
||||||
Stream text;
|
Stream text;
|
||||||
if (File.Exists(input))
|
if (File.Exists(input))
|
||||||
text = File.OpenRead(input);
|
text = new MemoryStream(await File.ReadAllBytesAsync(input));
|
||||||
|
|
||||||
else
|
else
|
||||||
text = new MemoryStream(Encoding.ASCII.GetBytes(input));
|
text = new MemoryStream(Encoding.ASCII.GetBytes(input));
|
||||||
text.Position = 0;
|
text.Position = 0;
|
||||||
|
|||||||
@@ -16,11 +16,6 @@ Plugin Types:
|
|||||||
1. Commands
|
1. Commands
|
||||||
2. Events
|
2. Events
|
||||||
|
|
||||||
<!--
|
|
||||||
Project Structure
|
|
||||||
|
|
||||||
-->
|
|
||||||
|
|
||||||
### How to create a plugin
|
### How to create a plugin
|
||||||
|
|
||||||
First of all, Create a new project (class library) in Visual Studio.
|
First of all, Create a new project (class library) in Visual Studio.
|
||||||
|
|||||||
Reference in New Issue
Block a user